Files
2023-05-19 11:51:11 +08:00

66 lines
2.2 KiB
PHP
Raw Permalink 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
defined('BASEPATH') OR exit('No direct script access allowed');
require_once APPPATH . 'controllers/api/BaseController.php';
/**
* Notes:角色分配的菜单
* Created on: 2022/9/09 17:15
* Created by: dengbw
*/
class RoleMenu extends BaseController
{
public function __construct()
{
parent::__construct();
$this->load->model('market/Market_sys_role_model', 'mdSysRole');
$this->load->model('market/Market_sys_menu_model', 'mdSysMenu');
}
/**
* Notes:获取角色分配的菜单 (ele-admin/system/role-menu)
* Created on: 2022/9/13 9:47
* Created by: dengbw
*/
public function index_get()
{
$roleId = $this->input_param('roleId');
if (!$roleId) {
$this->return_json('参数错误');
}
$re_ro = $this->mdSysRole->get(['roleId' => $roleId, 'status' => 0]);
$menuIds = $re_ro['menuIds'] ? explode(',', $re_ro['menuIds']) : [];
$where['status>='] = 0;
$res = $this->mdSysMenu->select($where, 'sortNumber asc,menuId desc');
foreach ($res as $k => $v) {
$menuId = intval($v['menuId']);
$res[$k]['menuId'] = $menuId;
$res[$k]['parentId'] = intval($v['parentId']);
$res[$k]['menuType'] = intval($v['menuType']);
$res[$k]['openType'] = intval($v['openType']);
$res[$k]['sortNumber'] = intval($v['sortNumber']);
$res[$k]['hide'] = intval($v['hide']);
$res[$k]['meta'] = json_decode($v['meta'], true);
$res[$k]['children'] = '';
$res[$k]['checked'] = in_array($menuId, $menuIds) ? true : false;
}
$this->return_response_list($res);
}
/**
* Notes:修改角色菜单(ele-admin/system/role-menu)
* Created on: 2022/9/13 11:50
* Created by: dengbw
*/
public function index_put()
{
$roleId = $this->input_param('roleId');
if (!$roleId) {
$this->return_json('参数错误');
}
$menuIds = $this->input_param('menuIds');
$menuIds = $menuIds ? implode(',', $menuIds) : '';
$this->mdSysRole->update(['menuIds' => $menuIds], ['roleId' => $roleId]);
$this->return_response();
}
}