角色管理
This commit is contained in:
parent
d9a9613bfb
commit
d6f7f1cbf0
|
|
@ -67,9 +67,9 @@ class System extends Base
|
|||
#[Auth(needAuth: false, auth: "menu:del")]
|
||||
public function menuDel()
|
||||
{
|
||||
$menu_id = $this->request->input("menu_id", "");
|
||||
if (!$menu_id) return $this->error("请选择要删除的菜单");
|
||||
$res = mModel::del($menu_id);
|
||||
$ids = $this->request->input("ids", "");
|
||||
if (!$ids) return $this->error("请选择要删除的菜单");
|
||||
$res = mModel::del($ids);
|
||||
return $res ? $this->success("操作成功") : $this->error("操作失败");
|
||||
}
|
||||
|
||||
|
|
@ -132,9 +132,9 @@ class System extends Base
|
|||
#[Auth(auth: "dept:del")]
|
||||
public function deptDel()
|
||||
{
|
||||
$dept_id = $this->request->input("dept_id", "");
|
||||
if (!$dept_id) return $this->error("请选择要删除的菜单");
|
||||
$res = dModel::del($dept_id);
|
||||
$ids = $this->request->input("ids", "");
|
||||
if (!$ids) return $this->error("请选择要删除的菜单");
|
||||
$res = dModel::del($ids);
|
||||
return $res ? $this->success("操作成功") : $this->error("操作失败");
|
||||
}
|
||||
|
||||
|
|
@ -162,7 +162,7 @@ class System extends Base
|
|||
{
|
||||
$request = $this->container->get(rRequest::class);
|
||||
$request->scene('add')->validateResolved();
|
||||
$data = Param::only(['role_name' => '', 'menus' => [], 'remark', 'status' => 1, 'rank', "checked_menus"]);
|
||||
$data = Param::only(['role_name' => '', 'menus' => [], 'status' => 1, 'rank', "checked_menus"]);
|
||||
$data['belong_id'] = $this->account['belong_id'];
|
||||
$data['account_type'] = $this->account['account_type'];
|
||||
$res = rModel::add($data);
|
||||
|
|
@ -176,7 +176,7 @@ class System extends Base
|
|||
{
|
||||
$request = $this->container->get(rRequest::class);
|
||||
$request->scene('edit')->validateResolved();
|
||||
$data = Param::only(['role_id' => '', 'role_name' => '', 'menus' => [], 'remark', 'status' => 1, 'rank', "checked_menus"]);
|
||||
$data = Param::only(['role_id' => '', 'role_name' => '', 'menus' => [], 'status' => 1, 'rank', "checked_menus"]);
|
||||
$res = rModel::edit($data);
|
||||
return $res ? $this->success("操作成功") : $this->error("操作失败");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,13 +39,12 @@ class Role extends Model
|
|||
|
||||
public static function list(int $belong_id, int $account_type, string $role_name)
|
||||
{
|
||||
$model = self::where('del_flag', 0)
|
||||
->where('belong_id', $belong_id)
|
||||
$model = self::where('belong_id', $belong_id)
|
||||
->where('account_type', $account_type);
|
||||
if ($role_name != '') {
|
||||
$model = $model->where("role_name","like", "%$role_name%");
|
||||
}
|
||||
return $model->select(["role_id","role_name","status","remark","create_time","rank","checked_menus"])
|
||||
return $model->select(["role_id","role_name","status","create_time","rank","checked_menus"])
|
||||
->get()->each(function ($item){
|
||||
$item['menus'] = RoleMenu::getMenu($item['role_id']);
|
||||
})->toArray();
|
||||
|
|
@ -53,8 +52,7 @@ class Role extends Model
|
|||
|
||||
public static function options(int $belong_id, int $account_type)
|
||||
{
|
||||
return self::where('del_flag', 0)
|
||||
->where('belong_id', $belong_id)
|
||||
return self::where('belong_id', $belong_id)
|
||||
->where('account_type', $account_type)
|
||||
->orderByDesc("rank")
|
||||
->select(["role_id","role_name"])
|
||||
|
|
@ -69,7 +67,6 @@ class Role extends Model
|
|||
public static function add(array $data)
|
||||
{
|
||||
$data['create_time'] = date("Y-m-d H:i:s");
|
||||
$data['del_flag'] = 0;
|
||||
$menus = $data['menus'];
|
||||
unset($data['menus']);
|
||||
Db::beginTransaction();
|
||||
|
|
@ -104,7 +101,7 @@ class Role extends Model
|
|||
$menus = $data['menus'];
|
||||
unset($data['menus']);
|
||||
Db::beginTransaction();
|
||||
$res = self::where("role_id", $data['role_id'])->where('del_flag', 0)->update($data);
|
||||
$res = self::where("role_id", $data['role_id'])->update($data);
|
||||
if (!$res) {
|
||||
Db::rollBack();
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ use Hyperf\DbConnection\Db;
|
|||
* @property int $role_id
|
||||
* @property int $menu_id
|
||||
*/
|
||||
class RoleMenu extends Model
|
||||
class RoleMenu extends \Hyperf\Database\Model\Model
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
|
|
|
|||
Loading…
Reference in New Issue