作者 ZhengBing He

chatroom_id

@@ -18,7 +18,7 @@ class FetchTicketProjects extends Command @@ -18,7 +18,7 @@ class FetchTicketProjects extends Command
18 * 18 *
19 * @var string 19 * @var string
20 */ 20 */
21 - protected $signature = 'workorder:fetch-ticket-projects {action}}'; 21 + protected $signature = 'workorder:fetch-ticket-projects {action}';
22 22
23 /** 23 /**
24 * The console command description. 24 * The console command description.
@@ -274,7 +274,7 @@ class FetchTicketProjects extends Command @@ -274,7 +274,7 @@ class FetchTicketProjects extends Command
274 'version' => 1, // 版本号 274 'version' => 1, // 版本号
275 'plan' => $item['plans'][0]['name'] ?? '', 275 'plan' => $item['plans'][0]['name'] ?? '',
276 'project_cate' => $project_cate, 276 'project_cate' => $project_cate,
277 - 'wechat_group_id' => $item['chatroom'], 277 + 'wechat_group_id' => $item['chatroom_id'],
278 ]; 278 ];
279 279
280 if (!$project) { 280 if (!$project) {
@@ -2,6 +2,8 @@ @@ -2,6 +2,8 @@
2 2
3 namespace App\Console\Commands\WorkOrder; 3 namespace App\Console\Commands\WorkOrder;
4 4
  5 +use App\Models\Manage\Manage;
  6 +use App\Models\WorkOrder\TicketChat;
5 use App\Models\WorkOrder\TicketLog; 7 use App\Models\WorkOrder\TicketLog;
6 use App\Services\DingTalkService; 8 use App\Services\DingTalkService;
7 use Illuminate\Console\Command; 9 use Illuminate\Console\Command;
@@ -14,7 +16,7 @@ class WorkOrderDing extends Command @@ -14,7 +16,7 @@ class WorkOrderDing extends Command
14 * 16 *
15 * @var string 17 * @var string
16 */ 18 */
17 - protected $signature = 'workorder:ding'; 19 + protected $signature = 'workorder:ding {action}';
18 20
19 /** 21 /**
20 * The console command description. 22 * The console command description.
@@ -40,6 +42,12 @@ class WorkOrderDing extends Command @@ -40,6 +42,12 @@ class WorkOrderDing extends Command
40 */ 42 */
41 public function handle() 43 public function handle()
42 { 44 {
  45 + $action = $this->argument('action');
  46 + $this->$action();
  47 + }
  48 +
  49 + public function dingLog()
  50 + {
43 while (true) { 51 while (true) {
44 try { 52 try {
45 $log = TicketLog::where('ding', 0)->first(); 53 $log = TicketLog::where('ding', 0)->first();
@@ -55,11 +63,6 @@ class WorkOrderDing extends Command @@ -55,11 +63,6 @@ class WorkOrderDing extends Command
55 )->get('https://oa.cmer.com/api/dingding/user/' . $mobile); 63 )->get('https://oa.cmer.com/api/dingding/user/' . $mobile);
56 if ($response->status() == 200) { 64 if ($response->status() == 200) {
57 $userid = $response->json()['data']['userid']; 65 $userid = $response->json()['data']['userid'];
58 -// $text = "**您有新的售后工单**<br>";  
59 -// $text .= "工单ID:{$log->ticket_id}<br>";  
60 -// $text .= "工单类型:<font color='red'>{$log->ticket->title}</font><br>";  
61 -// $text .= "项目:{$log->ticket->project->title}<br>";  
62 -// $text .= "时间:{$log->created_at}<br>";  
63 $ding = new DingTalkService(); 66 $ding = new DingTalkService();
64 $resp = $ding->danliao(json_encode([ 67 $resp = $ding->danliao(json_encode([
65 'text' => "您有新的工单(ID: {$log->ticket_id}),请及时处理!", 68 'text' => "您有新的工单(ID: {$log->ticket_id}),请及时处理!",
@@ -70,8 +73,10 @@ class WorkOrderDing extends Command @@ -70,8 +73,10 @@ class WorkOrderDing extends Command
70 $log->ding = 1; 73 $log->ding = 1;
71 echo now() . " | INFO | 工单ID: {$log->ticket_id} 通知成功\n"; 74 echo now() . " | INFO | 工单ID: {$log->ticket_id} 通知成功\n";
72 }else 75 }else
73 - echo now() . " | ERROR | 工单ID: {$log->ticket_id} 通知失败\n"; 76 + {
74 $log->ding = 2; 77 $log->ding = 2;
  78 + echo now() . " | ERROR | 工单ID: {$log->ticket_id} 通知失败\n";
  79 + }
75 $log->save(); 80 $log->save();
76 }catch (\Exception $exception){ 81 }catch (\Exception $exception){
77 echo now() . " | ERROR | log ID {$log->id} {$exception->getMessage()} {$exception->getTraceAsString()} \n"; 82 echo now() . " | ERROR | log ID {$log->id} {$exception->getMessage()} {$exception->getTraceAsString()} \n";
@@ -80,4 +85,61 @@ class WorkOrderDing extends Command @@ -80,4 +85,61 @@ class WorkOrderDing extends Command
80 } 85 }
81 } 86 }
82 } 87 }
  88 +
  89 + public function dingChat()
  90 + {
  91 + while (true) {
  92 + $chat = TicketChat::where([
  93 + 'ding' => 0,
  94 + 'submit_side' => 2
  95 + ])->first();
  96 +
  97 + if (!$chat) {
  98 + echo now() . " | INFO | 没有通知任务\n";
  99 + sleep(3);
  100 + continue;
  101 + }
  102 +
  103 + try {
  104 + $project = $chat->ticket->project;
  105 +
  106 + // 通知谁?暂时通知A端最近一次提交的chat记录的人,如果没有,则通第一负责人
  107 + $lastChat = TicketChat::where('ticket_id', $chat->ticket_id)
  108 + ->where('submit_side', 1)
  109 + ->orderBy('id', 'desc')
  110 + ->first();
  111 + if ($lastChat) {
  112 + $mobile = Manage::where('id', $lastChat->manage_id)->first()->mobile;
  113 + }else
  114 + {
  115 + $mobile = Manage::where('id', $project->first_engineer)->first()->mobile;
  116 + }
  117 + $response = Http::withBasicAuth(
  118 + env('DINGDING_BASIC_USER'),
  119 + env('DINGDING_BASIC_PASS')
  120 + )->get('https://oa.cmer.com/api/dingding/user/' . $mobile);
  121 + if ($response->status() == 200) {
  122 + $userid = $response->json()['data']['userid'];
  123 + $ding = new DingTalkService();
  124 + $resp = $ding->danliao(json_encode([
  125 + 'text' => "客户对工单(ID: {$chat->ticket_id})进行了补充,请及时查看处理!",
  126 + 'title' => 'AI协同工单 - ' . $project->title,
  127 + 'picUrl' => 'https://hub.globalso.com/logocm.png',
  128 + 'messageUrl' => 'https://oa.quanqiusou.cn/afterorder?project_id=' . $project->uuid,
  129 + ]), [$userid], 'sampleLink');
  130 + $chat->ding = 1;
  131 + echo now() . " | INFO | 工单ID: {$chat->ticket_id} 通知成功\n";
  132 + }else
  133 + {
  134 + $chat->ding = 2;
  135 + echo now() . " | ERROR | 工单ID: {$chat->ticket_id} 通知失败\n";
  136 + }
  137 + $chat->save();
  138 + }catch (\Exception $exception) {
  139 + echo now() . " | ERROR | chat ID {$chat->id} {$exception->getMessage()} {$exception->getTraceAsString()} \n";
  140 + $chat->ding = 2;
  141 + $chat->save();
  142 + }
  143 + }
  144 + }
83 } 145 }