Finish mzl_dev
This commit is contained in:
@@ -32,7 +32,8 @@ class RoleController extends BaseController
|
||||
public function menuResource(Request $request)
|
||||
{
|
||||
try {
|
||||
$data = $this->validate($this->service->getValidator(), $request->post(), 'allocation');
|
||||
// $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) {
|
||||
|
||||
@@ -51,6 +51,19 @@ class UserController extends BaseController
|
||||
|
||||
$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;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,34 +22,30 @@ class UserLogic
|
||||
$systemIds = $data['system_ids'] ?? [];
|
||||
$userId = $data['user_id'] ?? 0;
|
||||
|
||||
if (empty($roleId)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Db::beginTransaction();
|
||||
try {
|
||||
Db::table('user_roles')->where('user_id', $userId)->delete();
|
||||
if (!empty($roleIds)) {
|
||||
$insertData = [];
|
||||
if (count($roleIds) > 0) {
|
||||
$insertDataRole = [];
|
||||
foreach ($roleIds as $roleId) {
|
||||
$insertData[] = [
|
||||
$insertDataRole[] = [
|
||||
'role_id' => $roleId,
|
||||
'user_id' => $userId
|
||||
];
|
||||
}
|
||||
Db::table('user_roles')->insert($insertData);
|
||||
Db::table('user_roles')->insert($insertDataRole);
|
||||
}
|
||||
|
||||
Db::table('user_systems')->where('user_id', $userId)->delete();
|
||||
if (!empty($systemIds)) {
|
||||
$insertData = [];
|
||||
if (count($systemIds) > 0) {
|
||||
$insertDataSystem = [];
|
||||
foreach ($systemIds as $systemId) {
|
||||
$insertData[] = [
|
||||
$insertDataSystem[] = [
|
||||
'system_id' => $systemId,
|
||||
'user_id' => $userId
|
||||
];
|
||||
}
|
||||
Db::table('user_systems')->insert($insertData);
|
||||
Db::table('user_systems')->insert($insertDataSystem);
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
|
||||
@@ -38,4 +38,13 @@ class RoleService
|
||||
{
|
||||
return (new RoleLogic)->updateRoleResources($data);
|
||||
}
|
||||
|
||||
|
||||
public function getList()
|
||||
{
|
||||
$config['where']['status'] = 1;
|
||||
$config['order']['sort'] = 'asc';
|
||||
$config['order']['id'] = 'asc';
|
||||
return $this->logicListAll($config);
|
||||
}
|
||||
}
|
||||
@@ -63,6 +63,11 @@ class UserService
|
||||
}
|
||||
|
||||
$config['fields'] = ['id','sn', 'name', 'email', 'sex', 'phone', 'avatar', 'corp_id', 'country_id', 'position', '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'];
|
||||
|
||||
@@ -2,11 +2,14 @@
|
||||
|
||||
namespace app\common\controller;
|
||||
|
||||
use app\admin\service\RoleService;
|
||||
use support\Request;
|
||||
use app\common\service\CorpService;
|
||||
use app\common\service\CorpFeishuAppService;
|
||||
use app\common\service\SystemsService;
|
||||
use app\common\service\UserService;
|
||||
use support\Cache;
|
||||
use app\common\service\PermService;
|
||||
|
||||
class PresetController extends BaseController
|
||||
{
|
||||
@@ -61,4 +64,44 @@ class PresetController extends BaseController
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function roles()
|
||||
{
|
||||
try {
|
||||
$result = (new RoleService)->getList();
|
||||
return $this->success($result, '获取角色列表');
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function cacheClear()
|
||||
{
|
||||
try {
|
||||
Cache::clear();
|
||||
return $this->success([], '操作成功');
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function menus(Request $request)
|
||||
{
|
||||
try {
|
||||
$uid = $request->user->uid;
|
||||
$systemCode = $request->system_code;
|
||||
$permService = new PermService();
|
||||
$menuTree = $permService->getMenuTree($uid, $systemCode);
|
||||
$permissionCodes = $permService->getPermissionCodes($uid, $systemCode);
|
||||
$result = [
|
||||
'menu' => $menuTree,
|
||||
'permissions' => $permissionCodes
|
||||
];
|
||||
return $this->success($result, '获取菜单权限');
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -118,6 +118,12 @@ class AuthLogic
|
||||
}
|
||||
// 是否登陆
|
||||
$user->isLogin = false;
|
||||
|
||||
$options = [
|
||||
'corp_id' => $user->corp_id,
|
||||
'user_id' => $user->id
|
||||
];
|
||||
\Webman\RedisQueue\Redis::send('perm-agt', $options);
|
||||
} else {
|
||||
$updated = [
|
||||
'union_id' => $feishuUserInfo['union_id'],
|
||||
|
||||
@@ -110,4 +110,17 @@ class ResourceService
|
||||
$data = Tree::buildMenuTree($data->toArray());
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
public function beforeServiceStore($data, Request $request)
|
||||
{
|
||||
$data['parent_id'] = $data['parent_id'] != '' ? $data['parent_id'] : 0;
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function beforeServiceUpdate($data, Request $request)
|
||||
{
|
||||
$data['parent_id'] = $data['parent_id'] != '' ? $data['parent_id'] : 0;
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -25,9 +25,9 @@ class UserService
|
||||
public function getUserInfo(int $uid, string $systemCode)
|
||||
{
|
||||
$user = $this->logic->userInfo($uid);
|
||||
$permService = new PermService();
|
||||
$menuTree = $permService->getMenuTree($uid, $systemCode);
|
||||
$permissionCodes = $permService->getPermissionCodes($uid, $systemCode);
|
||||
// $permService = new PermService();
|
||||
// $menuTree = $permService->getMenuTree($uid, $systemCode);
|
||||
// $permissionCodes = $permService->getPermissionCodes($uid, $systemCode);
|
||||
return [
|
||||
'user' => [
|
||||
'id' => $user->id,
|
||||
@@ -38,8 +38,8 @@ class UserService
|
||||
'status' => $user->status,
|
||||
'roles' => $user->roles->pluck('name')
|
||||
],
|
||||
'menu' => $menuTree,
|
||||
'permissions' => $permissionCodes
|
||||
// 'menu' => $menuTree,
|
||||
// 'permissions' => $permissionCodes
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -62,7 +62,6 @@ trait CrudControllerTrait
|
||||
$res = $this->service->serviceStore($request, $data);
|
||||
return $this->success($res, '创建成功');
|
||||
} catch (\Throwable $e) {
|
||||
dpr($e);
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -358,7 +358,8 @@ class Tree
|
||||
$authList[] = [
|
||||
'id' => $permission['id'],
|
||||
'title' => $permission['name'] ?? '',
|
||||
'authMark' => $permission['code'] ?? ''
|
||||
'authMark' => $permission['code'] ?? '',
|
||||
'selected' => isset($permission['selected']) && $permission['selected'] ? true : false
|
||||
];
|
||||
}
|
||||
$menuItem['meta']['authList'] = $authList;
|
||||
@@ -487,8 +488,7 @@ class Tree
|
||||
{
|
||||
$extraFields = [];
|
||||
$standardFields = [
|
||||
'id', 'name', 'url', 'icon', 'parent_id', 'type', 'is_hide',
|
||||
'is_hide_tab', 'keep_alive', 'code', 'level'
|
||||
'id', 'name', 'url', 'icon', 'is_hide', 'is_hide_tab', 'keep_alive', 'level'
|
||||
];
|
||||
|
||||
foreach ($item as $key => $value) {
|
||||
|
||||
@@ -106,13 +106,21 @@ class IndexController
|
||||
public function test()
|
||||
{
|
||||
|
||||
$data = [
|
||||
'code' => 'GD20250703-1DC80',
|
||||
'category' => '账号类问题',
|
||||
'content' => '这是一条测试工单内容。'
|
||||
];
|
||||
\app\common\utils\email\MailSend::send('mzl@hnxinyouhe.com', '【XYH】新的工单提醒', replaceTpl($data, 'work_order'));
|
||||
// $data = [
|
||||
// 'code' => 'GD20250703-1DC80',
|
||||
// 'category' => '账号类问题',
|
||||
// 'content' => '这是一条测试工单内容。'
|
||||
// ];
|
||||
// \app\common\utils\email\MailSend::send('mzl@hnxinyouhe.com', '【XYH】新的工单提醒', replaceTpl($data, 'work_order'));
|
||||
|
||||
// $options = [
|
||||
// 'corp_id' => 3,
|
||||
// 'user_id' => 666
|
||||
// ];
|
||||
// \Webman\RedisQueue\Redis::send('perm-agt', $options);
|
||||
|
||||
$res = Cache::delete("user_resources_74_fdesk");
|
||||
|
||||
return 22;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
namespace app\queue\redis;
|
||||
|
||||
use support\Db;
|
||||
use support\exception\BusinessException;
|
||||
use Webman\RedisQueue\Consumer;
|
||||
|
||||
class PermAgt implements Consumer
|
||||
{
|
||||
// 要消费的队列名
|
||||
public $queue = 'perm-agt';
|
||||
|
||||
// 连接名,对应 plugin/webman/redis-queue/redis.php 里的连接`
|
||||
public $connection = 'default';
|
||||
|
||||
// 消费
|
||||
public function consume($data)
|
||||
{
|
||||
try {
|
||||
|
||||
$corpId = $data['corp_id'];
|
||||
$userId = $data['user_id'];
|
||||
|
||||
if ($corpId == 2) {
|
||||
$roles = [
|
||||
[
|
||||
'user_id' => $userId,
|
||||
'role_id' => 1
|
||||
],
|
||||
[
|
||||
'user_id' => $userId,
|
||||
'role_id' => 2
|
||||
],
|
||||
];
|
||||
$systems = [
|
||||
[
|
||||
'user_id' => $userId,
|
||||
'system_id' => 1
|
||||
],
|
||||
[
|
||||
'user_id' => $userId,
|
||||
'system_id' => 2
|
||||
],
|
||||
[
|
||||
'user_id' => $userId,
|
||||
'system_id' => 3
|
||||
],
|
||||
];
|
||||
} else {
|
||||
$roles = [
|
||||
'user_id' => $userId,
|
||||
'role_id' => 2
|
||||
];
|
||||
$systems = [
|
||||
[
|
||||
'user_id' => $userId,
|
||||
'system_id' => 2
|
||||
],
|
||||
[
|
||||
'user_id' => $userId,
|
||||
'system_id' => 3
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
Db::table('user_roles')->insert($roles);
|
||||
Db::table('user_systems')->insert($systems);
|
||||
return true;
|
||||
} catch (\Throwable $th) {
|
||||
throw new BusinessException($th->getFile()."|".$th->getLine()."|".$th->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// 消费失败回调
|
||||
/*
|
||||
$package = [
|
||||
'id' => 1357277951, // 消息ID
|
||||
'time' => 1709170510, // 消息时间
|
||||
'delay' => 0, // 延迟时间
|
||||
'attempts' => 2, // 消费次数
|
||||
'queue' => 'send-mail', // 队列名
|
||||
'data' => ['to' => 'tom@gmail.com', 'content' => 'hello'], // 消息内容
|
||||
'max_attempts' => 5, // 最大重试次数
|
||||
'error' => '错误信息' // 错误信息
|
||||
]
|
||||
*/
|
||||
public function onConsumeFailure(\Throwable $e, $package)
|
||||
{
|
||||
echo "consume failure\n";
|
||||
echo $e->getMessage() . "\n";
|
||||
// 无需反序列化
|
||||
var_export($package);
|
||||
}
|
||||
}
|
||||
@@ -58,6 +58,9 @@ Route::group('/common', function () {
|
||||
Route::any('/corps', [app\common\controller\PresetController::class, 'corps']);
|
||||
Route::any('/feishu/app', [app\common\controller\PresetController::class, 'feishuApp']);
|
||||
Route::any('/systems', [app\common\controller\PresetController::class, 'systems']);
|
||||
Route::any('/roles', [app\common\controller\PresetController::class, 'roles']);
|
||||
Route::any('/cache/clear', [app\common\controller\PresetController::class, 'cacheClear']);
|
||||
Route::any('/menus', [app\common\controller\PresetController::class, 'menus']);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user