123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- <?php
- /**
- * 菜单管理模块
- * Created by PhpStorm.
- * User: tpl
- * Date: 2019/10/30
- * Time: 13:54
- */
- namespace JinDouYun\Controller\System;
- use AlibabaCloud\Client\Clients\RamRoleArnClient;
- use Mall\Framework\Core\ErrorCode;
- use Mall\Framework\Core\StatusCode;
- use JinDouYun\Controller\BaseController;
- use JinDouYun\Model\System\MModule;
- class Module extends BaseController
- {
- private $objMModule;
- public function __construct($isCheckAcl = false, $isMustLogin = false)
- {
- parent::__construct($isCheckAcl, $isMustLogin,false);
- $this->objMModule = new MModule();
- }
- /**
- * 添加和编辑菜单管理公共字段处理方法
- *
- * @return array
- */
- public function commonFieldFilter(){
- $params = $this->request->getRawJson();
- if( empty($params) ){
- $this->sendOutput('参数为空', ErrorCode::$paramError );
- }
- $ModuleData = [
- 'name' => isset($params['name']) ? $params['name'] : '',
- 'alias' => isset($params['alias']) ? $params['alias'] : '',
- ];
- foreach($ModuleData as $key => $value){
- if(empty($value) && $value !== 0){
- $this->sendOutput($key.'参数错误', ErrorCode::$paramError );
- }
- }
- $ModuleData['pid'] = isset($params['pid']) ? $params['pid'] : 0;
- $ModuleData['extend'] = isset($params['extend']) ? $params['extend'] : '';
- $ModuleData['associate'] = isset($params['associate']) ? $params['associate'] : [];
- $ModuleData['associatePath'] = isset($params['associatePath']) ? $params['associatePath'] : [];
- $ModuleData['deleteStatus']= StatusCode::$standard;
- $ModuleData['enableStatus']= StatusCode::$standard;
- $ModuleData['createTime'] = time();
- $ModuleData['updateTime'] = time();
- return $ModuleData;
- }
- /**
- * 添加菜单
- */
- public function addModule()
- {
- $ModuleData = $this->commonFieldFilter();
- $result = $this->objMModule ->addModule($ModuleData);
- if($result->isSuccess()){
- parent::sendOutput($result->getData());
- }else{
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 获取指定菜单信息
- */
- public function getModuleInfo()
- {
- $ModuleId = $this->request->param('request_id');
- if ( !$ModuleId ) {
- $this->sendOutput('参数错误', ErrorCode::$paramError );
- }
- $result = $this->objMModule->getModuleInfo($ModuleId);
- if($result->isSuccess()){
- $this->sendOutput($result->getData());
- }else{
- $this->sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 编辑菜单
- */
- public function editModule()
- {
- $ModuleId = $this->request->param('request_id');
- if(empty($ModuleId)){
- $this->sendOutput('参数错误', ErrorCode::$paramError);
- }
- $ModuleData = $this->commonFieldFilter();
- $ModuleData['id'] = $ModuleId;
- unset($ModuleData['createTime']);
- $result = $this->objMModule->editModule($ModuleData);
- if($result->isSuccess()){
- parent::sendOutput($result->getData());
- }else{
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 删除菜单
- */
- public function delModule()
- {
- $ModuleId = $this->request->param('request_id');
- if(!$ModuleId){
- $this->sendOutput('参数错误', ErrorCode::$paramError);
- }
- $result = $this->objMModule->delModule($ModuleId);
- if($result->isSuccess()){
- parent::sendOutput($result->getData());
- }else{
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 菜单启用和禁用
- */
- public function updateModuleStatus()
- {
- $params = $this->request->getRawJson();
- if( empty($params['id']) && empty($params['enableStatus'])){
- $this->sendOutput('参数为空', ErrorCode::$paramError );
- }
- $result = $this->objMModule->updateModuleStatus($params);
- if($result->isSuccess()){
- parent::sendOutput($result->getData());
- }else{
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 后台所有菜单列表
- */
- public function getAllModule()
- {
- $params = $this->request->getRawJson();
- $data['enableStatus'] = isset($params['enableStatus']) ? $params['enableStatus'] : '';
- $result = $this->objMModule->getAllModule($data);
- if($result->isSuccess()){
- $returnData = $result->getData();
- parent::sendOutput($returnData);
- }else{
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 初始化缓存
- */
- public function initCache()
- {
- $result = $this->objMModule->initCache();
- if(!$result->isSuccess()){
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- parent::sendOutput($result->getData());
- }
- }
|