作者 ZhengBing He

合并分支 'workorder' 到 'master'

ding



查看合并请求 !2300
1 -<?php  
2 -  
3 -namespace App\Console\Commands\WorkOrder;  
4 -  
5 -use App\Models\ProjectAssociation\ProjectAssociation;  
6 -use App\Models\Workchat\MessagePush;  
7 -use App\Models\WorkOrder\Tickets;  
8 -use Illuminate\Console\Command;  
9 -  
10 -class PushNotify extends Command  
11 -{  
12 - /**  
13 - * The name and signature of the console command.  
14 - *  
15 - * @var string  
16 - */  
17 - protected $signature = 'workorder:push-notify';  
18 -  
19 - /**  
20 - * The console command description.  
21 - *  
22 - * @var string  
23 - */  
24 - protected $description = 'tickets push notify';  
25 -  
26 - /**  
27 - * Create a new command instance.  
28 - *  
29 - * @return void  
30 - */  
31 - public function __construct()  
32 - {  
33 - parent::__construct();  
34 - }  
35 -  
36 - /**  
37 - * Execute the console command.  
38 - *  
39 - * @return int  
40 - */  
41 - public function handle()  
42 - {  
43 - while (true) {  
44 - try {  
45 - $tick = Tickets::where('ding', 0)  
46 - ->where('submit_side', 2)  
47 -// ->where('project_id', 1)  
48 - ->first();  
49 - if (!$tick) {  
50 - echo now() . " WARNING | 没有待推送的工单\n";  
51 - sleep(3);  
52 - continue;  
53 - }  
54 - $project = $tick->project;  
55 - if ($project->version != 6 || $project->is_del == 1) {  
56 - echo now() . " WARNING | 项目版本或状态异常 \n";  
57 - $tick->ding = 1;  
58 - $tick->save();  
59 - continue;  
60 - }  
61 - $message_push = new MessagePush();  
62 - $message_push->project_id = $project->table_id;  
63 - $message_push->friend_id = ProjectAssociation::where('project_id', $project->table_id)  
64 - ->where('status', ProjectAssociation::STATUS_NORMAL)  
65 - ->where('binding_app', ProjectAssociation::ENTERPRISE_WECHAT)  
66 - ->value('friend_id');  
67 - if (empty($message_push->friend_id))  
68 - {  
69 - echo now() . " WARNING | 项目ID:{$project->table_id} 没有绑定企微群\n";  
70 - $tick->ding = 1;  
71 - $tick->save();  
72 - continue;  
73 - }  
74 - $message_push->content_type = 'Link';  
75 - $message_push->content = json_encode([  
76 - 'title' => '工单查看 - ' . $project->company_name,  
77 - 'desc' => $tick->title,  
78 - 'size' => 0,  
79 - 'thumbSize' => 0,  
80 - 'thumbUrl' => 'https://oa.quanqiusou.cn/logo.ico',  
81 - 'url' => 'https://oa.quanqiusou.cn/tickets?project_id='.$project->uuid  
82 - ], JSON_UNESCAPED_UNICODE);  
83 - $message_push->send_time = now();  
84 - $message_push->type = MessagePush::TYPE_TICKET;  
85 - $message_push->save();  
86 - $tick->ding = 1;  
87 - $tick->save();  
88 - echo now() . " INFO | 项目ID:{$project->table_id} 工单ID:{$tick->id} 推送成功\n";  
89 - }catch (\Exception $exception){  
90 - echo date('Y-m-d H:i:s')." ERROR | ".$exception->getMessage()."\n";  
91 - break;  
92 - }  
93 - }  
94 - }  
95 -}  
@@ -44,7 +44,7 @@ class WorkOrderDing extends Command @@ -44,7 +44,7 @@ class WorkOrderDing extends Command
44 try { 44 try {
45 $log = TicketLog::where('ding', 0)->first(); 45 $log = TicketLog::where('ding', 0)->first();
46 if (!$log) { 46 if (!$log) {
47 - echo now() . " INFO | 没有通知任务\n"; 47 + echo now() . " | INFO | 没有通知任务\n";
48 sleep(3); 48 sleep(3);
49 continue; 49 continue;
50 } 50 }
@@ -70,7 +70,7 @@ class WorkOrderDing extends Command @@ -70,7 +70,7 @@ class WorkOrderDing extends Command
70 $log->ding = 2; 70 $log->ding = 2;
71 $log->save(); 71 $log->save();
72 }catch (\Exception $exception){ 72 }catch (\Exception $exception){
73 - echo now() . " ERROR | ".$exception->getMessage()."\n"; 73 + echo now() . " | ERROR | {$exception->getMessage()} {$exception->getTraceAsString()} \n";
74 break; 74 break;
75 } 75 }
76 } 76 }