zilong 4 年之前
父節點
當前提交
bc5701c4b7
共有 4 個文件被更改,包括 93 次插入92 次删除
  1. 3 3
      app/Helpers/functions.php
  2. 1 1
      app/Http/Controllers/Api/V1/OrderController.php
  3. 17 6
      app/Models/Order.php
  4. 72 82
      config/config.php

+ 3 - 3
app/Helpers/functions.php

xqd xqd
@@ -535,7 +535,7 @@ if (!function_exists('numDays')){
 
 //发送微信消息
 if (!function_exists('send_wechat_message')) {
-    function send_wechat_message($type, $official_arr, $subscribe_arr, $url_param = [])
+    function send_wechat_message($type, $official_arr, $subscribe_arr = [])
     {
         try {
             $app = Factory::miniProgram(config('config.wechat_small_program'));
@@ -546,13 +546,13 @@ if (!function_exists('send_wechat_message')) {
             $data = json_decode($json, true);
             $ret = $app->uniform_message->send($data);
             //如果模板消息发送失败(可能因用户没有关注公众号而失败)再发送订阅消息
-            /*if (isset($ret['errcode']) && $ret['errcode'] != 0) {
+            if (!empty($subscribe_arr) && isset($ret['errcode']) && $ret['errcode'] != 0) {
                 $data = config('config.wechat_subscribe_message_template')[$type];
                 $json = json_encode($data, JSON_UNESCAPED_UNICODE);
                 $json = vsprintf($json, $subscribe_arr);
                 $data = json_decode($json, true);
                 $ret = $app->subscribe_message->send($data);
-            }*/
+            }
         } catch (Exception $e) {
             trace(['发送微信消息失败' => $e->getMessage(), '请求参数' => $data ?? '', '返回数据' => $ret ?? ''], 'error');
         }

+ 1 - 1
app/Http/Controllers/Api/V1/OrderController.php

xqd
@@ -507,7 +507,7 @@ class OrderController extends AuthController
             }
             $official_arr = [$user['openid'], $order['order_sn'], $keyword2, round($order['total_amount']/100, 2), date('Y-m-d H:i:s', $order['payment_time']), $order['order_patient']['name'], $server_name, $order['order_notes'], config('config.payment_status_map')[$order['payment_status']]];
             $subscribe_arr = [];
-            send_wechat_message(9, $official_arr, $subscribe_arr);
+            send_wechat_message(7, $official_arr, $subscribe_arr);
 
             DB::commit();
         } catch (Exception $e) {

+ 17 - 6
app/Models/Order.php

xqd
@@ -138,42 +138,53 @@ class Order extends BaseModel
             OrganizationVaccine::where('org_id', $order['organization_id'])->where('vaccine_id', $orderVaccine['vaccine_id'])->decrement('stock');
         }
 
-        //发送微信消息
+        //给用户发送微信消息
         $docter = Docter::where('id', $order['docter_id'])->first();
         if ($order['product_type'] == 1) {
             $official_arr = [$user['openid'], $docter['name'], date('Y-m-d H:i:s'), round($order['payment_amount']/100, 2)];
             $subscribe_arr = [];
             send_wechat_message(1, $official_arr, $subscribe_arr);
         }
-        if ($order['product_type'] == 2) {
+        elseif ($order['product_type'] == 2) {
             $official_arr = [$user['openid'], $docter['name'], $orderPatient['name'], $orderPatient['symptoms'], date('Y-m-d H:i:s'), round($order['payment_amount']/100, 2)];
             $subscribe_arr = [];
             send_wechat_message(2, $official_arr, $subscribe_arr);
         }
-        if ($order['product_type'] == 3) {
+        elseif ($order['product_type'] == 3) {
             $keyword2 = date('Y-m-d H:i', $orderPatient['appoint_start_time']).' - '.date('H:i', $orderPatient['appoint_end_time']);
             $official_arr = [$user['openid'], $docter['name'], $keyword2, $orderPatient['name'], $orderPatient['phone'], $order['organization']['name'], $order['organization']['address']];
             $subscribe_arr = [];
             send_wechat_message(3, $official_arr, $subscribe_arr);
         }
-        if ($order['product_type'] == 4) {
+        elseif ($order['product_type'] == 4) {
             $keyword2 = date('Y-m-d H:i', $orderPatient['appoint_start_time']).' - '.date('H:i', $orderPatient['appoint_end_time']);
             $official_arr = [$user['openid'], $order['organization']['name'], $order['order_vaccine']['vaccine_name'], $keyword2, $orderPatient['name'], $orderPatient['phone'], $order['organization']['name'], $order['organization']['address']];
             $subscribe_arr = [];
             send_wechat_message(4, $official_arr, $subscribe_arr);
         }
-        if ($order['product_type'] == 5) {
+        elseif ($order['product_type'] == 5) {
             $keyword2 = date('Y-m-d H:i', $orderPatient['appoint_start_time']).' - '.date('H:i', $orderPatient['appoint_end_time']);
             $official_arr = [$user['openid'], $order['organization']['name'], $order['order_nurse'][0]['nurse_name'], $keyword2, $orderPatient['name'], $orderPatient['phone'], $order['organization']['name'], $order['organization']['address']];
             $subscribe_arr = [];
             send_wechat_message(5, $official_arr, $subscribe_arr);
         }
-        if ($order['product_type'] == 6) {
+        elseif ($order['product_type'] == 6) {
             $official_arr = [$user['openid'], $order['order_pack']['pack_name'], date('Y-m-d H:i:s', $order['order_pack']['start_time']), date('Y-m-d H:i:s', $order['order_pack']['end_time'])];
             $subscribe_arr = [];
             send_wechat_message(6, $official_arr, $subscribe_arr);
         }
 
+        //给医生发送消息
+        if (in_array($order['product_type'], [1,2])) {
+            $official_arr = [$user['openid'], $order['order_sn'], config('config.product_type_map')[$order['product_type']], $orderPatient['name'], $orderPatient['phone']];
+            send_wechat_message(10, $official_arr);
+        }
+        elseif ($order['product_type'] == 3) {
+            $keyword4 = date('Y-m-d H:i', $orderPatient['appoint_start_time']).' - '.date('H:i', $orderPatient['appoint_end_time']);
+            $official_arr = [$user['openid'], $orderPatient['name'], $orderPatient['phone'], $keyword4, $order['organization']['name'], $docter['name']];
+            send_wechat_message(11, $official_arr);
+        }
+
         return true;
     }
 

+ 72 - 82
config/config.php

xqd xqd xqd xqd xqd xqd xqd xqd xqd
@@ -279,20 +279,20 @@ return [
                 ],
             ],
         ],
-        //咨询订单接单提醒
+        //订单取消提醒
         7 => [
             'touser' => '%s',
             'mp_template_msg' => [
                 'appid' => env('OFFICIAL_WECHAT_APPID'),
-                'template_id' => 'grtzjXaIQNMTI-UoxY8cakzVna4q65s6qqZFbW67rIk',
+                'template_id' => 'xYAvY_xez7Ou_qflGuPV7L277FCPpj3K-zFdRcUYaBI',
                 'url' => '',
                 'miniprogram' => [
                     'appid' => env('WECHAT_APPID', 'wx6131f74e623bf6bf'),
-                    'page' => '%s',
+                    'page' => '',
                 ],
                 'data' => [
                     'first' => [
-                        'value' => '%s',
+                        'value' => '尊敬的用户,你有一笔订单已取消!',
                     ],
                     'keyword1' => [
                         'value' => '%s',
@@ -301,23 +301,26 @@ return [
                         'value' => '%s',
                     ],
                     'keyword3' => [
-                        'value' => '%s',
+                        'value' => '%s',
                     ],
                     'keyword4' => [
                         'value' => '%s',
                     ],
+                    'keyword5' => [
+                        'value' => '%s患者在%s的服务终止',
+                    ],
                     'remark' => [
-                        'value' => '%s',
+                        'value' => '订单备注:%s; 支付状态:%s; 点击进入小程序查看相关详情,如有疑问,请联系我们',
                     ],
                 ],
             ],
         ],
-        //图文消息回复提醒
+        //服务包续费(即将到期)提醒
         8 => [
             'touser' => '%s',
             'mp_template_msg' => [
                 'appid' => env('OFFICIAL_WECHAT_APPID'),
-                'template_id' => '0T33vX4zLYSUbFH4NxEe_6Yt4b6m1AoanjpwvBbsRgE',
+                'template_id' => 'aqfqUZtxj8jrRQe5_rhjaoHCmtDUeDLRgVYVdTMTH2k',
                 'url' => '',
                 'miniprogram' => [
                     'appid' => env('WECHAT_APPID', 'wx6131f74e623bf6bf'),
@@ -342,20 +345,20 @@ return [
                 ],
             ],
         ],
-        //订单取消提醒
+        //服务包失效提醒
         9 => [
             'touser' => '%s',
             'mp_template_msg' => [
                 'appid' => env('OFFICIAL_WECHAT_APPID'),
-                'template_id' => 'xYAvY_xez7Ou_qflGuPV7L277FCPpj3K-zFdRcUYaBI',
+                'template_id' => 'aqfqUZtxj8jrRQe5_rhjaoHCmtDUeDLRgVYVdTMTH2k',
                 'url' => '',
                 'miniprogram' => [
                     'appid' => env('WECHAT_APPID', 'wx6131f74e623bf6bf'),
-                    'page' => '',
+                    'page' => '%s',
                 ],
                 'data' => [
                     'first' => [
-                        'value' => '尊敬的用户,你有一笔订单已取消!',
+                        'value' => '%s',
                     ],
                     'keyword1' => [
                         'value' => '%s',
@@ -364,34 +367,28 @@ return [
                         'value' => '%s',
                     ],
                     'keyword3' => [
-                        'value' => '%s元',
-                    ],
-                    'keyword4' => [
                         'value' => '%s',
                     ],
-                    'keyword5' => [
-                        'value' => '%s患者在%s的服务终止',
-                    ],
                     'remark' => [
-                        'value' => '订单备注:%s; 支付状态:%s; 点击进入小程序查看相关详情,如有疑问,请联系我们',
+                        'value' => '%s',
                     ],
                 ],
             ],
         ],
-        //服务包续费(即将到期)提醒
+        //咨询订单接单提醒 发给医生端的
         10 => [
             'touser' => '%s',
             'mp_template_msg' => [
-                'appid' => env('OFFICIAL_WECHAT_APPID'),
-                'template_id' => 'aqfqUZtxj8jrRQe5_rhjaoHCmtDUeDLRgVYVdTMTH2k',
+                'appid' => env('DOCTOR_OFFICIAL_WECHAT_APPID', 'wx6df68b725662f8a3'),
+                'template_id' => 'YjmwSkUlekckT41tpYqBJTJzV0cp5tqlqbNV86QQPmU',
                 'url' => '',
                 'miniprogram' => [
-                    'appid' => env('WECHAT_APPID', 'wx6131f74e623bf6bf'),
-                    'page' => '%s',
+                    'appid' => env('DOCTOR_WECHAT_APPID', 'wx92066f7587c34617'),
+                    'page' => '',
                 ],
                 'data' => [
                     'first' => [
-                        'value' => '%s',
+                        'value' => '您有新的咨询订单待处理,请及时处理',
                     ],
                     'keyword1' => [
                         'value' => '%s',
@@ -402,27 +399,66 @@ return [
                     'keyword3' => [
                         'value' => '%s',
                     ],
-                    'remark' => [
+                    'keyword4' => [
                         'value' => '%s',
                     ],
+                    'remark' => [
+                        'value' => '点击进入小程序查看详情',
+                    ],
                 ],
             ],
         ],
-        //服务包失效提醒
-        11 => [
+        //门诊预约确认提醒 发给医生端的
+        11 =>  [
             'touser' => '%s',
             'mp_template_msg' => [
-                'appid' => env('OFFICIAL_WECHAT_APPID'),
-                'template_id' => 'aqfqUZtxj8jrRQe5_rhjaoHCmtDUeDLRgVYVdTMTH2k',
+                'appid' => env('DOCTOR_OFFICIAL_WECHAT_APPID', 'wx6df68b725662f8a3'),
+                'template_id' => '7-NjWwPtBlKCiKedWRYn1VSkrwrRlfaw7qq9UqDOALM',
                 'url' => '',
                 'miniprogram' => [
-                    'appid' => env('WECHAT_APPID', 'wx6131f74e623bf6bf'),
-                    'page' => '%s',
+                    'appid' => env('DOCTOR_WECHAT_APPID', 'wx92066f7587c34617'),
+                    'page' => '',
                 ],
                 'data' => [
                     'first' => [
+                        'value' => '您好,你有新的预约订单,请及时确认。',
+                    ],
+                    'keyword1' => [
+                        'value' => '门诊预约',
+                    ],
+                    'keyword2' => [
+                        'value' => '%s',
+                    ],
+                    'keyword3' => [
+                        'value' => '%s',
+                    ],
+                    'keyword4' => [
                         'value' => '%s',
                     ],
+                    'keyword5' => [
+                        'value' => '%s - %s医生',
+                    ],
+                    'remark' => [
+                        'value' => '请合理安排时间进行就诊,点击查看详情。',
+                    ],
+                ],
+            ],
+        ],
+        //图文消息回复提醒 发给医生端的
+        12 => [
+            'touser' => '%s',
+            'mp_template_msg' => [
+                'appid' => env('DOCTOR_OFFICIAL_WECHAT_APPID', 'wx6df68b725662f8a3'),
+                'template_id' => 'x-vfzeyd8CnMo7WqrluIysjCc8Ya9rIdVE0HOKEkrSk',
+                'url' => '',
+                'miniprogram' => [
+                    'appid' => env('DOCTOR_WECHAT_APPID', 'wx92066f7587c34617'),
+                    'page' => '',
+                ],
+                'data' => [
+                    'first' => [
+                        'value' => '您有一条新的患者咨询聊天信息,请及时查看',
+                    ],
                     'keyword1' => [
                         'value' => '%s',
                     ],
@@ -433,7 +469,7 @@ return [
                         'value' => '%s',
                     ],
                     'remark' => [
-                        'value' => '%s',
+                        'value' => '点击立即进入小程序查看',
                     ],
                 ],
             ],
@@ -580,54 +616,8 @@ return [
                 ],
             ],
         ],
-        //咨询订单接单提醒
-        7 => [
-            'template_id' => '7tnOphwuX8aYenJd-m-LN0jxQm3gkF0HJc1nDX13VMw',
-            'touser' => '%s',
-            'page' => '%s',
-            'data' => [
-                'character_string6' => [
-                    'value' => '%s',
-                ],
-                'thing2' => [
-                    'value' => '%s',
-                ],
-                'thing7' => [
-                    'value' => '%s',
-                ],
-                'time8' => [
-                    'value' => '%s',
-                ],
-                'thing9' => [
-                    'value' => '%s',
-                ],
-            ],
-        ],
-        //图文消息回复提醒
-        8 => [
-            'template_id' => 'WCkfvW9NkV_oQgLsJJuwoVMF-G0ss9y4SkIgCObZwWA',
-            'touser' => '%s',
-            'page' => '%s',
-            'data' => [
-                'name1' => [
-                    'value' => '%s',
-                ],
-                'thing3' => [
-                    'value' => '%s',
-                ],
-                'thing6' => [
-                    'value' => '%s',
-                ],
-                'thing5' => [
-                    'value' => '%s',
-                ],
-                'time4' => [
-                    'value' => '%s',
-                ],
-            ],
-        ],
         //订单取消提醒
-        9 => [
+        7 => [
             'template_id' => 'bjZ-r79i8sl7zEtdttAtcCPZLkCgFSYHTNWnNVd1cG0',
             'touser' => '%s',
             'page' => '%s',
@@ -647,7 +637,7 @@ return [
             ],
         ],
         //服务包续费(即将到期)提醒
-        10 => [
+        8 => [
             'template_id' => 'obCFv2gAnl_RaW-OlnZkjCfi6teT3LUaHxxInUkwLbw',
             'touser' => '%s',
             'page' => '%s',
@@ -670,7 +660,7 @@ return [
             ],
         ],
         //服务包失效提醒
-        11 => [
+        9 => [
             'template_id' => 'obCFv2gAnl_RaW-OlnZkjCfi6teT3LUaHxxInUkwLbw',
             'touser' => '%s',
             'page' => '%s',