SystemTemplate.Class.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. /**
  3. * 系统模版
  4. * Created by PhpStorm.
  5. * User: XiaoMing
  6. * Date: 2019/11/29
  7. * Time: 15:38
  8. */
  9. namespace JinDouYun\Controller\System;
  10. use Mall\Framework\Core\ErrorCode;
  11. use Mall\Framework\Core\StatusCode;
  12. use JinDouYun\Controller\BaseController;
  13. use JinDouYun\Model\System\MSystemTemplate;
  14. class SystemTemplate extends BaseController
  15. {
  16. private $objMSystemTemplate;
  17. /**
  18. * SystemTemplate constructor.
  19. * @param bool $isCheckAcl
  20. * @param bool $isMustLogin
  21. */
  22. public function __construct($isCheckAcl = true, $isMustLogin = true)
  23. {
  24. parent::__construct($isCheckAcl, $isMustLogin);
  25. $this->objMSystemTemplate = new MSystemTemplate($this->onlineUserId, $this->onlineEnterpriseId);
  26. }
  27. /**
  28. * 添加,编辑系统模版
  29. * @return array
  30. */
  31. public function commonFieldFilter()
  32. {
  33. $params = $this->request->getRawJson();
  34. if (empty($params)) {
  35. $this->sendOutput('参数为空', ErrorCode::$paramError);
  36. }
  37. $data = [
  38. 'title' => isset($params['title']) ? $params['title'] : '',
  39. ];
  40. foreach ($data as $key => $value) {
  41. if (empty($value) && $value !== 0) {
  42. $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
  43. }
  44. }
  45. $data['enableStatus'] = isset($params['enableStatus']) ? $params['enableStatus'] : StatusCode::$delete;
  46. return $data;
  47. }
  48. /**
  49. * 添加系统模版
  50. * @throws \Exception
  51. */
  52. public function add()
  53. {
  54. $data = $this->commonFieldFilter();
  55. $result = $this->objMSystemTemplate->add($data);
  56. if ($result->isSuccess()) {
  57. parent::sendOutput($result->getData());
  58. }
  59. parent::sendOutput($result->getData(), $result->getErrorCode());
  60. }
  61. /**
  62. * 系统模版启用/停用
  63. */
  64. public function updateEnableStatus()
  65. {
  66. $params['id'] = $this->request->param('request_id');
  67. $params['enableStatus'] = $this->request->param('enableStatus');
  68. foreach ($params as $key => $value) {
  69. if (empty($value)) {
  70. $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
  71. }
  72. }
  73. $result = $this->objMSystemTemplate->updateEnableStatus($params);
  74. if ($result->isSuccess()) {
  75. parent::sendOutput($result->getData());
  76. }
  77. parent::sendOutput($result->getData(), $result->getErrorCode());
  78. }
  79. /**
  80. * 获取模版列表
  81. */
  82. public function getAll()
  83. {
  84. $page = $this->request->param('page') ?: 1;
  85. $pageSize = $this->request->param('pageSize') ?: 10;
  86. $offset = ($page - 1) * $pageSize;
  87. $selectParams = [
  88. 'limit' => $pageSize,
  89. 'offset' => $offset,
  90. ];
  91. $dbResult = $this->objMSystemTemplate->getAll($selectParams);
  92. if ($dbResult->isSuccess()) {
  93. $returnData = $dbResult->getData();
  94. $pageData = [
  95. 'pageIndex' => $page,
  96. 'pageSize' => $pageSize,
  97. 'pageTotal' => $returnData['total'],
  98. ];
  99. parent::sendOutput($returnData['data'], 0, $pageData);
  100. }
  101. parent::sendOutput($dbResult->getData(), ErrorCode::$dberror);
  102. }
  103. /**
  104. * 编辑系统模版
  105. */
  106. public function edit()
  107. {
  108. $id = $this->request->param('request_id');
  109. if (empty($id)) {
  110. $this->sendOutput('参数错误', ErrorCode::$paramError);
  111. }
  112. $data = $this->commonFieldFilter();
  113. $data['id'] = $id;
  114. $result = $this->objMSystemTemplate->edit($data);
  115. if ($result->isSuccess()) {
  116. parent::sendOutput($result->getData());
  117. }
  118. parent::sendOutput($result->getData(), $result->getErrorCode());
  119. }
  120. /**
  121. * 删除系统模版
  122. */
  123. public function del()
  124. {
  125. $id = $this->request->param('request_id');
  126. if (!$id) {
  127. $this->sendOutput('参数错误', ErrorCode::$paramError);
  128. }
  129. if (!is_array($id)) {
  130. $id = [$id];
  131. }
  132. $result = $this->objMSystemTemplate->del($id);
  133. if ($result->isSuccess()) {
  134. parent::sendOutput($result->getData());
  135. }
  136. parent::sendOutput($result->getData(), $result->getErrorCode());
  137. }
  138. }