shish 5 år sedan
förälder
incheckning
5bd615e441

+ 1 - 1
app-pt/controllers/RechargeController.php

@@ -47,7 +47,7 @@ class RechargeController extends BaseController
             $order = RechargeClass::addOrder($data, true);
             $tx = dict::getDict('yeTx', 'canNot');
             $capitalType = dict::getDict('capitalType', 'xhRecharge');
-            ShopClass::addBalance($shop, $amount, $order, $tx, $capitalType);
+            ShopClass::rechargeAddBalance($shop, $amount, $order, $tx, $capitalType);
             $transaction->commit();
             util::complete();
         } catch (\Exception $exception) {

+ 8 - 3
biz-ghs/order/services/OrderService.php

@@ -4,6 +4,7 @@ namespace bizGhs\order\services;
 
 use biz\ghs\classes\GhsClass;
 use biz\shop\classes\ShopAdminClass;
+use biz\shop\classes\ShopClass;
 use biz\shop\models\Shop;
 use bizGhs\base\services\BaseService;
 use bizGhs\custom\classes\CustomClass;
@@ -421,7 +422,7 @@ class OrderService extends BaseService
         /**门店资产变化**/
         $amount = $order->actPrice ?? 0.00;
         $currentShopId = $order->shopId ?? 0;
-        $shop = Shop::findBySql('select * from ' . Shop::tableName() . ' where id = :id for update', ['id' => $currentShopId])->one();
+        $shop = ShopClass::getLockById($currentShopId);
         if (empty($shop)) {
             util::fail('没有找到门店');
         }
@@ -431,8 +432,12 @@ class OrderService extends BaseService
         $shop->totalIncome = bcadd($shop->totalIncome, $amount, 2);
         $shop->save();
 
-        if($isPurchase == true){
-
+        //客户采购引起的开单,会增加余额
+        if ($isPurchase == true) {
+            $capitalType = dict::getDict('capitalType', 'xhGhsOrder', 'id');
+            if ($payWay == dict::getDict('payWay', 'wxPay') || $payWay == dict::getDict('payWay', 'balancePay')) {
+                ShopClass::customCreateOrderAddBalance($shop, $amount, $order, $capitalType);
+            }
         }
 
         //更新订单基础状态和支付状态

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

@@ -2,8 +2,8 @@
 
 namespace bizGhs\recharge\classes;
 
+use biz\shop\classes\ShopClass;
 use bizGhs\base\classes\BaseClass;
-use bizGhs\merchant\classes\ShopClass;
 use common\components\noticeUtil;
 use common\components\orderSn;
 
@@ -42,7 +42,7 @@ class RechargeClass extends BaseClass
             return false;
         }
         $amount = $recharge->amount;
-        ShopClass::addBalance($shop, $amount);
+        ShopClass::rechargeAddBalance($shop, $amount);
     }
 
 }

+ 47 - 1
biz/pt/classes/PtAssetClass.php

@@ -11,8 +11,54 @@ class PtAssetClass extends BaseClass
 
     public static $baseFile = '\biz\pt\models\PtAsset';
 
+    //客户下单增加商家余额 shish 20210520
+    public static function customCreateOrderAddBalance($shop, $amount, $order, $capitalType, $tx)
+    {
+        $ptStyle = $shop->ptStyle;
+        if ($ptStyle == dict::getDict('ptStyle', 'hd')) {
+            $asset = self::getHdBalance();
+        } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) {
+            $asset = self::getGhsBalance();
+        } else {
+            util::fail('没有找到平台');
+        }
+        $currentAmount = bcadd($asset->amount, $amount, 2);
+        $asset->amount = $currentAmount;
+        $asset->save();
+
+        if ($ptStyle == dict::getDict('ptStyle', 'hd')) {
+            $txAsset = self::getHdTxBalance();
+        } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) {
+            $txAsset = self::getGhsTxBalance();
+        } else {
+            util::fail('没有找到平台');
+        }
+        $currentTxBalance = $txAsset->amount;
+
+        $currentTxBalance = bcadd($currentTxBalance, $amount, 2);
+        $txAsset->amount = $currentTxBalance;
+        $txAsset->save();
+
+        $id = $order->id;
+        $event = "【{$shop->merchantName} {$shop->shopName}】的客户下单购买 {$amount}元 订单号:{$order->orderSn}";
+        $change = [
+            'relateId' => $id,
+            'capitalType' => $capitalType,
+            'amount' => $amount,
+            'balance' => $currentAmount,
+            'txBalance' => $currentTxBalance,
+            'io' => 1,
+            'payWay' => $order->payWay,
+            'event' => $event,
+            'sjId' => $order->sjId,
+            'shopId' => $order->shopId,
+            'tx' => $tx,
+        ];
+        PtYeChangeClass::addChange($change, true);
+    }
+
     //平台余额增加 shish 20210519
