From 9c19cca671065bd11c6fa752f43c94197bf9be23 Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Tue, 12 Aug 2025 13:53:48 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=84=E5=91=98=E7=94=A8=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/controller/UserController.php | 49 ++++++++++++++++ app/common/logic/UserLogic.php | 8 +++ app/common/model/User.php | 4 +- app/common/service/UserService.php | 68 +++++++++++++++++++++++ app/crm/controller/CustomerController.php | 45 +++++++++++++++ config/route.php | 3 + 6 files changed, 176 insertions(+), 1 deletion(-) diff --git a/app/common/controller/UserController.php b/app/common/controller/UserController.php index d725166..bf14859 100644 --- a/app/common/controller/UserController.php +++ b/app/common/controller/UserController.php @@ -2,12 +2,61 @@ namespace app\common\controller; +use app\common\traits\crud\CrudControllerTrait; use support\Request; use app\common\service\UserService; class UserController extends BaseController { + use CrudControllerTrait; + + protected $service; + + public function __construct() + { + $this->service = new UserService(); + } + + /** + * 获取组员列表 + * + * @param Request $request 请求对象 + * @return mixed 返回分页数据及总数 + */ + public function team(Request $request) + { + try { + $raw = $this->service->serviceTeam($request); + $data = $this->transformData($raw, method_exists($this, 'indexFormat') + ? [$this, 'indexFormat'] + : null); + return $this->success($data); + } catch (\Throwable $e) { + return $this->error($e->getMessage()); + } + } + + /** + * 标记组员离职 + * + * @param Request $request 请求对象 + * @return mixed 返回分页数据及总数 + */ + public function resignMember(Request $request) + { + try { + $userId = $request->post('user_id'); + if(empty($userId)){ + return $this->error('组员id不能为空'); + } + $user = $this->service->resignMember($request); + return $this->success($user, '获取用户信息'); + } catch (\Throwable $e) { + return $this->error($e->getMessage()); + } + } + /** * 用户信息 */ diff --git a/app/common/logic/UserLogic.php b/app/common/logic/UserLogic.php index 9f5ae44..c7d5343 100644 --- a/app/common/logic/UserLogic.php +++ b/app/common/logic/UserLogic.php @@ -3,10 +3,18 @@ namespace app\common\logic; use app\common\model\User; +use app\common\traits\crud\CrudLogicTrait; use support\exception\BusinessException; class UserLogic { + use CrudLogicTrait; + + /** + * 指定当前要操作的模型 + */ + protected string $modelClass = User::class; + /** * 用户信息 */ diff --git a/app/common/model/User.php b/app/common/model/User.php index 446ed46..88c670d 100644 --- a/app/common/model/User.php +++ b/app/common/model/User.php @@ -15,7 +15,8 @@ use support\Model; * @property string $email 邮箱 * @property integer $status 状态 * @property string $system_code 系统码 - * @property string $created_at + * @property string $report_to 上级用户ID + * @property string $created_at * @property string $updated_at */ class User extends Model @@ -69,6 +70,7 @@ class User extends Model 'position', 'socialize', 'socialize_pic', + 'report_to', ]; // 用户所有角色 diff --git a/app/common/service/UserService.php b/app/common/service/UserService.php index 1d5dab4..bfcf345 100644 --- a/app/common/service/UserService.php +++ b/app/common/service/UserService.php @@ -5,12 +5,21 @@ namespace app\common\service; use app\common\logic\UserLogic; use app\common\model\Corp; use app\common\model\User; +use app\common\traits\crud\CrudLogicTrait; +use app\common\traits\crud\CrudServiceTrait; use app\common\utils\CrudUtil; use app\crm\model\Country; use support\exception\BusinessException; +use support\Request; class UserService { + use CrudServiceTrait; + + /** + * 指定当前要操作的模型 + */ + protected string $modelClass = User::class; protected $logic; @@ -110,4 +119,63 @@ class UserService { return $this->logic->getList(); } + + /** 分页列表 */ + public function serviceTeam(Request $request) + { + if (method_exists($this, 'complexQuery')) { + $result = $this->complexQuery($request->get()); + } else { + $config = $this->buildQueryConfig($request, 'team'); + $limit = (int)$request->get('size', 15); + $page = (int)$request->get('current', 1); + $result = $this->logicList($config, $limit, $page); + } + return $this->postProcess('List', $result); + } + + /** 分页列表 */ + public function resignMember(Request $request) + { + $uid = $request->user->uid; + $userId = $request->post('user_id'); + $user = User::find($userId); + if ($user->report_to != $uid) { + throw new BusinessException('禁止操作非组员'); + } + + $data = [ + 'status' => 2, + ]; + $user = $this->logic->edit($userId,$data); + $user = $user->toArray(); + unset($user['password']); + unset($user['open_id']); + unset($user['tenant_key']); + unset($user['union_id']); + return $user; + } + + /** + * 构造 CrudUtil 查询配置 + */ + protected function buildQueryConfig(Request $request, string $scene = 'default'): array + { + $p = $request->all(); + + $config = []; + $config['model'] = $this->modelClass; + switch ($scene) { + case 'team': +// $config['where']['status'] = 1; // 关键字 + $config['order']['id'] = 'desc'; + + $config['dataLimit']['type'] = 'relation'; + $config['dataLimit']['userId'] = $request->user->uid; + $config['dataLimit']['userField'] = 'report_to'; + break; + } + + return $config; + } } \ No newline at end of file diff --git a/app/crm/controller/CustomerController.php b/app/crm/controller/CustomerController.php index d1e7cdb..8b141a2 100644 --- a/app/crm/controller/CustomerController.php +++ b/app/crm/controller/CustomerController.php @@ -526,6 +526,51 @@ class CustomerController extends BaseController } } + /** + * 客户转移至公海 + * @param Request $request + * @return \support\Response + */ + public function putSeas(Request $request) + { + $customerId = Util::getParam($request, 'customer_id'); + $userId = $request->user->uid; + if (Util::isEmpty($customerId)) { + return $this->error(trans('customer_id').trans('not_null')); + } + + try { + Db::beginTransaction(); + $customer= Customer::withTrashed()->where('user_id',$userId)->find($customerId); + + if(empty($customer)){ + return $this->error( 'customer_id错误'); + } + $data = [ + 'user_id' => 0, + ]; + + $res = $customer->update($data); + + //记录客户关系变化 + $his = CustomerHis::create([ + 'customer_id' => $customerId, + 'user_his' => $userId, + 'user_id' => 0, + ]); + Db::commit(); + } catch (\Throwable $e) { + Db::rollback(); + return $this->error($e->getMessage()); + } + + if ($res) { + return $this->success($res, trans('success')); + } else { + return $this->error(trans('fail')); + } + } + /** diff --git a/config/route.php b/config/route.php index 0c928eb..44bbe64 100644 --- a/config/route.php +++ b/config/route.php @@ -52,6 +52,8 @@ Route::group('/common', function () { Route::group('/user', function () { Route::any('/info', [app\common\controller\UserController::class, 'info']); Route::any('/get', [app\common\controller\UserController::class, 'getUser']); + Route::any('/team', [app\common\controller\UserController::class, 'team']); + Route::any('/resign', [app\common\controller\UserController::class, 'resignMember']); }); Route::group('/preset', function () { @@ -170,6 +172,7 @@ Route::group('/crm', function () { Route::any('/customer/getCountry', [app\crm\controller\CustomerController::class, 'getCountry']); Route::any('/customer/followNext', [app\crm\controller\CustomerController::class, 'followNext']); Route::any('/customer/report', [app\crm\controller\CustomerController::class, 'report']); + Route::any('/customer/seas', [app\crm\controller\CustomerController::class, 'putSeas']); Route::any('/tagGroup/list', [app\crm\controller\TagGroupController::class, 'list']); Route::any('/tagGroup/updatePivot', [app\crm\controller\TagGroupController::class, 'updatePivot']);