示例#1
0
 /**
  * 控制台命令
  */
 public function console()
 {
     $returnStruct = array('status' => 0, 'code' => 501, 'msg' => _('Not Implemented'), 'content' => array());
     try {
         //* 初始化返回数据 */
         $returnStatus = 1;
         $returnCode = 200;
         $returnMessage = '';
         $returnData = array();
         //* 收集请求数据 ==根据业务逻辑定制== */
         $requestData = $this->input->post();
         //* 实现功能后屏蔽此异常抛出 */
         //throw new MyRuntimeException(_('Not Implemented'),501);
         //* 权限验证,数据验证,逻辑验证 ==根据业务逻辑定制== */
         if (util::isAccess(array(Logon::$MGR_ROLE_LABEL_SYS_ADMIN), array(Logon::$MGR_ROLE_LABEL_DENIED, Logon::$MGR_ROLE_LABEL_GUEST), $this->getMgrRole()) == FALSE) {
             throw new MyRuntimeException(_('Access Denied'), 403);
         }
         //* 权限验证 ==根据业务逻辑定制== */
         //* 数据验证 ==根据业务逻辑定制== */
         //* 逻辑验证 ==根据业务逻辑定制== */
         // 调用底层服务
         // 执行业务逻辑
         //* 补充&修改返回结构体 */
         $returnStruct['status'] = $returnStatus;
         $returnStruct['code'] = $returnCode;
         $returnStruct['msg'] = $returnMessage;
         $returnStruct['content'] = $returnData;
         //* 请求类型 */
         if ($this->isAjaxRequest()) {
             throw new MyRuntimeException(_('Not Implemented'), 501);
             // ajax 请求
             // json 输出
             $this->template->content = $returnStruct;
         } else {
             // html 输出
             //* 模板输出 */
             $this->template = new View('layout/base_html');
             $this->template->returnStruct = $returnStruct;
             $content = new View($this->packageName . '/' . $this->className . '/' . __FUNCTION__);
             //* 变量绑定 */
             $this->template->title = Lemon::config('site.name');
             $this->template->content = $content;
             //* 请求结构数据绑定 */
             $this->template->content->requestData = $requestData;
             //* 返回结构体绑定 */
             $this->template->content->returnStruct = $returnStruct;
             //:: 当前应用专用数据
             $this->template->content->title = Lemon::config('site.name');
             $addonJsLinkContext = '';
             $addonJsLinkContext .= '<script type="text/javascript" src="http://res.zr4u.com/res/js/jquery/jquery-1.4.2.min.js"></script>' . PHP_EOL;
             $addonJsLinkContext .= '<script type="text/javascript" src="http://res.zr4u.com/res/js/jquery/plugins/jquery.terminal.min.js"></script>' . PHP_EOL;
             $this->template->addonJsLinkContext = $addonJsLinkContext;
             $addonCssContentContext = '';
             $addonCssContentContext .= 'body { margin: 0;}' . PHP_EOL;
             $this->template->addonCssContentContext = $addonCssContentContext;
         }
         // end of request type determine
     } catch (MyRuntimeException $ex) {
         $returnStruct['status'] = 0;
         $returnStruct['code'] = $ex->getCode();
         $returnStruct['msg'] = $ex->getMessage();
         //TODO 异常处理
         //throw $ex;
         if ($this->isAjaxRequest()) {
             $this->template->content = $returnStruct;
         } else {
             $this->template->returnStruct = $returnStruct;
             $content = new View('info');
             $this->template->content = $content;
             //* 请求结构数据绑定 */
             $this->template->content->requestData = $requestData;
             //* 返回结构体绑定 */
             $this->template->content->returnStruct = $returnStruct;
         }
     }
 }
