作者 lyh

gx

@@ -9,7 +9,9 @@ @@ -9,7 +9,9 @@
9 9
10 namespace App\Console\Commands\Ticket; 10 namespace App\Console\Commands\Ticket;
11 11
  12 +use App\Models\Manage\BelongingGroup;
12 use App\Models\Manage\ManageHr; 13 use App\Models\Manage\ManageHr;
  14 +use App\Models\Ticket\TicketDailyDeptCount;
13 use App\Models\Ticket\TicketDailyManageCount; 15 use App\Models\Ticket\TicketDailyManageCount;
14 use App\Models\WorkOrder\TicketLog; 16 use App\Models\WorkOrder\TicketLog;
15 use App\Models\WorkOrder\TicketProject; 17 use App\Models\WorkOrder\TicketProject;
@@ -33,6 +35,11 @@ class TicketCount extends Command @@ -33,6 +35,11 @@ class TicketCount extends Command
33 */ 35 */
34 protected $description = '日统计工单'; 36 protected $description = '日统计工单';
35 37
  38 + public $belong = [
  39 + 1 => [1,2,3,4,5,6,7,8,9],
  40 + 2 => [10,11,12],
  41 + ];
  42 +
36 /** 43 /**
37 * @remark :统计脚本 44 * @remark :统计脚本
38 * @name :handle 45 * @name :handle
@@ -41,7 +48,16 @@ class TicketCount extends Command @@ -41,7 +48,16 @@ class TicketCount extends Command
41 * @time :2025/8/7 17:45 48 * @time :2025/8/7 17:45
42 */ 49 */
43 public function handle(){ 50 public function handle(){
44 - 51 + $action = $this->argument('action');
  52 + if($action == 'manage_action'){
  53 + $this->manage_action();
  54 + }
  55 + if($action == 'dept_action'){
  56 + $this->dept_action();
  57 + }
  58 + if($action == 'yesterday_daily_action'){
  59 + $this->yesterday_daily_action();
  60 + }
45 } 61 }
46 62
47 /** 63 /**
@@ -57,7 +73,7 @@ class TicketCount extends Command @@ -57,7 +73,7 @@ class TicketCount extends Command
57 $date = date('Y-m-d'); 73 $date = date('Y-m-d');
58 $ticketManageCountModel = new TicketDailyManageCount(); 74 $ticketManageCountModel = new TicketDailyManageCount();
59 foreach ($manageList as $item){ 75 foreach ($manageList as $item){
60 - $this->output('执行的人员名称/id:'.$item['name'].'/'.$item['manage_id']); 76 + $this->output('按人员统计:执行的人员名称/id:'.$item['name'].'/'.$item['manage_id']);
61 $ticketLogModel = new TicketLog(); 77 $ticketLogModel = new TicketLog();
62 $ticket_num = $ticketLogModel->counts(['engineer_id'=>$item['manage_id'],'is_engineer'=>1]); 78 $ticket_num = $ticketLogModel->counts(['engineer_id'=>$item['manage_id'],'is_engineer'=>1]);
63 //工单总时长 79 //工单总时长
@@ -66,6 +82,7 @@ class TicketCount extends Command @@ -66,6 +82,7 @@ class TicketCount extends Command
66 if(!empty($timeCount)){ 82 if(!empty($timeCount)){
67 $average_time = round($timeCount / $ticket_end_num, 2); 83 $average_time = round($timeCount / $ticket_end_num, 2);
68 } 84 }
  85 + //最快完成的时间
69 $fastest_time = $ticketLogModel->formatQuery(['engineer_id'=>$item['manage_id'],'is_engineer'=>1,'end_at'=>['!=',null]])->min('end_time'); 86 $fastest_time = $ticketLogModel->formatQuery(['engineer_id'=>$item['manage_id'],'is_engineer'=>1,'end_at'=>['!=',null]])->min('end_time');
70 //超时工单数量 87 //超时工单数量
71 $timeout_num = $ticketLogModel->counts(['end_at'=>null,'plan_end_at'=>['>',date('Y-m-d H:i:s')]]); 88 $timeout_num = $ticketLogModel->counts(['end_at'=>null,'plan_end_at'=>['>',date('Y-m-d H:i:s')]]);
@@ -94,6 +111,76 @@ class TicketCount extends Command @@ -94,6 +111,76 @@ class TicketCount extends Command
94 } 111 }
95 112
96 /** 113 /**
  114 + * @remark :按技术组统计数据
  115 + * @name :dept_action
  116 + * @author :lyh
  117 + * @method :post
  118 + * @time :2025/8/8 11:48
  119 + */
  120 + public function dept_action(){
  121 + $belongingGroupModel = new BelongingGroup();
  122 + $groupList = $belongingGroupModel->list(['id'=>['in',[1,2,3,4,5,6,7,8,9]]],'id',['id','name']);
  123 + $manageHrModel = new ManageHr();
  124 + $ticketLogModel = new TicketLog();
  125 + $ticketDailyDeptModel = new TicketDailyDeptCount();
  126 + $date = date('Y-m-d');
  127 + foreach ($groupList as $item){
  128 + $this->output('组统计:执行的组/id:'.$item['name'].'/'.$item['id']);
  129 + $manageIdArr = $manageHrModel->selectField(['belong_group'=>$item['id'],'status'=>1],'manage_id');
  130 + $ticket_num = $ticketLogModel->counts(['engineer_id'=>['in',$manageIdArr],'is_engineer'=>1]);
  131 + $timeCount = $ticketLogModel->formatQuery(['engineer_id'=>['in',$manageIdArr],'is_engineer'=>1])->sum('end_time');
  132 + $average_time = round($timeCount / $ticket_num, 2);
  133 + $data = [
  134 + 'date'=>$date,
  135 + 'dept_id'=>$item['id'],
  136 + 'dept_name'=>$item['name'],
  137 + 'ticket_num'=>$ticket_num ?? 0,
  138 + 'average_time'=>$average_time
  139 + ];
  140 + $deptInfo = $ticketDailyDeptModel->read(['date'=>$date,'dept_id'=>$item['id']],['id']);
  141 + if($deptInfo === false){
  142 + $ticketDailyDeptModel->addReturnId($data);
  143 + }else{
  144 + $ticketDailyDeptModel->edit($data,['id'=>$deptInfo['id']]);
  145 + }
  146 + }
  147 + return true;
  148 + }
  149 +
  150 + /**
  151 + * @remark :
  152 + * @name :daily_action
  153 + * @author :lyh
  154 + * @method :post
  155 + * @time :2025/8/8 14:33
  156 + */
  157 + public function yesterday_daily_action(){
  158 + $ticketModel = new Tickets();
  159 + $date = Carbon::yesterday()->toDateString(); // "2025-08-07"
  160 + $ticket_num = $ticketModel->counts(['id'=>['!=',0]]);
  161 + $add_num = $ticketModel->counts(['created_at'=>['between',[$date.' 00:00:00',$date.' 23:59:59']]]);
  162 + $untreated_num = $ticketModel->counts(['end_at'=>null]);
  163 + $processed_num = $ticketModel->counts(['end_at'=>['between',[$date.' 00:00:00',$date.' 23:59:59']]]);
  164 + $submit_a_side = $ticketModel->formatQuery(['submit_side'=>1])->sum('submit_side');
  165 + $submit_b_side = $ticketModel->formatQuery(['submit_side'=>2])->sum('submit_side');
  166 + $data = [
  167 + 'date' => $date,
  168 + 'ticket_num'=>$ticket_num,
  169 + 'add_num'=>$add_num,
  170 + 'untreated_num'=>$untreated_num,
  171 + 'processed_num'=>$processed_num,
  172 + 'source'=>json_encode(['a'=>$submit_a_side,'b'=>$submit_b_side]),
  173 + ];
  174 + $ticketInfo = $ticketModel->read(['date'=>$date],['id']);
  175 + if($ticketInfo === false){
  176 + $ticketModel->addReturnId($data);
  177 + }else{
  178 + $ticketModel->edit($data,['id'=>$ticketInfo['id']]);
  179 + }
  180 + return true;
  181 + }
  182 +
  183 + /**
97 * @remark :日志 184 * @remark :日志
98 * @name :output 185 * @name :output
99 * @author :lyh 186 * @author :lyh