Merge branch 'feature/crm0808' into develop_bm

This commit is contained in:
2025-08-08 15:53:51 +08:00
5 changed files with 88 additions and 2 deletions
+5 -1
View File
@@ -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;
+31
View File
@@ -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
+51
View File
@@ -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) {
-1
View File
@@ -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');
}
}
+1
View File
@@ -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']);