Files
douba_shop/app/controller/admin/v1/system/SystemRole.php
Karlcarlo c9a98f342c chore: 添加静态资源文件和版本配置文件
添加大量图片、字体、音频等静态资源文件,包括用户界面图片、模板文件和安装界面素材
添加系统版本配置文件(.version)和常量定义文件(.constant)
更新供应商依赖文件,包括Symfony VarDumper组件和相关许可证文件
添加验证码配置文件(captcha.php)和.gitignore规则
2026-03-06 20:14:23 +08:00

143 lines
4.3 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\controller\admin\v1\system;
use app\controller\admin\AuthController;
use app\services\system\SystemRoleServices;
use app\services\system\SystemMenusServices;
use crmeb\services\CacheService;
use think\annotation\Inject;
/**
* Class SystemRole
* @package app\controller\admin\v1\setting
*/
class SystemRole extends AuthController
{
/**
* @var SystemRoleServices
*/
#[Inject]
protected SystemRoleServices $services;
/**
* 显示资源列表
*
* @return \think\Response
*/
public function index()
{
$where = $this->request->getMore([
['status', ''],
['role_name', ''],
]);
$where['type'] = 0;
$where['level'] = $this->adminInfo['level'] + 1;
return $this->success($this->services->getRoleList($where));
}
/**
* 显示创建资源表单页.
*
* @return \think\Response
*/
public function create(SystemMenusServices $services)
{
$menus = $services->getmenus($this->adminInfo['level'] == 0 ? [] : $this->adminInfo['roles'], 1, 0);
return $this->success(compact('menus'));
}
/**
* 保存新建的资源
*
* @return \think\Response
*/
public function save($id)
{
$data = $this->request->postMore([
'role_name',
['status', 0],
['checked_menus', [], '', 'rules']
]);
if (!$data['role_name']) return $this->fail('请输入身份名称');
if (!is_array($data['rules']) || !count($data['rules']))
return $this->fail('请选择最少一个权限');
$data['rules'] = implode(',', $data['rules']);
if ($id) {
if (!$this->services->update($id, $data)) return $this->fail('修改失败!');
CacheService::redisHandler('system_menus')->clear();
return $this->success('修改成功!');
} else {
$data['level'] = $this->adminInfo['level'] + 1;
if (!$this->services->save($data)) return $this->fail('添加身份失败!');
CacheService::redisHandler('system_menus')->clear();
return $this->success('添加身份成功!');
}
}
/**
* 显示编辑资源表单页.
*
* @param int $id
* @return \think\Response
*/
public function edit(SystemMenusServices $services, $id)
{
$role = $this->services->get($id);
if (!$role) {
return $this->fail('修改的角色不存在');
}
$menus = $services->getMenus($this->adminInfo['level'] == 0 ? [] : $this->adminInfo['roles'], 1, 0);
return $this->success(['role' => $role->toArray(), 'menus' => $menus]);
}
/**
* 删除指定资源
*
* @param int $id
* @return \think\Response
*/
public function delete($id)
{
if (!$this->services->delete($id))
return $this->fail('删除失败,请稍候再试!');
else {
CacheService::redisHandler('system_menus')->clear();
return $this->success('删除成功!');
}
}
/**
* 修改状态
* @param $id
* @param $status
* @return mixed
*/
public function set_status($id, $status)
{
if (!$id) {
return $this->fail('缺少参数');
}
$role = $this->services->get($id);
if (!$role) {
return $this->fail('没有查到此身份');
}
$role->status = $status;
if ($role->save()) {
CacheService::redisHandler('system_menus')->clear();
return $this->success('修改成功');
} else {
return $this->fail('修改失败');
}
}
}