Zone.Class.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. /**
  3. * 区块管理后台
  4. * Created by PhpStorm.
  5. * User: QianNiao-C
  6. * Date: 2019/10/25
  7. * Time: 11:32
  8. */
  9. namespace JinDouYun\Controller\BlockManage;
  10. use Mall\Framework\Core\ErrorCode;
  11. use JinDouYun\Controller\BaseController;
  12. use JinDouYun\Model\BlockManage\MZone;
  13. class Zone extends BaseController
  14. {
  15. public $objMZone;
  16. public function __construct($isCheckAcl = true, $isMustLogin = true)
  17. {
  18. parent::__construct($isCheckAcl, $isMustLogin);
  19. $this->objMZone = new MZone();
  20. }
  21. /**
  22. * 添加,编辑区块接收公共字段
  23. *
  24. * @return array
  25. */
  26. public function commonFieldFilter()
  27. {
  28. $params = $this->request->getRawJson();
  29. if (empty($params)) {
  30. $this->sendOutput('参数为空', ErrorCode::$paramError);
  31. }
  32. $zoneFieldData = [
  33. 'title' => isset($params['title']) ? $params['title'] : '',
  34. 'zoneData' => isset($params['data']) ? $params['data'] : '',
  35. ];
  36. foreach ($zoneFieldData as $key => $value) {
  37. if (empty($value) && $value !== 0) {
  38. $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
  39. }
  40. }
  41. $zoneFieldData['zoneData'] = json_encode($zoneFieldData['zoneData']);
  42. return $zoneFieldData;
  43. }
  44. /**
  45. * 添加区块
  46. */
  47. public function addZone()
  48. {
  49. $zoneData = $this->commonFieldFilter();
  50. $result = $this->objMZone->addZone($zoneData);
  51. if ($result->isSuccess()) {
  52. parent::sendOutput($result->getData());
  53. }
  54. parent::sendOutput($result->getData(), $result->getErrorCode());
  55. }
  56. /**
  57. * 区块启用和禁用
  58. */
  59. public function updateEnableStatus()
  60. {
  61. $params['id'] = $this->request->param('request_id');
  62. $params['enableStatus'] = $this->request->param('enableStatus');//5启用 4停用
  63. foreach ($params as $key => $value) {
  64. if (empty($value)) {
  65. $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
  66. }
  67. }
  68. $result = $this->objMZone->updateEnableStatus($params);
  69. if ($result->isSuccess()) {
  70. parent::sendOutput($result->getData());
  71. }
  72. parent::sendOutput($result->getData(), $result->getErrorCode());
  73. }
  74. /**
  75. * 获取指定区块信息
  76. */
  77. public function getZoneInfoById()
  78. {
  79. $id = $this->request->param('request_id');
  80. if (!$id) {
  81. $this->sendOutput('参数错误', ErrorCode::$paramError);
  82. }
  83. $result = $this->objMZone->getZoneInfoById($id);
  84. if ($result->isSuccess()) {
  85. $resultData = $result->getData();
  86. $resultData['zoneData'] = json_decode($resultData['zoneData'], true);
  87. parent::sendOutput($resultData);
  88. }
  89. parent::sendOutput($result->getData(), $result->getErrorCode());
  90. }
  91. /**
  92. * 编辑区块信息
  93. */
  94. public function editZone()
  95. {
  96. $id = $this->request->param('request_id');
  97. if (empty($id)) {
  98. $this->sendOutput('参数错误', ErrorCode::$paramError);
  99. }
  100. $zoneData = $this->commonFieldFilter();
  101. $zoneData['id'] = $id;
  102. unset($zoneData['createTime']);
  103. $result = $this->objMZone->editZone($zoneData);
  104. if ($result->isSuccess()) {
  105. parent::sendOutput($result->getData());
  106. }
  107. parent::sendOutput($result->getData(), $result->getErrorCode());
  108. }
  109. /**
  110. * 获取所有区块
  111. */
  112. public function getAllZone()
  113. {
  114. $page = $this->request->param('page') ?: 1;
  115. $pageSize = $this->request->param('pageSize') ?: 10;
  116. $offset = ($page - 1) * $pageSize;
  117. $selectParams = [
  118. 'limit' => $pageSize,
  119. 'offset' => $offset,
  120. ];
  121. $result = $this->objMZone->getAllZone($selectParams);
  122. if ($result->isSuccess()) {
  123. $returnData = $result->getData();
  124. $pageData = [
  125. 'pageIndex' => $page,
  126. 'pageSize' => $pageSize,
  127. 'pageTotal' => $returnData['total'],
  128. ];
  129. parent::sendOutput($returnData['data'], 0, $pageData);
  130. }
  131. parent::sendOutput($result->getData(), ErrorCode::$dberror);
  132. }
  133. }