123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- <?php
- /**
- * 角色权限管理Controller
- * Created by PhpStorm.
- * User: 小威
- * Date: 2019/11/08
- * Time: 16:00
- */
- namespace JinDouYun\Controller\Department;
- use Mall\Framework\Core\ErrorCode;
- use Mall\Framework\Core\StatusCode;
- use JinDouYun\Controller\BaseController;
- use JinDouYun\Model\Department\MRoleAcl;
- class RoleAcl extends BaseController
- {
- private $objMRoleAcl;
- public function __construct($isCheckAcl = true, $isMustLogin = true)
- {
- parent::__construct($isCheckAcl, $isMustLogin);
- $this->objMRoleAcl = new MRoleAcl($this->onlineEnterpriseId);
- }
- /**
- * 获取参数
- *
- * @return array
- */
- public function commonFieldFilter()
- {
- $params = $this->request->getRawJson();
- if (empty($params)) {
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
- $returnData = [
- "roleId" => isset($params['roleId']) ? $params['roleId'] : '',
- "isAdministrator" => isset($params['isAdministrator']) ? $params['isAdministrator'] : '',
- ];
- //必填项
- foreach ($returnData as $key => $value) {
- if (empty($value) && $value !== 0) {
- $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
- }
- }
- //选填项
- $returnData['userCenterId'] = isset($params['userCenterId']) ? $params['userCenterId'] : '';
- $returnData['acl'] = !empty($params['acl']) ? json_encode($params['acl']) : NULL;
- $returnData['updateTime'] = time();
- $returnData['createTime'] = time();
- return $returnData;
- }
- /**
- * 角色权限添加
- */
- public function addRoleAcl()
- {
- $addRoleAclData = $this->commonFieldFilter();
- $result = $this->objMRoleAcl->addRoleAcl($addRoleAclData);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 角色/用户 权限详情
- * 角色id
- */
- public function getRoleAclInfo()
- {
- $params = $this->request->getRawJson();
- $where = [];
- if(isset($params['roleId'])) {
- $where['roleId'] = $params['roleId'];
- }
- if(isset($params['userCenterId'])) {
- $where['userCenterId'] = $params['userCenterId'];
- }
- if (empty($where)) {
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
- $result = $this->objMRoleAcl->getRoleAclInfo($where);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 初始化缓存
- */
- public function initCache()
- {
- $result = $this->objMRoleAcl->initCache();
- if(!$result->isSuccess()){
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- parent::sendOutput($result->getData());
- }
- }
|