This commit is contained in:
luofei 2024-03-18 17:23:15 +08:00
commit e31ecf98d2
5 changed files with 239 additions and 10 deletions

View File

@ -15,12 +15,14 @@ namespace app\common\repositories\store\order;
use app\common\dao\store\order\StoreGroupOrderDao; use app\common\dao\store\order\StoreGroupOrderDao;
use app\common\model\store\order\StoreGroupOrder;
use app\common\repositories\BaseRepository; use app\common\repositories\BaseRepository;
use app\common\repositories\store\coupon\StoreCouponRepository; use app\common\repositories\store\coupon\StoreCouponRepository;
use app\common\repositories\store\coupon\StoreCouponUserRepository; use app\common\repositories\store\coupon\StoreCouponUserRepository;
use app\common\repositories\user\UserBillRepository; use app\common\repositories\user\UserBillRepository;
use app\common\repositories\user\UserRepository; use app\common\repositories\user\UserRepository;
use crmeb\jobs\CancelGroupOrderJob; use crmeb\jobs\CancelGroupOrderJob;
use think\db\exception\DataNotFoundException;
use think\exception\ValidateException; use think\exception\ValidateException;
use think\facade\Db; use think\facade\Db;
use think\facade\Queue; use think\facade\Queue;
@ -65,6 +67,34 @@ class StoreGroupOrderRepository extends BaseRepository
return compact('count', 'list'); return compact('count', 'list');
} }
public function detailOne($id, $flag = true)
{
$order = StoreGroupOrder::where('group_order_id', $id)
->with([
'orderList' => function (Relation $query) use ($flag) {
$query->when($flag, function ($query) {
$query->field('order_id,group_order_id,mer_id,order_sn,activity_type,pay_price,order_extend,order_type,is_virtual');
})->with([
'merchant' => function ($query) use ($flag) {
$flag && $query->field('mer_id,mer_name,service_phone')->append(['services_type']);
}, 'orderProduct', 'presellOrder'
]);
}])->find();
if ($order['paid'] == 1) {
throw new DataNotFoundException('订单不存在或已取消');
}
if (empty($order)) {
throw new DataNotFoundException('订单不存在或已取消');
}
return $order;
}
/** /**
* @param $uid * @param $uid
* @param $id * @param $id

View File

@ -12,9 +12,11 @@
namespace app\common\repositories\store\order; namespace app\common\repositories\store\order;
use app\common\dao\store\order\StoreOrderDao; use app\common\dao\store\order\StoreOrderDao;
use app\common\dao\system\financial\FinancialDao;
use app\common\dao\system\financial\FinancialRecordDao; use app\common\dao\system\financial\FinancialRecordDao;
use app\common\Enum; use app\common\Enum;
use app\common\model\store\order\StoreGroupOrder; use app\common\model\store\order\StoreGroupOrder;
use app\common\model\store\order\StoreGroupOrderOther;
use app\common\model\store\order\StoreOrder; use app\common\model\store\order\StoreOrder;
use app\common\model\store\order\StoreRefundOrder; use app\common\model\store\order\StoreRefundOrder;
use app\common\model\store\product\ProductAttrValue; use app\common\model\store\product\ProductAttrValue;
@ -2592,9 +2594,16 @@ class StoreOrderRepository extends BaseRepository
return $data; return $data;
} }
public function beginMerchant($mer_id)
{
$merchant = Merchant::getDB()->where('mer_id',$mer_id)->value('mer_name');
return compact('merchant');
}
public function dealGoodsList($where,$money)
public function dealGoodsList($where,$money,$merId)
{ {
//拆分2种方式 大于该金额的 50 +小于该金额的50条 //拆分2种方式 大于该金额的 50 +小于该金额的50条
$greaterWhere = function ($query) use ($money) { $greaterWhere = function ($query) use ($money) {
@ -2611,6 +2620,7 @@ class StoreOrderRepository extends BaseRepository
$count = count($list); $count = count($list);
$minMoney = bcsub($money, 600, 2); $minMoney = bcsub($money, 600, 2);
$merInfo = Merchant::getDB()->where('mer_id',$merId)->value('mer_name');
if ($count) { if ($count) {
$range = $this->getRangeNumber($minMoney); //减少一般的区间 $range = $this->getRangeNumber($minMoney); //减少一般的区间
//不存在--虚假的区间 //不存在--虚假的区间
@ -2641,10 +2651,10 @@ class StoreOrderRepository extends BaseRepository
// $count = array_sum(array_column($list, 'num')); //重复拿 // $count = array_sum(array_column($list, 'num')); //重复拿
$count = count($list);//计算数量的 $count = count($list);//计算数量的
return compact('count', 'list'); return compact('count', 'list','merInfo');
} else { } else {
return compact('count', 'list'); return compact('count', 'list','merInfo');
} }
} }
@ -2834,6 +2844,167 @@ class StoreOrderRepository extends BaseRepository
public function financialVoucher(StoreGroupOrder $groupOrder, $is_combine = 0, $subOrders = [])
{
$groupOrder->append(['user']);
//修改订单状态
Db::startTrans();
try {
$time = date('Y-m-d H:i:s');
$groupOrder->paid = 1;
$groupOrder->pay_time = $time;
$groupOrder->is_combine = $is_combine;
$orderStatus = [];
$groupOrder->append(['orderList.orderProduct']);
$flag = true;
$finance = [];
$profitsharing = [];
$financialRecordRepository = app()->make(FinancialRecordRepository::class);
$financeSn = $financialRecordRepository->getSn();
$userMerchantRepository = app()->make(UserMerchantRepository::class);
$storeOrderProfitsharingRepository = app()->make(StoreOrderProfitsharingRepository::class);
$uid = $groupOrder->uid;
$i = 1;
$isVipCoupon = app()->make(StoreGroupOrderRepository::class)->isVipCoupon($groupOrder);
//订单记录
$storeOrderStatusRepository = app()->make(StoreOrderStatusRepository::class);
$svipDiscount = 0;
$financeDao = new FinancialDao();
foreach ($groupOrder->orderList as $_k => $order) {
if($groupOrder->order_extend){
if($order->order_extend){
$order_extend=$order->order_extend;
}else{
$order_extend=[];
}
$order_extend['corporate_voucher']=$groupOrder->order_extend;
$order->order_extend=json_encode($order_extend,true);
}
$order->paid = 1;
$order->pay_time = $time;
$svipDiscount = bcadd($order->svip_discount, $svipDiscount, 2);
if (isset($subOrders[$order->order_sn])) {
$order->transaction_id = $subOrders[$order->order_sn]['transaction_id'];
}
$presell = false;
// 订单的类型 0 发货 1 自提
if ($order->order_type == 1 && $order->status != 10) {
$order->verify_code = $this->verifyCode();
}
$order->save();
$orderStatus[] = [
'order_id' => $order->order_id,
'order_sn' => $order->order_sn,
'type' => $storeOrderStatusRepository::TYPE_ORDER,
'change_message' => '订单支付成功',
'change_type' => $storeOrderStatusRepository::ORDER_STATUS_PAY_SUCCCESS,
'uid' => $order->uid,
'nickname' => $order->user->nickname,
'user_type' => $storeOrderStatusRepository::U_TYPE_USER,
];
$financeDao->order = $order;
$financeDao->user = $groupOrder->user;
$financialType = $presell ? 'order_presell' : 'order';
// 平台收入流水账单数据
$financeDao->platformIn($order->total_price, $financialType);
if ($order->consumption_money > 0) {
// 平台支出优惠金额
$financeDao->platformOut($order->consumption_money, 'platform_consumption');
}
$_payPrice = bcsub($order->pay_price, bcadd($order['extension_one'], $order['extension_two'], 3), 2);
$orderValidAmount = bcsub($order->total_price, bcadd($order['extension_one'], $order['extension_two'], 3), 2);
if ($presell) {
if (isset($order->orderProduct[0]['cart_info']['presell_extension_one']) && $order->orderProduct[0]['cart_info']['presell_extension_one'] > 0) {
$_payPrice = bcadd($_payPrice, $order->orderProduct[0]['cart_info']['presell_extension_one'], 2);
}
if (isset($order->orderProduct[0]['cart_info']['presell_extension_two']) && $order->orderProduct[0]['cart_info']['presell_extension_two'] > 0) {
$_payPrice = bcadd($_payPrice, $order->orderProduct[0]['cart_info']['presell_extension_two'], 2);
}
}
// 平台支出推广费
$promoter = $order->merchant->promoter();
$promoterCommission = bcmul($orderValidAmount, 0.003, 2);
if (!empty($promoter) && $promoterCommission > 0) {
$financeDao->user = $promoter;
$financeDao->platformOut($promoterCommission, 'commission_to_promoter');
}
// 平台收入手续费
$financeDao->user = $groupOrder->user;
$commission_rate = bcdiv((string)$order['commission_rate'],'100',6);
$platformCommission = bcmul($orderValidAmount, (string)$commission_rate, 2);
if ($commission_rate > 0 && $platformCommission > 0) {
$orderValidAmount = bcsub($orderValidAmount, $platformCommission, 2);
if ($promoterCommission > 0 && !empty($promoter)) {
$platformCommission = bcsub($platformCommission, $promoterCommission, 2);
}
$financeDao->platformIn($platformCommission, 'commission_to_platform', $order['mer_id']);
}
if (!$presell) {
//押金计算
if ($orderValidAmount > 0) {
/** @var MerchantRepository $merchantRepo */
$merchantRepo = app()->make(MerchantRepository::class);
$merchantRepo->merId = $order['mer_id'];
$merchantRepo->forceMargin = false;
[$orderValidAmount, $financeDao] = $merchantRepo->deductDeposit($orderValidAmount, $order, $financeDao);
}
// 商户收入金额
$financeDao->platformOut($orderValidAmount, 'merchant_order', $order['mer_id']);
if (!$is_combine) {
app()->make(MerchantRepository::class)->addLockMoney($order->mer_id, 'order', $order->order_id, $orderValidAmount);
}
// if (!$is_combine) {
// app()->make(MerchantRepository::class)->addLockMoney($order->mer_id, 'order', $order->order_id, $_payPrice);
// }
//短信 订单通知商户
$mer_phone=Db::name('merchant')->where('mer_id',$order->mer_id)->value('mer_phone');
if($mer_phone){
Queue::push(SendSmsJob::class, ['tempId' => 'ORDER_CREATE', 'phone' => $mer_phone,'orderId'=>$order->order_id,'id'=>0]);//短信通知
}
}
$userMerchantRepository->updatePayTime($uid, $order->mer_id, $order->pay_price);
SwooleTaskService::merchant('notice', [
'type' => 'new_order',
'data' => [
'title' => '新订单',
'message' => '您有一个新的订单',
'id' => $order->order_id
]
], $order->mer_id);
}
$this->giveIntegral($groupOrder);
$financialRecordRepository->insertAll($finance);
$storeOrderStatusRepository->batchCreateLog($orderStatus);
$groupOrder->save();
Db::commit();
return true;
} catch (\Exception $e) {
Log::error('财务点击支付失败'.$e->getMessage());
// 回滚事务
Db::rollback();
return false;
}
}
} }

