作者 lyh

未续费项目增加搜索

@@ -14,6 +14,7 @@ use App\Models\Manage\ManageHr; @@ -14,6 +14,7 @@ use App\Models\Manage\ManageHr;
14 use App\Models\Ticket\TicketDailyCount; 14 use App\Models\Ticket\TicketDailyCount;
15 use App\Models\Ticket\TicketDailyDeptCount; 15 use App\Models\Ticket\TicketDailyDeptCount;
16 use App\Models\Ticket\TicketDailyManageCount; 16 use App\Models\Ticket\TicketDailyManageCount;
  17 +use App\Models\Ticket\TicketMonthManageCount;
17 use App\Models\Ticket\TicketWeekManageCount; 18 use App\Models\Ticket\TicketWeekManageCount;
18 use App\Models\WorkOrder\TicketLog; 19 use App\Models\WorkOrder\TicketLog;
19 use App\Models\WorkOrder\TicketProject; 20 use App\Models\WorkOrder\TicketProject;
@@ -57,7 +58,14 @@ class TicketCount extends Command @@ -57,7 +58,14 @@ class TicketCount extends Command
57 $this->manage_action(); 58 $this->manage_action();
58 } 59 }
59 if($action == 'manage_week_action'){ 60 if($action == 'manage_week_action'){
60 - $this->manage_week_action(); 61 + $startOfLastWeek = Carbon::now()->subWeek()->startOfWeek(); // 上周一 00:00:00
  62 + $endOfLastWeek = Carbon::now()->subWeek()->endOfWeek(); // 上周日 23:59:59
  63 + $this->manage_week_month_action($startOfLastWeek,$endOfLastWeek,(new TicketWeekManageCount()));
  64 + }
  65 + if($action == 'manage_month_action'){
  66 + $startOfLastMonth = Carbon::now()->subMonth()->startOfMonth(); // 上个月 1号 00:00:00
  67 + $endOfLastMonth = Carbon::now()->subMonth()->endOfMonth(); // 上个月最后一天 23:59:59
  68 + $this->manage_week_month_action($startOfLastMonth,$endOfLastMonth,(new TicketMonthManageCount()));
61 } 69 }
62 if($action == 'dept_action'){ 70 if($action == 'dept_action'){
63 $this->dept_action(); 71 $this->dept_action();
@@ -142,29 +150,26 @@ class TicketCount extends Command @@ -142,29 +150,26 @@ class TicketCount extends Command
142 } 150 }
143 151
144 /** 152 /**
145 - * @remark :按周统计数据 153 + * @remark :按周/月统计数据
146 * @name :manage_week_action 154 * @name :manage_week_action
147 * @author :lyh 155 * @author :lyh
148 * @method :post 156 * @method :post
149 * @time :2025/8/30 9:36 157 * @time :2025/8/30 9:36
150 */ 158 */
151 - public function manage_week_action(){ 159 + public function manage_week_month_action($startOfLast,$endOfLast,$model = (new TicketWeekManageCount)){
152 $manageHrModel = new ManageHr(); 160 $manageHrModel = new ManageHr();
153 $manageList = $manageHrModel->list(['status'=>1,'dept_id'=>['in',[1,2]]],'id',['id','dept_id','manage_id','name','nickname']); 161 $manageList = $manageHrModel->list(['status'=>1,'dept_id'=>['in',[1,2]]],'id',['id','dept_id','manage_id','name','nickname']);
154 - $ticketManageCountModel = new TicketWeekManageCount();  
155 - $startOfLastWeek = Carbon::now()->subWeek()->startOfWeek(); // 上周一 00:00:00  
156 - $endOfLastWeek = Carbon::now()->subWeek()->endOfWeek(); // 上周日 23:59:59  
157 $ticketLogModel = new TicketLog(); 162 $ticketLogModel = new TicketLog();
158 foreach ($manageList as $item){ 163 foreach ($manageList as $item){
159 $this->output('按人员统计:执行的人员名称/id:'.$item['name'].'/'.$item['manage_id']); 164 $this->output('按人员统计:执行的人员名称/id:'.$item['name'].'/'.$item['manage_id']);
160 //上一周新增工单总数 165 //上一周新增工单总数
161 - $add_num = $ticketLogModel->counts(['created_at'=>['between',[$startOfLastWeek,$endOfLastWeek]],'engineer_id'=>$item['manage_id'],'is_engineer'=>1,'status'=>['!=',9]]); 166 + $add_num = $ticketLogModel->counts(['created_at'=>['between',[$startOfLast,$endOfLast]],'engineer_id'=>$item['manage_id'],'is_engineer'=>1,'status'=>['!=',9]]);
162 //上一周完成工单(创建+完成都在当周,算一条有效数据) 167 //上一周完成工单(创建+完成都在当周,算一条有效数据)
163 - $complete_num = $ticketLogModel->counts(['created_at'=>['between',[$startOfLastWeek,$endOfLastWeek]],'engineer_id'=>$item['manage_id'],'status'=>['!=',9],'is_engineer'=>1,'end_at'=>['between',[$startOfLastWeek,$endOfLastWeek]]]); 168 + $complete_num = $ticketLogModel->counts(['created_at'=>['between',[$startOfLast,$endOfLast]],'engineer_id'=>$item['manage_id'],'status'=>['!=',9],'is_engineer'=>1,'end_at'=>['between',[$startOfLast,$endOfLast]]]);
164 //上一周最快完成时长 169 //上一周最快完成时长
165 - $fastest_time = $ticketLogModel->formatQuery(['engineer_id'=>$item['manage_id'],'status'=>['!=',9],'is_engineer'=>1,'end_at'=>['between',[$startOfLastWeek,$endOfLastWeek]]])->min('end_time'); 170 + $fastest_time = $ticketLogModel->formatQuery(['engineer_id'=>$item['manage_id'],'status'=>['!=',9],'is_engineer'=>1,'end_at'=>['between',[$startOfLast,$endOfLast]]])->min('end_time');
166 //上一周完成工单总时长 171 //上一周完成工单总时长
167 - $timeCount = $ticketLogModel->formatQuery(['created_at'=>['between',[$startOfLastWeek,$endOfLastWeek]],'end_at'=>['between',[$startOfLastWeek,$endOfLastWeek]],'engineer_id'=>$item['manage_id'],'is_engineer'=>1,'status'=>['!=',9]])->sum('end_time'); 172 + $timeCount = $ticketLogModel->formatQuery(['created_at'=>['between',[$startOfLast,$endOfLast]],'end_at'=>['between',[$startOfLast,$endOfLast]],'engineer_id'=>$item['manage_id'],'is_engineer'=>1,'status'=>['!=',9]])->sum('end_time');
168 if(!empty($timeCount)){ 173 if(!empty($timeCount)){
169 $average_time = round($timeCount / $complete_num, 3); 174 $average_time = round($timeCount / $complete_num, 3);
170 } 175 }
@@ -177,17 +182,17 @@ class TicketCount extends Command @@ -177,17 +182,17 @@ class TicketCount extends Command
177 'complete_num'=>$complete_num,//完成工单数量 182 'complete_num'=>$complete_num,//完成工单数量
178 'dept_id'=>$item['dept_id'], 183 'dept_id'=>$item['dept_id'],
179 'timeout_ratio'=>$timeout_ratio ?? null, 184 'timeout_ratio'=>$timeout_ratio ?? null,
180 - 'start_at'=>$startOfLastWeek,  
181 - 'end_at'=>$endOfLastWeek 185 + 'start_at'=>$startOfLast,
  186 + 'end_at'=>$endOfLast
182 ]; 187 ];
183 //查询当前用户是否当日已有记录 188 //查询当前用户是否当日已有记录
184 - $ticketManageInfo = $ticketManageCountModel->read(['start_at'=>$startOfLastWeek,'end_at'=>$endOfLastWeek,'manage_id'=>$item['id']],['id']); 189 + $ticketManageInfo = $model->read(['start_at'=>$startOfLast,'end_at'=>$endOfLast,'manage_id'=>$item['id']],['id']);
185 if($ticketManageInfo === false){ 190 if($ticketManageInfo === false){
186 //TODO::执行新增 191 //TODO::执行新增
187 - $ticketManageCountModel->addReturnId($data); 192 + $model->addReturnId($data);
188 }else{ 193 }else{
189 //TODO::执行编辑 194 //TODO::执行编辑
190 - $ticketManageCountModel->edit($data,['id'=>$ticketManageInfo['id']]); 195 + $model->edit($data,['id'=>$ticketManageInfo['id']]);
191 } 196 }
192 } 197 }
193 return true; 198 return true;
  1 +<?php
  2 +/**
  3 + * @remark :
  4 + * @name :TicketDailyManageCount.php
  5 + * @author :lyh
  6 + * @method :post
  7 + * @time :2025/8/7 17:52
  8 + */
  9 +
  10 +namespace App\Models\Ticket;
  11 +
  12 +use App\Models\Base;
  13 +
  14 +/**
  15 + * @remark :工单日统计:按照人员统计(月)
  16 + * @name :TicketDailyManageCount
  17 + * @author :lyh
  18 + * @method :post
  19 + * @time :2025/8/7 17:53
  20 + */
  21 +class TicketMonthManageCount extends Base
  22 +{
  23 + protected $table = 'gl_ticket_month_manage_count';
  24 +}