From 5d6e7be7b95fdd10f6a169613c71a5a1e5fd8724 Mon Sep 17 00:00:00 2001 From: lqmac Date: Thu, 8 Aug 2024 02:05:53 +0800 Subject: [PATCH] 1 --- app/api/service/order/PaySuccess.php | 45 +++++++++++++++++----------- app/common/model/MerchantPay.php | 5 ++-- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/app/api/service/order/PaySuccess.php b/app/api/service/order/PaySuccess.php index 2a1ed9bb..e24bbe3b 100644 --- a/app/api/service/order/PaySuccess.php +++ b/app/api/service/order/PaySuccess.php @@ -344,27 +344,36 @@ class PaySuccess extends BaseService // 当前订单信息 $orderInfo = $this->getOrderInfo(); // 余额支付 - if ($this->method == PaymentMethodEnum::BALANCE) { - // 更新用户余额 - UserModel::setDecBalance((int)$orderInfo['user_id'], (float)$orderInfo['pay_price']); - // 新增余额变动记录 - BalanceLogModel::add(SceneEnum::CONSUME, [ - 'user_id' => (int)$orderInfo['user_id'], - 'money' => -$orderInfo['pay_price'], - ], ['order_no' => $orderInfo['order_no']]); + if ($this->method == PaymentMethodEnum::BALANCE || $this->method == PaymentMethodEnum::HUIFU) { + if ($this->method == PaymentMethodEnum::BALANCE) { + // 更新用户余额 + UserModel::setDecBalance((int)$orderInfo['user_id'], (float)$orderInfo['pay_price']); + // 新增余额变动记录 + BalanceLogModel::add(SceneEnum::CONSUME, [ + 'user_id' => (int)$orderInfo['user_id'], + 'money' => -$orderInfo['pay_price'], + ], ['order_no' => $orderInfo['order_no']]); + } + - // //增加商户支付详情 - // $model = \app\store\model\Merchant::detail($orderInfo['merchant_id']); - // $precent = 1; + if ($orderInfo['merchant_id']) { + //增加商户支付详情 + $model = \app\store\model\Merchant::detail($orderInfo['merchant_id']); + if ($model) { + $precent = 1; - // if ($model['commission_ratio']) { - // $precent = (1 - $model['commission_ratio'] / 1000); - // } - // $precentPrice = round($precent * $orderInfo['pay_price'], 2); - // (new merchantPayModel())->addDetail($orderInfo, $precentPrice); + if ($model['commission_ratio']) { + $precent = (1 - $model['commission_ratio'] / 1000); + } + $precentPrice = round($precent * $orderInfo['pay_price'], 2); + (new merchantPayModel())->addDetail($orderInfo, $precentPrice, $this->method == PaymentMethodEnum::HUIFU ? 1 : 0); - // //累计商户余额支付金额 - // merchantModel::setIncTotal($orderInfo['merchant_id'], $precentPrice); + //累计商户余额支付金额 + merchantModel::setIncTotal($orderInfo['merchant_id'], $precentPrice); + } + + } + } // 将第三方交易记录更新为已支付状态 if (in_array($this->method, [PaymentMethodEnum::WECHAT, PaymentMethodEnum::ALIPAY, PaymentMethodEnum::HUIFU])) { diff --git a/app/common/model/MerchantPay.php b/app/common/model/MerchantPay.php index 0725e0ee..401f77be 100644 --- a/app/common/model/MerchantPay.php +++ b/app/common/model/MerchantPay.php @@ -34,14 +34,15 @@ class MerchantPay extends BaseModel * @param float $money * @return mixed */ - public function addDetail($orderInfo, $precentPrice) + public function addDetail($orderInfo, $precentPrice, $source = 0) { if (!empty($orderInfo['merchant_id'])) { $data = [ 'order_id' => $orderInfo['order_id'], - //'store_id' => $orderInfo['store_id'], + 'store_id' => $orderInfo['store_id'], 'merchant_id' => $orderInfo['merchant_id'], 'total_amount' => $precentPrice, + 'source' => $source, ]; return $this->save($this->createData($data)); }