shish hace 1 año
padre
commit
8c517c045c

+ 7 - 25
app-hd/controllers/OrderController.php

@@ -942,31 +942,13 @@ class OrderController extends BaseController
         $detail = OrderClass::getFullInfo($id);
         OrderService::valid($detail, $this->mainId);
 
-        //0表示按正常流程售后,1表示开负数订单售后
-        $addMinusOrderRefund = 0;
-        //只能开负数订单的几种情况:0、开的欠款单,并且已经全部或者部分结清,1、可售后时间到了
-        $addMinusOrderReason = 0;
-        if ($detail['payWay'] == 3) {
-            if ($detail['debtPrice'] > $detail['remainDebtPrice']) {
-                $addMinusOrderRefund = 1;
-            }
-        }
-        $mainId = $this->mainId;
-        $main = MainClass::getById($mainId, true);
-        $refundLimit = $main->refundLimit ?? 0;
-        if ($refundLimit > 0) {
-            $payTime = $main->payTime;
-            $currentPayTime = strtotime($payTime);
-            $addDateTime = $refundLimit * 86400;
-            $refundDeadTime = $currentPayTime + $addDateTime;
-            $now = time();
-            if ($now > $refundDeadTime) {
-                $addMinusOrderRefund = 1;
-                $addMinusOrderReason = 1;
-            }
-        }
-        $detail['addMinusOrderRefund'] = $addMinusOrderRefund;
-        $detail['addMinusOrderReason'] = $addMinusOrderReason;
+        $main = $this->main;
+        //是否要走开负数订单模式判断 ssh
+        $ret = OrderClass::ifMinusRefund($detail, $main, 0);
+        $minusOrderRefund = $ret['minusOrderRefund'];
+        $minusOrderReason = $ret['minusOrderReason'];
+        $detail['minusOrderRefund'] = $minusOrderRefund;
+        $detail['minusOrderReason'] = $minusOrderReason;
 
         util::success($detail);
     }

+ 15 - 2
app-hd/controllers/RefundController.php

@@ -92,6 +92,9 @@ class RefundController extends BaseController
 
             $order = OrderClass::getById($id, true);
             OrderClass::valid($order, $this->mainId);
+            if ($order->payStatus == 0) {
+                util::fail('订单没有付款');
+            }
             if ($order->status == OrderClass::ORDER_STATUS_UN_PAY) {
                 util::fail("待付款订单无法退款");
             }
@@ -102,7 +105,7 @@ class RefundController extends BaseController
                 util::fail('请在美团APP发起退货退款');
             }
             if ($order->debt != 1 && $order->addTime < '2023-10-17 00:00:00') {
-                util::fail('10月17日前订单无法申请退款');
+                util::fail('2023年10月17日前订单无法申请退款');
             }
 
             if ($order->payWay == 2) {
@@ -145,7 +148,17 @@ class RefundController extends BaseController
             $shopAdmin = $this->shopAdmin;
             $adminName = $shopAdmin['name'] ?? '';
             $post['shopAdminName'] = $adminName;
-            HdRefundService::addRefund($post, $order);
+
+            $main = $this->main;
+            //判断是否开负数订单
+            $ret = OrderClass::ifMinusRefund($order, $main, $post['price']);
+            $minusOrderRefund = $ret['minusOrderRefund'] ?? 0;
+            if ($minusOrderRefund == 1) {
+                //走负数订单
+            } else {
+                //走正常售后
+                HdRefundService::addRefund($post, $order);
+            }
             $transaction->commit();
 
             //制作单取消通知

+ 49 - 0
biz-hd/order/classes/OrderClass.php

@@ -86,6 +86,55 @@ class OrderClass extends BaseClass
         20000 => [90, 100],
     ];
 
