shish 3 жил өмнө
parent
commit
8dba95124d

+ 64 - 0
app-hd/controllers/RefundController.php

@@ -2,11 +2,15 @@
 //退款退货
 namespace hd\controllers;
 
+use biz\shop\classes\ShopExtClass;
 use bizHd\order\classes\OrderClass;
+use bizHd\order\classes\OrderGoodsClass;
+use bizHd\order\classes\OrderItemClass;
 use bizHd\refund\classes\HdRefundClass;
 use bizHd\refund\classes\HdRefundGoodsClass;
 use bizHd\refund\classes\HdRefundItemClass;
 use bizHd\refund\services\HdRefundService;
+use common\components\noticeUtil;
 use Yii;
 use common\components\util;
 
@@ -109,6 +113,11 @@ class RefundController extends BaseController
             HdRefundService::addRefund($post, $order);
             $transaction->commit();
 
+            //制作单取消通知
+            $shopId = $this->shopId ?? 0;
+            $shopExt = ShopExtClass::getByCondition(['shopId' => $shopId], true);
+            ShopExtClass::orderCancelRemind($shopExt, $order);
+
         } catch (\Exception $exception) {
             $transaction->rollBack();
             Yii::info("出错了:" . $exception->getMessage());
@@ -117,4 +126,59 @@ class RefundController extends BaseController
         util::complete();
     }
 
+    public function actionAllRefund()
+    {
+        $get = Yii::$app->request->get();
+
+        $connection = Yii::$app->db;//事务处理
+        $transaction = $connection->beginTransaction();
+        try {
+            $id = $get['id'] ?? 0;
+            $order = OrderClass::getById($id, true);
+            OrderClass::valid($order, $this->mainId);
+
+            $shopId = $this->shopId ?? 0;
+            $sjId = $this->sjId ?? 0;
+            $mainId = $this->mainId ?? 0;
+            $post = [];
+            $post['price'] = $order->actPrice ?? 0;
+            $post['refundType'] = HdRefundClass::REFUND_TYPE_MONEY_GOOD;
+            $post['id'] = $order->id ?? 0;
+            $post['shopId'] = $shopId;
+            $post['sjId'] = $sjId;
+            $post['shopAdminId'] = 0;
+            $post['mainId'] = $mainId;
+            $staff = $this->shopAdmin;
+            $post['shopAdminName'] = $staff->name ?? '';
+            $orderSn = $order->orderSn ?? '';
+            $orderGoods = OrderGoodsClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
+            $productData = [];
+            if (!empty($orderGoods)) {
+                foreach ($orderGoods as $goodsItem) {
+                    $productData[] = ['productId' => $goodsItem->goodsId, 'num' => $goodsItem->num, 'unitPrice' => $goodsItem->unitPrice, 'property' => 0,];
+                }
+            }
+            $orderItem = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
+            if (!empty($orderItem)) {
+                foreach ($orderItem as $singe) {
+                    $productData[] = ['productId' => $singe->itemId, 'num' => $singe->num, 'unitPrice' => $singe->unitPrice, 'property' => 1,];
+                }
+            }
+            $post['product'] = $productData;
+            HdRefundService::addRefund($post, $order);
+
+            $transaction->commit();
+
+            //制作单取消通知
+            $shopExt = ShopExtClass::getByCondition(['shopId' => $shopId], true);
+            ShopExtClass::orderCancelRemind($shopExt, $order);
+
+        } catch (\Exception $e) {
+            $transaction->rollBack();
+            $msg = $e->getMessage();
+            noticeUtil::push("取消报错了,错误信息:{$msg}", '15280215347');
+            util::fail('退款失败');
+        }
+    }
+
 }

+ 1 - 1
biz-hd/order/classes/OrderGoodsClass.php

@@ -77,7 +77,7 @@ class OrderGoodsClass extends BaseClass
     {
         //取消制作单
         $work = WorkClass::getByCondition(['orderId' => $orderId, 'goodsId' => $goodsId], true);
-        WorkClass::removeWork($work);
+        WorkClass::removeWork($work, $goodsNum);
 
         //加商品库存
         $respond = GoodsClass::addStock($goodsId, $mainId, $goodsNum);

+ 8 - 3
biz-hd/work/classes/WorkClass.php

@@ -235,7 +235,7 @@ class WorkClass extends BaseClass
     }
 
     //美团取消订单同时取消制作单 ssh 20220925
-    public static function removeWork($work)
+    public static function removeWork($work, $num)
     {
         if (empty($work)) {
             return false;
@@ -243,8 +243,13 @@ class WorkClass extends BaseClass
         if ($work->status != 0) {
             return false;
         }
-        $work->status = 2;
-        $work->save();
+        if ($work->num <= $num) {
+            $work->status = 2;
+            $work->save();
+        } else {
+            $work->num = bcsub($work->num, $num);
+            $work->save();
+        }
     }
 
     //取消制作单

+ 2 - 2
biz/shop/classes/ShopExtClass.php

@@ -17,10 +17,10 @@ class ShopExtClass extends BaseClass
     public static function orderCancelRemind($shopExt, $order)
     {
         $sendNum = $order->sendNum ?? 0;
-        $sound = $sendNum . '号单已被取消';
+        $sound = $sendNum . '号单已被取消或修改';
         if ($order->fromType == 4) {
             $mtSn = $order->thirdSn ?? 0;
-            $sound = '美团' . $mtSn . '号单已被取消';
+            $sound = '美团' . $mtSn . '号单已被取消或修改';
         }
         $hasSh = 0;
         $hasHs = 0;