Module.Class.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <?php
  2. /**
  3. * 菜单管理模块
  4. * Created by PhpStorm.
  5. * User: tpl
  6. * Date: 2019/10/30
  7. * Time: 13:54
  8. */
  9. namespace JinDouYun\Controller\System;
  10. use AlibabaCloud\Client\Clients\RamRoleArnClient;
  11. use Mall\Framework\Core\ErrorCode;
  12. use Mall\Framework\Core\StatusCode;
  13. use JinDouYun\Controller\BaseController;
  14. use JinDouYun\Model\System\MModule;
  15. class Module extends BaseController
  16. {
  17. private $objMModule;
  18. public function __construct($isCheckAcl = false, $isMustLogin = false)
  19. {
  20. parent::__construct($isCheckAcl, $isMustLogin,false);
  21. $this->objMModule = new MModule();
  22. }
  23. /**
  24. * 添加和编辑菜单管理公共字段处理方法
  25. *
  26. * @return array
  27. */
  28. public function commonFieldFilter(){
  29. $params = $this->request->getRawJson();
  30. if( empty($params) ){
  31. $this->sendOutput('参数为空', ErrorCode::$paramError );
  32. }
  33. $ModuleData = [
  34. 'name' => isset($params['name']) ? $params['name'] : '',
  35. 'alias' => isset($params['alias']) ? $params['alias'] : '',
  36. ];
  37. foreach($ModuleData as $key => $value){
  38. if(empty($value) && $value !== 0){
  39. $this->sendOutput($key.'参数错误', ErrorCode::$paramError );
  40. }
  41. }
  42. $ModuleData['pid'] = isset($params['pid']) ? $params['pid'] : 0;
  43. $ModuleData['extend'] = isset($params['extend']) ? $params['extend'] : '';
  44. $ModuleData['associate'] = isset($params['associate']) ? $params['associate'] : [];
  45. $ModuleData['associatePath'] = isset($params['associatePath']) ? $params['associatePath'] : [];
  46. $ModuleData['deleteStatus']= StatusCode::$standard;
  47. $ModuleData['enableStatus']= StatusCode::$standard;
  48. $ModuleData['createTime'] = time();
  49. $ModuleData['updateTime'] = time();
  50. return $ModuleData;
  51. }
  52. /**
  53. * 添加菜单
  54. */
  55. public function addModule()
  56. {
  57. $ModuleData = $this->commonFieldFilter();
  58. $result = $this->objMModule ->addModule($ModuleData);
  59. if($result->isSuccess()){
  60. parent::sendOutput($result->getData());
  61. }else{
  62. parent::sendOutput($result->getData(), $result->getErrorCode());
  63. }
  64. }
  65. /**
  66. * 获取指定菜单信息
  67. */
  68. public function getModuleInfo()
  69. {
  70. $ModuleId = $this->request->param('request_id');
  71. if ( !$ModuleId ) {
  72. $this->sendOutput('参数错误', ErrorCode::$paramError );
  73. }
  74. $result = $this->objMModule->getModuleInfo($ModuleId);
  75. if($result->isSuccess()){
  76. $this->sendOutput($result->getData());
  77. }else{
  78. $this->sendOutput($result->getData(), $result->getErrorCode());
  79. }
  80. }
  81. /**
  82. * 编辑菜单
  83. */
  84. public function editModule()
  85. {
  86. $ModuleId = $this->request->param('request_id');
  87. if(empty($ModuleId)){
  88. $this->sendOutput('参数错误', ErrorCode::$paramError);
  89. }
  90. $ModuleData = $this->commonFieldFilter();
  91. $ModuleData['id'] = $ModuleId;
  92. unset($ModuleData['createTime']);
  93. $result = $this->objMModule->editModule($ModuleData);
  94. if($result->isSuccess()){
  95. parent::sendOutput($result->getData());
  96. }else{
  97. parent::sendOutput($result->getData(), $result->getErrorCode());
  98. }
  99. }
  100. /**
  101. * 删除菜单
  102. */
  103. public function delModule()
  104. {
  105. $ModuleId = $this->request->param('request_id');
  106. if(!$ModuleId){
  107. $this->sendOutput('参数错误', ErrorCode::$paramError);
  108. }
  109. $result = $this->objMModule->delModule($ModuleId);
  110. if($result->isSuccess()){
  111. parent::sendOutput($result->getData());
  112. }else{
  113. parent::sendOutput($result->getData(), $result->getErrorCode());
  114. }
  115. }
  116. /**
  117. * 菜单启用和禁用
  118. */
  119. public function updateModuleStatus()
  120. {
  121. $params = $this->request->getRawJson();
  122. if( empty($params['id']) && empty($params['enableStatus'])){
  123. $this->sendOutput('参数为空', ErrorCode::$paramError );
  124. }
  125. $result = $this->objMModule->updateModuleStatus($params);
  126. if($result->isSuccess()){
  127. parent::sendOutput($result->getData());
  128. }else{
  129. parent::sendOutput($result->getData(), $result->getErrorCode());
  130. }
  131. }
  132. /**
  133. * 后台所有菜单列表
  134. */
  135. public function getAllModule()
  136. {
  137. $params = $this->request->getRawJson();
  138. $data['enableStatus'] = isset($params['enableStatus']) ? $params['enableStatus'] : '';
  139. $result = $this->objMModule->getAllModule($data);
  140. if($result->isSuccess()){
  141. $returnData = $result->getData();
  142. parent::sendOutput($returnData);
  143. }else{
  144. parent::sendOutput($result->getData(), $result->getErrorCode());
  145. }
  146. }
  147. /**
  148. * 初始化缓存
  149. */
  150. public function initCache()
  151. {
  152. $result = $this->objMModule->initCache();
  153. if(!$result->isSuccess()){
  154. parent::sendOutput($result->getData(), $result->getErrorCode());
  155. }
  156. parent::sendOutput($result->getData());
  157. }
  158. }