shish hai 1 ano
pai
achega
74d542c230
Modificáronse 2 ficheiros con 42 adicións e 4 borrados
  1. 41 1
      biz-hd/custom/classes/CustomClass.php
  2. 1 3
      biz-hd/order/classes/OrderClass.php

+ 41 - 1
biz-hd/custom/classes/CustomClass.php

@@ -22,13 +22,53 @@ class CustomClass extends BaseClass
     public static $baseFile = '\bizHd\custom\models\Custom';
 
     //用余额支付,客户余额减少 ssh 20250410
-    public static function payByChangeBalance($order)
+    public static function payToChangeBalance($order)
     {
+        $actPrice = $order->actPrice ?? 0;
+
         $hdId = $order->hdId ?? 0;
         $hd = HdClass::getLockById($hdId);
+        $balance = $hd->balance ?? 0;
+        if ($actPrice > $balance) {
+            util::fail('余额不足');
+        }
+        $remain = bcsub($balance, $actPrice, 2);
+        $hd->balance = $remain;
+        $hd->save();
 
         $customId = $order->customId ?? 0;
         $custom = self::getLockById($customId);
+        $balance = $custom->balance ?? 0;
+        if ($actPrice > $balance) {
+            util::fail('余额不足');
+        }
+        $remain = bcsub($balance, $actPrice, 2);
+        $custom->balance = $remain;
+        $custom->save();
+
+        if ($custom->balance != $hd->balance) {
+            util::fail('余额有问题哦');
+        }
+
+        $change = [
+            'customId' => $customId,
+            'customName' => $customName,
+            'relateId' => $relateId,
+            'onlinePay' => $onlinePay,
+            'capitalType' => $capitalType,
+            'amount' => $totalAmount,
+            'balance' => $hd->balance,
+            'io' => 1,
+            'side' => $side,
+            'payWay' => $payWay,
+            'event' => $event,
+            'staffId' => $staffId,
+            'staffName' => $staffName,
+            'shopId' => $shopId,
+            'mainId' => $mainId,
+            'remark' => '',
+        ];
+        $returnChange = BalanceChangeClass::add($change, true);
     }
 
     //会员等级变化,包括手动修改、自动降会员和充值升会员等 ssh 20250324

+ 1 - 3
biz-hd/order/classes/OrderClass.php

@@ -340,9 +340,7 @@ class OrderClass extends BaseClass
 
         //客户使用余额付款
         if ($payWay == dict::getDict('payWay', 'balancePay')) {
-            //客户端余额减少
-            //增加余额变动记录
-            CustomClass::payByChangeBalance($order);
+            CustomClass::payToChangeBalance($order);
         }
 
         //有尾款或全欠款