作者 ZhengBing He

tickeding

... ... @@ -149,7 +149,7 @@ class AsideTicketController extends BaseController
$ticket->save();
// 分配工单参与人
$this->saveEngineers($request->input('engineer_ids', []));
$ticket->saveEngineers($request->input('engineer_ids', []));
$project->pushWechatGroupMsg("创贸({$ticket->submit_username})新增了工单(ID:{$ticket->id}),请及时处理!");
return $ticket;
});
... ...
... ... @@ -78,6 +78,7 @@ class AsideTicketLogController extends BaseController
// 是否有未完成的子任务
$pending = $ticket->logs()
->where('status', '<', TicketLog::STATUS_COMPLETED)
->where('is_engineer', 1)
->count();
if ($pending)
{
... ... @@ -89,6 +90,7 @@ class AsideTicketLogController extends BaseController
$ticket->end_at = now();
$project = $ticket->project;
$project->pushWechatGroupMsg("工单(ID:{$ticket->id})已全部完成,请访问查看详情!");
$ticket->pushDing('finish');
}
$ticket->save();
return $log;
... ...
<?php
namespace App\Models\WorkOrder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class TicketDing extends Model
{
use HasFactory;
protected $table = 'gl_ticket_dings';
}
... ...
... ... @@ -62,7 +62,9 @@ class Tickets extends Base
$log->engineer_id = $engineer_id;
$log->is_engineer = in_array($engineer_id, $engineer_ids);
$this->logs()->save($log);
}catch (\Exception $exception){}
}catch (\Exception $exception){
Log::error(" | ERRPR | Ticket saveEngineers {$exception->getMessage()} \n {$exception->getTraceAsString()}");
}
}
// 删除没有参与当前工单的人员(若之前已有)
... ... @@ -70,15 +72,16 @@ class Tickets extends Base
}
/**
* 推送钉钉通知任务
* TODO 这个是一个补充功能
* 那些情况需要推送钉钉内部通知?
* 1. 客户提交了工单
* - 通知第一负责人
* - 通知第一负责人 (gl_ticket_logs 表做了标记)
* 2. 客户补充了工单
* - 通知最近的聊天技术
* - 通知最近的聊天技术(gl_ticket_chats 表做了标记)
* 3. 技术完成了工单
* - 通知第一负责人,通知企微群
* - 通知第一负责人 (暂无,所以这里做补充,如果以后要把上面的逻辑也加进来也可以,只是我为了偷懒,暂时只考虑完成工单请款)
*/
public function pushDing($action = 'create')
public function pushDing($type = 'finish')
{
try {
$ding = new TicketDing();
... ... @@ -86,36 +89,23 @@ class Tickets extends Base
$ding->table_name = 'gl_tickets';
$ding->table_id = $this->id;
if ($action == 'create')
if ($type == 'finish')
{
// 客户提交了工单
// 所以技术完成了工单,通知第一负责人 和 工单的提交人
$ding->userIds = [$this->project->engineer_id];
if ($this->submit_side == 1) {
// A 端提的,还要通知提交人
$ding->userIds[] = $this->submit_user_id;
// 去重
$ding->userIds = array_unique($ding->userIds);
}
$ding->msgParam = json_encode([
'text' => "您有新的工单(ID: {$this->id}),请及时处理!",
'text' => "工单(ID: {$this->id}),已经全部完成,请访问查看详情!",
'title' => 'AI协同工单 - ' . $this->project->title,
'picUrl' => 'https://hub.globalso.com/logocm.png',
'messageUrl' => 'https://oa.quanqiusou.cn/afterorder?project_id=' . $this->project->uuid,
], JSON_UNESCAPED_UNICODE);
$ding->save();
}elseif ($action == 'chat'){
// 客户补充了工单
$ding = new TicketDing();
$lastChat = TicketChat::where('ticket_id', $this->id)
->where('submit_side', 1)
->orderBy('id', 'desc')
->first();
$ding->userIds = [!empty($lastChat) ? $lastChat->manage_id : $this->project->engineer_id];
$ding->msgParam = json_encode([
'text' => "客户补充了工单(ID: {$this->id}),请及时处理!",
'title' => 'AI协同工单 - ' . $this->project->title,
'picUrl' => 'https://hub.globalso.com/logocm.png',
'messageUrl' => 'https://oa.quanqiusou.cn/afterorder?project_id=' . $this->project->uuid,
], JSON_UNESCAPED_UNICODE);
$ding->save();
}elseif ($action == 'finish'){
// 完成工单
}
}catch (\Exception $exception){
Log::error(" | ERRPR | Ticket {$exception->getMessage()} \n {$exception->getTraceAsString()}");
... ...
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateTicketDingsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('gl_ticket_dings', function (Blueprint $table) {
$table->id();
$table->json('userIds')->comment('接收人ID列表');
$table->string('msgKey')->default('sampleMarkdown')->comment('消息模板标识');
$table->json('msgParam')->comment('消息内容参数,JSON格式');
$table->smallInteger('status')->default(0)->index()->comment('发送状态:0-未发送,1-已发送,2-发送失败');
$table->string('errorMsg')->nullable()->comment('错误信息,发送失败时记录');
$table->string('table_name', 50)->nullable()->comment('关联表名称');
$table->string('table_id', 50)->nullable()->comment('关联表ID');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('gl_ticket_dings');
}
}
... ...