shish 5 роки тому
батько
коміт
7d4d2ea2df

+ 11 - 1
app-hd/controllers/RechargeController.php

@@ -2,6 +2,7 @@
 
 namespace hd\controllers;
 
+use biz\ghs\classes\GhsClass;
 use biz\recharge\classes\RechargeClass;
 use biz\shop\classes\ShopClass;
 use biz\sj\classes\SjClass;
@@ -70,6 +71,10 @@ class RechargeController extends BaseController
         $name = $order->orderName ?? '充值';
         $totalFee = $order->amount;
 
+        if (isset($this->shopAdmin['super']) == false || $this->shopAdmin['super'] != 1) {
+            util::fail('超级管理员才有权限操作');
+        }
+
         //强制使用小程序的miniOpenId
         $openId = isset($this->admin) && !empty($this->admin) ? $this->admin->miniOpenId : '';
         if (empty($openId)) {
@@ -78,7 +83,12 @@ class RechargeController extends BaseController
         $capitalType = dict::getDict('capitalType', 'xhRecharge', 'id');
         //流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
         $wxPayType = 1;
-        $attach = "couponId=0&capitalType=" . $capitalType . '&wxPayType=' . $wxPayType . '&rechargeRenew=1';
+
+        $ghsId = Yii::$app->request->get('ghsId', 0);
+        $ghs = GhsClass::getById($ghsId);
+        GhsClass::valid($ghs, $this->shopId);
+
+        $attach = "couponId=0&capitalType=" . $capitalType . '&wxPayType=' . $wxPayType . '&rechargeRenew=1&ghsId=' . $ghsId;
         //订单30分钟后过期
         $now = time();
         $expireTime = $now + 1800;

+ 8 - 2
biz/recharge/classes/RechargeClass.php

@@ -32,7 +32,7 @@ class RechargeClass extends BaseClass
     }
 
     //处理充值流程 ssh 2021.2.21
-    public static function complete($recharge, $payWay, $rechargeRenew = 0)
+    public static function complete($recharge, $payWay, $rechargeRenew = 0, $ghsId = 0)
     {
         $recharge->payWay = $payWay;
         $recharge->payStatus = self::PAY_STATUS_HAS_PAY;
@@ -46,6 +46,11 @@ class RechargeClass extends BaseClass
         $amount = $recharge->amount;
         $recharge->save();
 
+        if (!empty($ghsId)) {
+            $shop->fixGhsId = $ghsId;
+            $shop->save();
+        }
+
         //门店和平台余额增加
         $tx = dict::getDict('yeTx', 'canNot');
         $capitalType = dict::getDict('capitalType', 'xhRecharge');
@@ -78,8 +83,9 @@ class RechargeClass extends BaseClass
         parse_str($attach);
         //是否充值免费续期
         $rechargeRenew = isset($rechargeRenew) ? $rechargeRenew : 0;
+        $ghsId = isset($ghsId) ? $ghsId : 0;
         //处理充值成功的流程
-        self::complete($recharge, $payWay, $rechargeRenew);
+        self::complete($recharge, $payWay, $rechargeRenew, $ghsId);
     }
 
 }

+ 17 - 22
biz/shop/classes/ShopClass.php

@@ -317,28 +317,23 @@ class ShopClass extends BaseClass
 
         //定向消费余额
         $currentFixBalance = $shop->fixBalance;
-        $ghsId = $order->ghsId;
-        $ghs = GhsClass::getById($ghsId, true);
-        if (empty($ghs)) {
-            util::fail('没有找到供货商');
-        }
-
-        //找出推荐人
-        $ghsShopId = $ghs->shopId;
-        $parentShopId = SjClass::getParentShopId($sjId);
-
-        //指定消费判断
-        if ($ghsShopId != $parentShopId) {
-            //如果不是在自己推荐人那边采购,需确认扣掉定向消费余额后还够不够扣
-            $notFixBalance = bcsub($shop->balance, $currentFixBalance, 2);
-            if (bccomp($amount, $notFixBalance, 2) == 1) {
-                util::fail('充值余额只能在介绍您的门店消费');
-            }
-        } else {
-            //需要定向消费余额不够本次扣时全部扣掉
-            if ($currentFixBalance > 0) {
-                $reduceFix = $currentFixBalance > $amount ? $amount : $currentFixBalance;
-                $shop->fixBalance = bcsub($currentFixBalance, $reduceFix, 2);
+        $ghsId = $order->ghsId ?? 0;
+        $fixGhsId = $shop->fixGhsId ?? 0;
+
+        //定向消费判断
+        if (!empty($fixGhsId)) {
+            if ($ghsId != $fixGhsId) {
+                //如果不是在自己推荐人那边采购,需确认扣掉定向消费余额后还够不够扣
+                $notFixBalance = bcsub($shop->balance, $currentFixBalance, 2);
+                if (bccomp($amount, $notFixBalance, 2) == 1) {
+                    util::fail('充值余额只能在介绍您的门店消费');
+                }
+            } else {
+                //需要定向消费余额不够本次扣时全部扣掉
+                if ($currentFixBalance > 0) {
+                    $reduceFix = $currentFixBalance > $amount ? $amount : $currentFixBalance;
+                    $shop->fixBalance = bcsub($currentFixBalance, $reduceFix, 2);
+                }
             }
         }
         $currentBalance = bcsub($shop->balance, $amount, 2);