Browse Source

客户结帐增加余额

shish 5 năm trước cách đây
mục cha
commit
d404f3690f

+ 2 - 23
biz-hd/purchase/classes/PurchaseClearClass.php

@@ -137,30 +137,9 @@ class PurchaseClearClass extends BaseClass
         if (empty($shop)) {
             util::fail('没有找到供应商门店');
         }
-        //供应商的门店余额增加
         if ($payWay == dict::getDict('payWay', 'wxPay')) {
-            $balance = bcadd($shop->balance, $order->actPrice, 2);
-            $txBalance = bcadd($shop->txBalance, $order->actPrice, 2);
-            $shop->balance = $balance;
-            $shop->txBalance = $txBalance;
-            $shop->save();
-
-            $capitalType = dict::getDict('capitalType', 'hdPurchaseClear', 'id');
-            $change = [
-                'relateId' => $clearId,
-                'capitalType' => $capitalType,
-                'amount' => $order->actPrice,
-                'balance' => $balance,
-                'txBalance' => $txBalance,
-                'io' => 1,
-                'payWay' => $order->payWay,
-                'event' => "客户欠款结帐(订单:{$order->orderSn})",
-                'sjId' => $order->sjId,
-                'shopId' => $order->shopId,
-                'tx' => dict::getDict('yeTx', 'can'),
-                'ptStyle' => $shop->ptStyle,
-            ];
-            ShopYeChangeClass::addChange($change, true);
+            //供应商门店余额增加
+            ShopClass::customClearAddBalance($shop, $order);
         }
         //供应商的门店应收客户款减少
         $currentGathering = bcsub($shop->mayGathering, $order->actPrice, 2);

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

@@ -60,6 +60,61 @@ class PtAssetClass extends BaseClass
         PtYeChangeClass::addChange($change, true);
     }
 
+    //客户结帐增加加余额 shish 20210729
+    public static function customClearAddBalance($shop, $order, $capitalType, $tx)
+    {
+        $amount = $order->actPrice ?? 0;
+        $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;
+        if ($tx == dict::getDict('yeTx', 'can')) {
+            $currentTxBalance = bcadd($currentTxBalance, $amount, 2);
+            $txAsset->amount = $currentTxBalance;
+            $txAsset->save();
+        }
+        $sjName = $shop->merchantName ?? '';
+        if (isset($shop->default) == false || $shop->default != 1) {
+            $sjName .= ' ' . $shop->shopName;
+        }
+
+        $id = $order->id;
+        $event = "客户结帐给商家-{$sjName}(单号:{$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,
+            'ptStyle' => $ptStyle,
+            'shopName' => $shop->shopName,
+            'sjName' => $shop->merchantName,
+        ];
+        PtYeChangeClass::addChange($change, true);
+    }
+
     //客户使用优惠券增加余额 shish 20210601
     public static function customKdUseCouponAddBalance($shop, $order, $capitalType, $tx)
     {
@@ -274,7 +329,6 @@ class PtAssetClass extends BaseClass
         PtYeChangeClass::addChange($change, true);
     }
 
-
     //零售平台余额对象 shish 20210519
     public static function getHdBalance()
     {

+ 33 - 1
biz/shop/classes/ShopClass.php

@@ -182,6 +182,38 @@ class ShopClass extends BaseClass
         return $imgUrl;
     }
 
+    //客户结帐增加余额 shish 20210729
+    public static function customClearAddBalance($shop, $order)
+    {
+        $balance = bcadd($shop->balance, $order->actPrice, 2);
+        $txBalance = bcadd($shop->txBalance, $order->actPrice, 2);
+        $shop->balance = $balance;
+        $shop->txBalance = $txBalance;
+        $shop->save();
+        $clearId = $order->id ?? 0;
+        $tx = dict::getDict('yeTx', 'can');
+        $capitalType = dict::getDict('capitalType', 'hdPurchaseClear', 'id');
+        $change = [
+            'relateId' => $clearId,
+            'capitalType' => $capitalType,
+            'amount' => $order->actPrice,
+            'balance' => $balance,
+            'txBalance' => $txBalance,
+            'io' => 1,
+            'payWay' => $order->payWay,
+            'event' => "客户结帐(单号:{$order->orderSn})",
+            'sjId' => $shop->sjId,
+            'shopId' => $shop->id,
+            'tx' => $tx,
+            'ptStyle' => $shop->ptStyle,
+        ];
+        ShopYeChangeClass::addChange($change, true);
+
+        //平台余额增加
+        PtAssetClass::customClearAddBalance($shop, $order, $capitalType, $tx);
+
+    }
+
     //客户使用优惠券增加余额 shish 20210601
     public static function customKdUseCouponAddBalance($shop, $order, $capitalType)
     {
@@ -233,7 +265,7 @@ class ShopClass extends BaseClass
 
         //增加余额变动记录
         $id = $order->id;
-        $event = "客户下单 {$amount}元";
+        $event = "客户下单{$amount}元";
         $tx = dict::getDict('yeTx', 'can');
         $change = [
             'relateId' => $id,

+ 5 - 5
common/components/payUtil.php

@@ -36,23 +36,23 @@ class payUtil
             //流水类型列表
             switch ($capitalType) {
                 case dict::getDict('capitalType', 'xhRecharge', 'id'):
-                    //零售和供应商充值
+                    //商充值
                     RechargeClass::thirdPay($payWay, $orderSn, $totalFee, $attach);
                     break;
                 case dict::getDict('capitalType', 'xhPurchase', 'id'):
-                    //零售采购订单
+                    //零售采购
                     PurchaseService::thirdPay($payWay, $orderSn, $totalFee, $attach, $transactionId);
                     break;
                 case dict::getDict('capitalType', 'hdPurchaseClear', 'id'):
-                    //零售采购订单结清欠款
+                    //零售结帐
                     PurchaseClearClass::thirdPay($payWay, $orderSn, $totalFee, $attach);
                     break;
                 case dict::getDict('capitalType', 'xhOrder', 'id'):
-                    //零售订
+                    //花粉下
                     OrderClass::thirdPay($payWay, $orderSn, $totalFee, $attach);
                     break;
                 case dict::getDict('capitalType', 'xhRenew', 'id'):
-                    //零售和供应商续费订单
+                    //商家续期
                     RenewClass::thirdPay($payWay, $orderSn, $totalFee, $attach);
                     break;
                 case dict::getDict('capitalType', 'pxApply', 'id'):