Explorar el Código

欠款金额调整

shish hace 4 años
padre
commit
42840614df

+ 9 - 1
biz-ghs/order/services/RefundOrderService.php

@@ -216,19 +216,27 @@ class RefundOrderService extends BaseService
             //订单总金额需要减掉退款部分
             $currentRefund = bcadd($order->refundPrice, $refundPrice, 2);
             $order->refundPrice = $currentRefund;
+
             $currentActPrice = bcsub($order->actPrice, $refundPrice, 2);
             if ($currentActPrice < 0) {
                 util::fail('退款金额有问题!');
             }
             $order->actPrice = $currentActPrice;
+
             $currentRealPrice = bcsub($order->realPrice, $refundPrice, 2);
             if ($currentRealPrice < 0) {
                 util::fail('退款金额有问题,请排查');
             }
             $order->realPrice = $currentRealPrice;
-            if ($currentRealPrice == 0) {
+
+            $currentRemainDebt = bcsub($order->remainDebtPrice, $refundPrice, 2);
+            if ($currentRemainDebt < 0) {
+                util::fail('退款金额有问题');
+            }
+            if ($currentRemainDebt == 0) {
                 $order->debt = OrderClass::DEBT_NO;
             }
+            $order->remainDebtPrice = $currentRemainDebt;
             $order->save();
 
             //门店客户欠款减少

+ 10 - 4
biz-hd/cg/services/CgRefundService.php

@@ -224,19 +224,27 @@ class CgRefundService extends BaseService
             //采购单总金额还要减去退款
             $currentRefund = bcadd($cg->refundPrice, $refundPrice, 2);
             $cg->refundPrice = $currentRefund;
+
             $currentActPrice = bcsub($cg->actPrice, $refundPrice, 2);
             if ($currentActPrice < 0) {
                 util::fail('退款金额有问题!');
             }
             $cg->actPrice = $currentActPrice;
+
             $currentRealPrice = bcsub($cg->realPrice, $refundPrice, 2);
             if ($currentRealPrice < 0) {
                 util::fail('退款金额有问题,请排查');
             }
-            if ($currentRealPrice == 0) {
+            $cg->realPrice = $currentRealPrice;
+
+            $currentRemainDebt = bcsub($cg->remainDebtPrice, $refundPrice, 2);
+            if ($currentRemainDebt < 0) {
+                util::fail('退款金额有问题哦');
+            }
+            if ($currentRemainDebt == 0) {
                 $cg->debt = PurchaseClass::DEBT_NO;
             }
-            $cg->realPrice = $currentRealPrice;
+            $cg->remainDebtPrice = $currentRemainDebt;
             $cg->save();
 
             //门店应付总款减少
@@ -247,11 +255,9 @@ class CgRefundService extends BaseService
             $main->mayPay = $currentMayPay;
             $main->save();
 
-
             //应付供应商款减少
             \bizHd\ghs\classes\GhsClass::refundDebtAmountReduce($ghs, $cgRefund, $cg);
 
-
         } elseif ($payWay == dict::getDict('payWay', 'balancePay')) {
 
             //采购单总金额还要减去退款