示例#2
0
 /**
  * 删除数据 action
  */
 public function delete()
 {
     $returnStruct = array('status' => 0, 'code' => 501, 'msg' => _('Not Implemented'), 'content' => array());
     try {
         // 是否调用本地服务
         $useLocalService = TRUE;
         //$useLocalService = FALSE;
         //* 初始化返回数据 */
         $returnStatus = 1;
         $returnCode = 200;
         $returnMessage = '';
         $returnData = array();
         //* 收集请求数据 ==根据业务逻辑定制== */
         $requestData = $this->input->get();
         //* 实现功能后屏蔽此异常抛出 */
         //throw new MyRuntimeException(_('Not Implemented'),501);
         //* 权限验证,数据验证,逻辑验证 ==根据业务逻辑定制== */
         //if(util::isAccess(array(Logon::$MGR_ROLE_LABEL_SYS_ADMIN,), array(Logon::$USER_ROLE_LABEL_DENIED,Logon::$USER_ROLE_LABEL_GUEST), $this->getUserRoleLabel())==FALSE){
         //    throw new MyRuntimeException(_('Access Denied'),403);
         //}
         if (util::isAccess('*', array(Logon::$USER_ROLE_LABEL_DENIED), $this->getUserRoleLabel()) == FALSE) {
             throw new MyRuntimeException(_('Access Denied'), 403);
         }
         //* 权限验证 ==根据业务逻辑定制== */
         //* 数据验证 ==根据业务逻辑定制== */
         if (!isset($requestData['id']) || empty($requestData['id']) || !is_numeric($requestData['id'])) {
             throw new MyRuntimeException(_('Bad Request,id required'), 400);
         }
         //* 逻辑验证 ==根据业务逻辑定制== */
         // 调用底层服务
         !isset($servRouteInstance) && ($servRouteInstance = ServRouteInstance::getInstance(ServRouteConfig::getInstance()));
         // 执行业务逻辑
         // TODO 根据数据特征定制对应的服务实例
         if ($useLocalService == TRUE) {
             !isset($attachmentService) && ($attachmentService = Attachment_Service::getInstance($servRouteInstance));
         } else {
             require_once Lemon::find_file('vendor', 'phprpc/phprpc_client', TRUE);
             !isset($attachmentService) && ($attachmentService = new PHPRPC_Client(Lemon::config('phprpc.remote.Attachment.host')));
             !isset($phprpcApiKey) && ($phprpcApiKey = Lemon::config('phprpc.remote.Attachment.apiKey'));
         }
         try {
             if ($useLocalService == TRUE) {
                 $attachmentService->removeAttachmentDataByAttachmentId($requestData['id']);
             } else {
                 $args = array($requestData['id']);
                 $sign = md5(json_encode($args) . $phprpcApiKey);
                 $attachmentService->phprpc_removeAttachmentDataByAttachmentId($requestData['id'], $sign);
             }
         } catch (MyRuntimeException $ex) {
             //* ==根据业务逻辑定制== */
             //FIXME 根据service层的异常做一些对应处理并抛出用户友好的异常Message
             throw $ex;
         }
         $returnMessage = _('Sucess');
         //* 补充&修改返回结构体 */
         $returnStruct['status'] = $returnStatus;
         $returnStruct['code'] = $returnCode;
         $returnStruct['msg'] = $returnMessage;
         $returnStruct['content'] = $returnData;
         //* 请求类型 */
         if ($this->isAjaxRequest()) {
             // ajax 请求
             // json 输出
             $this->template->content = $returnStruct;
         } else {
             // html 输出
             //* 模板输出 */
             $this->template->returnStruct = $returnStruct;
             $content = new View('info');
             //* 变量绑定 */
             $this->template->title = Lemon::config('site.name');
             $this->template->content = $content;
             //* 请求结构数据绑定 */
             $this->template->content->requestData = $requestData;
             //* 返回结构体绑定 */
             $this->template->content->returnStruct = $returnStruct;
             //:: 当前应用专用数据
             $this->template->content->title = Lemon::config('site.name');
         }
         // end of request type determine
     } catch (MyRuntimeException $ex) {
         $returnStruct['status'] = 0;
         $returnStruct['code'] = $ex->getCode();
         $returnStruct['msg'] = $ex->getMessage();
         //TODO 异常处理
         //throw $ex;
         if ($this->isAjaxRequest()) {
             $this->template->content = $returnStruct;
         } else {
             $this->template->returnStruct = $returnStruct;
             $content = new View('info');
             $this->template->content = $content;
             //* 请求结构数据绑定 */
             $this->template->content->requestData = $requestData;
             //* 返回结构体绑定 */
             $this->template->content->returnStruct = $returnStruct;
         }
     }
 }
