Просмотр исходного кода

Merge branch 'master' of http://git.huaml.com/zhh/huahuibao

林琦海 5 лет назад
Родитель
Сommit
7670fcff52

+ 0 - 43
biz-hd/merchant/classes/ShopClass.php

@@ -104,47 +104,4 @@ class ShopClass extends BaseClass
         return $gatheringCode;
     }
 
-    //门店增加余额 ssh 2021.2.21
-    //$fix = true 余额只能在指定门店使用
-    public static function addBalance($shop, $amount, $order, $tx, $capitalType, $fix = false)
-    {
-        //门店余额增加
-        $currentBalance = bcadd($shop->balance, $amount, 2);
-        $shop->balance = $currentBalance;
-        $shop->totalRecharge += $amount;
-        //定向消费余额
-        if ($fix) {
-            $currentFix = bcadd($shop->fixBalance, $amount, 2);
-            $shop->fixBalance = $currentFix;
-        }
-        $currentTx = $shop->txBalance;
-        //提现余额
-        if ($tx == dict::getDict('yeTx', 'can')) {
-            $currentTx = bcadd($shop->txBalance, $amount, 2);
-            $shop->txBalance = $currentTx;
-        }
-        $shop->save();
-
-        //增加余额变动记录
-        $id = $order->id;
-        $change = [
-            'relateId' => $id,
-            'capitalType' => $capitalType,
-            'amount' => $amount,
-            'balance' => $currentBalance,
-            'txBalance' => $currentTx,
-            'io' => 1,
-            'payWay' => $order->payWay,
-            'event' => "充值{$amount}元",
-            'sjId' => $order->sjId,
-            'shopId' => $order->shopId,
-            'tx' => $tx,
-        ];
-        ShopYeChangeClass::addChange($change, true);
-
-        //平台余额增加
-        PtAssetClass::addBalance($shop, $amount, $order, $capitalType, $tx);
-
-    }
-
 }

+ 2 - 4
biz-hd/purchase/services/PurchaseService.php

@@ -237,10 +237,8 @@ class PurchaseService extends BaseService
         }
         $actPrice = $info->actPrice;
         if ($payWay == dict::getDict('payWay', 'balancePay')) {
-            if (bccomp($actPrice, $shop->balance, 2) == 1) {
-                util::fail('余额不足');
-            }
-            $shop->balance = bcsub($shop->balance, $actPrice, 2);
+            //余额支付,余额减少
+            ShopClass::purchaseReduceBalance($shop, $actPrice, $info);
         }
         $shop->totalPurchase = bcadd($shop->totalPurchase, $actPrice, 2);
         $shop->cgUnPay -= 1;

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

@@ -49,7 +49,7 @@ class PtAssetClass extends BaseClass
             'txBalance' => $currentTxBalance,
             'io' => 1,
             'payWay' => $order->payWay,
-            'event' => "【{$shop->merchantName} {$shop->shopName}】充值{$amount}元(订单:{$order->orderSn})",
+            'event' => "【{$shop->merchantName} {$shop->shopName}】 充值{$amount}元 订单号:{$order->orderSn}",
             'sjId' => $order->sjId,
             'shopId' => $order->shopId,
             'tx' => $tx,
@@ -57,6 +57,56 @@ class PtAssetClass extends BaseClass
         PtYeChangeClass::addChange($change, true);
     }
 
+    //平台余额增加 shish 20210519
+    public static function reduceBalance($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 = bcsub($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;
+        if ($tx == dict::getDict('yeTx', 'can')) {
+            if (!empty($currentTxBalance)) {
+                $reduceTxBalance = $currentTxBalance > $amount ? $amount : $currentTxBalance;
+                $currentTxBalance = bcsub($currentTxBalance, $reduceTxBalance, 2);
+                $txAsset->amount = $currentTxBalance;
+                $txAsset->save();
+            }
+        }
+
+        $id = $order->id;
+        $change = [
+            'relateId' => $id,
+            'capitalType' => $capitalType,
+            'amount' => $amount,
+            'balance' => $currentAmount,
+            'txBalance' => $currentTxBalance,
+            'io' => 0,
+            'payWay' => $order->payWay,
+            'event' => "【{$shop->merchantName} {$shop->shopName}】 {$amount}元 订单号:{$order->orderSn}",
+            'sjId' => $order->sjId,
+            'shopId' => $order->shopId,
+            'tx' => $tx,
+        ];
+        PtYeChangeClass::addChange($change, true);
+    }
+
+
     //零售平台余额对象 shish 20210519
     public static function getHdBalance()
     {

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

@@ -49,6 +49,7 @@ class RechargeClass extends BaseClass
         //门店和平台余额增加
         $tx = dict::getDict('yeTx', 'canNot');
         $capitalType = dict::getDict('capitalType', 'xhRecharge');
+        //余额是否指定门店使用
         $fix = false;
         if ($rechargeRenew == 1) {
             $sjId = $recharge->sjId;
@@ -56,8 +57,7 @@ class RechargeClass extends BaseClass
             $fix = true;
         }
 
-        ShopClass::addBalance($shop, $amount, $recharge, $tx, $capitalType, $fix);
-
+        \biz\shop\classes\ShopClass::addBalance($shop, $amount, $recharge, $tx, $capitalType, $fix);
     }
 
     //第三支付后流程 shish 2021.4.27

+ 114 - 5
biz/shop/classes/ShopClass.php

@@ -2,9 +2,13 @@
 
 namespace biz\shop\classes;
 
+use biz\ghs\classes\GhsClass;
+use biz\pt\classes\PtAssetClass;
+use biz\sj\classes\SjClass;
 use bizGhs\product\classes\ProductClass;
 use bizHd\admin\classes\ShopAdminClass;
 use biz\sj\classes\MerchantClass;
+use common\components\dict;
 use common\components\dirUtil;
 use common\components\httpUtil;
 use common\components\imgUtil;
@@ -141,16 +145,121 @@ class ShopClass extends BaseClass
         return $gatheringCode;
     }
 
