Browse Source

减少余额

shish 6 months ago
parent
commit
52a3d33ffc

+ 0 - 1
app-hd/controllers/DeductController.php

@@ -16,7 +16,6 @@ class DeductController extends BaseController
     //减少余额 ssh 20250329(这个方法应该建在CustomController的)
     //减少余额 ssh 20250329(这个方法应该建在CustomController的)
     public function actionDeductAmount()
     public function actionDeductAmount()
     {
     {
-        util::fail('即将上线');
         $post = Yii::$app->request->post();
         $post = Yii::$app->request->post();
         $customId = $post['customId'] ?? 0;
         $customId = $post['customId'] ?? 0;
         $remark = $post['remark'] ?? '';
         $remark = $post['remark'] ?? '';

+ 2 - 2
biz-hd/custom/classes/CustomClass.php

@@ -103,7 +103,7 @@ class CustomClass extends BaseClass
             }
             }
         }
         }
 
 
-        /************************* 充值余额 *****************************/
+        /************************* 使用充值余额 *****************************/
         $customBalancePay = bcsub($custom->balancePay, $payAmount, 2);
         $customBalancePay = bcsub($custom->balancePay, $payAmount, 2);
         $custom->balancePay = $customBalancePay;
         $custom->balancePay = $customBalancePay;
         $custom->save();
         $custom->save();
@@ -134,7 +134,7 @@ class CustomClass extends BaseClass
         $order->payBalance = $payAmount;
         $order->payBalance = $payAmount;
         $order->save();
         $order->save();
 
 
-        /***************************** 赠送余额 ******************************/
+        /***************************** 使用赠送余额 ******************************/
         //应用掉的赠送金额
         //应用掉的赠送金额
         if ($mustUseGiveAmount > 0) {
         if ($mustUseGiveAmount > 0) {
             $customBalanceGive = bcsub($custom->balanceGive, $mustUseGiveAmount, 2);
             $customBalanceGive = bcsub($custom->balanceGive, $mustUseGiveAmount, 2);

+ 85 - 0
biz-hd/deduct/classes/DeductClass.php

@@ -3,6 +3,8 @@
 namespace bizHd\deduct\classes;
 namespace bizHd\deduct\classes;
 
 
 use bizHd\balance\classes\BalanceChangeClass;
 use bizHd\balance\classes\BalanceChangeClass;
+use bizHd\balance\classes\BalanceGiveChangeClass;
+use bizHd\balance\classes\BalancePayChangeClass;
 use common\components\dict;
 use common\components\dict;
 use common\components\util;
 use common\components\util;
 use Yii;
 use Yii;
@@ -77,6 +79,89 @@ class DeductClass extends BaseClass
             'remark' => $remark,
             'remark' => $remark,
         ];
         ];
         BalanceChangeClass::add($change, true);
         BalanceChangeClass::add($change, true);
+
+        // 多处需要同步修改 balance_pay_give
+        if ($hd->balancePay >= $amount) {
+            $payAmount = $amount;
+            $mustUseGiveAmount = 0;
+        } else {
+            $payAmount = $hd->balancePay;
+            $mustUseGiveAmount = bcsub($amount, $payAmount, 2);
+            if ($mustUseGiveAmount > $hd->balanceGive) {
+                util::fail('赠送余额异常,不够扣');
+            }
+        }
+
+        /************************* 使用充值余额 *****************************/
+        $customBalancePay = bcsub($custom->balancePay, $payAmount, 2);
+        $custom->balancePay = $customBalancePay;
+        $custom->save();
+        $hdBalancePay = bcsub($hd->balancePay, $payAmount, 2);
+        $hd->balancePay = $hdBalancePay;
+        $hd->save();
+        $payChange = [
+            'hdId' => $hdId,
+            'hdName' => $hdName,
+            'customId' => $customId,
+            'customName' => $customName,
+            'relateId' => $relateId,
+            'onlinePay' => 1,
+            'capitalType' => $capitalType,
+            'amount' => $payAmount,
+            'balance' => $customBalancePay,
+            'io' => 0,
+            'side' => 0,
+            'payWay' => 0,
+            'event' => $event,
+            'staffId' => $staffId,
+            'staffName' => $staffName,
+            'shopId' => $shopId,
+            'mainId' => $mainId,
+            'remark' => '',
+        ];
+        BalancePayChangeClass::add($payChange, true);
+
+        /***************************** 使用赠送余额 ******************************/
+        //应用掉的赠送金额
+        if ($mustUseGiveAmount > 0) {
+            $customBalanceGive = bcsub($custom->balanceGive, $mustUseGiveAmount, 2);
+            if ($customBalanceGive < 0) {
+                util::fail('余额异常哈!请联系管理员,编号' . $hdId . ' ' . $custom->balanceGive);
+            }
+            $custom->balanceGive = $customBalanceGive;
+            $custom->save();
+            $hdBalanceGive = bcsub($hd->balanceGive, $mustUseGiveAmount, 2);
+            $hd->balanceGive = $hdBalanceGive;
+            $hd->save();
+            if (floatval($customBalanceGive) != floatval($hdBalanceGive)) {
+                util::fail('余额有问题呢!请联系管理员,编号' . $hdId);
+            }
+            $giveChange = [
+                'hdId' => $hdId,
+                'hdName' => $hdName,
+                'customId' => $customId,
+                'customName' => $customName,
+                'relateId' => $relateId,
+                'onlinePay' => 1,
+                'capitalType' => $capitalType,
+                'amount' => $mustUseGiveAmount,
+                'balance' => $customBalanceGive,
+                'io' => 0,
+                'side' => 0,
+                'payWay' => 0,
+                'event' => $event,
+                'staffId' => $staffId,
+                'staffName' => $staffName,
+                'shopId' => $shopId,
+                'mainId' => $mainId,
+                'remark' => '',
+            ];
+            BalanceGiveChangeClass::add($giveChange, true);
+        }
+        $addBalance = bcadd($hd->balancePay, $hd->balanceGive, 2);
+        if (floatval($addBalance) != floatval($custom->balance)) {
+            util::fail('账户余额有问题!请检查哈,编号' . $customId);
+        }
     }
     }
 
 
 }
 }