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