-    //增加余额 ssh 2021.2.21
-    //$fix = false 余额使用时不需要指定在谁那边
-    public static function addBalance($shop, $amount, $fix = false)
+    //门店增加余额 ssh 2021.2.21
+    //$fix = true 余额只能在指定门店使
+    public static function addBalance($shop, $amount, $order, $tx, $capitalType, $fix = false)
     {
-        $shop->balance += $amount;
+        //门店余额增加
+        $currentBalance = bcadd($shop->balance, $amount, 2);
+        $shop->balance = $currentBalance;
         $shop->totalRecharge += $amount;
+        //定向消费余额
         if ($fix) {
-            $shop->fixBalance += $amount;
+            $currentFix = bcadd($shop->fixBalance, $amount, 2);
+            $shop->fixBalance = $currentFix;
+        }
+        $currentTx = $shop->txBalance;
+        //提现余额
+        if ($tx == dict::getDict('yeTx', 'can')) {
+            $currentTx = bcadd($shop->txBalance, $amount, 2);
+            $shop->txBalance = $currentTx;
+        }
+        $shop->save();
+
+        //增加余额变动记录
+        $id = $order->id;
+        $change = [
+            'relateId' => $id,
+            'capitalType' => $capitalType,
+            'amount' => $amount,
+            'balance' => $currentBalance,
+            'txBalance' => $currentTx,
+            'io' => 1,
+            'payWay' => $order->payWay,
+            'event' => "充值{$amount}元",
+            'sjId' => $order->sjId,
+            'shopId' => $order->shopId,
+            'tx' => $tx,
+        ];
+        ShopYeChangeClass::addChange($change, true);
+
+        //平台余额增加
+        PtAssetClass::addBalance($shop, $amount, $order, $capitalType, $tx);
+
+    }
+
+
+    //采购余额付款,减少余额 shish 20210519
+    public static function purchaseReduceBalance($shop, $amount, $order)
+    {
+        if (bccomp($amount, $shop->balance, 2) == 1) {
+            util::fail('余额不足');
+        }
+        $sjId = $order->sjId;
+        $shopId = $order->shopId;
+
+        //定向消费余额
+        $currentFixBalance = $shop->fixBalance;
+        $ghsId = $order->ghsId;
+        $ghs = GhsClass::getById($ghsId, true);
+        if (empty($ghs)) {
+            util::fail('没有找到供货商');
+        }
+
+        //找出推荐人
+        $ghsSjId = $ghs->sjId;
+        $parentShopId = SjClass::getParentShopId($sjId);
+
+        //指定消费判断
+        if ($ghsSjId != $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);
+            }
+        }
+        $currentBalance = bcsub($shop->balance, $amount, 2);
+        $shop->balance = $currentBalance;
+
+        $tx = dict::getDict('yeTx', 'canNot');
+
+        //还有可提现余额也要先用掉
+        $currentTxBalance = $shop->txBalance;
+        if ($currentTxBalance > 0) {
+            $reduceTxBalance = $currentTxBalance > $amount ? $amount : $currentTxBalance;
+            $shop->txBalance = bcsub($currentTxBalance, $reduceTxBalance, 2);
+            $tx = dict::getDict('yeTx', 'can');
         }
         $shop->save();
+
+        $capitalType = dict::getDict('capitalType', 'xhPurchase', 'id');
+
+        //增加余额变动记录
+        $id = $order->id;
+        $change = [
+            'relateId' => $id,
+            'capitalType' => $capitalType,
+            'amount' => $amount,
+            'balance' => $currentBalance,
+            'txBalance' => $currentTxBalance,
+            'io' => 1,
+            'payWay' => $order->payWay,
+            'event' => "余额支付{$amount}元",
+            'sjId' => $sjId,
+            'shopId' => $shopId,
+            'tx' => $tx,
+        ];
+        ShopYeChangeClass::addChange($change, true);
+
+        //平台余额增加
+        PtAssetClass::reduceBalance($shop, $amount, $order, $capitalType, $tx);
+
     }
 
     //获取商家所有的门店 ssh 2021.2.26

+ 10 - 0
biz/sj/classes/SjClass.php

@@ -84,4 +84,14 @@ class SjClass extends BaseClass
         return true;
     }
 
+    //获取介绍人的门店 shish 2021.5.19
+    public static function getParentShopId($sjId)
+    {
+        $sj = self::getById($sjId, true);
+        if (empty($sj)) {
+            util::fail('没有介绍人商家信息');
+        }
+        return $sj->parentShopId;
+    }
+
 }

+ 2 - 1
common/components/dict.php

@@ -9,7 +9,7 @@ class dict
 
     public static $data = [
 
-        //余额提现
+        //本条流水的余额是否可以提现
         'yeTx' => [
             //不可以
             'canNot' => 1,
@@ -17,6 +17,7 @@ class dict
             'can' => 2,
         ],
 
+        //平台资产
         'ptAsset' => [
             'hdBalance' => ['id' => 1, 'name' => '零售平台余额'],
             'ghsBalance' => ['id' => 2, 'name' => '供货商平台余额'],