RoleAcl.Class.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. /**
  3. * 角色权限管理Controller
  4. * Created by PhpStorm.
  5. * User: 小威
  6. * Date: 2019/11/08
  7. * Time: 16:00
  8. */
  9. namespace JinDouYun\Controller\Department;
  10. use Mall\Framework\Core\ErrorCode;
  11. use Mall\Framework\Core\StatusCode;
  12. use JinDouYun\Controller\BaseController;
  13. use JinDouYun\Model\Department\MRoleAcl;
  14. class RoleAcl extends BaseController
  15. {
  16. private $objMRoleAcl;
  17. public function __construct($isCheckAcl = true, $isMustLogin = true)
  18. {
  19. parent::__construct($isCheckAcl, $isMustLogin);
  20. $this->objMRoleAcl = new MRoleAcl($this->onlineEnterpriseId);
  21. }
  22. /**
  23. * 获取参数
  24. *
  25. * @return array
  26. */
  27. public function commonFieldFilter()
  28. {
  29. $params = $this->request->getRawJson();
  30. if (empty($params)) {
  31. $this->sendOutput('参数为空', ErrorCode::$paramError);
  32. }
  33. $returnData = [
  34. "roleId" => isset($params['roleId']) ? $params['roleId'] : '',
  35. "isAdministrator" => isset($params['isAdministrator']) ? $params['isAdministrator'] : '',
  36. ];
  37. //必填项
  38. foreach ($returnData as $key => $value) {
  39. if (empty($value) && $value !== 0) {
  40. $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
  41. }
  42. }
  43. //选填项
  44. $returnData['userCenterId'] = isset($params['userCenterId']) ? $params['userCenterId'] : '';
  45. $returnData['acl'] = !empty($params['acl']) ? json_encode($params['acl']) : NULL;
  46. $returnData['updateTime'] = time();
  47. $returnData['createTime'] = time();
  48. return $returnData;
  49. }
  50. /**
  51. * 角色权限添加
  52. */
  53. public function addRoleAcl()
  54. {
  55. $addRoleAclData = $this->commonFieldFilter();
  56. $result = $this->objMRoleAcl->addRoleAcl($addRoleAclData);
  57. if ($result->isSuccess()) {
  58. parent::sendOutput($result->getData());
  59. } else {
  60. parent::sendOutput($result->getData(), $result->getErrorCode());
  61. }
  62. }
  63. /**
  64. * 角色/用户 权限详情
  65. * 角色id
  66. */
  67. public function getRoleAclInfo()
  68. {
  69. $params = $this->request->getRawJson();
  70. $where = [];
  71. if(isset($params['roleId'])) {
  72. $where['roleId'] = $params['roleId'];
  73. }
  74. if(isset($params['userCenterId'])) {
  75. $where['userCenterId'] = $params['userCenterId'];
  76. }
  77. if (empty($where)) {
  78. $this->sendOutput('参数为空', ErrorCode::$paramError);
  79. }
  80. $result = $this->objMRoleAcl->getRoleAclInfo($where);
  81. if ($result->isSuccess()) {
  82. parent::sendOutput($result->getData());
  83. } else {
  84. parent::sendOutput($result->getData(), $result->getErrorCode());
  85. }
  86. }
  87. /**
  88. * 初始化缓存
  89. */
  90. public function initCache()
  91. {
  92. $result = $this->objMRoleAcl->initCache();
  93. if(!$result->isSuccess()){
  94. parent::sendOutput($result->getData(), $result->getErrorCode());
  95. }
  96. parent::sendOutput($result->getData());
  97. }
  98. }