View File

@ -13,6 +13,7 @@
namespace app\controller\admin\order; namespace app\controller\admin\order;
use app\common\repositories\store\order\StoreGroupOrderRepository;
use crmeb\basic\BaseController; use crmeb\basic\BaseController;
use app\common\repositories\store\ExcelRepository; use app\common\repositories\store\ExcelRepository;
use app\common\repositories\system\merchant\MerchantRepository; use app\common\repositories\system\merchant\MerchantRepository;
@ -88,8 +89,16 @@ class Order extends BaseController
$data = $this->request->params(['img']); $data = $this->request->params(['img']);
if(!$data['img']) if(!$data['img'])
return app('json')->fail('请上传凭证'); return app('json')->fail('请上传凭证');
$this->repository->dealChangeStatus($data['img'],$id); $groupOrderRepository = \app()->make(StoreGroupOrderRepository::class);
return app('json')->success('更新成功'); $groupOrder = $groupOrderRepository->detailOne((int)$id, false);
$groupOrder->order_extend=$data['img'];
// $this->repository->dealChangeStatus($data['img'],$id);
$res=$this->repository->financialVoucher($groupOrder);
if($res){
return app('json')->success('更新成功');
}else{
return app('json')->fail('操作失败');
}
} }

View File

@ -559,8 +559,10 @@ class Auth extends BaseController
return $user; return $user;
} else if ($auth['type'] === 'app_wechat') { } else if ($auth['type'] === 'app_wechat') {
$oauth = WechatService::create()->getApplication()->oauth; $oauth = WechatService::create()->getApplication()->oauth;
$accessToken = $oauth->getAccessToken($data['code']);
try { try {
$wechatInfo = $oauth->user(new AccessToken(['access_token' => $data['code'], 'openid' => $data['openid']]))->getOriginal(); // $wechatInfo = $oauth->user(new AccessToken(['access_token' => $data['code'], 'openid' => $data['openid']]))->getOriginal();
$wechatInfo = $oauth->user($accessToken)->getOriginal();
} catch (Exception $e) { } catch (Exception $e) {
throw new ValidateException('授权失败[001]' . $e->getMessage()); throw new ValidateException('授权失败[001]' . $e->getMessage());
} }
@ -568,7 +570,8 @@ class Auth extends BaseController
if (!$user) if (!$user)
throw new ValidateException('授权失败'); throw new ValidateException('授权失败');
return $user; return $user;
} else if ($auth['type'] === 'apple') { }
else if ($auth['type'] === 'apple') {
$identityToken = $data['userInfo']['identityToken']; $identityToken = $data['userInfo']['identityToken'];
$tks = explode('.', $identityToken); $tks = explode('.', $identityToken);
if (count($tks) != 3) { if (count($tks) != 3) {
@ -996,10 +999,17 @@ class Auth extends BaseController
$agent = strtolower($this->request->server('HTTP_USER_AGENT')); $agent = strtolower($this->request->server('HTTP_USER_AGENT'));
// 检查是否为iOS设备包括iPhone和iPad // 检查是否为iOS设备包括iPhone和iPad
if (strpos($agent, 'iphone') !== false || strpos($agent, 'ipad') !== false) { if (strpos($agent, 'iphone') !== false || strpos($agent, 'ipad') !== false) {
$appInfo=[]; $appInfo = Db::name('AppUpdate')->where('type', $type)->order('id','desc')->find();
} elseif (strpos($agent, 'android') !== false) { } elseif (strpos($agent, 'android') !== false) {
// 检查是否为Android设备 // 检查是否为Android设备
$appInfo = Db::name('AppUpdate')->where('type', $type)->order('id','desc')->find(); $appInfo = Db::name('AppUpdate')->where('type', $type)->order('id','desc')->find();
if($agent == 'ios'){
$pattern = '/\.wgt$/i';
if (preg_match($pattern, basename($appInfo['dow_url']))) {
$appInfo =[];
}
}
} else { } else {
$appInfo=[]; $appInfo=[];
// 如果都不是,则输出其他 // 如果都不是,则输出其他

View File

@ -315,9 +315,18 @@ class StoreOrder extends BaseController
//商户id 金额 //商户id 金额
$merId = $this->request->param('mer_id'); $merId = $this->request->param('mer_id');
$money = $this->request->param('money'); $money = $this->request->param('money');
if(empty($money) || empty($merId)){
if(empty($merId)){
return app('json')->fail('参数缺失'); return app('json')->fail('参数缺失');
} }
if(empty($money)){
//初始化
return app('json')->success($this->repository->beginMerchant($merId));
}
$where = [ $where = [
"a.mer_id" => $merId, "a.mer_id" => $merId,
"p.is_show" => 1, "p.is_show" => 1,
@ -325,7 +334,7 @@ class StoreOrder extends BaseController
"p.is_gift_bag" => 0 "p.is_gift_bag" => 0
]; ];
return app('json')->success($this->repository->dealGoodsList($where,$money)); return app('json')->success($this->repository->dealGoodsList($where,$money,$merId));
} }