Procházet zdrojové kódy

消费队列中发送跑腿失败时,要给商家发送APP通知

shizhongqi před 6 měsíci
rodič
revize
a07672599a

+ 14 - 7
biz-ghs/express/classes/GhsDeliveryOrderClass.php

@@ -253,28 +253,35 @@ class GhsDeliveryOrderClass extends BaseClass
                 if (isset($ret['msg'])) {
                     Yii::error("ghs-orderId={$orderId}, 创建跑腿失败:" . $ret['msg']);
                     noticeUtil::push("ghs-orderId={$orderId}, 创建跑腿失败:" . $ret['msg']);
+                    self::sendAppNotice($shopId, $orderId, "ghs-orderId={$orderId}, 创建跑腿失败:" . $ret['msg']); // 发 App 通知
                     return ConsumerInterface::MSG_REJECT;
                 }
 
                 Yii::error("ghs-orderId={$orderId}, 创建跑腿失败");
                 noticeUtil::push("ghs-orderId={$orderId}, 创建跑腿失败");
+                self::sendAppNotice($shopId, $orderId, '创建跑腿失败'); // 发 App 通知
                 return ConsumerInterface::MSG_REJECT;
             }
         } catch (\Exception $e) {
             Yii::error("ghs-orderId={$orderId}, 创建跑腿失败:" . $e->getMessage());
             noticeUtil::push("ghs-orderId={$orderId}, 创建跑腿失败:" . $e->getMessage());
-
             // 发 App 通知
-            $title = '发跑腿失败';
-            $msg = "批发订单:{$orderId}, 创建跑腿失败:" . $e->getMessage();
-            $allDevices = \bizGhs\device\classes\GhsDeviceClass::getAllByCondition(['shopId' => $shopId, 'status' => 1]);
-            $cids = array_column($allDevices, 'clientId');
-            $push = new push('ghs', push::MSG_TYPE_WORK);
-            $push->pushByCloud($cids, $title, $msg, []);
+            self::sendAppNotice($shopId, $orderId, $e->getMessage());
 
             return ConsumerInterface::MSG_REJECT;
         }
     }
+
+    // 发 App 通知
+    public static function sendAppNotice($shopId, $orderId, $msg)
+    {
+        $title = '发跑腿失败';
+        $msg = "批发订单:{$orderId}, 创建跑腿失败:" . $msg;
+        $allDevices = \bizGhs\device\classes\GhsDeviceClass::getAllByCondition(['shopId' => $shopId, 'status' => 1]);
+        $cids = array_column($allDevices, 'clientId');
+        $push = new push('ghs', push::MSG_TYPE_WORK);
+        $push->pushByCloud($cids, $title, $msg, []);
+    }
 }
 
 // 在同文件末尾追加一个内联的 AR 类

+ 16 - 9
biz-hd/express/classes/HdDeliveryOrderClass.php

@@ -238,28 +238,35 @@ class HdDeliveryOrderClass extends BaseClass
                 if (isset($ret['msg'])) {
                     Yii::error("hd-orderId={$orderId}, 创建跑腿失败:" . $ret['msg']);
                     noticeUtil::push("hd-orderId={$orderId}, 创建跑腿失败:" . $ret['msg']);
+                    self::sendAppNotice($shopId, $orderId, "hd-orderId={$orderId}, 创建跑腿失败:" . $ret['msg']); // 发 App 通知
                     return ConsumerInterface::MSG_REJECT;
                 }
 
-                Yii::error("ghs-orderId={$orderId}, 创建跑腿失败");
-                noticeUtil::push("ghs-orderId={$orderId}, 创建跑腿失败");
+                Yii::error("hd-orderId={$orderId}, 创建跑腿失败");
+                noticeUtil::push("hd-orderId={$orderId}, 创建跑腿失败");
+                self::sendAppNotice($shopId, $orderId, '创建跑腿失败'); // 发 App 通知
                 return ConsumerInterface::MSG_REJECT;
             }
         } catch (\Exception $e) {
             Yii::error("hd-orderId={$orderId} 创建跑腿失败:" . $e->getMessage());
             noticeUtil::push("hd-orderId={$orderId} 创建跑腿失败:" . $e->getMessage());
-
             // 发 App 通知
-            $title = '发跑腿失败';
-            $msg = "零售订单:{$orderId}, 创建跑腿失败:" . $e->getMessage();
-            $allDevices = \bizHd\device\classes\HdDeviceClass::getAllByCondition(['shopId' => $shopId, 'status' => 1]);
-            $cids = array_column($allDevices, 'clientId');
-            $push = new push('hd', push::MSG_TYPE_WORK);
-            $push->pushByCloud($cids, $title, $msg, []);
+            self::sendAppNotice($shopId, $orderId, $e->getMessage());
             
             return ConsumerInterface::MSG_REJECT;
         }
     }
+
+    // 发 App 通知
+    public static function sendAppNotice($shopId, $orderId, $msg)
+    {
+        $title = '发跑腿失败';
+        $msg = "零售订单:{$orderId}, 创建跑腿失败:" . $msg;
+        $allDevices = \bizHd\device\classes\HdDeviceClass::getAllByCondition(['shopId' => $shopId, 'status' => 1]);
+        $cids = array_column($allDevices, 'clientId');
+        $push = new push('hd', push::MSG_TYPE_WORK);
+        $push->pushByCloud($cids, $title, $msg, []);
+    }
 }
 
 // 在同文件末尾追加一个内联的 AR 类