作者 ZhengBing He

bug

  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('project_id', 1)
  47 + ->first();
  48 + if (!$tick) {
  49 + sleep(3);
  50 + continue;
  51 + }
  52 + $project = $tick->project;
  53 + if ($project->version != 6 || $project->is_del == 1) {
  54 + $tick->ding = 1;
  55 + $tick->save();
  56 + continue;
  57 + }
  58 + $message_push = new MessagePush();
  59 + $message_push->project_id = $project->table_id;
  60 + $message_push->friend_id = ProjectAssociation::where('project_id', $project->table_id)
  61 + ->where('status', ProjectAssociation::STATUS_NORMAL)
  62 + ->where('binding_app', ProjectAssociation::ENTERPRISE_WECHAT)
  63 + ->value('friend_id');
  64 + if (empty($message_push->friend_id))
  65 + {
  66 + echo now() . " 项目ID:{$project->table_id} 没有绑定企微群\n";
  67 + $tick->ding = 1;
  68 + $tick->save();
  69 + continue;
  70 + }
  71 + $message_push->content_type = 'Link';
  72 + $message_push->content = json_encode([
  73 + 'title' => '工单查看 - ' . $project->company_name,
  74 + 'desc' => $tick->title,
  75 + 'size' => 0,
  76 + 'thumbSize' => 0,
  77 + 'thumbUrl' => 'https://www.cmer.com/uploads/logo1.png',
  78 + 'url' => 'https://oa.quanqiusou.cn/tickets?project_id='.$project->uuid
  79 + ], JSON_UNESCAPED_UNICODE);
  80 + $message_push->send_time = now();
  81 + $message_push->type = MessagePush::TYPE_TICKET;
  82 + $message_push->save();
  83 + $tick->ding = 1;
  84 + $tick->save();
  85 + echo now() . " 项目ID:{$project->table_id} 工单ID:{$tick->id} 推送成功\n";
  86 + }catch (\Exception $exception){
  87 + echo date('Y-m-d H:i:s')." ".$exception->getMessage()."\n";
  88 + break;
  89 + }
  90 + }
  91 + }
  92 +}
@@ -26,7 +26,7 @@ class AsideTicketController extends BaseController @@ -26,7 +26,7 @@ class AsideTicketController extends BaseController
26 'logs.engineer:id,name', 26 'logs.engineer:id,name',
27 'project', 27 'project',
28 ]) 28 ])
29 - ->when($validated['engineer_id'], function ($query) use ($validated) { 29 + ->when(!empty($validated['engineer_id']), function ($query) use ($validated) {
30 // 查 gl_tickets 表 submit_user_id 或 gl_ticket_logs 表 engineer_id 30 // 查 gl_tickets 表 submit_user_id 或 gl_ticket_logs 表 engineer_id
31 $engineerId = $validated['engineer_id']; 31 $engineerId = $validated['engineer_id'];
32 return $query->where(function ($q) use ($engineerId) { 32 return $query->where(function ($q) use ($engineerId) {
@@ -27,6 +27,7 @@ class MessagePush extends Base @@ -27,6 +27,7 @@ class MessagePush extends Base
27 27
28 const TYPE_INQUIRY = 'inquiry'; 28 const TYPE_INQUIRY = 'inquiry';
29 const TYPE_WEEK = 'week'; 29 const TYPE_WEEK = 'week';
  30 + const TYPE_TICKET = 'ticket';
30 //设置关联表名 31 //设置关联表名
31 /** 32 /**
32 * @var mixed 33 * @var mixed