shizhongqi 11 месяцев назад
Родитель
Сommit
2c9d6ac6ac
2 измененных файлов с 69 добавлено и 19 удалено
  1. 9 7
      app-ghs/controllers/TestController.php
  2. 60 12
      biz/wx/classes/WxMessageClass.php

+ 9 - 7
app-ghs/controllers/TestController.php

@@ -1390,14 +1390,17 @@ class TestController extends BaseController
 
     public function actionNotice()
     {
-        $data = ['messageType' => 'inform', 'informWay' => 'wx', 'userType' => 'admin', 'id' => 6, 'mobile' => '15280215347'];
-        $producer = Yii::$app->rabbitmq->getProducer('informProducer');
-        echo '<pre>';
-        print_r($data);
-        $msg = serialize($data);
-        $r = $producer->publish($msg, 'informExchange', 'informRoute');
+        if (getenv('YII_ENV') != 'production') {
+            $orderId = 524691;
+            $order = \bizHd\order\classes\OrderClass::getById($orderId, true);
+            $shop = ShopClass::getById(36524, true);
+            $customName = $order->customName ?? '';
+            $result = '配送方取消';
+            WxMessageClass::expressErrorInform($shop, $customName, $orderId, $result);
+        }
     }
 
+    //重要有用的方法 ssh 20250717
     public function actionSim()
     {
         //将石少华的号模拟成别人的号进行测试,有多处需要同步修改,关键词 simulate_other ssh 20250717
@@ -1413,7 +1416,6 @@ class TestController extends BaseController
             util::fail('管理员无效');
         }
         $adminName = $admin->name ?? '';
-        $simulateKey = 'simulate_admin_id';
         Yii::$app->redis->executeCommand('SET', [$simulateKey, $id]);
         echo "已将石少华账号设置为:" . $adminName;
     }

+ 60 - 12
biz/wx/classes/WxMessageClass.php

@@ -82,6 +82,54 @@ class WxMessageClass extends BaseClass
         ];
     }
 
+    /**
+     * 跑腿配送异常通知 ssh 20250825
+     * @param $shop 对象
+     * @param $customName 客户名称
+     * @param $orderId 订单id
+     * @param $result 异常状态说明内容:配送异常、配送员撤单、配送方取消订单、商家取消订单,这四种情况,其它不是异常的不需要通知
+     * @return false|void
+     */
+    public static function expressErrorInform($shop, $customName, $orderId, $result)
+    {
+        $ptStyle = $shop->ptStyle ?? 0;
+        $wxBase = WxOpenClass::getWxBase();
+        $wx = $wxBase[$ptStyle] ?? [];
+        $message = self::getAllByCondition(['ptStyle' => $ptStyle], null, '*', 'shortTemplateId');
+        $shortTempId = 'OPENTM408238177';
+        $tempId = $message[$shortTempId]['templateId'] ?? '';
+        if (empty($tempId)) {
+            return false;
+        }
+        $adminList = ShopAdminClass::getRemainAdmin($shop);
+        if (empty($adminList)) {
+            return false;
+        }
+        foreach ($adminList as $admin) {
+            $openId = $admin['openId'] ?? '';
+            if ($ptStyle == dict::getDict('ptStyle', 'ghs')) {
+                $openId = $admin['ghsOpenId'] ?? '';
+            }
+            if (empty($openId)) {
+                continue;
+            }
+            $data = [
+                "touser" => $openId,
+                "template_id" => $tempId,
+                "url" => Yii::$app->params['ghsDomain'],
+                "data" => [
+                    "first" => ["value" => $result, "color" => "#173177"],
+                    "keyword1" => ["value" => "【{$result}】", "color" => "#173177"],
+                    "keyword2" => ["value" => $customName . '的订单', "color" => "#173177"],
+                    "remark" => ["value" => '点击查看详情', "color" => "#173177"]
+                ]
+            ];
+            $data['miniprogram']['appid'] = $wx['miniAppId'];
+            $data['miniprogram']['pagepath'] = 'admin/order/detail?id=' . $orderId;
+            wxUtil::sendTaskInform($data, $wx, $ptStyle);
+        }
+    }
+
     //初始化消息模板
     // ./yii.bat wx-message/init
     public static function init()
