ReservoirArea.Class.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <?php
  2. /**
  3. * 库区Controller
  4. * Created by PhpStorm.
  5. * User: haoren
  6. * Date: 2020/12/14
  7. * Time: 16:00
  8. */
  9. namespace JinDouYun\Controller\Stock;
  10. use Mall\Framework\Core\ErrorCode;
  11. use Mall\Framework\Core\StatusCode;
  12. use JinDouYun\Controller\BaseController;
  13. use JinDouYun\Model\Stock\MReservoirArea;
  14. class ReservoirArea extends BaseController
  15. {
  16. private $objMReservoirArea;
  17. public function __construct($isCheckAcl = true, $isMustLogin = true)
  18. {
  19. parent::__construct($isCheckAcl, $isMustLogin);
  20. $this->objMReservoirArea = new MReservoirArea($this->onlineEnterpriseId, $this->onlineUserId);
  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. $data = [
  33. "enterpriseId" => $this->onlineEnterpriseId,
  34. "warehouseId" => getArrayItem($params,'warehouseId'), // 仓库id
  35. "name" => getArrayItem($params,'name'),
  36. "code" => getArrayItem($params,'code'),
  37. "type" => getArrayItem($params,'type'),
  38. ];
  39. foreach ($data as $key => $value) {
  40. if (empty($value) && $value !== 0) {
  41. $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
  42. }
  43. }
  44. $data['length'] = getArrayItem($params,'length', 0);
  45. $data['width'] = getArrayItem($params,'width', 0);
  46. $data['height'] = getArrayItem($params,'height', 0);
  47. $data['weight'] = getArrayItem($params,'weight', 0);
  48. $data['enableStatus'] = getArrayItem($params,'enableStatus',5);
  49. return $data;
  50. }
  51. /**
  52. * 库区添加
  53. */
  54. public function addReservoir()
  55. {
  56. $data = $this->commonFieldFilter();
  57. $result = $this->objMReservoirArea->addReservoir($data);
  58. if (!$result->isSuccess()) {
  59. parent::sendOutput($result->getData(), $result->getErrorCode());
  60. }
  61. parent::sendOutput($result->getData());
  62. }
  63. /**
  64. * 库区删除
  65. */
  66. public function deleteReservoir()
  67. {
  68. $id = $this->request->param('request_id');
  69. if (empty($id)) {
  70. $this->sendOutput('参数为空', ErrorCode::$paramError);
  71. }
  72. $update = [
  73. 'deleteStatus' => StatusCode::$delete
  74. ];
  75. $result = $this->objMReservoirArea->updateReservoir($update, ['id' => $id,'enterpriseId' => $this->onlineEnterpriseId]);
  76. if (!$result->isSuccess()) {
  77. parent::sendOutput($result->getData(), $result->getErrorCode());
  78. }
  79. parent::sendOutput($result->getData());
  80. }
  81. /**
  82. * 库区修改
  83. */
  84. public function updateReservoir()
  85. {
  86. $id = $this->request->param('request_id');
  87. if (empty($id)) {
  88. $this->sendOutput('参数为空', ErrorCode::$paramError);
  89. }
  90. $update = $this->commonFieldFilter();
  91. $result = $this->objMReservoirArea->updateReservoir($update, ['id' => $id,'enterpriseId' => $this->onlineEnterpriseId]);
  92. if (!$result->isSuccess()) {
  93. parent::sendOutput($result->getData(), $result->getErrorCode());
  94. }
  95. parent::sendOutput($result->getData());
  96. }
  97. /**
  98. * 库区启用/禁用
  99. */
  100. public function enableReservoir()
  101. {
  102. $id = $this->request->param('request_id');
  103. if (empty($id)) {
  104. $this->sendOutput('参数为空', ErrorCode::$paramError);
  105. }
  106. $params = $this->request->getRawJson();
  107. $data = [
  108. 'enableStatus' => getArrayItem($params,'enableStatus',5),
  109. ];
  110. foreach ($data as $key => $value) {
  111. if (empty($value) && $value !== 0) {
  112. $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
  113. }
  114. }
  115. $result = $this->objMReservoirArea->updateReservoir($data, ['id' => $id,'enterpriseId' => $this->onlineEnterpriseId]);
  116. if (!$result->isSuccess()) {
  117. parent::sendOutput($result->getData(), $result->getErrorCode());
  118. }
  119. parent::sendOutput($result->getData());
  120. }
  121. /**
  122. * 库区列表
  123. */
  124. public function getAllReservoir()
  125. {
  126. $params = $this->request->getRawJson();
  127. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  128. $selectParams['limit'] = $pageParams['limit'];
  129. $selectParams['offset'] = $pageParams['offset'];
  130. $selectParams['enterpriseId'] = $this->onlineEnterpriseId;
  131. $selectParams['deleteStatus'] = StatusCode::$standard;
  132. if(isset($params['warehouseId']) && !empty($params['warehouseId'])){
  133. $selectParams['warehouseId'] = $params['warehouseId'];
  134. }
  135. if(isset($params['type']) && !empty($params['type'])){
  136. $selectParams['type'] = $params['type'];
  137. }
  138. $result = $this->objMReservoirArea->getAllReservoir($selectParams);
  139. if (!$result->isSuccess()) {
  140. parent::sendOutput($result->getData(), ErrorCode::$dberror);
  141. }
  142. $returnData = $result->getData();
  143. $pageData = [
  144. 'pageIndex' => $params['page'],
  145. 'pageSize' => $params['pageSize'],
  146. 'pageTotal' => $returnData['total'],
  147. ];
  148. parent::sendOutput($returnData['data'], 0, $pageData);
  149. }
  150. /**
  151. * 库区列表(不分页)
  152. */
  153. public function getListReservoir()
  154. {
  155. $params = $this->request->getRawJson();
  156. $selectParams = [];
  157. if(isset($params['warehouseId']) && !empty($params['warehouseId'])){
  158. $selectParams['warehouseId'] = $params['warehouseId'];
  159. }
  160. if(isset($params['type']) && !empty($params['type'])){
  161. $selectParams['type'] = $params['type'];
  162. }
  163. $selectParams['enterpriseId'] = $this->onlineEnterpriseId;
  164. $result = $this->objMReservoirArea->getListReservoir($selectParams);
  165. if (!$result->isSuccess()) {
  166. parent::sendOutput($result->getData(), ErrorCode::$dberror);
  167. }
  168. parent::sendOutput($result->getData());
  169. }
  170. /**
  171. * 库区详情
  172. */
  173. public function getReservoirInfo()
  174. {
  175. $params = $this->request->param('request_id');
  176. if (empty($params)) {
  177. $this->sendOutput('参数为空', ErrorCode::$paramError);
  178. }
  179. $result = $this->objMReservoirArea->getReservoirInfo($params);
  180. if (!$result->isSuccess()) {
  181. parent::sendOutput($result->getData(), $result->getErrorCode());
  182. }
  183. parent::sendOutput($result->getData());
  184. }
  185. }