Merge branch 'develop'
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\common\controller\BaseController;
|
||||
use app\common\traits\crud\CrudControllerTrait;
|
||||
use app\admin\service\CorpFeishuAppService;
|
||||
|
||||
class CorpFeishuAppController extends BaseController
|
||||
{
|
||||
use CrudControllerTrait;
|
||||
|
||||
protected $service;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->service = new CorpFeishuAppService();
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表页数据格式化
|
||||
*
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
protected function indexFormat($data)
|
||||
{
|
||||
if (isset($data['created_at']))
|
||||
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
|
||||
if (isset($data['updated_at']))
|
||||
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\common\controller\BaseController;
|
||||
use app\common\traits\crud\CrudControllerTrait;
|
||||
use app\admin\service\CountryService;
|
||||
|
||||
class CountryController extends BaseController
|
||||
{
|
||||
use CrudControllerTrait;
|
||||
|
||||
protected $service;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->service = new CountryService();
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表页数据格式化
|
||||
*
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
// protected function indexFormat($data)
|
||||
// {
|
||||
// if (isset($data['created_at']))
|
||||
// $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
|
||||
// if (isset($data['updated_at']))
|
||||
// $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
|
||||
// return $data;
|
||||
// }
|
||||
}
|
||||
@@ -5,6 +5,7 @@ namespace app\admin\controller;
|
||||
use app\common\controller\BaseController;
|
||||
use app\admin\service\RoleService;
|
||||
use app\common\traits\crud\CrudControllerTrait;
|
||||
use support\Request;
|
||||
|
||||
class RoleController extends BaseController
|
||||
{
|
||||
@@ -27,91 +28,16 @@ class RoleController extends BaseController
|
||||
return $data;
|
||||
}
|
||||
|
||||
// /**
|
||||
// * 获取角色列表
|
||||
// */
|
||||
// public function list(Request $request)
|
||||
// {
|
||||
// try {
|
||||
// $params = $request->all();
|
||||
// $result = (new RoleService())->getRoleList($params);
|
||||
// // 定义后处理器
|
||||
// $postProcessor = function($formattedData) {
|
||||
// if (isset($formattedData['created_at']))
|
||||
// $formattedData['created_at'] = date('Y-m-d H:i:s', $formattedData['created_at']);
|
||||
// if (isset($formattedData['updated_at']))
|
||||
// $formattedData['updated_at'] = date('Y-m-d H:i:s', $formattedData['updated_at']);
|
||||
// return $formattedData;
|
||||
// };
|
||||
// return $this->success($this->transformData($result, $postProcessor), '角色列表获取成功');
|
||||
// } catch (\Throwable $e) {
|
||||
// return $this->error($e->getMessage());
|
||||
// }
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * 获取角色详情
|
||||
// */
|
||||
// public function detail(Request $request)
|
||||
// {
|
||||
// try {
|
||||
// $roleId = $request->get('role_id');
|
||||
// if (!$roleId) {
|
||||
// return $this->error('缺少角色ID', 422);
|
||||
// }
|
||||
// $result = (new RoleService())->getRoleDetail($roleId);
|
||||
// return $this->success($result, '角色详情获取成功');
|
||||
// } catch (\Throwable $e) {
|
||||
// return $this->error($e->getMessage());
|
||||
// }
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * 增加角色
|
||||
// */
|
||||
// public function create(Request $request)
|
||||
// {
|
||||
// try {
|
||||
// $data = $this->validate(new RoleValidate(), $request->post(), 'role_create');
|
||||
// $result = (new RoleService())->createRole($data);
|
||||
// return $this->success($result, '角色创建成功');
|
||||
// } catch (\think\exception\ValidateException $e) {
|
||||
// return $this->error($e->getError(), 422);
|
||||
// } catch (\Throwable $e) {
|
||||
// return $this->error($e->getMessage());
|
||||
// }
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * 修改角色
|
||||
// */
|
||||
// public function update(Request $request)
|
||||
// {
|
||||
// try {
|
||||
// $data = $this->validate(new RoleValidate(), $request->post(), 'role_update');
|
||||
// $result = (new RoleService())->updateRole($data);
|
||||
// return $this->success($result, '角色更新成功');
|
||||
// } catch (\think\exception\ValidateException $e) {
|
||||
// return $this->error($e->getError(), 422);
|
||||
// } catch (\Throwable $e) {
|
||||
// return $this->error($e->getMessage());
|
||||
// }
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * 删除角色
|
||||
// */
|
||||
// public function delete(Request $request)
|
||||
// {
|
||||
// try {
|
||||
// $roleId = $request->get('role_id');
|
||||
// if (!$roleId) {
|
||||
// return $this->error('缺少角色ID', 422);
|
||||
// }
|
||||
// (new RoleService())->deleteRole($roleId);
|
||||
// return $this->success([], '角色删除成功');
|
||||
// } catch (\Throwable $e) {
|
||||
// return $this->error($e->getMessage());
|
||||
// }
|
||||
// }
|
||||
}
|
||||
public function menuResource(Request $request)
|
||||
{
|
||||
try {
|
||||
// $data = $this->validate($this->service->getValidator(), $request->post(), 'allocation');
|
||||
$data = $request->post();
|
||||
$res = $this->service->menuResource($request, $data);
|
||||
return $this->success($res);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,12 +22,12 @@ class SystemsController extends BaseController
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
// protected function indexFormat($data)
|
||||
// {
|
||||
// if (isset($data['created_at']))
|
||||
// $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
|
||||
// if (isset($data['updated_at']))
|
||||
// $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
|
||||
// return $data;
|
||||
// }
|
||||
protected function indexFormat($data)
|
||||
{
|
||||
if (isset($data['created_at']))
|
||||
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
|
||||
if (isset($data['updated_at']))
|
||||
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ use app\common\model\Corp;
|
||||
use app\common\traits\crud\CrudControllerTrait;
|
||||
use app\admin\service\UserService;
|
||||
use app\crm\model\Customer;
|
||||
use support\Request;
|
||||
|
||||
class UserController extends BaseController
|
||||
{
|
||||
@@ -17,6 +18,60 @@ class UserController extends BaseController
|
||||
{
|
||||
$this->service = new UserService();
|
||||
}
|
||||
/**
|
||||
* 更新
|
||||
*
|
||||
* @param Request $request 请求对象
|
||||
* @return mixed 返回更新成功的数据或信息
|
||||
*/
|
||||
public function update(Request $request)
|
||||
{
|
||||
try {
|
||||
$data = $request->post();
|
||||
$res = $this->service->serviceUpdateUser($request, $data);
|
||||
return $this->success([], '更新成功');
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改密码
|
||||
* @param Request $request
|
||||
* @return \support\Response
|
||||
* @throws \Random\RandomException
|
||||
*/
|
||||
public function savePassword(Request $request)
|
||||
{
|
||||
try {
|
||||
$data = $request->all();
|
||||
if(empty($data['password'])){
|
||||
return $this->error('密码不能为空');
|
||||
}
|
||||
$result = $this->service->savePassword($request,$data);;
|
||||
return $this->success($result, '编辑成功');
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新
|
||||
*
|
||||
* @param Request $request 请求对象
|
||||
* @return mixed 返回更新成功的数据或信息
|
||||
*/
|
||||
public function edit(Request $request)
|
||||
{
|
||||
try {
|
||||
$data = $request->post();
|
||||
$data['id'] = $data['id']??$request->user->uid;
|
||||
$res = $this->service->serviceUpdate($request, $data);
|
||||
return $this->success([], '更新成功');
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表页数据格式化
|
||||
@@ -24,32 +79,79 @@ class UserController extends BaseController
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
protected function indexFormat($data)
|
||||
{
|
||||
if(isset($data['records'])){
|
||||
return $data;
|
||||
}
|
||||
$data['sex_txt'] = '';
|
||||
if (isset($data['sex']) && $data['sex'] == 1){
|
||||
$data['sex_txt'] = '男';
|
||||
}elseif(isset($data['sex']) && $data['sex'] == 2){
|
||||
$data['sex_txt'] = '女';
|
||||
}
|
||||
protected function indexFormat($data)
|
||||
{
|
||||
if(isset($data['records'])){
|
||||
return $data;
|
||||
}
|
||||
$data['sex_txt'] = '';
|
||||
if (isset($data['sex']) && $data['sex'] == 1){
|
||||
$data['sex_txt'] = '男';
|
||||
}elseif(isset($data['sex']) && $data['sex'] == 2){
|
||||
$data['sex_txt'] = '女';
|
||||
}
|
||||
|
||||
switch ($data['status']){
|
||||
case 1:
|
||||
$data['status_txt'] = '正常';
|
||||
break;
|
||||
case 2:
|
||||
$data['status_txt'] = '离职';
|
||||
break;
|
||||
default:
|
||||
$data['status_txt'] = '';
|
||||
break;
|
||||
}
|
||||
switch ($data['status']){
|
||||
case 1:
|
||||
$data['status_txt'] = '正常';
|
||||
break;
|
||||
case 2:
|
||||
$data['status_txt'] = '离职';
|
||||
break;
|
||||
default:
|
||||
$data['status_txt'] = '';
|
||||
break;
|
||||
}
|
||||
|
||||
$data['corp_name'] = Corp::where('id', $data['corp_id'])->value('name');
|
||||
$data['customer_count'] = Customer::where('user_id', $data['id'])->count();
|
||||
return $data;
|
||||
}
|
||||
$data['corp_name'] = Corp::where('id', $data['corp_id'])->value('name');
|
||||
$data['customer_count'] = Customer::where('user_id', $data['id'])->count();
|
||||
|
||||
$data['role_ids'] = [];
|
||||
$data['system_ids'] = [];
|
||||
if (isset($data['roles']) && count($data['roles']) > 0) {
|
||||
foreach ($data['roles'] as $role) {
|
||||
$data['role_ids'][] = $role['id'];
|
||||
}
|
||||
}
|
||||
if (isset($data['systems']) && count($data['systems']) > 0) {
|
||||
foreach ($data['systems'] as $system) {
|
||||
$data['system_ids'][] = $system['id'];
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 授权
|
||||
*
|
||||
* @param Request $request
|
||||
* @return mixed
|
||||
*/
|
||||
public function authorize(Request $request)
|
||||
{
|
||||
try {
|
||||
$data = $request->post();
|
||||
$res = $this->service->authorize($request, $data);
|
||||
return $this->success([], '分配成功');
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 直接授权
|
||||
*
|
||||
* @param Request $request
|
||||
* @return mixed
|
||||
*/
|
||||
public function updateResources(Request $request)
|
||||
{
|
||||
try {
|
||||
$data = $request->post();
|
||||
$res = $this->service->updateResources($request, $data);
|
||||
return $this->success([], '分配成功');
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ namespace app\admin\logic;
|
||||
|
||||
use app\common\traits\crud\CrudLogicTrait;
|
||||
use app\common\model\User;
|
||||
use support\Db;
|
||||
|
||||
class UserLogic
|
||||
{
|
||||
@@ -14,4 +15,79 @@ class UserLogic
|
||||
*/
|
||||
protected string $modelClass = User::class;
|
||||
|
||||
|
||||
public function updateRoleAndSystem(array $data): bool
|
||||
{
|
||||
$roleIds = $data['role_ids'] ?? [];
|
||||
$systemIds = $data['system_ids'] ?? [];
|
||||
$userId = $data['user_id'] ?? 0;
|
||||
|
||||
Db::beginTransaction();
|
||||
try {
|
||||
Db::table('user_roles')->where('user_id', $userId)->delete();
|
||||
if (count($roleIds) > 0) {
|
||||
$insertDataRole = [];
|
||||
foreach ($roleIds as $roleId) {
|
||||
$insertDataRole[] = [
|
||||
'role_id' => $roleId,
|
||||
'user_id' => $userId
|
||||
];
|
||||
}
|
||||
Db::table('user_roles')->insert($insertDataRole);
|
||||
}
|
||||
|
||||
Db::table('user_systems')->where('user_id', $userId)->delete();
|
||||
if (count($systemIds) > 0) {
|
||||
$insertDataSystem = [];
|
||||
foreach ($systemIds as $systemId) {
|
||||
$insertDataSystem[] = [
|
||||
'system_id' => $systemId,
|
||||
'user_id' => $userId
|
||||
];
|
||||
}
|
||||
Db::table('user_systems')->insert($insertDataSystem);
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Throwable $exception) {
|
||||
Db::rollBack();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function updateUserResources(array $data): bool
|
||||
{
|
||||
$userId = $data['user_id'] ?? 0;
|
||||
$resources = $data['resources'] ?? [];
|
||||
|
||||
if (empty($userId)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Db::beginTransaction();
|
||||
try {
|
||||
// 删除原有资源关联
|
||||
Db::table('user_resources')->where('user_id', $userId)->delete();
|
||||
|
||||
// 批量插入新角色资源关联
|
||||
if (!empty($resources)) {
|
||||
$insertData = [];
|
||||
foreach ($resources as $resourceId) {
|
||||
$insertData[] = [
|
||||
'user_id' => $userId,
|
||||
'resource_id' => $resourceId
|
||||
];
|
||||
}
|
||||
Db::table('user_resources')->insert($insertData);
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Throwable $exception) {
|
||||
Db::rollBack();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\service;
|
||||
|
||||
use app\common\validate\CorpFeishuAppValidate;
|
||||
use app\common\traits\crud\CrudServiceTrait;
|
||||
use app\common\model\CorpFeishuApp;
|
||||
use support\Request;
|
||||
|
||||
class CorpFeishuAppService
|
||||
{
|
||||
|
||||
use CrudServiceTrait;
|
||||
|
||||
/**
|
||||
* 指定当前要操作的模型
|
||||
*/
|
||||
protected string $modelClass = CorpFeishuApp::class;
|
||||
|
||||
/**
|
||||
* 验证器
|
||||
*/
|
||||
protected $validator = CorpFeishuAppValidate::class;
|
||||
|
||||
/**
|
||||
* 获取验证器
|
||||
*/
|
||||
public function getValidator()
|
||||
{
|
||||
return new $this->validator;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建查询条件
|
||||
*/
|
||||
protected function buildQueryConfig(Request $request, string $scene = 'index'): array
|
||||
{
|
||||
$p = $request->all();
|
||||
|
||||
$config = [];
|
||||
$config['model'] = $this->modelClass;
|
||||
switch ($scene) {
|
||||
case 'index':
|
||||
$config['where']['status'] = 1;
|
||||
$config['order']['sort'] = 'desc';
|
||||
$config['order']['id'] = 'desc';
|
||||
|
||||
$config['with']['corpInfo'][] = 'name';
|
||||
$config['with']['systemInfo'][] = 'name';
|
||||
break;
|
||||
case 'show':
|
||||
$config['where']['id'] = $p['id'];
|
||||
$config['where']['status'] = 1;
|
||||
|
||||
$config['with']['corpInfo'][] = 'name';
|
||||
$config['with']['systemInfo'][] = 'name';
|
||||
break;
|
||||
case 'store':
|
||||
break;
|
||||
case 'update':
|
||||
$config['where']['id'] = $p['id'];
|
||||
break;
|
||||
case 'destroy':
|
||||
$config['where']['id'] = $p['id'];
|
||||
break;
|
||||
}
|
||||
|
||||
return $config;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\service;
|
||||
|
||||
use app\common\validate\CountryValidate;
|
||||
use app\common\traits\crud\CrudServiceTrait;
|
||||
use app\common\model\CorpFeishuApp;
|
||||
|
||||
class CountryService
|
||||
{
|
||||
|
||||
use CrudServiceTrait;
|
||||
|
||||
/**
|
||||
* 指定当前要操作的模型
|
||||
*/
|
||||
protected string $modelClass = CorpFeishuApp::class;
|
||||
|
||||
/**
|
||||
* 验证器
|
||||
*/
|
||||
protected $validator = CountryValidate::class;
|
||||
|
||||
/**
|
||||
* 获取验证器
|
||||
*/
|
||||
public function getValidator()
|
||||
{
|
||||
return new $this->validator;
|
||||
}
|
||||
}
|
||||
@@ -2,9 +2,11 @@
|
||||
|
||||
namespace app\admin\service;
|
||||
|
||||
use app\common\logic\RoleLogic;
|
||||
use app\common\validate\RoleValidate;
|
||||
use app\common\traits\crud\CrudServiceTrait;
|
||||
use app\common\model\Role;
|
||||
use support\Db;
|
||||
|
||||
class RoleService
|
||||
{
|
||||
@@ -28,4 +30,21 @@ class RoleService
|
||||
{
|
||||
return new $this->validator;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取角色资源
|
||||
*/
|
||||
public function menuResource($request, $data)
|
||||
{
|
||||
return (new RoleLogic)->updateRoleResources($data);
|
||||
}
|
||||
|
||||
|
||||
public function getList()
|
||||
{
|
||||
$config['where']['status'] = 1;
|
||||
$config['order']['sort'] = 'asc';
|
||||
$config['order']['id'] = 'asc';
|
||||
return $this->logicListAll($config);
|
||||
}
|
||||
}
|
||||
@@ -2,9 +2,11 @@
|
||||
|
||||
namespace app\admin\service;
|
||||
|
||||
use app\admin\validate\UserValidate;
|
||||
use app\admin\logic\UserLogic;
|
||||
use app\common\traits\crud\CrudServiceTrait;
|
||||
use app\common\model\User;
|
||||
use app\common\validate\UserValidate;
|
||||
use support\exception\BusinessException;
|
||||
use support\Request;
|
||||
|
||||
class UserService
|
||||
@@ -30,6 +32,25 @@ class UserService
|
||||
return new $this->validator;
|
||||
}
|
||||
|
||||
/** 更新 */
|
||||
public function serviceUpdateUser(Request $request, array $data = [])
|
||||
{
|
||||
$data = $this->preProcess('Update', $data, $request);
|
||||
$config = $this->buildQueryConfig($request, 'update');
|
||||
$updated = $this->logicUpdateBy($config, $data);
|
||||
return $this->postProcess('Update', $data);
|
||||
}
|
||||
|
||||
/** 更新 */
|
||||
public function serviceUpdate(Request $request, array $data = [])
|
||||
{
|
||||
unset($data['roles']);
|
||||
unset($data['corp_name']);
|
||||
$data = $this->preProcess('Update', $data, $request);
|
||||
$config = $this->buildQueryConfig($request, 'edit');
|
||||
$updated = $this->logicUpdateBy($config, $data);
|
||||
return $this->postProcess('Update', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造 CrudUtil 查询配置
|
||||
@@ -61,7 +82,12 @@ class UserService
|
||||
$config['where']['id'] = $p['id'];
|
||||
}
|
||||
|
||||
$config['fields'] = ['id','sn', 'name', 'email', 'sex', 'phone', 'avatar', 'corp_id', 'country_id', 'position', 'status', 'created_at'];
|
||||
$config['fields'] = ['id','sn', 'name', 'email', 'sex', 'phone', 'avatar', 'corp_id', 'country_id', 'position', 'report_to', 'status', 'created_at'];
|
||||
|
||||
$config['with']['roles'][] = 'id';
|
||||
$config['with']['roles'][] = 'name';
|
||||
$config['with']['systems'][] = 'id';
|
||||
$config['with']['systems'][] = 'name';
|
||||
break;
|
||||
case 'show':
|
||||
$config['where']['id'] = $p['id'];
|
||||
@@ -74,8 +100,49 @@ class UserService
|
||||
case 'destroy':
|
||||
$config['where']['id'] = $p['id'];
|
||||
break;
|
||||
case 'savePassword':
|
||||
$config['where']['id'] = $p['id'];
|
||||
break;
|
||||
case 'edit':
|
||||
$config['where']['id'] = $request->user->uid;
|
||||
break;
|
||||
}
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* 授权
|
||||
*
|
||||
* @param Request $request
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize(Request $request, array $data = [])
|
||||
{
|
||||
return (new UserLogic())->updateRoleAndSystem($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新用户资源权限
|
||||
*
|
||||
* @param Request $request
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*/
|
||||
public function updateResources(Request $request, array $data = [])
|
||||
{
|
||||
return (new UserLogic())->updateUserResources($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改用户密码
|
||||
*/
|
||||
public function savePassword(Request $request, array $data)
|
||||
{
|
||||
$config = $this->buildQueryConfig($request, 'savePassword');
|
||||
$data['password'] = password_hash($data['password'], PASSWORD_DEFAULT);
|
||||
$user = $this->logicUpdateBy($config,$data);
|
||||
return $user;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user