示例#3
0
 /**
  * rpc服务
  */
 public function attachment()
 {
     $returnStruct = array('status' => 0, 'code' => 501, 'msg' => _('Not Implemented'), 'content' => array());
     try {
         //* 初始化返回数据 */
         $returnStatus = 1;
         $returnCode = 200;
         $returnMessage = '';
         $returnData = array();
         //* 收集请求数据 ==根据业务逻辑定制== */
         $requestData = $this->input->get();
         //* 实现功能后屏蔽此异常抛出 */
         //throw new MyRuntimeException(_('Not Implemented'),501);
         //* 权限验证,数据验证,逻辑验证 ==根据业务逻辑定制== */
         //if(util::isAccess(array(Logon::$MGR_ROLE_LABEL_SYS_ADMIN,), array(Logon::$USER_ROLE_LABEL_DENIED,Logon::$USER_ROLE_LABEL_GUEST), $this->getUserRoleLabel())==FALSE){
         //    throw new MyRuntimeException(_('Access Denied'),403);
         //}
         if (util::isAccess('*', array(Logon::$USER_ROLE_LABEL_DENIED), $this->getUserRoleLabel()) == FALSE) {
             throw new MyRuntimeException(_('Access Denied'), 403);
         }
         //* 权限验证 ==根据业务逻辑定制== */
         //* 数据验证 ==根据业务逻辑定制== */
         //* 逻辑验证 ==根据业务逻辑定制== */
         // 调用底层服务
         !isset($servRouteInstance) && ($servRouteInstance = ServRouteInstance::getInstance(ServRouteConfig::getInstance()));
         // 执行业务逻辑
         require_once Lemon::find_file('vendor', 'phprpc/phprpc_server', TRUE);
         $server = new PHPRPC_Server();
         $server->add(array('phprpc_addAttachmentFileData', 'phprpc_getAttachmentDataById', 'phprpc_getStoreDataByStoreId', 'phprpc_getStoreDataByAttachmentId', 'phprpc_removeAttachmentDataByAttachmentId', 'phprpc_getStoreInfoByStoreId'), Attachment_Service::getInstance());
         $server->start();
         exit;
         throw new MyRuntimeException(_('Internal Error'), 500);
         //* 补充&修改返回结构体 */
         $returnStruct['status'] = $returnStatus;
         $returnStruct['code'] = $returnCode;
         $returnStruct['msg'] = $returnMessage;
         $returnStruct['content'] = $returnData;
         //* 请求类型 */
         if ($this->isAjaxRequest()) {
             // ajax 请求
             // json 输出
             $this->template->content = $returnStruct;
         } else {
             // html 输出
             //* 模板输出 */
             $this->template->returnStruct = $returnStruct;
             $content = new View('info');
             //* 变量绑定 */
             $this->template->title = Lemon::config('site.name');
             $this->template->content = $content;
             //* 请求结构数据绑定 */
             $this->template->content->requestData = $requestData;
             //* 返回结构体绑定 */
             $this->template->content->returnStruct = $returnStruct;
             //:: 当前应用专用数据
             $this->template->content->title = Lemon::config('site.name');
         }
         // end of request type determine
     } catch (MyRuntimeException $ex) {
         $returnStruct['status'] = 0;
         $returnStruct['code'] = $ex->getCode();
         $returnStruct['msg'] = $ex->getMessage();
         //TODO 异常处理
         //throw $ex;
         if ($this->isAjaxRequest()) {
             $this->template->content = $returnStruct;
         } else {
             $this->template->returnStruct = $returnStruct;
             $content = new View('info');
             $this->template->content = $content;
             //* 请求结构数据绑定 */
             $this->template->content->requestData = $requestData;
             //* 返回结构体绑定 */
             $this->template->content->returnStruct = $returnStruct;
         }
     }
 }
示例#4
0
 public function info()
 {
     $returnStruct = array('status' => 0, 'code' => 501, 'msg' => _('Not Implemented'), 'content' => array());
     try {
         //* 初始化返回数据 */
         $returnStatus = 1;
         $returnCode = 200;
         $returnMessage = '';
         $returnData = array();
         //* 收集请求数据 ==根据业务逻辑定制== */
         $requestData = $this->input->get();
         //* 实现功能后屏蔽此异常抛出 */
         throw new MyRuntimeException(_('Not Implemented'), 501);
         //* 权限验证,数据验证,逻辑验证 ==根据业务逻辑定制== */
         if (util::isAccess('*', array(Logon::$USER_ROLE_LABEL_DENIED, Logon::$USER_ROLE_LABEL_GUEST), $this->getUserRoleLabel()) == FALSE) {
             throw new MyRuntimeException(_('Access Denied'), 403);
         }
         //* 权限验证 ==根据业务逻辑定制== */
         //* 数据验证 ==根据业务逻辑定制== */
         //* 逻辑验证 ==根据业务逻辑定制== */
         // 调用底层服务
         // 执行业务逻辑
         //* 补充&修改返回结构体 */
         $returnStruct['status'] = $returnStatus;
         $returnStruct['code'] = $returnCode;
         $returnStruct['msg'] = $returnMessage;
         $returnStruct['content'] = $returnData;
         //* 请求类型 */
         if ($this->isAjaxRequest()) {
             // ajax 请求
             // json 输出
             $this->template->content = $returnStruct;
         } else {
             // html 输出
             //* 模板输出 */
             $this->template->returnStruct = $returnStruct;
             $content = new View('info');
             //* 变量绑定 */
             $this->template->title = Lemon::config('site.name');
             $this->template->content = $content;
             //* 请求结构数据绑定 */
             $this->template->content->requestData = $requestData;
             //* 返回结构体绑定 */
             $this->template->content->returnStruct = $returnStruct;
             //:: 当前应用专用数据
             $this->template->content->title = Lemon::config('site.name');
         }
         // end of request type determine
     } catch (MyRuntimeException $ex) {
         $returnStruct['status'] = 0;
         $returnStruct['code'] = $ex->getCode();
         $returnStruct['msg'] = $ex->getMessage();
         //TODO 异常处理
         //throw $ex;
         if ($this->isAjaxRequest()) {
             $this->template->content = $returnStruct;
         } else {
             $this->template->returnStruct = $returnStruct;
             $content = new View('info');
             $this->template->content = $content;
             //* 请求结构数据绑定 */
             $this->template->content->requestData = $requestData;
             //* 返回结构体绑定 */
             $this->template->content->returnStruct = $returnStruct;
         }
     }
 }