最新版本
This commit is contained in:
@@ -4,6 +4,7 @@ namespace app\common\service;
|
||||
|
||||
use app\common\model\Tickets;
|
||||
use app\common\model\CompanyOperators;
|
||||
use app\common\model\Companys;
|
||||
use app\common\model\User;
|
||||
|
||||
use think\facade\Cache;
|
||||
@@ -26,20 +27,20 @@ class TicketService
|
||||
}
|
||||
|
||||
// 运营人员筛选
|
||||
if (!empty($params['operator_name'])) {
|
||||
$query->where('operator_name', $params['operator_name']);
|
||||
if (!empty($params['operator_id'])) {
|
||||
$query->where('operator_id', $params['operator_id']);
|
||||
}
|
||||
|
||||
// 负责人筛选
|
||||
if (!empty($params['username'])) {
|
||||
$query->where('username', $params['username']);
|
||||
if (!empty($params['user_id'])) {
|
||||
$query->where('user_id', $params['user_id']);
|
||||
}
|
||||
|
||||
// 关键词搜索
|
||||
if (!empty($params['searchKeyword'])) {
|
||||
$query->where(function ($q) use ($params) {
|
||||
$q->where('website', 'like', '%' . $params['searchKeyword'] . '%')
|
||||
->whereOr('operator_name', 'like', '%' . $params['searchKeyword'] . '%');
|
||||
->whereOr('remark', 'like', '%' . $params['searchKeyword'] . '%');
|
||||
});
|
||||
}
|
||||
|
||||
@@ -109,7 +110,6 @@ class TicketService
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 更新工单
|
||||
* @param $id 工单id
|
||||
@@ -170,13 +170,70 @@ class TicketService
|
||||
}
|
||||
|
||||
|
||||
public function TestgetAllOperators()
|
||||
{
|
||||
$operators = Companys::with('companyoperators')->select();
|
||||
return $operators;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取员工列表(下拉筛选用)
|
||||
* 统计各状态工单数量
|
||||
*/
|
||||
public function getTicketDashboardStats()
|
||||
{
|
||||
return [
|
||||
'total' => Tickets::count(),
|
||||
'status_counts' => Tickets::field('status, COUNT(*) as count')
|
||||
->group('status')
|
||||
->select()
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量更新工单(事务内执行)
|
||||
*/
|
||||
public function batchUpdateTickets(array $ids, array $data, array $allowFields, $uid, $isSuper = false)
|
||||
{
|
||||
if (empty($ids)) {
|
||||
throw new \Exception('请选择要更新的工单');
|
||||
}
|
||||
|
||||
$updateData = [];
|
||||
foreach ($allowFields as $field) {
|
||||
if (array_key_exists($field, $data)) {
|
||||
$updateData[$field] = $data[$field];
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($updateData)) {
|
||||
throw new \Exception('没有合法的更新字段');
|
||||
}
|
||||
|
||||
$tickets = Tickets::whereIn('id', $ids)->select();
|
||||
|
||||
if ($tickets->isEmpty()) {
|
||||
throw new \Exception('未找到任何工单');
|
||||
}
|
||||
|
||||
\think\facade\Db::transaction(function () use ($tickets, $updateData, $uid, $isSuper) {
|
||||
foreach ($tickets as $ticket) {
|
||||
if (!$isSuper) {
|
||||
if (!is_null($ticket->user_id) && $ticket->user_id != $uid) {
|
||||
throw new \Exception("工单 #{$ticket->id} 没有权限修改");
|
||||
}
|
||||
}
|
||||
$ticket->save($updateData);
|
||||
}
|
||||
});
|
||||
|
||||
return ['updated_count' => count($tickets)];
|
||||
}
|
||||
|
||||
public function getStaffList()
|
||||
{
|
||||
$map = [
|
||||
'role' => 'user',
|
||||
'role' => ['user', 'admin'],
|
||||
'status' => 1
|
||||
];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user