From 859fd1cff1476c50869faf670ce3533379a68ccf Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Fri, 8 Aug 2025 15:52:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E4=B8=8B=E5=B1=9E=E5=AE=A2?= =?UTF-8?q?=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/crm/controller/BaseController.php | 6 ++- app/crm/controller/CustomerController.php | 31 ++++++++++++++ app/crm/service/CustomerService.php | 51 +++++++++++++++++++++++ app/crmAdmin/service/CustomerService.php | 1 - config/route.php | 1 + 5 files changed, 88 insertions(+), 2 deletions(-) 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..4478233 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 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/config/route.php b/config/route.php index 7ad0f19..0c928eb 100644 --- a/config/route.php +++ b/config/route.php @@ -158,6 +158,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']);