|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @remark :
|
|
|
|
* @name :TicketCount.php
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2025/8/7 17:42
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Console\Commands\Ticket;
|
|
|
|
|
|
|
|
use App\Models\Manage\BelongingGroup;
|
|
|
|
use App\Models\Manage\ManageHr;
|
|
|
|
use App\Models\Ticket\TicketDailyCount;
|
|
|
|
use App\Models\Ticket\TicketDailyDeptCount;
|
|
|
|
use App\Models\Ticket\TicketDailyManageCount;
|
|
|
|
use App\Models\WorkOrder\TicketLog;
|
|
|
|
use App\Models\WorkOrder\TicketProject;
|
|
|
|
use App\Models\WorkOrder\Tickets;
|
|
|
|
use Illuminate\Console\Command;
|
|
|
|
use Illuminate\Support\Carbon;
|
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
|
|
|
|
class TicketCount extends Command
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The name and signature of the console command.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $signature = 'ticket_count {action}';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The console command description.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $description = '日统计工单';
|
|
|
|
|
|
|
|
public $belong = [
|
|
|
|
1 => [1,2,3,4,5,6,7,8,9],
|
|
|
|
2 => [10,11,12],
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :统计脚本
|
|
|
|
* @name :handle
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2025/8/7 17:45
|
|
|
|
*/
|
|
|
|
public function handle(){
|
|
|
|
$action = $this->argument('action');
|
|
|
|
if($action == 'manage_action'){
|
|
|
|
$this->manage_action();
|
|
|
|
}
|
|
|
|
if($action == 'dept_action'){
|
|
|
|
$this->dept_action();
|
|
|
|
}
|
|
|
|
if($action == 'yesterday_daily_action'){
|
|
|
|
$this->yesterday_daily_action();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :按管理员统计(只统计技术组)
|
|
|
|
* @name :manage_action
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2025/8/7 17:45
|
|
|
|
*/
|
|
|
|
public function manage_action(){
|
|
|
|
$manageHrModel = new ManageHr();
|
|
|
|
$manageList = $manageHrModel->list(['status'=>1,'dept_id'=>['in',[1,2]]],'id',['id','dept_id','manage_id','name','nickname']);
|
|
|
|
$date = Carbon::yesterday()->toDateString(); // 昨日时间
|
|
|
|
$ticketManageCountModel = new TicketDailyManageCount();
|
|
|
|
foreach ($manageList as $item){
|
|
|
|
$this->output('按人员统计:执行的人员名称/id:'.$item['name'].'/'.$item['manage_id']);
|
|
|
|
$ticketLogModel = new TicketLog();
|
|
|
|
$ticket_num = $ticketLogModel->counts(['engineer_id'=>$item['manage_id'],'is_engineer'=>1]);
|
|
|
|
//工单总时长
|
|
|
|
$timeCount = $ticketLogModel->formatQuery(['engineer_id'=>$item['manage_id'],'is_engineer'=>1])->sum('end_time');
|
|
|
|
$ticket_end_num = $ticketLogModel->counts(['engineer_id'=>$item['manage_id'],'is_engineer'=>1,'end_at'=>['!=',null]]);
|
|
|
|
if(!empty($timeCount)){
|
|
|
|
$average_time = round($timeCount / $ticket_end_num, 2);
|
|
|
|
}
|
|
|
|
//最快完成的时间
|
|
|
|
$fastest_time = $ticketLogModel->formatQuery(['engineer_id'=>$item['manage_id'],'is_engineer'=>1,'end_at'=>['!=',null]])->min('end_time');
|
|
|
|
//超时工单数量
|
|
|
|
$timeout_num = $ticketLogModel->counts(['end_at'=>null,'engineer_id'=>$item['manage_id'],'is_engineer'=>1,'plan_end_at'=>['>',date('Y-m-d H:i:s')]]);
|
|
|
|
$complete_num = $ticketLogModel->counts(['end_at'=>['!=',null],'engineer_id'=>$item['manage_id'],'is_engineer'=>1]);
|
|
|
|
$data = [
|
|
|
|
'date'=>$date,
|
|
|
|
'manage_id'=>$item['id'],
|
|
|
|
'manage_name'=>$item['name'],
|
|
|
|
'ticket_num'=>$ticket_num,//工单总数量
|
|
|
|
'average_time'=>$average_time ?? '',//平均完成工单时长
|
|
|
|
'fastest_time'=>$fastest_time,//最快完成工单时间
|
|
|
|
'timeout_num'=>$timeout_num,//超时工单数量
|
|
|
|
'complete_num'=>$complete_num,//完成工单数量
|
|
|
|
'dept_id'=>$item['dept_id']
|
|
|
|
];
|
|
|
|
//查询当前用户是否当日已有记录
|
|
|
|
$ticketManageInfo = $ticketManageCountModel->read(['date'=>$date,'manage_id'=>$item['id']],['id']);
|
|
|
|
if($ticketManageInfo === false){
|
|
|
|
//TODO::执行新增
|
|
|
|
$ticketManageCountModel->addReturnId($data);
|
|
|
|
}else{
|
|
|
|
//TODO::执行编辑
|
|
|
|
$ticketManageCountModel->edit($data,['id'=>$ticketManageInfo['id']]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :按技术组统计数据
|
|
|
|
* @name :dept_action
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2025/8/8 11:48
|
|
|
|
*/
|
|
|
|
public function dept_action(){
|
|
|
|
$belongingGroupModel = new BelongingGroup();
|
|
|
|
$groupList = $belongingGroupModel->list(['id'=>['in',[1,2,3,4,5,6,7,8,9]]],'id',['id','name']);
|
|
|
|
$manageHrModel = new ManageHr();
|
|
|
|
$ticketLogModel = new TicketLog();
|
|
|
|
$ticketDailyDeptModel = new TicketDailyDeptCount();
|
|
|
|
$date = Carbon::yesterday()->toDateString(); // "2025-08-07"
|
|
|
|
foreach ($groupList as $item){
|
|
|
|
$this->output('组统计:执行的组/id:'.$item['name'].'/'.$item['id']);
|
|
|
|
$manageIdArr = $manageHrModel->selectField(['belong_group'=>$item['id'],'status'=>1,'dept_id'=>1],'manage_id');
|
|
|
|
$ticket_num = $ticketLogModel->counts(['engineer_id'=>['in',$manageIdArr],'is_engineer'=>1]);
|
|
|
|
$timeCount = $ticketLogModel->formatQuery(['engineer_id'=>['in',$manageIdArr],'is_engineer'=>1])->sum('end_time');
|
|
|
|
if(!empty($timeCount)){
|
|
|
|
$average_time = round($timeCount / $ticket_num, 2);
|
|
|
|
}
|
|
|
|
$data = [
|
|
|
|
'date'=>$date,
|
|
|
|
'dept_id'=>$item['id'],
|
|
|
|
'dept_name'=>$item['name'],
|
|
|
|
'ticket_num'=>$ticket_num ?? 0,
|
|
|
|
'average_time'=>$average_time ?? 0
|
|
|
|
];
|
|
|
|
$deptInfo = $ticketDailyDeptModel->read(['date'=>$date,'dept_id'=>$item['id']],['id']);
|
|
|
|
if($deptInfo === false){
|
|
|
|
$ticketDailyDeptModel->addReturnId($data);
|
|
|
|
}else{
|
|
|
|
$ticketDailyDeptModel->edit($data,['id'=>$deptInfo['id']]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :技术组所有工单记录
|
|
|
|
* @name :daily_action
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2025/8/8 14:33
|
|
|
|
*/
|
|
|
|
public function yesterday_daily_action(){
|
|
|
|
$ticketModel = new Tickets();
|
|
|
|
$date = Carbon::yesterday()->toDateString(); // "2025-08-07"
|
|
|
|
$ticket_num = $ticketModel->counts(['id'=>['!=',0]]);
|
|
|
|
$time_end_num = $ticketModel->counts(['end_at'=>['!=',null]]);//已完成的工单
|
|
|
|
$time_end_count = $ticketModel->formatQuery(['end_at'=>['!=',null]])->sum('end_time');//已完成工单时长
|
|
|
|
if(!empty($time_end_count)){
|
|
|
|
$average_time = round($time_end_count / $time_end_num, 2);
|
|
|
|
}
|
|
|
|
$add_num = $ticketModel->counts(['created_at'=>['between',[$date.' 00:00:00',$date.' 23:59:59']]]);
|
|
|
|
$untreated_num = $ticketModel->counts(['end_at'=>null]);
|
|
|
|
$processed_num = $ticketModel->counts(['end_at'=>['between',[$date.' 00:00:00',$date.' 23:59:59']]]);
|
|
|
|
$submit_a_side = $ticketModel->formatQuery(['submit_side'=>1])->sum('submit_side');
|
|
|
|
$submit_b_side = $ticketModel->formatQuery(['submit_side'=>2])->sum('submit_side');
|
|
|
|
$data = [
|
|
|
|
'date' => $date,
|
|
|
|
'ticket_num'=>$ticket_num,
|
|
|
|
'add_num'=>$add_num,
|
|
|
|
'untreated_num'=>$untreated_num,
|
|
|
|
'processed_num'=>$processed_num,
|
|
|
|
'average_time'=>$average_time ?? '',
|
|
|
|
'source'=>json_encode(['a'=>$submit_a_side,'b'=>$submit_b_side],true),
|
|
|
|
];
|
|
|
|
$ticketDailyModel = new TicketDailyCount();
|
|
|
|
$ticketDailyInfo = $ticketDailyModel->read(['date'=>$date],['id']);
|
|
|
|
if($ticketDailyInfo === false){
|
|
|
|
$ticketDailyModel->addReturnId($data);
|
|
|
|
}else{
|
|
|
|
$ticketDailyModel->edit($data,['id'=>$ticketDailyInfo['id']]);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :日志
|
|
|
|
* @name :output
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2025/8/8 11:43
|
|
|
|
*/
|
|
|
|
public function output($message)
|
|
|
|
{
|
|
|
|
// Log::channel('ticket_log')->info($message);
|
|
|
|
echo date('Y-m-d H:i:s') . ' ' . $message . PHP_EOL;
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|