Units.Class.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. /**
  3. * 计量单位
  4. * Created by PhpStorm.
  5. * User: XiaoMing
  6. * Date: 2020/3/17
  7. * Time: 16:52
  8. */
  9. namespace JinDouYun\Controller\GoodsManage;
  10. use JinDouYun\Controller\BaseController;
  11. use JinDouYun\Model\GoodsManage\MUnits;
  12. use Mall\Framework\Core\ErrorCode;
  13. use Mall\Framework\Core\StatusCode;
  14. class Units extends BaseController
  15. {
  16. private $objMUnits;
  17. /**
  18. * Units 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->objMUnits = new MUnits($this->onlineUserId, $this->onlineEnterpriseId);
  27. }
  28. /**
  29. * 添加和编辑计量单位公共字段
  30. *
  31. * @return array
  32. */
  33. public function commonFieldFilter()
  34. {
  35. $params = $this->request->getRawJson();
  36. if (empty($params)) {
  37. parent::sendOutput('参数为空', ErrorCode::$paramError);
  38. }
  39. $data = [
  40. 'unitName' => isset($params['unitName']) ? $params['unitName'] : '',
  41. 'enableStatus' => isset($params['enableStatus']) ? $params['enableStatus'] : StatusCode::$delete
  42. ];
  43. foreach ($data as $key => $value) {
  44. if (empty($value)) {
  45. parent::sendOutput($key . '参数错误', ErrorCode::$paramError);
  46. }
  47. }
  48. return $data;
  49. }
  50. /**
  51. * 添加计量单位
  52. */
  53. public function add()
  54. {
  55. $data = $this->commonFieldFilter();
  56. $result = $this->objMUnits->add($data);
  57. if ($result->isSuccess()) {
  58. parent::sendOutput($result->getData());
  59. }
  60. parent::sendOutput($result->getData(), $result->getErrorCode());
  61. }
  62. /**
  63. * 删除计量单位
  64. */
  65. public function del()
  66. {
  67. $id = $this->request->param('request_id');
  68. if (empty($id)) {
  69. parent::sendOutput('参数错误', ErrorCode::$paramError);
  70. }
  71. $result = $this->objMUnits->del($id);
  72. if ($result->isSuccess()) {
  73. parent::sendOutput($result->getData());
  74. }
  75. parent::sendOutput($result->getData(), $result->getErrorCode());
  76. }
  77. /**
  78. * 更新 启用/禁用状态
  79. *
  80. */
  81. public function updateEnablesStatus()
  82. {
  83. $params = $this->request->getRawJson();
  84. if (empty($params['id']) && empty($params['enableStatus'])) {
  85. parent::sendOutput('参数为空', ErrorCode::$paramError);
  86. }
  87. $result = $this->objMUnits->updateEnableStatus($params);
  88. if ($result->isSuccess()) {
  89. parent::sendOutput($result->getData());
  90. }
  91. parent::sendOutput($result->getData(), $result->getErrorCode());
  92. }
  93. /**
  94. * 编辑计量单位
  95. */
  96. public function edit()
  97. {
  98. $id = $this->request->param('request_id');
  99. if (empty($id)) {
  100. $this->sendOutput('参数错误', ErrorCode::$paramError);
  101. }
  102. $data = $this->commonFieldFilter();
  103. $data['id'] = $id;
  104. $result = $this->objMUnits->edit($data);
  105. if ($result->isSuccess()) {
  106. parent::sendOutput($result->getData());
  107. }
  108. parent::sendOutput($result->getData(), $result->getErrorCode());
  109. }
  110. /**
  111. * 获取单位列表
  112. */
  113. public function getAll()
  114. {
  115. $params = $this->request->getRawJson();
  116. if (empty($params)) {
  117. parent::sendOutput('参数为空', ErrorCode::$paramError);
  118. }
  119. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  120. $selectParams['limit'] = $pageParams['limit'];
  121. $selectParams['offset'] = $pageParams['offset'];
  122. $selectParams['enableStatus'] = !empty($params['source']) ? $params['source'] :"";
  123. $result = $this->objMUnits->getAll($selectParams);
  124. if ($result->isSuccess()) {
  125. $returnData = $result->getData();
  126. $pageData = [
  127. 'pageIndex' => $params['page'],
  128. 'pageSize' => $params['pageSize'],
  129. 'pageTotal' => $returnData['total'],
  130. ];
  131. parent::sendOutput($returnData['data'], 0, $pageData);
  132. }
  133. parent::sendOutput($result->getData(), $result->getErrorCode());
  134. }
  135. }