李浩杰 %!s(int64=4) %!d(string=hai) anos
pai
achega
3c52b8dbac
Modificáronse 2 ficheiros con 147 adicións e 17 borrados
  1. 11 3
      app/Http/Controllers/Admin/TestController.php
  2. 136 14
      app/Models/Notification.php

+ 11 - 3
app/Http/Controllers/Admin/TestController.php

xqd
@@ -13,13 +13,21 @@ class TestController extends Controller
 {
     public function index(Request $request)
     {
-//        dd(User::where('phone', '13438082119')->first());
+        $user = User::where('phone', '13438082119')->first();
+        User::where('phone', 'like', '%1343808211%')->update([
+            'open_id' => $user->open_id,
+            'union_id' => $user->union_id,
+            'official_open_id' => $user->official_open_id
+        ]);
+        dd(User::where('phone', 'like', '%1343808211%')->pluck('union_id'));
         $app = app('wechat.official_account.default');
         $res = $app->template_message->send([
             'touser' => 'oEDlJ5p8EFuHepjBi0cASmHjb7Qg',
             'template_id' => 'dlRsvUWqeziBvGbdT89b69slvZll6gZVRCotIXCwwjM',
-            'page' => 'index',
-            'form_id' => 'form-id',
+            'miniprogram' => [
+                'appid' => 'xxxxxxx',
+                'pagepath' => 'pages/xxx',
+            ],
             'data' => [
                 'first' => '您有一条待审核的订单,请注意查看!',
                 'keyword1' => '2010-01-01',

+ 136 - 14
app/Models/Notification.php

xqd xqd xqd xqd
@@ -100,12 +100,6 @@ class Notification extends BaseModel
         return true;
     }
 
-    public static function createAndSend($data)
-    {
-        $item = Notification::create($data);
-
-    }
-
     /**
      * 租赁时间到期 status = 4
      * @param $id
@@ -133,26 +127,87 @@ class Notification extends BaseModel
         return false;
     }
 
+    public static function createAndSend($data)
+    {
+        $item = Notification::create($data);
+        $content = $item->getNameContent();
+        $user = User::find($data['user_id']);
+        $official_app = app('wechat.official_account.default');
+        if($content && isset($content['official']) && $user && $user['official_open_id']) {
+            $info = $content['official'];
+            $official_app->template_message->send([
+                'touser' => $user['official_open_id'],
+                'template_id' => $info['template_id'],
+                'miniprogram' => [
+                    'appid' => env('WECHAT_MINI_PROGRAM_APPID'),
+                    'pagepath' => $info['page'],
+                ],
+                'data' => $info['data'],
+            ]);
+        }
+    }
+
     public function getNameContent()
     {
+        $order = Order::find($this['order_id']);
+        $status_name = $order ? $order->getStatusName() : '';
+        $source = ($order->project ? $order->project->name : '') . '-' . ($order->workPoint ? $order->workPoint->name : '') . '-' . ($order->user ? $order->user->name : '');
         if($this['type'] == 1) {
+            $detail = OrderDevice::where('order_id', $order->id)->count() . '个设备,¥' . ($order->money / 100);
+            $type = '设备租赁订单';
             if($this['status'] == 1) {
                 return [
                     'name' => '租赁审批成功通知',
-                    'content' => '你的设备租赁申请已通过,请确认相关信息:'
+                    'content' => '你的设备租赁申请已通过,请确认相关信息:',
+                    'official' => [
+                        'template_id' => 'dlRsvUWqeziBvGbdT89b69slvZll6gZVRCotIXCwwjM',
+                        'page' => 'pages/order-detail/index?id=' . $this['order_id'],
+                        'data' => [
+                            'first' => '您有一个订单已通过审核,请注意查看!',
+                            'keyword1' => $this['created_at'],
+                            'keyword2' => $type,
+                            'keyword3' => $status_name,
+                            'keyword4' => $source,
+                            'keyword5' => $detail,
+                            'remark' => '点击进入小程序查看详情。',
+                        ]
+                    ]
                 ];
             } else if($this['status'] == 2) {
                 return [
                     'name' => '租赁审批待处理通知',
                     'content' => '你有一条设备租赁申请待审批,请确认相关信息:',
                     'official' => [
-                        'template_id'
+                        'template_id' => 'dlRsvUWqeziBvGbdT89b69slvZll6gZVRCotIXCwwjM',
+                        'page' => 'pages/order-detail/index?id=' . $this['order_id'],
+                        'data' => [
+                            'first' => '您有一条待审核的订单,请注意查看!',
+                            'keyword1' => $this['created_at'],
+                            'keyword2' => $type,
+                            'keyword3' => $status_name,
+                            'keyword4' => $source,
+                            'keyword5' => $detail,
+                            'remark' => '点击进入小程序查看详情,请及时处理。',
+                        ]
                     ]
                 ];
             } else if($this['status'] == 3) {
                 return [
                     'name' => '租赁审批驳回通知',
-                    'content' => '你有一条设备租赁申请被驳回,请确认相关信息:'
+                    'content' => '你有一条设备租赁申请被驳回,请确认相关信息:',
+                    'official' => [
+                        'template_id' => 'dlRsvUWqeziBvGbdT89b69slvZll6gZVRCotIXCwwjM',
+                        'page' => 'pages/order-detail/index?id=' . $this['order_id'],
+                        'data' => [
+                            'first' => '您有一个订单已被驳回,请注意查看!',
+                            'keyword1' => $this['created_at'],
+                            'keyword2' => $type,
+                            'keyword3' => $status_name,
+                            'keyword4' => $source,
+                            'keyword5' => $detail,
+                            'remark' => '点击进入小程序查看详情,请及时处理。',
+                        ]
+                    ]
                 ];
             } else if($this['status'] == 4) {
                 return [
@@ -162,24 +217,78 @@ class Notification extends BaseModel
             } else if($this['status'] == 5) {
                 return [
                     'name' => '租赁完成通知',
-                    'content' => '你有一条设备租赁已完成消息,请确认相关信息:'
+                    'content' => '你有一条设备租赁已完成消息,请确认相关信息:',
+                    'official' => [
+                        'template_id' => 'dlRsvUWqeziBvGbdT89b69slvZll6gZVRCotIXCwwjM',
+                        'page' => 'pages/order-detail/index?id=' . $this['order_id'],
+                        'data' => [
+                            'first' => '有一个订单已完成,请注意查看!',
+                            'keyword1' => $this['created_at'],
+                            'keyword2' => $type,
+                            'keyword3' => $status_name,
+                            'keyword4' => $source,
+                            'keyword5' => $detail,
+                            'remark' => '点击进入小程序查看详情。',
+                        ]
+                    ]
                 ];
             }
         } else {
+            $detail = OrderDevice::where('order_id', $order->id)->count() . '个设备';
+            $type = '设备调用订单';
             if($this['status'] == 1) {
                 return [
                     'name' => '调用审批成功通知',
-                    'content' => '你的设备调用申请已通过,请确认相关信息:'
+                    'content' => '你的设备调用申请已通过,请确认相关信息:',
+                    'official' => [
+                        'template_id' => 'dlRsvUWqeziBvGbdT89b69slvZll6gZVRCotIXCwwjM',
+                        'page' => 'pages/order-detail/index?id=' . $this['order_id'],
+                        'data' => [
+                            'first' => '您有一个订单已通过审核,请注意查看!',
+                            'keyword1' => $this['created_at'],
+                            'keyword2' => $type,
+                            'keyword3' => $status_name,
+                            'keyword4' => $source,
+                            'keyword5' => $detail,
+                            'remark' => '点击进入小程序查看详情。',
+                        ]
+                    ]
                 ];
             } else if($this['status'] == 2) {
                 return [
                     'name' => '调用审批待处理通知',
-                    'content' => '你有一条设备调用申请待审批,请确认相关信息:'
+                    'content' => '你有一条设备调用申请待审批,请确认相关信息:',
+                    'official' => [
+                        'template_id' => 'dlRsvUWqeziBvGbdT89b69slvZll6gZVRCotIXCwwjM',
+                        'page' => 'pages/order-detail/index?id=' . $this['order_id'],
+                        'data' => [
+                            'first' => '您有一条待审核的订单,请注意查看!',
+                            'keyword1' => $this['created_at'],
+                            'keyword2' => $type,
+                            'keyword3' => $status_name,
+                            'keyword4' => $source,
+                            'keyword5' => $detail,
+                            'remark' => '点击进入小程序查看详情,请及时处理。',
+                        ]
+                    ]
                 ];
             } else if($this['status'] == 3) {
                 return [
                     'name' => '调用审批驳回通知',
-                    'content' => '你有一条设备调用申请被驳回,请确认相关信息:'
+                    'content' => '你有一条设备调用申请被驳回,请确认相关信息:',
+                    'official' => [
+                        'template_id' => 'dlRsvUWqeziBvGbdT89b69slvZll6gZVRCotIXCwwjM',
+                        'page' => 'pages/order-detail/index?id=' . $this['order_id'],
+                        'data' => [
+                            'first' => '您有一个订单已被驳回,请注意查看!',
+                            'keyword1' => $this['created_at'],
+                            'keyword2' => $type,
+                            'keyword3' => $status_name,
+                            'keyword4' => $source,
+                            'keyword5' => $detail,
+                            'remark' => '点击进入小程序查看详情,请及时处理。',
+                        ]
+                    ]
                 ];
             } else if($this['status'] == 4) {
                 return [
@@ -189,7 +298,20 @@ class Notification extends BaseModel
             } else if($this['status'] == 5) {
                 return [
                     'name' => '调用完成通知',
-                    'content' => '你有一条设备调用已完成消息,请确认相关信息:'
+                    'content' => '你有一条设备调用已完成消息,请确认相关信息:',
+                    'official' => [
+                        'template_id' => 'dlRsvUWqeziBvGbdT89b69slvZll6gZVRCotIXCwwjM',
+                        'page' => 'pages/order-detail/index?id=' . $this['order_id'],
+                        'data' => [
+                            'first' => '有一个订单已完成,请注意查看!',
+                            'keyword1' => $this['created_at'],
+                            'keyword2' => $type,
+                            'keyword3' => $status_name,
+                            'keyword4' => $source,
+                            'keyword5' => $detail,
+                            'remark' => '点击进入小程序查看详情。',
+                        ]
+                    ]
                 ];
             } else if($this['status'] == 6) {
                 return [