StorageLocation.Class.php 6.5 KB

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