Merge branch 'develop' into feature/mzl_dev

This commit is contained in:
mzl
2025-08-12 11:23:15 +08:00
12 changed files with 131 additions and 35 deletions
+3
View File
@@ -54,6 +54,9 @@ class UserService
$k = '%' . $p['keyword'] . '%'; $k = '%' . $p['keyword'] . '%';
$config['where']['name'] = ['like', $k]; $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']) { if (isset($p['id']) && $p['id']) {
$config['where']['id'] = $p['id']; $config['where']['id'] = $p['id'];
} }
+1 -1
View File
@@ -435,7 +435,7 @@ class Emails
$channelInfo = InquiryChannel::where('id', $channel)->first(); $channelInfo = InquiryChannel::where('id', $channel)->first();
// 初始化 UID 轮询器 // 初始化 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]); $uidRotator->setUids([64, 63, 83, 93, 108, 118, 131, 132, 145, 150, 143, 156, 157, 158]);
EmailParsedResult::where('status', 0) EmailParsedResult::where('status', 0)
+8 -3
View File
@@ -106,8 +106,13 @@ class IndexController
public function test() public function test()
{ {
$data = DataPermission::getRoleTreeUserIds(1); $uidRotator = new \app\common\utils\RedisUidRotator('email_parsed_result_20250804');
var_dump($data); $uidRotator->setUids([64, 63, 83, 93, 108, 118, 131, 132, 145, 150, 143, 156, 157, 158]);
return 22;
$assignedUid = $uidRotator->next();
flg($assignedUid, false);
return $assignedUid;
} }
} }
+5 -1
View File
@@ -2,6 +2,7 @@
namespace app\crm\controller; namespace app\crm\controller;
use app\common\traits\DataTransformer;
use support\Request; use support\Request;
use support\Response; use support\Response;
use support\exception\BusinessException; use support\exception\BusinessException;
@@ -10,7 +11,10 @@ use think\Validate;
abstract class BaseController abstract class BaseController
{ {
use ResponseTrait; /**
* 响应处理、数据格式化处理
*/
use ResponseTrait, DataTransformer;
protected mixed $validator = null; protected mixed $validator = null;
+33 -25
View File
@@ -5,6 +5,7 @@ namespace app\crm\controller;
use app\common\model\Corp; use app\common\model\Corp;
use app\common\model\InquiryLog; use app\common\model\InquiryLog;
use app\common\model\User; use app\common\model\User;
use app\common\traits\crud\CrudControllerTrait;
use app\crm\model\Channel; use app\crm\model\Channel;
use app\crm\model\Country; use app\crm\model\Country;
use app\crm\model\Customer; use app\crm\model\Customer;
@@ -18,6 +19,7 @@ use support\Request;
class CustomerController extends BaseController class CustomerController extends BaseController
{ {
use CrudControllerTrait;
/** /**
* 不需要头信息的方法 * 不需要头信息的方法
@@ -26,6 +28,35 @@ class CustomerController extends BaseController
protected $noNeedLogin = ['getChannel', 'getCountry']; 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 * @param Request $request
@@ -505,37 +536,14 @@ class CustomerController extends BaseController
public function cede(Request $request) public function cede(Request $request)
{ {
$customerId = Util::getParam($request, 'customer_id'); $customerId = Util::getParam($request, 'customer_id');
$user_sn = Util::getParam($request, 'user_sn'); $userId = Util::getParam($request, 'user_id');
$userId = $request->user->uid;
if (Util::isEmpty($user_sn)) {
return $this->error('ID'.trans('not_null'));
}
$user = User::where(['sn' => $user_sn])->first(); $user = User::where(['id' => $userId])->first();
if (Util::isEmpty($user)) { if (Util::isEmpty($user)) {
return $this->error( trans('user_none')); 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)); $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]);
try { try {
$customer = $query->get(); $customer = $query->get();
+51
View File
@@ -4,6 +4,7 @@ namespace app\crm\service;
use app\common\model\Corp; use app\common\model\Corp;
use app\common\model\User; use app\common\model\User;
use app\common\traits\crud\CrudServiceTrait;
use app\crm\logic\CustomerLogic; use app\crm\logic\CustomerLogic;
use app\crm\model\Channel; use app\crm\model\Channel;
use app\crm\model\Country; use app\crm\model\Country;
@@ -12,9 +13,18 @@ use app\crm\model\CustomerHis;
use app\crm\model\Follow; use app\crm\model\Follow;
use app\crm\utils\Util; use app\crm\utils\Util;
use config\constants\Constants; use config\constants\Constants;
use support\Request;
class CustomerService class CustomerService
{ {
use CrudServiceTrait;
/**
* 指定当前要操作的模型
*/
protected string $modelClass = Customer::class;
public function list($params) public function list($params)
{ {
// $page = $request->input('page', 1); // $page = $request->input('page', 1);
@@ -112,6 +122,46 @@ class CustomerService
return $customer; 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) public function report($params)
{ {
$id = $params['id']; $id = $params['id'];
@@ -187,6 +237,7 @@ class CustomerService
// $customer['last_follow'] = $last_follow; // $customer['last_follow'] = $last_follow;
$customer['enter_user_name'] = empty($customer['enter_user_id']) ? '' : User::where('id',$customer['enter_user_id'])->value('name'); $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) { if ($tag) {
foreach ($customer['tags'] as &$tag) { foreach ($customer['tags'] as &$tag) {
-1
View File
@@ -130,7 +130,6 @@ class CustomerService
} }
if ($scene == 'audit') { //审核时查询举报人姓名 if ($scene == 'audit') { //审核时查询举报人姓名
$customerHis = CustomerHis::where('customer_id', $item->id)->orderBy('id', 'desc')->first(['user_his']); $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'); $item['user_name'] = empty($customerHis['user_his']) ? '' : User::where('id',$customerHis['user_his'])->value('name');
} }
} }
@@ -28,7 +28,7 @@ class ConversationController extends BaseController
? $this->success() ? $this->success()
: $this->error(); : $this->error();
} catch (\Throwable $th) { } catch (\Throwable $th) {
return $this->error($th->getMessage().' '.$th->getLine().' '.$th->getFile()); return $this->error($th->getMessage());
} }
} }
public function edit(Request $request) public function edit(Request $request)
+1
View File
@@ -29,5 +29,6 @@ class Conversation extends Model
'ticket_id', 'ticket_id',
'user_id', 'user_id',
'content', 'content',
'attachment',
]; ];
} }
+18 -1
View File
@@ -2,6 +2,8 @@
namespace app\ticket\service; namespace app\ticket\service;
use app\common\model\User;
use app\common\service\OssService;
use app\ticket\logic\ConversationLogic; use app\ticket\logic\ConversationLogic;
use config\constants\Constants; use config\constants\Constants;
use support\Db; use support\Db;
@@ -19,8 +21,18 @@ class ConversationService
$result = (new ConversationLogic())->list($params); $result = (new ConversationLogic())->list($params);
$status_fanyi = array_map(fn($v) => "{{{$v}}}", array_flip(Constants::TICKET_STATUS)); $status_fanyi = array_map(fn($v) => "{{{$v}}}", array_flip(Constants::TICKET_STATUS));
$ossservice = new OssService();
foreach ($result as $key => $value) { 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; return $result;
} }
@@ -28,6 +40,10 @@ class ConversationService
public function add(array $data) public function add(array $data)
{ {
try { try {
$data['attachment'] = serialize($data['attachment']);
if (empty($data['content'])) {
throw new BusinessException('消息内容不能为空');
}
return (new ConversationLogic())->add($data); return (new ConversationLogic())->add($data);
} catch (\Throwable $e) { } catch (\Throwable $e) {
throw $e; throw $e;
@@ -38,6 +54,7 @@ class ConversationService
{ {
try { try {
Db::beginTransaction(); Db::beginTransaction();
$data['attachment'] = serialize($data['attachment']);
$result = (new ConversationLogic())->edit($data); $result = (new ConversationLogic())->edit($data);
Db::commit(); Db::commit();
return $result; return $result;
+8 -1
View File
@@ -2,6 +2,7 @@
namespace app\ticket\service; namespace app\ticket\service;
use app\common\model\User;
use app\ticket\logic\AttachmentLogic; use app\ticket\logic\AttachmentLogic;
use app\ticket\logic\ConversationLogic; use app\ticket\logic\ConversationLogic;
use app\ticket\logic\TicketLogic; use app\ticket\logic\TicketLogic;
@@ -28,6 +29,10 @@ class TicketService
foreach ($v['attachments'] as &$attachments) { foreach ($v['attachments'] as &$attachments) {
$attachments['storage_path_full'] = (new \app\common\service\OssService())->generatePrivateUrl($attachments['storage_path']); $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($v);
unset($attachments); unset($attachments);
@@ -45,10 +50,12 @@ class TicketService
(new AttachmentLogic())->adds($attachment, $result->id, $data['user_id']); (new AttachmentLogic())->adds($attachment, $result->id, $data['user_id']);
} }
$cleanContent = trim(preg_replace('/\s+/', ' ', strip_tags($data['content'] ?? '')));
$conversation = [ $conversation = [
'ticket_id' => $result->id, 'ticket_id' => $result->id,
'content' => $data['content'], 'content' => $cleanContent,
'user_id' => $data['user_id'], 'user_id' => $data['user_id'],
'attachment' => $data['attachment'],
]; ];
(new ConversationService())->add($conversation); (new ConversationService())->add($conversation);
+1
View File
@@ -186,6 +186,7 @@ Route::group('/crm', function () {
//客户 //客户
Route::any('/customer/list', [app\crm\controller\CustomerController::class, 'list']); 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/detail', [app\crm\controller\CustomerController::class, 'detail']);
Route::any('/customer/add', [app\crm\controller\CustomerController::class, 'save']); Route::any('/customer/add', [app\crm\controller\CustomerController::class, 'save']);
Route::any('/customer/claim', [app\crm\controller\CustomerController::class, 'claim']); Route::any('/customer/claim', [app\crm\controller\CustomerController::class, 'claim']);