From 7bf188ada3450e56df387e14a026450c963ea699 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Wed, 27 Sep 2023 20:01:17 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E4=BF=9D=E8=AF=81=E9=87=91=20=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../store/order/StoreOrderRepository.php | 16 +++++++++----- .../system/merchant/MerchantRepository.php | 22 ++++++++++--------- app/listener/paySuccessMargin.php | 2 +- 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/app/common/repositories/store/order/StoreOrderRepository.php b/app/common/repositories/store/order/StoreOrderRepository.php index ba00602d..287cb5b2 100644 --- a/app/common/repositories/store/order/StoreOrderRepository.php +++ b/app/common/repositories/store/order/StoreOrderRepository.php @@ -317,6 +317,7 @@ class StoreOrderRepository extends BaseRepository $_order_rate = 0; + //平台手续费 if ($order['commission_rate'] > 0) { $commission_rate = ($order['commission_rate'] / 100); @@ -324,7 +325,8 @@ class StoreOrderRepository extends BaseRepository $_order_rate = bcmul($_payPrice, $commission_rate, 2); $_payPrice = bcsub($_payPrice, $_order_rate, 2); - event('order.paySuccessOrder', compact('order','_order_rate')); + // 结算各镇 小组佣金 + // event('order.paySuccessOrder', compact('order','_order_rate')); } @@ -373,6 +375,7 @@ class StoreOrderRepository extends BaseRepository 'financial_record_sn' => $financeSn . ($i++) ]; } + //保证金计算 if ($_payPrice > 0) { /** @var MerchantRepository $merchantRepo */ $merchantRepo = app()->make(MerchantRepository::class); @@ -435,10 +438,11 @@ class StoreOrderRepository extends BaseRepository //自动打印订单 $this->autoPrinter($order->order_id, $order->mer_id); } - if ($groupOrder->user->spread_uid) { - Queue::push(UserBrokerageLevelJob::class, ['uid' => $groupOrder->user->spread_uid, 'type' => 'spread_pay_num', 'inc' => 1]); - Queue::push(UserBrokerageLevelJob::class, ['uid' => $groupOrder->user->spread_uid, 'type' => 'spread_money', 'inc' => $groupOrder->pay_price]); - } + //分销判断 + // if ($groupOrder->user->spread_uid) { + // Queue::push(UserBrokerageLevelJob::class, ['uid' => $groupOrder->user->spread_uid, 'type' => 'spread_pay_num', 'inc' => 1]); + // Queue::push(UserBrokerageLevelJob::class, ['uid' => $groupOrder->user->spread_uid, 'type' => 'spread_money', 'inc' => $groupOrder->pay_price]); + // } app()->make(UserRepository::class)->update($groupOrder->uid, [ 'pay_count' => Db::raw('pay_count+' . count($groupOrder->orderList)), 'pay_price' => Db::raw('pay_price+' . $groupOrder->pay_price), @@ -467,7 +471,7 @@ class StoreOrderRepository extends BaseRepository Queue::push(UserBrokerageLevelJob::class, ['uid' => $groupOrder->uid, 'type' => 'pay_money', 'inc' => $groupOrder->pay_price]); Queue::push(UserBrokerageLevelJob::class, ['uid' => $groupOrder->uid, 'type' => 'pay_num', 'inc' => 1]); app()->make(UserBrokerageRepository::class)->incMemberValue($groupOrder->uid, 'member_pay_num', $groupOrder->group_order_id); - event('order.paySuccess', compact('groupOrder')); + // event('order.paySuccess', compact('groupOrder')); //店内扫码支付 if (isset($groupOrder['micro_pay']) && $groupOrder['micro_pay'] == 1) { $order = $this->dao->search(['uid' => $groupOrder->uid])->where('group_order_id', $groupOrder->group_order_id)->find(); diff --git a/app/common/repositories/system/merchant/MerchantRepository.php b/app/common/repositories/system/merchant/MerchantRepository.php index baefe349..16d32f24 100644 --- a/app/common/repositories/system/merchant/MerchantRepository.php +++ b/app/common/repositories/system/merchant/MerchantRepository.php @@ -51,6 +51,7 @@ use think\db\exception\ModelNotFoundException; use think\Exception; use think\exception\ValidateException; use think\facade\Db; +use think\facade\Log; use think\facade\Queue; use think\facade\Route; use think\Model; @@ -688,18 +689,19 @@ class MerchantRepository extends BaseRepository public function autoMargin($income, $order, $finance, $financeSn, $index = 0) { $merchant = Merchant::find($this->merId); - //商户保证金未完全缴纳且设置了自动扣除比例 - if ($merchant['margin'] <= $merchant['paid_margin'] || ($this->forceMargin === false && $merchant['auto_margin_rate'] <= 0 && $merchant['auto_margin_rate'] > 100)) { + $margin = Db::name('MerchantType')->where('mer_type_id', $merchant['type_id'])->value('margin'); + //商户保证金大于支付保证金 或者forceMargin==false 直接返回 不计算保证金 + if ($merchant['paid_margin']>= $margin|| ($this->forceMargin === false && $merchant['auto_margin_rate'] == 0)) { return [$income, $finance, false]; } $rate = $this->forceMargin ? 100 : $merchant['auto_margin_rate']; - //商户保证金未完全缴纳且设置了自动扣除比例 - $margin = bcmul($income, $rate / 100, 2); - $margin = min(bcsub($merchant['margin'], $merchant['paid_margin'], 2), $margin); - $income = max(bcsub($income, $margin, 2), 0); - if ($margin <= 0) { - return [$income, $finance, false]; - } + // //商户保证金未完全缴纳且设置了自动扣除比例 + $margin = bcmul($income, bcdiv($rate, 100,2), 2); + // $margin = min(bcsub($margin, $merchant['paid_margin'], 2), $margin); + // $income = max(bcsub($income, $margin, 2), 0); + // if ($margin <= 0) { + // return [$income, $finance, false]; + // } $finance[] = [ 'order_id' => $order->order_id, 'order_sn' => $order->order_sn, @@ -741,7 +743,7 @@ class MerchantRepository extends BaseRepository throw new \Exception('merchant 保存出错', 500); } - return [$income, $finance, true]; + return [bcsub($income,$margin), $finance, true]; } } diff --git a/app/listener/paySuccessMargin.php b/app/listener/paySuccessMargin.php index a7499adb..cb4bb2a4 100644 --- a/app/listener/paySuccessMargin.php +++ b/app/listener/paySuccessMargin.php @@ -30,7 +30,7 @@ class paySuccessMargin //已支付的保证金 $paidMarginAmount = bcadd($merchantInfo['paid_margin'], $marginInfo['total_price'], 2); Db::name('merchant')->where('mer_id', $marginInfo['mer_id'])->where('uid', $marginInfo['uid'])->update([ - 'paid_margin' => $paidMarginAmount + 'paid_margin' => $paidMarginAmount,'ot_margin'=>$paidMarginAmount ]); Db::name('merchant')->where('mer_id', $marginInfo['mer_id'])->where('uid', $marginInfo['uid'])->update([ 'margin' => 0 From c5a8aafa621895d601365ff717be67d561bf0bc4 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Wed, 27 Sep 2023 20:16:15 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api/store/merchant/Merchant.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controller/api/store/merchant/Merchant.php b/app/controller/api/store/merchant/Merchant.php index 17728995..c421199d 100644 --- a/app/controller/api/store/merchant/Merchant.php +++ b/app/controller/api/store/merchant/Merchant.php @@ -268,7 +268,8 @@ class Merchant extends BaseController if(empty($merchantInfo)){ return app('json')->fail('参数错误'); } - $merchantInfo['unpaid_margin'] = $merchantInfo['margin']; + $margin = Db::name('MerchantType')->where('mer_type_id', $merchantInfo['type_id'])->value('margin'); + $merchantInfo['unpaid_margin'] = bcsub($margin,$merchantInfo['paid_margin']); return app('json')->success($merchantInfo); } From f7a9d0c2914b18dc3a2c85cfe9d9b0120b216e0b Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Wed, 27 Sep 2023 20:17:49 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=8A=BC=E9=87=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api/store/merchant/Merchant.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/controller/api/store/merchant/Merchant.php b/app/controller/api/store/merchant/Merchant.php index c421199d..826a6831 100644 --- a/app/controller/api/store/merchant/Merchant.php +++ b/app/controller/api/store/merchant/Merchant.php @@ -270,6 +270,9 @@ class Merchant extends BaseController } $margin = Db::name('MerchantType')->where('mer_type_id', $merchantInfo['type_id'])->value('margin'); $merchantInfo['unpaid_margin'] = bcsub($margin,$merchantInfo['paid_margin']); + if($merchantInfo['margin']==0){ + $merchantInfo['margin']=$merchantInfo['unpaid_margin']; + } return app('json')->success($merchantInfo); } From e8dfbec97062922c4355bc1114fa242129b3c0cd Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Wed, 27 Sep 2023 20:40:08 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api/store/merchant/Merchant.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controller/api/store/merchant/Merchant.php b/app/controller/api/store/merchant/Merchant.php index 826a6831..4acf62db 100644 --- a/app/controller/api/store/merchant/Merchant.php +++ b/app/controller/api/store/merchant/Merchant.php @@ -269,7 +269,7 @@ class Merchant extends BaseController return app('json')->fail('参数错误'); } $margin = Db::name('MerchantType')->where('mer_type_id', $merchantInfo['type_id'])->value('margin'); - $merchantInfo['unpaid_margin'] = bcsub($margin,$merchantInfo['paid_margin']); + $merchantInfo['unpaid_margin'] = bcsub($margin,$merchantInfo['paid_margin'],2); if($merchantInfo['margin']==0){ $merchantInfo['margin']=$merchantInfo['unpaid_margin']; } From ac3593404a3c52fc63e56c1e42d917016189058b Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Wed, 27 Sep 2023 20:57:02 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api/Auth.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/app/controller/api/Auth.php b/app/controller/api/Auth.php index 09b4bd94..82874a11 100644 --- a/app/controller/api/Auth.php +++ b/app/controller/api/Auth.php @@ -281,14 +281,20 @@ class Auth extends BaseController return app('json')->fail('用户店铺异常'); } if($merchant['margin'] == 0){ - return app('json')->fail('当前金额为0,不能进行充值'); + $margin = Db::name('MerchantType')->where('mer_type_id', $merchant['type_id'])->value('margin'); + $margin = bcsub($margin,$merchant['paid_margin'],2); + if($margin==0){ + return app('json')->fail('当前金额为0,不能进行充值'); + } + }else{ + $margin=0; } $orderSn = "bzj" . date('YmdHis') . uniqid(); Db::name('margin_order')->insert([ 'uid' => $user['uid'], 'mer_id' => $merchant['mer_id'], 'order_sn' => $orderSn, - 'total_price' => $merchant['margin'], + 'total_price' => $margin, 'pay_type' => 1, 'create_time' => date('Y-m-d H:i:s') ]); @@ -298,10 +304,10 @@ class Auth extends BaseController "mer_id" => $merchant['mer_id'], "pay_type" => 1, "attach" => "margin", - "order_info" => '{"is_margin":1,"margin":"' . $merchant['margin'] . '"}', - "pay_price" => $merchant['margin'], + "order_info" => '{"is_margin":1,"margin":"' . $margin . '"}', + "pay_price" => $margin, "order_sn" => $orderSn, - "body" => $merchant['mer_name'] . ' - ' . $merchant['margin'], + "body" => $merchant['mer_name'] . ' - ' . $margin, ]; $payType = 'weixinApp'; $service = new PayService($payType, $param);