-    public static function addBalance($shop, $amount, $order, $capitalType, $tx)
+    public static function rechargeAddBalance($shop, $amount, $order, $capitalType, $tx)
     {
         $ptStyle = $shop->ptStyle;
         if ($ptStyle == dict::getDict('ptStyle', 'hd')) {

+ 1 - 1
biz/recharge/classes/RechargeClass.php

@@ -57,7 +57,7 @@ class RechargeClass extends BaseClass
             $fix = true;
         }
 
-        \biz\shop\classes\ShopClass::addBalance($shop, $amount, $recharge, $tx, $capitalType, $fix);
+        \biz\shop\classes\ShopClass::rechargeAddBalance($shop, $amount, $recharge, $tx, $capitalType, $fix);
     }
 
     //第三支付后流程 shish 2021.4.27

+ 42 - 8
biz/shop/classes/ShopClass.php

@@ -145,9 +145,44 @@ class ShopClass extends BaseClass
         return $gatheringCode;
     }
 
-    //门店增加余额 ssh 2021.2.21
+    //客户下单引起的余额增加 shish 20210520
+    public static function customCreateOrderAddBalance($shop, $amount, $order, $capitalType)
+    {
+        //门店余额增加
+        $currentBalance = bcadd($shop->balance, $amount, 2);
+        $shop->balance = $currentBalance;
+        $shop->totalRecharge += $amount;
+        //可提现余额同步增加
+        $currentTx = bcadd($shop->txBalance, $amount, 2);
+        $shop->txBalance = $currentTx;
+        $shop->save();
+
+        //增加余额变动记录
+        $id = $order->id;
+        $event = "客户下单 {$amount}元";
+        $tx = dict::getDict('yeTx', 'can');
+        $change = [
+            'relateId' => $id,
+            'capitalType' => $capitalType,
+            'amount' => $amount,
+            'balance' => $currentBalance,
+            'txBalance' => $currentTx,
+            'io' => 1,
+            'payWay' => $order->payWay,
+            'event' => $event,
+            'sjId' => $order->sjId,
+            'shopId' => $order->shopId,
+            'tx' => $tx,
+        ];
+        ShopYeChangeClass::addChange($change, true);
+
+        //平台余额增加
+        PtAssetClass::customCreateOrderAddBalance($shop, $amount, $order, $capitalType, $tx);
+    }
+
+    //门店充值增加余额 ssh 2021.2.21
     //$fix = true 余额只能在指定门店使用
-    public static function addBalance($shop, $amount, $order, $tx, $capitalType, $fix = false)
+    public static function rechargeAddBalance($shop, $amount, $order, $tx, $capitalType, $fix = false)
     {
         //门店余额增加
         $currentBalance = bcadd($shop->balance, $amount, 2);
@@ -188,8 +223,7 @@ class ShopClass extends BaseClass
         ShopYeChangeClass::addChange($change, true);
 
         //平台余额增加
-        PtAssetClass::addBalance($shop, $amount, $order, $capitalType, $tx);
-
+        PtAssetClass::rechargeAddBalance($shop, $amount, $order, $capitalType, $tx);
     }
 
 
@@ -211,18 +245,18 @@ class ShopClass extends BaseClass
         }
 
         //找出推荐人
-        $ghsSjId = $ghs->sjId;
+        $ghsShopId = $ghs->shopId;
         $parentShopId = SjClass::getParentShopId($sjId);
 
         //指定消费判断
-        if ($ghsSjId != $parentShopId) {
+        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);
@@ -252,7 +286,7 @@ class ShopClass extends BaseClass
             'amount' => $amount,
             'balance' => $currentBalance,
             'txBalance' => $currentTxBalance,
-            'io' => 1,
+            'io' => 0,
             'payWay' => $order->payWay,
             'event' => "余额支付{$amount}元",
             'sjId' => $sjId,