shish 4 rokov pred
rodič
commit
9a02b5bf67
1 zmenil súbory, kde vykonal 88 pridanie a 78 odobranie
  1. 88 78
      biz-ghs/order/services/RefundOrderService.php

+ 88 - 78
biz-ghs/order/services/RefundOrderService.php

@@ -35,6 +35,8 @@ class RefundOrderService extends BaseService
         $order->refund = OrderClass::REFUND_YES;
         $order->save();
 
+        $onlinePay = $order->onlinePay ?? 1;
+
         $refundPrice = $post['price'] ?? 0;
         if ($refundPrice <= 0) {
             util::fail('请填写退款金额');
@@ -179,98 +181,106 @@ class RefundOrderService extends BaseService
         $order->refund = OrderClass::REFUND_YES;
         $order->save();
 
-        //退款流程
-        if ($payWay == dict::getDict('payWay', 'wxPay')) {
 
-            $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;
-            $order->save();
+        if ($onlinePay == dict::getDict('onlinePay', 'yes')) {
+            //退款流程
+            if ($payWay == dict::getDict('payWay', 'wxPay')) {
 
-            //门店余额减少
-            ShopClass::saleRefundReduceBalance($main, $shop, $refund, $refundPrice);
-        } elseif ($payWay == dict::getDict('payWay', 'debtPay')) {
+                $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;
+                $order->save();
 
-            $clearId = $order->clearId;
-            if (!empty($clearId)) {
-                util::fail('订单已结账,无法再发起退款');
+                //门店余额减少
+                ShopClass::saleRefundReduceBalance($main, $shop, $refund, $refundPrice);
+            } else {
+                util::fail('此支付方式暂不支持退款');
             }
+        } else {
+            if ($payWay == dict::getDict('payWay', 'debtPay')) {
 
-            //门店应收款减少
-            $currentMayGathering = bcsub($main->mayGathering, $refundPrice, 2);
-            if ($currentMayGathering < 0) {
-                util::fail('应付款有问题');
-            }
-            $main->mayGathering = $currentMayGathering;
-            $main->save();
+                $clearId = $order->clearId;
+                if (!empty($clearId)) {
+                    util::fail('订单已结账,无法再发起退款');
+                }
 
-            //订单总金额需要减掉退款部分
-            $currentRefund = bcadd($order->refundPrice, $refundPrice, 2);
-            $order->refundPrice = $currentRefund;
+                //门店应收款减少
+                $currentMayGathering = bcsub($main->mayGathering, $refundPrice, 2);
+                if ($currentMayGathering < 0) {
+                    util::fail('应付款有问题');
+                }
+                $main->mayGathering = $currentMayGathering;
+                $main->save();
 
-            $currentActPrice = bcsub($order->actPrice, $refundPrice, 2);
-            if ($currentActPrice < 0) {
-                util::fail('退款金额有问题!');
-            }
-            $order->actPrice = $currentActPrice;
+                //订单总金额需要减掉退款部分
+                $currentRefund = bcadd($order->refundPrice, $refundPrice, 2);
+                $order->refundPrice = $currentRefund;
 
-            $currentRealPrice = bcsub($order->realPrice, $refundPrice, 2);
-            if ($currentRealPrice < 0) {
-                util::fail('退款金额有问题,请排查');
-            }
-            $order->realPrice = $currentRealPrice;
+                $currentActPrice = bcsub($order->actPrice, $refundPrice, 2);
+                if ($currentActPrice < 0) {
+                    util::fail('退款金额有问题!');
+                }
+                $order->actPrice = $currentActPrice;
 
-            $currentRemainDebt = bcsub($order->remainDebtPrice, $refundPrice, 2);
-            if ($currentRemainDebt < 0) {
-                util::fail('退款金额有问题');
-            }
-            if ($currentRemainDebt == 0) {
-                $order->debt = OrderClass::DEBT_NO;
-            }
-            $order->remainDebtPrice = $currentRemainDebt;
-            $order->save();
-
-            //门店客户欠款减少
-            $customId = $order->customId;
-            $custom = CustomClass::getLockById($customId);
-            if (empty($custom)) {
-                util::fail('没有找到客户');
-            }
+                $currentRealPrice = bcsub($order->realPrice, $refundPrice, 2);
+                if ($currentRealPrice < 0) {
+                    util::fail('退款金额有问题,请排查');
+                }
+                $order->realPrice = $currentRealPrice;
 
-            //客户欠款金额减少
-            CustomClass::refundDebtAmountReduce($custom, $refund, $order);
+                $currentRemainDebt = bcsub($order->remainDebtPrice, $refundPrice, 2);
+                if ($currentRemainDebt < 0) {
+                    util::fail('退款金额有问题');
+                }
+                if ($currentRemainDebt == 0) {
+                    $order->debt = OrderClass::DEBT_NO;
+                }
+                $order->remainDebtPrice = $currentRemainDebt;
+                $order->save();
+
+                //门店客户欠款减少
+                $customId = $order->customId;
+                $custom = CustomClass::getLockById($customId);
+                if (empty($custom)) {
+                    util::fail('没有找到客户');
+                }
 
-        } elseif ($payWay == dict::getDict('payWay', 'balancePay')) {
+                //客户欠款金额减少
+                CustomClass::refundDebtAmountReduce($custom, $refund, $order);
 
-            $currentRefund = bcadd($order->refundPrice, $refundPrice, 2);
-            $order->refundPrice = $currentRefund;
-            $currentActPrice = bcsub($order->actPrice, $refundPrice, 2);
-            if ($currentActPrice < 0) {
-                util::fail('退款金额有问题!');
-            }
-            $currentRealPrice = bcsub($order->realPrice, $refundPrice, 2);
-            if ($currentRealPrice < 0) {
-                util::fail('退款金额有问题');
-            }
-            $order->actPrice = $currentActPrice;
-            $order->realPrice = $currentRealPrice;
-            $order->save();
+            } elseif ($payWay == dict::getDict('payWay', 'balancePay')) {
 
-            //门店余额减少
-            ShopClass::saleRefundReduceBalance($main, $shop, $refund, $refundPrice);
-        } else {
-            util::fail('此支付方式暂不支持线上退款');
-        }
+                util::fail('余额支付暂不支持退款');
 
+                $currentRefund = bcadd($order->refundPrice, $refundPrice, 2);
+                $order->refundPrice = $currentRefund;
+                $currentActPrice = bcsub($order->actPrice, $refundPrice, 2);
+                if ($currentActPrice < 0) {
+                    util::fail('退款金额有问题!');
+                }
+                $currentRealPrice = bcsub($order->realPrice, $refundPrice, 2);
+                if ($currentRealPrice < 0) {
+                    util::fail('退款金额有问题');
+                }
+                $order->actPrice = $currentActPrice;
+                $order->realPrice = $currentRealPrice;
+                $order->save();
+
+                //门店余额减少
+                ShopClass::saleRefundReduceBalance($main, $shop, $refund, $refundPrice);
+            } else {
+                //其它线下退款直接完成
+            }
+        }
         return $refund;
     }
 }