diff --git a/app/common/logic/PayNotifyLogic.php b/app/common/logic/PayNotifyLogic.php index c1bec932c..ade3ec1ed 100644 --- a/app/common/logic/PayNotifyLogic.php +++ b/app/common/logic/PayNotifyLogic.php @@ -284,8 +284,8 @@ class PayNotifyLogic extends BaseLogic // self::dealProductLog($order); if ($order->pay_type == 7) { - $openid=UserAuth::where('user_id',$order['uid'])->value('openid'); - if($openid){ + $openid = UserAuth::where('user_id', $order['uid'])->value('openid'); + if ($openid) { Redis::send('push-delivery', ['order_id' => $order['order_id'], 'openid' => $openid, 'logistics_type' => 4]); } } @@ -326,8 +326,8 @@ class PayNotifyLogic extends BaseLogic UserSignLogic::RefundRecharge($orderRe); return true; } - $refund=bcdiv($extra['amount']['refund'], 100, 2); - if($refund==$order['pay_price']){ + $refund = bcdiv($extra['amount']['refund'], 100, 2); + if ($refund == $order['pay_price']) { $order->status = OrderEnum::REFUND_PAY; $order->refund_status = OrderEnum::REFUND_STATUS_FINISH; $order->refund_price = $refund; @@ -351,7 +351,7 @@ class PayNotifyLogic extends BaseLogic // $user = User::where('id', $order['uid'])->findOrEmpty(); // $capitalFlowDao = new CapitalFlowLogic($user); // $capitalFlowDao->userIncome('user_order_refund', 'system_back', $order['id'], $order['pay_price'], '', 1); - self::addStock($order['id'],$order); + self::addStock($order['id'], $order); return true; } @@ -374,7 +374,7 @@ class PayNotifyLogic extends BaseLogic } $user->save(); //增加数量 - self::addStock($order['id'],$order); + self::addStock($order['id'], $order); } if ($order['pay_type'] == PayEnum::PURCHASE_FUNDS) { //采购款支付 $user = User::where('id', $order['uid'])->findOrEmpty(); @@ -389,7 +389,7 @@ class PayNotifyLogic extends BaseLogic } $user->save(); //增加数量 - self::addStock($order['id'],$order); + self::addStock($order['id'], $order); } UserSignLogic::RefundOrder($order); @@ -427,7 +427,7 @@ class PayNotifyLogic extends BaseLogic $model->status = YesNoEnum::YES; $model->save(); //增加数量 - self::addStock($order['id'],$order); + self::addStock($order['id'], $order); StoreOrderCartInfo::where('oid', $order['id'])->update(['status' => OrderEnum::REFUND_STATUS_FINISH]); (new StoreFinanceFlowLogic())->store_finance_back($orderSn, $order['store_id']); @@ -502,7 +502,7 @@ class PayNotifyLogic extends BaseLogic $uid = $order['other_uid']; } $cashFlowLogic = new CashFlowLogic(); - $cashFlowLogic->insert($order['store_id'], $order['price'],$orderSn); + $cashFlowLogic->insert($order['store_id'], $order['price'], $orderSn); PushService::push('wechat_mmp_' . $uid, $uid, ['type' => 'INDUSTRYMEMBERS', 'msg' => '订单支付成功', 'data' => ['id' => $order['id'], 'paid' => 1]]); PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type' => 'INDUSTRYMEMBERS', 'msg' => '订单支付成功', 'data' => ['id' => $order['id'], 'paid' => 1]]); @@ -624,25 +624,27 @@ class PayNotifyLogic extends BaseLogic 'total_price' => bcmul($stock, $storeProduct['purchase'], 2), 'sales' => bcadd($storeProduct['sales'], $v['cart_num'], 2) ], ['id' => $v['product_id']]); - if($storeProduct['product_type']==5){ - continue; + if ($storeProduct['product_type'] == 5) { + continue; } } - if ($branchProduct) { - $stock = bcsub($branchProduct['stock'], $v['cart_num'], 2); - StoreBranchProduct::update([ - 'stock' => $stock, - 'total_price' => bcmul($stock, $branchProduct['purchase'], 2), - 'sales' => bcadd($branchProduct['sales'], $v['cart_num'], 2) - ], ['id' => $branchProduct['id']]); - SqlChannelLog('StoreBranchProduct',$branchProduct['id'], $v['cart_num'], -1, Request()->url()); - } else { - StoreProductLogic::ordinary(['id' => $v['product_id']], $v['store_id'], 0, $storeProduct); - StoreBranchProduct::update([ - 'stock' => -$v['cart_num'], - 'sales' => $v['cart_num'] - ], ['product_id' => $v['product_id'],'store_id'=>$v['store_id']]); - SqlChannelLog('StoreBranchProduct',$branchProduct['id'], $v['cart_num'], -1, Request()->url()); + if ($order['source'] != OrderEnum::SOURCE_20) { + if ($branchProduct) { + $stock = bcsub($branchProduct['stock'], $v['cart_num'], 2); + StoreBranchProduct::update([ + 'stock' => $stock, + 'total_price' => bcmul($stock, $branchProduct['purchase'], 2), + 'sales' => bcadd($branchProduct['sales'], $v['cart_num'], 2) + ], ['id' => $branchProduct['id']]); + SqlChannelLog('StoreBranchProduct', $branchProduct['id'], $v['cart_num'], -1, Request()->url()); + } else { + StoreProductLogic::ordinary(['id' => $v['product_id']], $v['store_id'], 0, $storeProduct); + StoreBranchProduct::update([ + 'stock' => -$v['cart_num'], + 'sales' => $v['cart_num'] + ], ['product_id' => $v['product_id'], 'store_id' => $v['store_id']]); + SqlChannelLog('StoreBranchProduct', $branchProduct['id'], $v['cart_num'], -1, Request()->url()); + } } } } catch (\Throwable $e) { @@ -660,8 +662,8 @@ class PayNotifyLogic extends BaseLogic if ($order['uid'] != 1) { Redis::send('order_wetcha_push_send', ['order' => $order]); } - $xprinter=DictData::where('type_value','xprinter')->where('name','xprinter_'.$order['store_id'])->where('status',1)->find(); - if($xprinter){ + $xprinter = DictData::where('type_value', 'xprinter')->where('name', 'xprinter_' . $order['store_id'])->where('status', 1)->find(); + if ($xprinter) { Redis::send('order_xprinter_push_send', ['order' => $order]); } } catch (\Exception $e) { @@ -866,9 +868,9 @@ class PayNotifyLogic extends BaseLogic * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ - public static function addStock($oid,$order) + public static function addStock($oid, $order) { - if($order && $order['source']==OrderEnum::SOURCE_20){ + if ($order && $order['source'] == OrderEnum::SOURCE_20) { return true; } $updateData = []; @@ -884,14 +886,14 @@ class PayNotifyLogic extends BaseLogic $updateData[] = [ 'id' => $StoreBranchProduct['id'], 'stock' => $StoreBranchProduct['stock'] + $v['cart_num'], - 'sales' => ['dec', $v['cart_num']] + 'sales' => ['dec', $v['cart_num']] // 'sales' => ['inc', $v['cart_num']] ]; } } (new StoreBranchProduct())->saveAll($updateData); - SqlChannelLog('StoreBranchProduct',0,0,1,Request()->url()); + SqlChannelLog('StoreBranchProduct', 0, 0, 1, Request()->url()); }