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()); } }