diff --git a/app/admin/service/UserService.php b/app/admin/service/UserService.php index 4ce782a..d3d1175 100644 --- a/app/admin/service/UserService.php +++ b/app/admin/service/UserService.php @@ -55,6 +55,9 @@ class UserService $k = '%' . $p['keyword'] . '%'; $config['where']['name'] = ['like', $k]; } + if (isset($p['user_id']) && $p['user_id']) { + $config['where']['user_id'] = $p['user_id']; + } if (isset($p['id']) && $p['id']) { $config['where']['id'] = $p['id']; } diff --git a/app/common/utils/email/Emails.php b/app/common/utils/email/Emails.php index 0bb8376..51e09f9 100644 --- a/app/common/utils/email/Emails.php +++ b/app/common/utils/email/Emails.php @@ -435,7 +435,7 @@ class Emails $channelInfo = InquiryChannel::where('id', $channel)->first(); // 初始化 UID 轮询器 - $uidRotator = new \app\common\utils\RedisUidRotator('email_parsed_result_20250804'); + $uidRotator = new \app\common\utils\RedisUidRotator('email_parsed_result_20250804', false); $uidRotator->setUids([64, 63, 83, 93, 108, 118, 131, 132, 145, 150, 143, 156, 157, 158]); EmailParsedResult::where('status', 0) diff --git a/app/controller/IndexController.php b/app/controller/IndexController.php index 6cd6d6a..995f05e 100644 --- a/app/controller/IndexController.php +++ b/app/controller/IndexController.php @@ -106,8 +106,13 @@ class IndexController public function test() { - $data = DataPermission::getRoleTreeUserIds(1); - var_dump($data); - return 22; + $uidRotator = new \app\common\utils\RedisUidRotator('email_parsed_result_20250804'); + $uidRotator->setUids([64, 63, 83, 93, 108, 118, 131, 132, 145, 150, 143, 156, 157, 158]); + + $assignedUid = $uidRotator->next(); + + flg($assignedUid, false); + + return $assignedUid; } } \ No newline at end of file diff --git a/app/crm/controller/BaseController.php b/app/crm/controller/BaseController.php index 1b824e0..91f0e95 100644 --- a/app/crm/controller/BaseController.php +++ b/app/crm/controller/BaseController.php @@ -2,6 +2,7 @@ namespace app\crm\controller; +use app\common\traits\DataTransformer; use support\Request; use support\Response; use support\exception\BusinessException; @@ -10,7 +11,10 @@ use think\Validate; abstract class BaseController { - use ResponseTrait; + /** + * 响应处理、数据格式化处理 + */ + use ResponseTrait, DataTransformer; protected mixed $validator = null; diff --git a/app/crm/controller/CustomerController.php b/app/crm/controller/CustomerController.php index 2efbceb..d1e7cdb 100644 --- a/app/crm/controller/CustomerController.php +++ b/app/crm/controller/CustomerController.php @@ -5,6 +5,7 @@ namespace app\crm\controller; use app\common\model\Corp; use app\common\model\InquiryLog; use app\common\model\User; +use app\common\traits\crud\CrudControllerTrait; use app\crm\model\Channel; use app\crm\model\Country; use app\crm\model\Customer; @@ -18,6 +19,7 @@ use support\Request; class CustomerController extends BaseController { + use CrudControllerTrait; /** * 不需要头信息的方法 @@ -26,6 +28,35 @@ class CustomerController extends BaseController protected $noNeedLogin = ['getChannel', 'getCountry']; + protected $service; + + public function __construct() + { + $this->service = new CustomerService(); + } + + /** + * 获取列表 + * + * @param Request $request 请求对象 + * @return mixed 返回分页数据及总数 + */ + public function index(Request $request) + { + try { + $raw = $this->service->serviceList($request); + $data = $this->transformData($raw, method_exists($this, 'indexFormat') + ? [$this, 'indexFormat'] + : null); + foreach ($data['records'] as &$item) { + $item = $this->service->getCustomer($item); + } + return $this->success($data); + } catch (\Throwable $e) { + return $this->error($e->getMessage().$e->getLine().$e->getFile()); + } + } + /** * 客户分级 * @param Request $request @@ -505,37 +536,14 @@ class CustomerController extends BaseController public function cede(Request $request) { $customerId = Util::getParam($request, 'customer_id'); - $user_sn = Util::getParam($request, 'user_sn'); - $userId = $request->user->uid; - if (Util::isEmpty($user_sn)) { - return $this->error('ID'.trans('not_null')); - } + $userId = Util::getParam($request, 'user_id'); - $user = User::where(['sn' => $user_sn])->first(); + $user = User::where(['id' => $userId])->first(); if (Util::isEmpty($user)) { return $this->error( trans('user_none')); } - if(Util::isEmpty($customerId)){ - $data = [ - 'user_id' => $userId - ]; - $query= Customer::where($data); - }else{ - $query= Customer::whereIn('id',explode(',',$customerId)); - } -// $customer = $query->get(); -// -// foreach ($customer as $item) { -// //记录客户关系变化 -// $his = CustomerHis::create([ -// 'customer_id' => $item->id, -// 'user_his' => $item->user_id, -// 'user_id' => $user['id'], -// ]); -// } -// $res = $query->update(['user_id' => $user->id]); - + $query= Customer::whereIn('id',explode(',',$customerId)); try { $customer = $query->get(); diff --git a/app/crm/service/CustomerService.php b/app/crm/service/CustomerService.php index 608ec04..8621636 100644 --- a/app/crm/service/CustomerService.php +++ b/app/crm/service/CustomerService.php @@ -4,6 +4,7 @@ namespace app\crm\service; use app\common\model\Corp; use app\common\model\User; +use app\common\traits\crud\CrudServiceTrait; use app\crm\logic\CustomerLogic; use app\crm\model\Channel; use app\crm\model\Country; @@ -12,9 +13,18 @@ use app\crm\model\CustomerHis; use app\crm\model\Follow; use app\crm\utils\Util; use config\constants\Constants; +use support\Request; class CustomerService { + + use CrudServiceTrait; + + /** + * 指定当前要操作的模型 + */ + protected string $modelClass = Customer::class; + public function list($params) { // $page = $request->input('page', 1); @@ -112,6 +122,46 @@ class CustomerService return $customer; } + + /** 分页列表 */ + public function serviceList(Request $request) + { + if (method_exists($this, 'complexQuery')) { + $result = $this->complexQuery($request->get()); + } else { + $config = $this->buildQueryConfig($request, 'index'); + $limit = (int)$request->get('size', 15); + $page = (int)$request->get('current', 1); + $result = $this->logicList($config, $limit, $page); + } + return $this->postProcess('List', $result); + } + /** + * 构造 CrudUtil 查询配置 + */ + protected function buildQueryConfig(Request $request, string $scene = 'default'): array + { + $p = $request->all(); + + $config = []; + $config['model'] = $this->modelClass; + switch ($scene) { + case 'index': + $config['where']['status'] = 1; // 关键字 + if (isset($p['keyword']) && $p['keyword']) { + $k = '%' . $p['keyword'] . '%'; + $config['where']['contacts'] = ['like', $k]; + } + $config['order']['id'] = 'desc'; + $config['dataLimit']['type'] = 'relation'; + $config['dataLimit']['userId'] = $request->user->uid; + $config['dataLimit']['userField'] = 'user_id'; + break; + } + + return $config; + } + public function report($params) { $id = $params['id']; @@ -187,6 +237,7 @@ class CustomerService // $customer['last_follow'] = $last_follow; $customer['enter_user_name'] = empty($customer['enter_user_id']) ? '' : User::where('id',$customer['enter_user_id'])->value('name'); + $customer['user_name'] = empty($customer['user_id']) ? '公海' : User::where('id',$customer['user_id'])->value('name'); if ($tag) { foreach ($customer['tags'] as &$tag) { diff --git a/app/crmAdmin/service/CustomerService.php b/app/crmAdmin/service/CustomerService.php index 25fb519..5f08943 100644 --- a/app/crmAdmin/service/CustomerService.php +++ b/app/crmAdmin/service/CustomerService.php @@ -130,7 +130,6 @@ class CustomerService } if ($scene == 'audit') { //审核时查询举报人姓名 $customerHis = CustomerHis::where('customer_id', $item->id)->orderBy('id', 'desc')->first(['user_his']); - var_dump($customerHis['user_his']); $item['user_name'] = empty($customerHis['user_his']) ? '' : User::where('id',$customerHis['user_his'])->value('name'); } } diff --git a/app/ticket/controller/ConversationController.php b/app/ticket/controller/ConversationController.php index 86d4fd7..fcc8ef6 100644 --- a/app/ticket/controller/ConversationController.php +++ b/app/ticket/controller/ConversationController.php @@ -28,7 +28,7 @@ class ConversationController extends BaseController ? $this->success() : $this->error(); } catch (\Throwable $th) { - return $this->error($th->getMessage().' '.$th->getLine().' '.$th->getFile()); + return $this->error($th->getMessage()); } } public function edit(Request $request) diff --git a/app/ticket/model/Conversation.php b/app/ticket/model/Conversation.php index 6d63cb5..f275f2b 100644 --- a/app/ticket/model/Conversation.php +++ b/app/ticket/model/Conversation.php @@ -29,5 +29,6 @@ class Conversation extends Model 'ticket_id', 'user_id', 'content', + 'attachment', ]; } \ No newline at end of file diff --git a/app/ticket/service/ConversationService.php b/app/ticket/service/ConversationService.php index 1716b8f..c9cbd17 100644 --- a/app/ticket/service/ConversationService.php +++ b/app/ticket/service/ConversationService.php @@ -2,6 +2,8 @@ namespace app\ticket\service; +use app\common\model\User; +use app\common\service\OssService; use app\ticket\logic\ConversationLogic; use config\constants\Constants; use support\Db; @@ -19,8 +21,18 @@ class ConversationService $result = (new ConversationLogic())->list($params); $status_fanyi = array_map(fn($v) => "{{{$v}}}", array_flip(Constants::TICKET_STATUS)); + $ossservice = new OssService(); foreach ($result as $key => $value) { - $result[$key]['content'] = str_replace($status_fanyi,$ticket_status,$value['content']); + $value=$value->toArray(); + $value['content'] = str_replace($status_fanyi,$ticket_status,$value['content']); + $value['attachment'] = empty($value['attachment'])?[]:unserialize($value['attachment']); + foreach ($value['attachment'] as $k => $attachment) { + $value['attachment'][$k]['storage_path_full'] = (!empty($attachment))?$ossservice->generatePrivateUrl($attachment['storage_path']):''; + } + $user = User::where('id', $value['user_id'])->first(); + $value['user_name'] = $user?->name; + $value['user_avatar'] = $user?->avatar; + $result[$key] = $value; } return $result; } @@ -28,6 +40,10 @@ class ConversationService public function add(array $data) { try { + $data['attachment'] = serialize($data['attachment']); + if (empty($data['content'])) { + throw new BusinessException('消息内容不能为空'); + } return (new ConversationLogic())->add($data); } catch (\Throwable $e) { throw $e; @@ -38,6 +54,7 @@ class ConversationService { try { Db::beginTransaction(); + $data['attachment'] = serialize($data['attachment']); $result = (new ConversationLogic())->edit($data); Db::commit(); return $result; diff --git a/app/ticket/service/TicketService.php b/app/ticket/service/TicketService.php index e225dec..5d451be 100644 --- a/app/ticket/service/TicketService.php +++ b/app/ticket/service/TicketService.php @@ -2,6 +2,7 @@ namespace app\ticket\service; +use app\common\model\User; use app\ticket\logic\AttachmentLogic; use app\ticket\logic\ConversationLogic; use app\ticket\logic\TicketLogic; @@ -28,6 +29,10 @@ class TicketService foreach ($v['attachments'] as &$attachments) { $attachments['storage_path_full'] = (new \app\common\service\OssService())->generatePrivateUrl($attachments['storage_path']); } + + $user = User::where('id', $v['user_id'])->first(); + $res[$k]['user_name'] = $user?->name; + $res[$k]['user_avatar'] = $user?->avatar; } unset($v); unset($attachments); @@ -45,10 +50,12 @@ class TicketService (new AttachmentLogic())->adds($attachment, $result->id, $data['user_id']); } + $cleanContent = trim(preg_replace('/\s+/', ' ', strip_tags($data['content'] ?? ''))); $conversation = [ 'ticket_id' => $result->id, - 'content' => $data['content'], + 'content' => $cleanContent, 'user_id' => $data['user_id'], + 'attachment' => $data['attachment'], ]; (new ConversationService())->add($conversation); diff --git a/config/route.php b/config/route.php index 880c4a5..9ec3687 100644 --- a/config/route.php +++ b/config/route.php @@ -190,6 +190,7 @@ Route::group('/crm', function () { //客户 Route::any('/customer/list', [app\crm\controller\CustomerController::class, 'list']); + Route::any('/customer/index', [app\crm\controller\CustomerController::class, 'index']); Route::any('/customer/detail', [app\crm\controller\CustomerController::class, 'detail']); Route::any('/customer/add', [app\crm\controller\CustomerController::class, 'save']); Route::any('/customer/claim', [app\crm\controller\CustomerController::class, 'claim']);