作者 ZhengBing He

bug

<?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('project_id', 1)
->first();
if (!$tick) {
sleep(3);
continue;
}
$project = $tick->project;
if ($project->version != 6 || $project->is_del == 1) {
$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() . " 项目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://www.cmer.com/uploads/logo1.png',
'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() . " 项目ID:{$project->table_id} 工单ID:{$tick->id} 推送成功\n";
}catch (\Exception $exception){
echo date('Y-m-d H:i:s')." ".$exception->getMessage()."\n";
break;
}
}
}
}
... ...
... ... @@ -26,7 +26,7 @@ class AsideTicketController extends BaseController
'logs.engineer:id,name',
'project',
])
->when($validated['engineer_id'], function ($query) use ($validated) {
->when(!empty($validated['engineer_id']), function ($query) use ($validated) {
// 查 gl_tickets 表 submit_user_id 或 gl_ticket_logs 表 engineer_id
$engineerId = $validated['engineer_id'];
return $query->where(function ($q) use ($engineerId) {
... ...
... ... @@ -27,6 +27,7 @@ class MessagePush extends Base
const TYPE_INQUIRY = 'inquiry';
const TYPE_WEEK = 'week';
const TYPE_TICKET = 'ticket';
//设置关联表名
/**
* @var mixed
... ...