最新版本

This commit is contained in:
2026-05-26 09:44:21 +08:00
parent 822ed9a099
commit fa41edf857
24 changed files with 597 additions and 163 deletions

View File

@@ -9,6 +9,8 @@ class CompanyOperators extends Model
{
protected $table = 'company_operators';
protected $hidden = ['company_id', 'create_time', 'status'];
public function company()
{
return $this->belongsTo(Companys::class, 'company_id', 'id');

View File

@@ -9,4 +9,20 @@ class Companys extends Model
{
protected $table = 'companys';
public function companyoperators()
{
return $this->hasMany(CompanyOperators::class, 'company_id', 'id');
}
public static function customDelete($id)
{
$companyAndOperators = self::with(['companyoperators'])->where('id', $id)->find();
if (!$companyAndOperators) {
return false;
}
$companyAndOperators->companyoperators()->delete();
$companyAndOperators->delete();
return true;
}
}

View File

@@ -1,32 +0,0 @@
<?php
namespace app\common\model;
use think\Model;
use app\common\model\CustomerEmployees;
class Customers extends Model
{
protected $table = 'customers';
public function employees()
{
return $this->hasMany(CustomerEmployees::class, 'customer_id', 'id');
}
/* 模型事件:在删除客户记录之后执行 */
public static function onAfterDelete($customer)
{
// 删除与该客户相关的员工记录
$customer->employees()->delete();
}
public function getCompanyOfAccount(){
return $this->hasMany(User::class,'company_id','id');
}
}

View File

@@ -3,6 +3,9 @@
namespace app\common\model;
use think\Model;
use app\common\model\Companys;
use app\common\model\Tickets;
class User extends Model
@@ -13,4 +16,9 @@ class User extends Model
return $this->belongsTo(Companys::class,'company_id','id');
}
public function tickets()
{
return $this->hasMany(Tickets::class, 'user_id', 'id');
}
}

View File

@@ -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
];