shish пре 1 година
родитељ
комит
090ff39f6e

+ 17 - 5
app-hd/controllers/RefundController.php

@@ -29,11 +29,23 @@ class RefundController extends BaseController
         if ($order->mainId != $this->mainId) {
             util::fail('不是你的订单');
         }
-        $shop = $this->shop;
-        $respond = HdRefundClass::onlyRefundAmount($shop, $order);
-        $status = $respond['status'];
-        $msg = $respond['msg'];
-        util::success(['status' => $status], $msg);
+
+        $connection = Yii::$app->db;
+        $transaction = $connection->beginTransaction();
+        try {
+
+            $shop = $this->shop;
+            $respond = HdRefundClass::onlyRefundAmount($shop, $order);
+            $status = $respond['status'];
+            $msg = $respond['msg'];
+            $transaction->commit();
+            util::success(['status' => $status], $msg);
+
+        } catch (\Exception $exception) {
+            $transaction->rollBack();
+            util::fail('操作失败');
+        }
+
     }
 
     //列表

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

@@ -265,7 +265,12 @@ class OrderClass extends BaseClass
             $shopId = $order->shopId;
             $shop = ShopClass::getById($shopId, true);
             if (!empty($shop)) {
-                //HdRefundClass::onlyRefundAmount($shop, $order);
+                $respond = HdRefundClass::onlyRefundAmount($shop, $order);
+                $status = $respond['status'] ?? 0;
+                if ($status == 1) {
+                    $shopId = $respond['shopId'] ?? 0;
+                    ShopExtClass::orderCancelBackMoneyReport($shopId);
+                }
             }
             util::stop("SUCCESS");
         }

+ 10 - 4
biz-hd/refund/classes/HdRefundClass.php

@@ -3,6 +3,7 @@
 namespace bizHd\refund\classes;
 
 use biz\shop\classes\ShopExtClass;
+use bizHd\shop\classes\MainClass;
 use common\components\noticeUtil;
 use common\components\orderSn;
 use Yii;
@@ -40,7 +41,7 @@ class HdRefundClass extends BaseClass
         $refundReason = '';
         $orderSn = '';
         $thirdNo = $order->thirdNo ?? '';
-		//竟然会出现thirdNo为空的情况,好像客户付款时有优惠金额时
+        //竟然会出现thirdNo为空的情况,好像客户付款时有优惠金额时
         if (empty($thirdNo)) {
             $orderSn = $order->orderSn ?? '';
         }
@@ -55,15 +56,20 @@ class HdRefundClass extends BaseClass
         if (!isset($response['code']) || $response['code'] != 'BBS00000') {
             $errMsg = $response['msg'] ?? '';
             noticeUtil::push("钱没有退回 {$xsOrderSn} {$errMsg}", '15280215347');
-            return ['status' => 0, 'msg' => $errMsg];
+            return ['status' => 0, 'msg' => $errMsg, 'shopId' => 0];
         } else {
+
             $shopId = $shop->id;
-            ShopExtClass::orderCancelBackMoneyReport($shopId);
+            $mainId = $shop->mainId;
+            $main = MainClass::getLockById($mainId);
+            $refund = ['id' => 0, 'refundSn' => $refundSn, 'orderSn' => ''];
+            \biz\shop\classes\ShopClass::hdSaleRefundReduceBalance($main, $shop, $refund, $refundPrice);
+
             $sjName = $shop->merchantName;
             $shopName = $shop->shopName;
             $name = $shopName == '首店' ? $sjName : $sjName . '-' . $shopName;
             noticeUtil::push("钱已经原路退回 success {$xsOrderSn} {$name}", '15280215347');
-            return ['status' => 1, 'msg' => '退款成功'];
+            return ['status' => 1, 'msg' => '退款成功', 'shopId' => $shopId];
         }
     }
 

+ 6 - 5
biz/shop/classes/ShopClass.php

@@ -592,15 +592,16 @@ class ShopClass extends BaseClass
         $main->save();
 
         $currentType = dict::getDict('capitalType', 'hdOrderRefund');
-        $id = $refund->id;
-        $event = "退款给客户(退款单 {$refund->refundSn})";
+        $id = $refund['id'];
+        $refundSn = $refund['refundSn']??'';
+        $event = "退款给客户(退款单 {$refundSn})";
 
-        $relateOrderSn = $refund->orderSn ?? '';
+        $relateOrderSn = $refund['orderSn'] ?? '';
         if (!empty($relateOrderSn)) {
             $relateOrder = OrderClass::getByCondition(['orderSn' => $relateOrderSn], true);
             $customName = $relateOrder->customName ?? '';
             if (!empty($customName)) {
-                $event = "退款给{$customName}(退款单 {$refund->refundSn})";
+                $event = "退款给{$customName}(退款单 {$refundSn})";
             }
         }
 
@@ -623,7 +624,7 @@ class ShopClass extends BaseClass
         ShopYeChangeClass::addChange($change, true);
 
         //平台余额增加
-        PtAssetClass::hdSaleRefundReduceBalance($shop, $refund, $refundPrice);
+        //PtAssetClass::hdSaleRefundReduceBalance($shop, $refund, $refundPrice);
     }
 
     //销售单退款减少余额 ssh 2021.2.21