TicketLogic.php
4.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
/**
* @remark :
* @name :TicketLogic.php
* @author :lyh
* @method :post
* @time :2025/8/11 10:54
*/
namespace App\Http\Logic\Aside\Ticket;
use App\Http\Logic\Aside\BaseLogic;
use App\Models\Manage\ManageHr;
use App\Models\Project\Project;
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\Support\Carbon;
class TicketLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->param = $this->requestAll;
}
/**
* @remark :获取今日统计数据
* @name :getTicketCount
* @author :lyh
* @method :post
* @time :2025/8/11 10:54
*/
public function getTicketCount(){
$data = [];
$ticketModel = new Tickets();
$data['ticket_num'] = $ticketModel->count();//工单总数
$date = date('Y-m-d');//今日时间
$data['add_num'] = $ticketModel->counts(['created_at'=>['between',[$date.' 00:00:00',$date.' 23:59:59']]]);//今日新增工单
$data['processed_num'] = $ticketModel->counts(['end_at'=>['between',[$date.' 00:00:00',$date.' 23:59:59']]]);//今日已处理工单
$data['untreated_num'] = $ticketModel->counts(['end_at'=>null]);//今日未处理工单
$submit_a_side = $ticketModel->formatQuery(['submit_side'=>1])->sum('submit_side');
$submit_b_side = $ticketModel->formatQuery(['submit_side'=>2])->sum('submit_side');
$data['source'] = ['a'=>$submit_a_side,'b'=>$submit_b_side];
return $this->success($data);
}
/**
* @remark :按日统计数据
* @name :getDailyTicketCount
* @author :lyh
* @method :post
* @time :2025/8/11 10:57
*/
public function getDailyTicketCount(){
$date = Carbon::yesterday()->toDateString(); //昨日时间
$dailyModel = new TicketDailyCount();
$dailyList = $dailyModel->list([],'date',['*'],'desc',5);//取最近5条数据
$manageModel = new TicketDailyManageCount();
$manageList = $manageModel->list(['date'=>$date,'ticket_num'=>['!=',0],'average_time'=>['!=',null]],'average_time',['*'],'asc',5);//取最近5条数据
$deptModel = new TicketDailyDeptCount();
$deptList = $deptModel->list(['date'=>$date],'average_time',['*'],'asc',5);
$data = ['daily'=>$dailyList,'manage'=>$manageList,'dept'=>$deptList];
return $this->success($data);
}
/**
* @remark :获取随机工单列表(20条)
* @name :ticketList
* @author :lyh
* @method :post
* @time :2025/8/12 11:06
*/
public function getTicketList(){
$ticketsList = Tickets::select(['project_id','title','end_at','end_time','id'])->inRandomOrder()->limit(20)->get();
$projectModel = new TicketProject();
$ticketLogModel = new TicketLog();
$manageModel = new ManageHr();
foreach ($ticketsList as $key => $item){
$item['project_name'] = $projectModel->getValue(['id'=>$item['project_id']],'title');
$engineer_id = $ticketLogModel->getValue(['ticket_id'=>$item['id'],'is_engineer'=>1],'engineer_id');
if(!empty($engineer_id)){
$item['manage_name'] = $manageModel->getValue(['manage_id'=>$engineer_id],'name');
}else{
$item['manage_name'] = '未分配';
}
$ticketsList[$key] = $item;
$item['status'] = (empty($item['end_at']) ? '未完成' : '完成');
}
return $this->success($ticketsList);
}
/**
* @remark :根据技术组获取
* @name :getManageTicketCount
* @author :lyh
* @method :post
* @time :2025/8/11 14:41
*/
public function getManageTicketCount($map,$order = 'ticket_num',$desc = 'desc'){
$manageModel = new TicketDailyManageCount();
unset($map['sort']);
$map['date'] = Carbon::yesterday()->toDateString();
$manageList = $manageModel->list($map,$order,['*'],$desc);
return $this->success($manageList);
}
}