This commit is contained in:
2026-08-19 19:56:47 +08:00
parent 07a24c5297
commit d3866efcd8
11 changed files with 193 additions and 23 deletions

View File

@@ -2,11 +2,15 @@
namespace app\common\service;
use app\admin\controller\Ticket;
use app\common\model\Tickets;
use app\common\model\CompanyOperators;
use app\common\model\Companys;
use app\common\model\User;
use think\facade\Db;
use app\common\service\TicketScope;
class TicketService
{
@@ -17,12 +21,14 @@ class TicketService
* @param int $limit 每页数量
* @param string $order 排序方式
*/
public function queryTickets(array $params, int $page, int $limit, string $order)
public function queryTickets(array $params, int $page, int $limit, string $order, TicketScope $scope)
{
try {
// 查询构造器
$query = Tickets::with(['ticketStaff', 'ticketCompany', 'ticketOperator']);
$this->applyScope($query, $scope);
$equalFilters = ['operator_id', 'user_id', 'status'];
foreach ($equalFilters as $field) {
if (isset($params[$field]) && $params[$field] !== '') {
@@ -56,6 +62,21 @@ class TicketService
}
private function applyScope($query, TicketScope $scope): void
{
match ($scope->type) {
'admin' => null,
'staff' => $query->where(fn($q) => $q
->where('status', Tickets::STATUS_UNASSIGNED)
->where('user_id', $scope->staffId)),
};
}
/**
* 创建工单业务逻辑
* @param array $data 工单数据