@@ -513,7 +561,7 @@ class WxMessageClass extends BaseClass
     //预订增加减少通知 ssh 20240820
     public static function bookChangeInform($shop, $arr)
     {
-        $orderId = $arr['orderId']??0;
+        $orderId = $arr['orderId'] ?? 0;
         $ptStyle = $shop->ptStyle;
         $wxBase = WxOpenClass::getWxBase();
         $wx = $wxBase[$ptStyle] ?? [];
@@ -523,11 +571,11 @@ class WxMessageClass extends BaseClass
         if (empty($tempId)) {
             return false;
         }
-        $itemName = $arr['itemName']??'';
-        $io = $arr['io']??0;
+        $itemName = $arr['itemName'] ?? '';
+        $io = $arr['io'] ?? 0;
         $plus = $io == 1 ? '加' : '减';
-        $num = $arr['num']??0;
-        $title = $plus.$num.' '.$itemName;
+        $num = $arr['num'] ?? 0;
+        $title = $plus . $num . ' ' . $itemName;
         $customName = $arr['customName'] ?? '';
         $customName = stringUtil::subStringUtf8($customName, 5, '...');
 
@@ -548,7 +596,7 @@ class WxMessageClass extends BaseClass
                 "data" => [
                     "first" => ["value" => '', "color" => "#173177"],
                     "keyword1" => ["value" => $title, "color" => "#173177"],
-                    "keyword2" => ["value" => '客户-'.$customName, "color" => "#173177"],
+                    "keyword2" => ["value" => '客户-' . $customName, "color" => "#173177"],
                     "keyword3" => ["value" => date("Y-m-d H:i"), "color" => "#173177"],
                     "remark" => ["value" => "点击查看详情", "color" => "#173177"]
                 ]
@@ -1205,7 +1253,7 @@ class WxMessageClass extends BaseClass
         $wx = $wxBase[$ptStyle] ?? [];
         $message = self::getAllByCondition(['ptStyle' => $ptStyle], null, '*', 'shortTemplateId');
         $shortTempId = 'OPENTM408238177';
-        $tempId = isset($message[$shortTempId]['templateId']) ? $message[$shortTempId]['templateId'] : '';
+        $tempId = $message[$shortTempId]['templateId'] ?? '';
         if (empty($tempId)) {
             return false;
         }
@@ -1218,9 +1266,9 @@ class WxMessageClass extends BaseClass
         }
 
         foreach ($adminList as $admin) {
-            $openId = isset($admin['openId']) ? $admin['openId'] : '';
+            $openId = $admin['openId'] ?? '';
             if ($ptStyle == dict::getDict('ptStyle', 'ghs')) {
-                $openId = isset($admin['ghsOpenId']) ? $admin['ghsOpenId'] : '';
+                $openId = $admin['ghsOpenId'] ?? '';
             }
             if (empty($openId)) {
                 continue;
@@ -1250,7 +1298,7 @@ class WxMessageClass extends BaseClass
         $wx = $wxBase[$ptStyle] ?? [];
         $message = self::getAllByCondition(['ptStyle' => $ptStyle], null, '*', 'shortTemplateId');
         $shortTempId = 'OPENTM203447669';
-        $tempId = isset($message[$shortTempId]['templateId']) ? $message[$shortTempId]['templateId'] : '';
+        $tempId = $message[$shortTempId]['templateId'] ?? '';
         if (empty($tempId)) {
             return false;
         }
@@ -1267,9 +1315,9 @@ class WxMessageClass extends BaseClass
             $first = "此客户由【{$introName}】介绍";
         }
         foreach ($adminList as $admin) {
-            $openId = isset($admin['openId']) ? $admin['openId'] : '';
+            $openId = $admin['openId'] ?? '';
             if ($ptStyle == dict::getDict('ptStyle', 'ghs')) {
-                $openId = isset($admin['ghsOpenId']) ? $admin['ghsOpenId'] : '';
+                $openId = $admin['ghsOpenId'] ?? '';
             }
             if (empty($openId)) {
                 continue;