123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- <?php
- /**
- * 页面设计
- * Created by PhpStorm.
- * User: XiaoMing
- * Date: 2020/3/19
- * Time: 12:22
- */
- namespace JinDouYun\Controller\System;
- use JinDouYun\Controller\BaseController;
- use JinDouYun\Model\System\MPage;
- use Mall\Framework\Core\ErrorCode;
- use Mall\Framework\Core\StatusCode;
- class Page extends BaseController
- {
- private $objMPage;
- /**
- * Page constructor.
- * @param bool $isCheckAcl
- * @param bool $isMustLogin
- * @throws \Exception
- */
- public function __construct($isCheckAcl = true, $isMustLogin = true)
- {
- parent::__construct($isCheckAcl, $isMustLogin);
- $this->objMPage = new MPage($this->onlineUserId, $this->onlineEnterpriseId);
- }
- /**
- * 添加,编辑 页面数据
- * @return array
- */
- public function commonFieldFilter()
- {
- $params = $this->request->getRawJson();
- if (empty($params)) {
- parent::sendOutput('参数为空', ErrorCode::$paramError);
- }
- $data = [
- 'pageType' => isset($params['pageType']) ? $params['pageType'] : StatusCode::$pageType['home'],//页面类型
- 'pageName' => isset($params['pageName']) ? $params['pageName'] : '首页',//页面名称
- 'pageData' => isset($params['pageData']) ? json_encode($params['pageData']) : [],
- ];
- foreach ($data as $key => $value) {
- if (empty($value) && $value !== 0) {
- parent::sendOutput($key . '参数错误', ErrorCode::$paramError);
- }
- }
- $data['isStore'] = ( isset($params['isStore']) && $params['isStore'] == true ) ? $params['isStore'] : false;
- if (isset($params['id'])) $data['id'] = $params['id'];
- return $data;
- }
- /**
- * 保存页面
- */
- public function save()
- {
- $data = $this->commonFieldFilter();
- $isStore = $data['isStore'];
- unset($data['isStore']);
- $result = $this->objMPage->save($data,$isStore,$this->shopId);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- }
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- /**
- * 获取页面信息
- */
- public function getPageInfo()
- {
- $id = $this->request->param('request_id');
- if (empty($id)) {
- parent::sendOutput('参数错误', ErrorCode::$paramError);
- }
- $result = $this->objMPage->getPageInfo($id);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- }
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- /**
- * 启用此页面/禁用此页面
- */
- public function updateEnableStatus()
- {
- $params = $this->request->getRawJson();
- if (empty($params['id']) && empty($params['enableStatus']) && empty($params['pageType'])) {
- parent::sendOutput('参数为空', ErrorCode::$paramError);
- }
- $result = $this->objMPage->updateEnableStatus($params);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- }
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- /**
- * 删除页面
- */
- public function del()
- {
- $id = $this->request->param('request_id');
- if (empty($id)) {
- parent::sendOutput('参数错误', ErrorCode::$paramError);
- }
- $result = $this->objMPage->del($id);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- }
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- /**
- * 获取页面列表
- */
- public function getAll()
- {
- $params = $this->request->getRawJson();
- if (empty($params)) {
- parent::sendOutput('参数为空', ErrorCode::$paramError);
- }
- $pageParams = pageToOffset(isset($params['page']) ? $params['page'] : 1, isset($params['pageSize']) ? $params['pageSize'] : 10);
- $selectParams['limit'] = $pageParams['limit'];
- $selectParams['offset'] = $pageParams['offset'];
- $selectParams['shopId'] = 0;
- !empty($this->shopId) && $selectParams['shopId'] = $this->shopId;
- $result = $this->objMPage->getAll($selectParams);
- if ($result->isSuccess()) {
- $returnData = $result->getData();
- $pageData = [
- 'pageIndex' => isset($params['page']) ? $params['page'] : 1,
- 'pageSize' => isset($params['pageSize']) ? $params['pageSize'] : 10,
- 'pageTotal' => $returnData['total'],
- ];
- parent::sendOutput($returnData['data'], 0, $pageData);
- }
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- /**
- * 获取专题
- */
- public function getSpecial()
- {
- $params = $this->request->getRawJson();
- $pageParams = pageToOffset(isset($params['page']) ? $params['page'] : 1, isset($params['pageSize']) ? $params['pageSize'] : 10);
- $selectParams['limit'] = $pageParams['limit'];
- $selectParams['offset'] = $pageParams['offset'];
- if (isset($params['id']) && !empty($params['id'])) {
- $selectParams['id'] = $params['id'];
- }
- $selectParams['shopId'] = 0;
- !empty($this->shopId) && $selectParams['shopId'] = $this->shopId;
- $result = $this->objMPage->getSpecial($selectParams);
- if ($result->isSuccess()) {
- $returnData = $result->getData();
- $pageData = [
- 'pageIndex' => isset($params['page']) ? $params['page'] : 1,
- 'pageSize' => isset($params['pageSize']) ? $params['pageSize'] : 10,
- 'pageTotal' => $returnData['total'],
- ];
- parent::sendOutput($returnData['data'], 0, $pageData);
- }
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
|