浏览代码

fix: 小程序订单服务收货逻辑

Gosowong 2 年之前
父节点
当前提交
852fa790ed

+ 6 - 1
crmeb/app/dao/order/StoreOrderDao.php

@@ -980,6 +980,11 @@ class StoreOrderDao extends BaseDao
 
     public function getSubOrderNotSend(int $pid, int $order_id)
     {
-        return $this->getModel()->where('pid', $pid)->where('status', '0')->where('id', '<>', $order_id)->count();
+        return $this->getModel()->where('pid', $pid)->where('status', 0)->where('id', '<>', $order_id)->count();
+    }
+
+    public function getSubOrderNotTake(int $pid, int $order_id)
+    {
+        return $this->getModel()->where('pid', $pid)->where('status', 1)->where('id', '<>', $order_id)->count();
     }
 }

+ 1 - 1
crmeb/app/listener/order/OrderShippingListener.php

@@ -18,7 +18,7 @@ class OrderShippingListener implements ListenerInterface
         [$order, $delivery_type, $delivery_id, $delivery_name] = $event;
         $order_shipping_open = sys_config('order_shipping_open', 0);  // 小程序发货信息管理服务开关
         if ($order && $order_shipping_open) {
-            if ($order['channel_type'] = 'routine') {
+            if ($order['is_channel'] == 1 && $order['pay_type'] == 'weixin') {
                 $out_trade_no = $order['order_id'];
                 //判断订单是否拆单
                 $delivery_mode = 1;

+ 20 - 2
crmeb/app/services/order/StoreOrderServices.php

@@ -2498,8 +2498,16 @@ HTML;
         }
         // 判断是否开启小程序订单管理
         $orderData['order_shipping_open'] = false;
-        if (sys_config('order_shipping_open', 0) && MiniOrderService::isManaged() && $order['channel_type'] == 'routine') {
-            $orderData['order_shipping_open'] = true;
+        if (sys_config('order_shipping_open', 0) && MiniOrderService::isManaged() && $order['is_channel'] == 1 && $order['pay_type'] == 'weixin') {
+            // 判断是否存在子未收货子订单
+            if ($order['pid'] > 0) {
+                if ($this->checkSubOrderNotTake((int)$order['pid'], (int)$order['id'])) {
+                    $orderData['order_shipping_open'] = true;
+                }
+            } else {
+                $orderData['order_shipping_open'] = true;
+            }
+
         }
         return $orderData;
     }
@@ -2713,4 +2721,14 @@ HTML;
             return true;
         }
     }
+
+    public function checkSubOrderNotTake(int $pid, int $order_id)
+    {
+        $order_count = $this->dao->getSubOrderNotTake($pid, $order_id);
+        if ($order_count > 0) {
+            return false;
+        } else {
+            return true;
+        }
+    }
 }

+ 31 - 0
crmeb/app/services/order/StoreOrderTakeServices.php

@@ -42,6 +42,37 @@ class StoreOrderTakeServices extends BaseServices
         $this->dao = $dao;
     }
 
+    /**
+     * 小程序订单服务收货
+     * @param $merchant_trade_no
+     * @return bool
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     *
+     * @date 2023/05/18
+     * @author yyw
+     */
+    public function miniOrderTakeOrder($merchant_trade_no)
+    {
+        //查找订单信息
+        $order = $this->dao->getOne(['order_id' => $merchant_trade_no]);
+        if (!$order) {
+            throw new ApiException(410173);
+        }
+        if ($order == -1) {  // 有子订单
+            // 查找待收货的子订单
+            $son_order_list = $this->dao->getList(['pid' => $order['id'], 'pay_type' => 'weixin', 'is_channel' => 1, 'status' => 1, 'refund_status' => 0], ['*']);
+            foreach ($son_order_list as $son_order) {
+                $this->takeOrder($son_order['order_id'], $son_order['uid']);
+            }
+        } else {
+            $this->takeOrder($merchant_trade_no, $order['uid']);
+        }
+
+        return true;
+    }
+
     /**
      * 用户订单收货
      * @param $uni

+ 1 - 1
crmeb/crmeb/services/app/MiniProgramService.php

@@ -892,7 +892,7 @@ class MiniProgramService
                             if (isset($message['confirm_receive_method'])) {  // 订单结算时
                                 /** @var StoreOrderTakeServices $StoreOrderTakeServices */
                                 $storeOrderTakeServices = app()->make(StoreOrderTakeServices::class);
-                                $storeOrderTakeServices->takeOrder($message['merchant_trade_no'], 0);
+                                $storeOrderTakeServices->miniOrderTakeOrder($message['merchant_trade_no']);
                             }
                             break;
                     };