From bae7a58f0e87d48f5b9e023304d4f649628b4fbe Mon Sep 17 00:00:00 2001 From: liu <1873441552@qq.com> Date: Thu, 6 Jun 2024 10:59:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=9E=E8=B0=83=E5=8A=A0=E5=85=A5=E8=B5=84?= =?UTF-8?q?=E9=87=91=E6=B5=81=E6=B0=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/logic/CapitalFlowLogic.php | 13 ++++--- app/common/logic/PayNotifyLogic.php | 51 +++++++++++++++------------ 2 files changed, 38 insertions(+), 26 deletions(-) diff --git a/app/common/logic/CapitalFlowLogic.php b/app/common/logic/CapitalFlowLogic.php index fea095bfd..4f11acdcc 100644 --- a/app/common/logic/CapitalFlowLogic.php +++ b/app/common/logic/CapitalFlowLogic.php @@ -31,7 +31,7 @@ class CapitalFlowLogic extends BaseLogic public function userIncome($category, $linkType, $linkId, $amount, $mark = '') { $model = new CapitalFlow(); - $model->uid = $this->user['uid']; + $model->uid = $this->user['id']; $model->category = $category; $model->link_type = $linkType; $model->link_id = $linkId; @@ -55,7 +55,7 @@ class CapitalFlowLogic extends BaseLogic * @param $mark * @return mixed */ - public function userExpense($category, $linkType, $linkId, $amount, $mark = '') + public function userExpense($category, $linkType, $linkId, $amount, $mark = '',$payType=0) { $model = new CapitalFlow(); $model->uid = $this->user['id']; @@ -63,8 +63,13 @@ class CapitalFlowLogic extends BaseLogic $model->link_type = $linkType; $model->link_id = $linkId; $model->amount = $amount; - $model->before_balance = $this->user['now_money']; - $model->balance = bcsub($this->user['now_money'], $amount, 2); + if($payType == 1){ + $model->before_balance = $this->user['now_money']; + $model->balance = $this->user['now_money']; + }else{ + $model->before_balance = $this->user['now_money']; + $model->balance = bcsub($this->user['now_money'], $amount, 2); + } $model->create_time = date('Y-m-d H:i:s'); $model->type = 'out'; $model->title = $this->getTitle($category, $amount); diff --git a/app/common/logic/PayNotifyLogic.php b/app/common/logic/PayNotifyLogic.php index 0a38dcec8..b982eefeb 100644 --- a/app/common/logic/PayNotifyLogic.php +++ b/app/common/logic/PayNotifyLogic.php @@ -49,7 +49,7 @@ class PayNotifyLogic extends BaseLogic * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ - static function balancePay($orderSn, $extra = []) + public static function balancePay($orderSn, $extra = []) { $order = StoreOrder::where('order_id', $orderSn)->findOrEmpty(); $user = User::where('id', $order['uid'])->find(); @@ -92,6 +92,10 @@ class PayNotifyLogic extends BaseLogic if ($order->pay_type == 9) { $order->status = 2; } + $user = User::where('id', $order['uid'])->find(); + $capitalFlowDao = new CapitalFlowLogic($user); + //微信支付和用户余额无关 + $capitalFlowDao->userExpense('user_order_pay', 'order', $order['id'], $order->pay_price,'',1); self::afterPay($order,$extra['transaction_id']); if ($order->pay_type == 9) { @@ -111,27 +115,30 @@ class PayNotifyLogic extends BaseLogic public static function recharge($orderSn, $extra = []) { - $order = UserRecharge::where('order_id', $orderSn)->findOrEmpty(); - if ($order->isEmpty() || $order->paid == PayEnum::ISPAID) { + $order = UserRecharge::where('order_id', $orderSn)->findOrEmpty(); + if ($order->isEmpty() || $order->paid == PayEnum::ISPAID) { + return true; + } + $price = bcdiv($extra['amount']['payer_total'], 100, 2); + $order->price = $price; + $order->paid = 1; + $order->pay_time = time(); + $order->save(); + $uid = $order->uid; + $user = User::where('id',$uid)->findOrEmpty(); + if ($user->isEmpty()) { + return true; + } + bcscale(2); + $user->user_money = bcadd($user->user_money, $price, 2); + $user->total_recharge_amount = bcadd($user->total_recharge_amount, $price, 2); + $user->save(); + //用户的财务add + $capitalFlowDao = new CapitalFlowLogic($user); + $capitalFlowDao->userIncome('user_balance_recharge', 'user_recharge', $order['id'], $price); + //更新等级 + self::dealLevel($uid,$user->total_recharge_amount); return true; - } - $price = bcdiv($extra['amount']['payer_total'], 100, 2); - $order->price = $price; - $order->paid = 1; - $order->pay_time = time(); - $order->save(); - $uid = $order->uid; - $user = User::where('id',$uid)->findOrEmpty(); - if ($user->isEmpty()) { - return true; - } - bcscale(2); - $user->user_money = bcadd($user->user_money, $price, 2); - $user->total_recharge_amount = bcadd($user->total_recharge_amount, $price, 2); - $user->save(); - //更新等级 - self::dealLevel($uid,$user->total_recharge_amount); - return true; } @@ -196,7 +203,7 @@ class PayNotifyLogic extends BaseLogic * @param $order * @return void */ - public static function afterPay($order,$transaction_id) + public static function afterPay($order,$transaction_id=0) { $financeLogic = new StoreFinanceFlowLogic(); $financeLogic->order = $order;