+    /**
+     * @param $order
+     * @param $mainId
+     * @return array
+     * $minusOrderRefund 0走正常流程售后,1走开负数订单售后
+     * $minusOrderReason 只能开负数订单的原因:0、售后金额大于剩余欠款(剩余欠款可能没有了,可能还有);1、可售后时间到了
+     */
+    public static function ifMinusRefund($order, $main, $refundAmount = 0)
+    {
+        $minusOrderRefund = 0;
+        $minusOrderReason = 0;
+        $payStatus = $order['payStatus'] ?? 0;
+        if ($payStatus == 1) {
+            if ($order['payWay'] == 3) {
+                if ($order['remainDebtPrice'] <= 0) {
+                    //不管是否要售后,没有剩余欠款了,只能走开负数订单模式
+                    $minusOrderRefund = 1;
+                } else {
+                    if ($refundAmount > 0 && $refundAmount > $order['remainDebtPrice']) {
+                        //如果需要售后,并且售后金额大于剩余欠款,走开负数订单模式
+                        $minusOrderRefund = 1;
+                    }
+                }
+            }
+            $cRet = OrderClass::couldRefund($order, $main);
+            $could = $cRet['could'];
+            if (!$could) {
+                //可售后时间到了
+                $minusOrderRefund = 1;
+                $minusOrderReason = 1;
+            }
+        }
+        return ['minusOrderRefund' => $minusOrderRefund, 'minusOrderReason' => $minusOrderReason];
+    }
+
+    //订单是否过了可以售后的时间 ssh 20250730
+    // $could false 过了售后时间,不能售后,true可以
+    public static function couldRefund($order, $main)
+    {
+        $refundLimit = $main->refundLimit ?? 0;
+        $payTime = $order['payTime'];
+        $currentPayTime = strtotime($payTime);
+        $addDateTime = $refundLimit * 86400;
+        $couldRefundTime = $currentPayTime + $addDateTime;
+        $now = time();
+        $could = $couldRefundTime > $now;
+        return ['could' => $could];
+    }
+
     public static function valid($order, $mainId)
     {
         if (isset($order->mainId) == false || $order->mainId != $mainId) {

+ 11 - 20
biz-hd/refund/services/HdRefundService.php

@@ -82,6 +82,7 @@ class HdRefundService extends BaseService
         }
         $goodsInfoList = [];
         $itemInfoList = [];
+        $calcAmount = 0;
         foreach ($postProduct as $current) {
             $property = $current['property'] ?? 0;
             if ($property == 0) {
@@ -89,7 +90,16 @@ class HdRefundService extends BaseService
             } else {
                 $itemInfoList[] = $current;
             }
+            $calcNum = $current['num'] ?? 0;
+            $calcUnitPrice = $current['unitPrice'] ?? 0;
+            $calcPrice = bcmul($calcNum, $calcUnitPrice, 2);
+            $calcAmount = bcadd($calcAmount, $calcPrice, 2);
         }
+
+        if (floatval($refundPrice) != floatval($calcAmount)) {
+            util::fail('数量与单价的总乘积,与退款金额不一致');
+        }
+
         if (!empty($itemInfoList)) {
             $ids = array_column($itemInfoList, 'productId');
             $productInfo = ProductClass::getByids($ids, null, 'id');
@@ -185,7 +195,6 @@ class HdRefundService extends BaseService
             }
         }
 
-
         $data['customId'] = $order->customId ?? 0;
         $data['remark'] = $post['remark'] ?? '';
         $data['refundPrice'] = $refundPrice;
@@ -288,25 +297,8 @@ class HdRefundService extends BaseService
 
                 CustomClass::refundDebtAmountReduce($custom, $refundPrice, $refund);
 
-            } else {
-                //部分欠款的订单,付了订金的订单
-                if ($order->remainDebtPrice > 0) {
-                    if ($refundPrice > $order->remainDebtPrice) {
-                        CustomClass::refundDebtAmountReduce($custom, $order->remainDebtPrice, $refund);
-                        $order->remainDebtPrice = 0;
-                        $order->debt = 0;
-                        $order->save();
-                    } else {
-                        CustomClass::refundDebtAmountReduce($custom, $refundPrice, $refund);
-                        $currentRemain = bcsub($order->remainDebtPrice, $refundPrice, 2);
-                        $order->remainDebtPrice = $currentRemain;
-                        if ($currentRemain <= 0) {
-                            $order->debt = 0;
-                        }
-                        $order->save();
-                    }
-                }
             }
+
             if ($payWay == dict::getDict('payWay', 'cash')) {
                 $moneyData = [
                     'shopId' => $shopId,
@@ -316,7 +308,6 @@ class HdRefundService extends BaseService
                 ];
                 ShopMoneyClass::hdRefundSkOutAmount($moneyData, $main);
             }
-
         }
         return $refund;
     }