作者 ZhengBing He

chatroom_id

... ... @@ -18,7 +18,7 @@ class FetchTicketProjects extends Command
*
* @var string
*/
protected $signature = 'workorder:fetch-ticket-projects {action}}';
protected $signature = 'workorder:fetch-ticket-projects {action}';
/**
* The console command description.
... ... @@ -274,7 +274,7 @@ class FetchTicketProjects extends Command
'version' => 1, // 版本号
'plan' => $item['plans'][0]['name'] ?? '',
'project_cate' => $project_cate,
'wechat_group_id' => $item['chatroom'],
'wechat_group_id' => $item['chatroom_id'],
];
if (!$project) {
... ...
... ... @@ -2,6 +2,8 @@
namespace App\Console\Commands\WorkOrder;
use App\Models\Manage\Manage;
use App\Models\WorkOrder\TicketChat;
use App\Models\WorkOrder\TicketLog;
use App\Services\DingTalkService;
use Illuminate\Console\Command;
... ... @@ -14,7 +16,7 @@ class WorkOrderDing extends Command
*
* @var string
*/
protected $signature = 'workorder:ding';
protected $signature = 'workorder:ding {action}';
/**
* The console command description.
... ... @@ -40,6 +42,12 @@ class WorkOrderDing extends Command
*/
public function handle()
{
$action = $this->argument('action');
$this->$action();
}
public function dingLog()
{
while (true) {
try {
$log = TicketLog::where('ding', 0)->first();
... ... @@ -55,11 +63,6 @@ class WorkOrderDing extends Command
)->get('https://oa.cmer.com/api/dingding/user/' . $mobile);
if ($response->status() == 200) {
$userid = $response->json()['data']['userid'];
// $text = "**您有新的售后工单**<br>";
// $text .= "工单ID:{$log->ticket_id}<br>";
// $text .= "工单类型:<font color='red'>{$log->ticket->title}</font><br>";
// $text .= "项目:{$log->ticket->project->title}<br>";
// $text .= "时间:{$log->created_at}<br>";
$ding = new DingTalkService();
$resp = $ding->danliao(json_encode([
'text' => "您有新的工单(ID: {$log->ticket_id}),请及时处理!",
... ... @@ -70,8 +73,10 @@ class WorkOrderDing extends Command
$log->ding = 1;
echo now() . " | INFO | 工单ID: {$log->ticket_id} 通知成功\n";
}else
echo now() . " | ERROR | 工单ID: {$log->ticket_id} 通知失败\n";
{
$log->ding = 2;
echo now() . " | ERROR | 工单ID: {$log->ticket_id} 通知失败\n";
}
$log->save();
}catch (\Exception $exception){
echo now() . " | ERROR | log ID {$log->id} {$exception->getMessage()} {$exception->getTraceAsString()} \n";
... ... @@ -80,4 +85,61 @@ class WorkOrderDing extends Command
}
}
}
public function dingChat()
{
while (true) {
$chat = TicketChat::where([
'ding' => 0,
'submit_side' => 2
])->first();
if (!$chat) {
echo now() . " | INFO | 没有通知任务\n";
sleep(3);
continue;
}
try {
$project = $chat->ticket->project;
// 通知谁?暂时通知A端最近一次提交的chat记录的人,如果没有,则通第一负责人
$lastChat = TicketChat::where('ticket_id', $chat->ticket_id)
->where('submit_side', 1)
->orderBy('id', 'desc')
->first();
if ($lastChat) {
$mobile = Manage::where('id', $lastChat->manage_id)->first()->mobile;
}else
{
$mobile = Manage::where('id', $project->first_engineer)->first()->mobile;
}
$response = Http::withBasicAuth(
env('DINGDING_BASIC_USER'),
env('DINGDING_BASIC_PASS')
)->get('https://oa.cmer.com/api/dingding/user/' . $mobile);
if ($response->status() == 200) {
$userid = $response->json()['data']['userid'];
$ding = new DingTalkService();
$resp = $ding->danliao(json_encode([
'text' => "客户对工单(ID: {$chat->ticket_id})进行了补充,请及时查看处理!",
'title' => 'AI协同工单 - ' . $project->title,
'picUrl' => 'https://hub.globalso.com/logocm.png',
'messageUrl' => 'https://oa.quanqiusou.cn/afterorder?project_id=' . $project->uuid,
]), [$userid], 'sampleLink');
$chat->ding = 1;
echo now() . " | INFO | 工单ID: {$chat->ticket_id} 通知成功\n";
}else
{
$chat->ding = 2;
echo now() . " | ERROR | 工单ID: {$chat->ticket_id} 通知失败\n";
}
$chat->save();
}catch (\Exception $exception) {
echo now() . " | ERROR | chat ID {$chat->id} {$exception->getMessage()} {$exception->getTraceAsString()} \n";
$chat->ding = 2;
$chat->save();
}
}
}
}
... ...