组员用户
This commit is contained in:
@@ -2,12 +2,61 @@
|
|||||||
|
|
||||||
namespace app\common\controller;
|
namespace app\common\controller;
|
||||||
|
|
||||||
|
use app\common\traits\crud\CrudControllerTrait;
|
||||||
use support\Request;
|
use support\Request;
|
||||||
use app\common\service\UserService;
|
use app\common\service\UserService;
|
||||||
|
|
||||||
class UserController extends BaseController
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户信息
|
* 用户信息
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -3,10 +3,18 @@
|
|||||||
namespace app\common\logic;
|
namespace app\common\logic;
|
||||||
|
|
||||||
use app\common\model\User;
|
use app\common\model\User;
|
||||||
|
use app\common\traits\crud\CrudLogicTrait;
|
||||||
use support\exception\BusinessException;
|
use support\exception\BusinessException;
|
||||||
|
|
||||||
class UserLogic
|
class UserLogic
|
||||||
{
|
{
|
||||||
|
use CrudLogicTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 指定当前要操作的模型
|
||||||
|
*/
|
||||||
|
protected string $modelClass = User::class;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户信息
|
* 用户信息
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -15,7 +15,8 @@ use support\Model;
|
|||||||
* @property string $email 邮箱
|
* @property string $email 邮箱
|
||||||
* @property integer $status 状态
|
* @property integer $status 状态
|
||||||
* @property string $system_code 系统码
|
* @property string $system_code 系统码
|
||||||
* @property string $created_at
|
* @property string $report_to 上级用户ID
|
||||||
|
* @property string $created_at
|
||||||
* @property string $updated_at
|
* @property string $updated_at
|
||||||
*/
|
*/
|
||||||
class User extends Model
|
class User extends Model
|
||||||
@@ -69,6 +70,7 @@ class User extends Model
|
|||||||
'position',
|
'position',
|
||||||
'socialize',
|
'socialize',
|
||||||
'socialize_pic',
|
'socialize_pic',
|
||||||
|
'report_to',
|
||||||
];
|
];
|
||||||
|
|
||||||
// 用户所有角色
|
// 用户所有角色
|
||||||
|
|||||||
@@ -5,12 +5,21 @@ namespace app\common\service;
|
|||||||
use app\common\logic\UserLogic;
|
use app\common\logic\UserLogic;
|
||||||
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\CrudLogicTrait;
|
||||||
|
use app\common\traits\crud\CrudServiceTrait;
|
||||||
use app\common\utils\CrudUtil;
|
use app\common\utils\CrudUtil;
|
||||||
use app\crm\model\Country;
|
use app\crm\model\Country;
|
||||||
use support\exception\BusinessException;
|
use support\exception\BusinessException;
|
||||||
|
use support\Request;
|
||||||
|
|
||||||
class UserService
|
class UserService
|
||||||
{
|
{
|
||||||
|
use CrudServiceTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 指定当前要操作的模型
|
||||||
|
*/
|
||||||
|
protected string $modelClass = User::class;
|
||||||
|
|
||||||
protected $logic;
|
protected $logic;
|
||||||
|
|
||||||
@@ -110,4 +119,63 @@ class UserService
|
|||||||
{
|
{
|
||||||
return $this->logic->getList();
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -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'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -52,6 +52,8 @@ Route::group('/common', function () {
|
|||||||
Route::group('/user', function () {
|
Route::group('/user', function () {
|
||||||
Route::any('/info', [app\common\controller\UserController::class, 'info']);
|
Route::any('/info', [app\common\controller\UserController::class, 'info']);
|
||||||
Route::any('/get', [app\common\controller\UserController::class, 'getUser']);
|
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 () {
|
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/getCountry', [app\crm\controller\CustomerController::class, 'getCountry']);
|
||||||
Route::any('/customer/followNext', [app\crm\controller\CustomerController::class, 'followNext']);
|
Route::any('/customer/followNext', [app\crm\controller\CustomerController::class, 'followNext']);
|
||||||
Route::any('/customer/report', [app\crm\controller\CustomerController::class, 'report']);
|
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/list', [app\crm\controller\TagGroupController::class, 'list']);
|
||||||
Route::any('/tagGroup/updatePivot', [app\crm\controller\TagGroupController::class, 'updatePivot']);
|
Route::any('/tagGroup/updatePivot', [app\crm\controller\TagGroupController::class, 'updatePivot']);
|
||||||
|
|||||||
Reference in New Issue
Block a user