Page.Class.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <?php
  2. /**
  3. * 页面设计
  4. * Created by PhpStorm.
  5. * User: XiaoMing
  6. * Date: 2020/3/19
  7. * Time: 12:22
  8. */
  9. namespace JinDouYun\Controller\System;
  10. use JinDouYun\Controller\BaseController;
  11. use JinDouYun\Model\System\MPage;
  12. use Mall\Framework\Core\ErrorCode;
  13. use Mall\Framework\Core\StatusCode;
  14. class Page extends BaseController
  15. {
  16. private $objMPage;
  17. /**
  18. * Page constructor.
  19. * @param bool $isCheckAcl
  20. * @param bool $isMustLogin
  21. * @throws \Exception
  22. */
  23. public function __construct($isCheckAcl = true, $isMustLogin = true)
  24. {
  25. parent::__construct($isCheckAcl, $isMustLogin);
  26. $this->objMPage = new MPage($this->onlineUserId, $this->onlineEnterpriseId);
  27. }
  28. /**
  29. * 添加,编辑 页面数据
  30. * @return array
  31. */
  32. public function commonFieldFilter()
  33. {
  34. $params = $this->request->getRawJson();
  35. if (empty($params)) {
  36. parent::sendOutput('参数为空', ErrorCode::$paramError);
  37. }
  38. $data = [
  39. 'pageType' => isset($params['pageType']) ? $params['pageType'] : StatusCode::$pageType['home'],//页面类型
  40. 'pageName' => isset($params['pageName']) ? $params['pageName'] : '首页',//页面名称
  41. 'pageData' => isset($params['pageData']) ? json_encode($params['pageData']) : [],
  42. ];
  43. foreach ($data as $key => $value) {
  44. if (empty($value) && $value !== 0) {
  45. parent::sendOutput($key . '参数错误', ErrorCode::$paramError);
  46. }
  47. }
  48. $data['isStore'] = ( isset($params['isStore']) && $params['isStore'] == true ) ? $params['isStore'] : false;
  49. if (isset($params['id'])) $data['id'] = $params['id'];
  50. return $data;
  51. }
  52. /**
  53. * 保存页面
  54. */
  55. public function save()
  56. {
  57. $data = $this->commonFieldFilter();
  58. $isStore = $data['isStore'];
  59. unset($data['isStore']);
  60. $result = $this->objMPage->save($data,$isStore,$this->shopId);
  61. if ($result->isSuccess()) {
  62. parent::sendOutput($result->getData());
  63. }
  64. parent::sendOutput($result->getData(), $result->getErrorCode());
  65. }
  66. /**
  67. * 获取页面信息
  68. */
  69. public function getPageInfo()
  70. {
  71. $id = $this->request->param('request_id');
  72. if (empty($id)) {
  73. parent::sendOutput('参数错误', ErrorCode::$paramError);
  74. }
  75. $result = $this->objMPage->getPageInfo($id);
  76. if ($result->isSuccess()) {
  77. parent::sendOutput($result->getData());
  78. }
  79. parent::sendOutput($result->getData(), $result->getErrorCode());
  80. }
  81. /**
  82. * 启用此页面/禁用此页面
  83. */
  84. public function updateEnableStatus()
  85. {
  86. $params = $this->request->getRawJson();
  87. if (empty($params['id']) && empty($params['enableStatus']) && empty($params['pageType'])) {
  88. parent::sendOutput('参数为空', ErrorCode::$paramError);
  89. }
  90. $result = $this->objMPage->updateEnableStatus($params);
  91. if ($result->isSuccess()) {
  92. parent::sendOutput($result->getData());
  93. }
  94. parent::sendOutput($result->getData(), $result->getErrorCode());
  95. }
  96. /**
  97. * 删除页面
  98. */
  99. public function del()
  100. {
  101. $id = $this->request->param('request_id');
  102. if (empty($id)) {
  103. parent::sendOutput('参数错误', ErrorCode::$paramError);
  104. }
  105. $result = $this->objMPage->del($id);
  106. if ($result->isSuccess()) {
  107. parent::sendOutput($result->getData());
  108. }
  109. parent::sendOutput($result->getData(), $result->getErrorCode());
  110. }
  111. /**
  112. * 获取页面列表
  113. */
  114. public function getAll()
  115. {
  116. $params = $this->request->getRawJson();
  117. if (empty($params)) {
  118. parent::sendOutput('参数为空', ErrorCode::$paramError);
  119. }
  120. $pageParams = pageToOffset(isset($params['page']) ? $params['page'] : 1, isset($params['pageSize']) ? $params['pageSize'] : 10);
  121. $selectParams['limit'] = $pageParams['limit'];
  122. $selectParams['offset'] = $pageParams['offset'];
  123. $selectParams['shopId'] = 0;
  124. !empty($this->shopId) && $selectParams['shopId'] = $this->shopId;
  125. $result = $this->objMPage->getAll($selectParams);
  126. if ($result->isSuccess()) {
  127. $returnData = $result->getData();
  128. $pageData = [
  129. 'pageIndex' => isset($params['page']) ? $params['page'] : 1,
  130. 'pageSize' => isset($params['pageSize']) ? $params['pageSize'] : 10,
  131. 'pageTotal' => $returnData['total'],
  132. ];
  133. parent::sendOutput($returnData['data'], 0, $pageData);
  134. }
  135. parent::sendOutput($result->getData(), $result->getErrorCode());
  136. }
  137. /**
  138. * 获取专题
  139. */
  140. public function getSpecial()
  141. {
  142. $params = $this->request->getRawJson();
  143. $pageParams = pageToOffset(isset($params['page']) ? $params['page'] : 1, isset($params['pageSize']) ? $params['pageSize'] : 10);
  144. $selectParams['limit'] = $pageParams['limit'];
  145. $selectParams['offset'] = $pageParams['offset'];
  146. if (isset($params['id']) && !empty($params['id'])) {
  147. $selectParams['id'] = $params['id'];
  148. }
  149. $selectParams['shopId'] = 0;
  150. !empty($this->shopId) && $selectParams['shopId'] = $this->shopId;
  151. $result = $this->objMPage->getSpecial($selectParams);
  152. if ($result->isSuccess()) {
  153. $returnData = $result->getData();
  154. $pageData = [
  155. 'pageIndex' => isset($params['page']) ? $params['page'] : 1,
  156. 'pageSize' => isset($params['pageSize']) ? $params['pageSize'] : 10,
  157. 'pageTotal' => $returnData['total'],
  158. ];
  159. parent::sendOutput($returnData['data'], 0, $pageData);
  160. }
  161. parent::sendOutput($result->getData(), $result->getErrorCode());
  162. }
  163. }