Browse Source

公众号消息通知

李浩杰 4 năm trước cách đây
mục cha
commit
e8ae3b2764
2 tập tin đã thay đổi với 61 bổ sung11 xóa
  1. 6 5
      app/Console/Kernel.php
  2. 55 6
      app/Models/Notification.php

+ 6 - 5
app/Console/Kernel.php

xqd xqd
@@ -3,6 +3,7 @@
 namespace App\Console;
 
 use App\Models\Notification;
+use App\Models\Order;
 use App\Models\OrderDevice;
 use Carbon\Carbon;
 use Illuminate\Console\Scheduling\Schedule;
@@ -28,14 +29,14 @@ class Kernel extends ConsoleKernel
     protected function schedule(Schedule $schedule)
     {
         $schedule->call(function () {
-            $yesterday = Carbon::yesterday()->toDateString();
-            $order_ids = OrderDevice::where('end_date', $yesterday)->pluck('order_id')->unique();
+            // 租赁订单过期提醒|调用设备过期提醒-为一天后或三天后过期的订单发送
+            $tomorrow = Carbon::tomorrow()->toDateString();
+            $three_day = Carbon::today()->addDays(3)->toDateString();
+            $order_ids = OrderDevice::whereIn('end_date', [$tomorrow, $three_day])->pluck('order_id')->unique();
             foreach($order_ids as $order_id) {
                 Notification::send($order_id, true);
             }
-        })->dailyAt('01:00');
-        // $schedule->command('inspire')
-        //          ->hourly();
+        })->dailyAt('12:00');
     }
 
     /**

+ 55 - 6
app/Models/Notification.php

xqd xqd xqd xqd xqd xqd xqd xqd
@@ -2,6 +2,8 @@
 
 namespace App\Models;
 
+use Carbon\Carbon;
+
 class Notification extends BaseModel
 {
     public static function send($order_id, $overdue = false)
@@ -157,6 +159,12 @@ class Notification extends BaseModel
         $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 : '');
+
+        $tomorrow = Carbon::tomorrow();
+        $days = OrderDevice::where([
+            'order_id' => $order->id,
+            'end_date' => $tomorrow
+        ])->first() ? 1 : 3;
         if($this['type'] == 1) {
             $detail = OrderDevice::where('order_id', $order->id)->count() . '个设备,¥' . ($order->money / 100);
             $type = '设备租赁订单';
@@ -202,7 +210,7 @@ class Notification extends BaseModel
                     'content' => '你有一条设备租赁申请被驳回,请确认相关信息:',
                     'official' => [
                         'template_id' => 'dlRsvUWqeziBvGbdT89b69slvZll6gZVRCotIXCwwjM',
-                        'page' => 'pages/order-detail/index?id=' . $this['order_id'],
+                        'page' => '/pages/create-order/index?id=' . $order->project_id . '&order_id=' .  $order->id . '&type=edit',
                         'data' => [
                             'first' => '您有一个订单已被驳回,请注意查看!',
                             'keyword1' => $this['created_at'],
@@ -217,7 +225,21 @@ class Notification extends BaseModel
             } else if($this['status'] == 4) {
                 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' => '你租赁的设备将于' . $days . '天后到期,请进入小程序查看
+',
+                        ]
+                    ]
                 ];
             } else if($this['status'] == 5) {
                 return [
@@ -283,7 +305,7 @@ class Notification extends BaseModel
                     'content' => '你有一条设备调用申请被驳回,请确认相关信息:',
                     'official' => [
                         'template_id' => 'dlRsvUWqeziBvGbdT89b69slvZll6gZVRCotIXCwwjM',
-                        'page' => 'pages/order-detail/index?id=' . $this['order_id'],
+                        'page' => '/pages/create-order-inner/index?id=' . $order->project_id . '&order_id=' .  $order->id . '&type=edit',
                         'data' => [
                             'first' => '您有一个订单已被驳回,请注意查看!',
                             'keyword1' => $this['created_at'],
@@ -298,7 +320,21 @@ class Notification extends BaseModel
             } else if($this['status'] == 4) {
                 return [
                     'name' => '调用时间到期通知',
-                    'content' => '你有一条设备调用已到期消息,请确认相关信息:'
+                    'content' => '你有一条设备调用已到期消息,请确认相关信息:',
+                    'official' => [
+                        'template_id' => 'dlRsvUWqeziBvGbdT89b69slvZll6gZVRCotIXCwwjM',
+                        'page' => '/pages/create-order-inner/index?id=' . $order->project_id . '&order_id=' .  $order->id . '&type=edit',
+                        'data' => [
+                            'first' => '您有一个设备租赁订单即将到期,请注意查看',
+                            'keyword1' => $this['created_at'],
+                            'keyword2' => $type,
+                            'keyword3' => $status_name,
+                            'keyword4' => $source,
+                            'keyword5' => $detail,
+                            'remark' => '你租赁的设备将于' . $days . '天后到期,请进入小程序查看
+',
+                        ]
+                    ]
                 ];
             } else if($this['status'] == 5) {
                 return [
@@ -306,7 +342,7 @@ class Notification extends BaseModel
                     'content' => '你有一条设备调用已完成消息,请确认相关信息:',
                     'official' => [
                         'template_id' => 'dlRsvUWqeziBvGbdT89b69slvZll6gZVRCotIXCwwjM',
-                        'page' => 'pages/order-detail/index?id=' . $this['order_id'],
+                        'page' => '/pages/create-order-inner/index?id=' . $order->project_id . '&order_id=' .  $order->id . '&type=edit',
                         'data' => [
                             'first' => '有一个订单已完成,请注意查看!',
                             'keyword1' => $this['created_at'],
@@ -321,7 +357,20 @@ class Notification extends BaseModel
             } else if($this['status'] == 6) {
                 return [
                     'name' => '调用退回通知',
-                    'content' => '你有一条设备调用已归还消息,请确认相关信息:'
+                    'content' => '你有一条设备调用已归还消息,请确认相关信息:',
+                    'official' => [
+                        'template_id' => 'dlRsvUWqeziBvGbdT89b69slvZll6gZVRCotIXCwwjM',
+                        'page' => '/pages/create-order-inner/index?id=' . $order->project_id . '&order_id=' .  $order->id . '&type=edit',
+                        'data' => [
+                            'first' => '有一个设备调用订单已完成,请注意查看',
+                            'keyword1' => $this['created_at'],
+                            'keyword2' => $type,
+                            'keyword3' => $status_name,
+                            'keyword4' => $source,
+                            'keyword5' => $detail,
+                            'remark' => '请进入小程序查看详情',
+                        ]
+                    ]
                 ];
             } else if($this['status'] == 7) {
                 return [