Allocate.Class.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. <?php
  2. /**
  3. * 仓库调拨Controller
  4. * Created by PhpStorm.
  5. * User: 小威
  6. * Date: 2019/11/29
  7. * Time: 15:00
  8. */
  9. namespace JinDouYun\Controller\Stock;
  10. use Exception;
  11. use Mall\Framework\Core\ErrorCode;
  12. use Mall\Framework\Core\StatusCode;
  13. use JinDouYun\Controller\BaseController;
  14. use JinDouYun\Model\Stock\MAllocate;
  15. class Allocate extends BaseController
  16. {
  17. private $objMAllocate;
  18. public function __construct($isCheckAcl = true, $isMustLogin = true)
  19. {
  20. parent::__construct($isCheckAcl, $isMustLogin);
  21. $this->objMAllocate = new MAllocate($this->onlineEnterpriseId, $this->onlineUserId);
  22. }
  23. /**
  24. * 获取参数
  25. *
  26. * @return array
  27. */
  28. public function commonFieldFilter()
  29. {
  30. $params = $this->request->getRawJson();
  31. if (empty($params)) {
  32. parent::sendOutput('参数为空', ErrorCode::$paramError);
  33. }
  34. $data = [
  35. 'warehouseId' => isset($params['warehouseId']) ? $params['warehouseId'] : '',
  36. 'inWarehouseId' => isset($params['inWarehouseId']) ? $params['inWarehouseId'] : '',
  37. 'operatorName' => isset($params['operatorName']) ? $params['operatorName'] : '',
  38. ];
  39. isset($params['operatorName']) && $data['operatorId'] = $this->onlineUserId;
  40. isset($params['operatorName']) && $data['operatorName'] = $params['operatorName'];
  41. foreach($data as $key => $value){
  42. if(empty($value)){
  43. parent::sendOutput($key.'参数错误', ErrorCode::$paramError);
  44. }
  45. }
  46. isset($params['remark']) && $data['remark'] = $params['remark'];
  47. isset($params['no']) && $data['no'] = $params['no'];
  48. $data['auditId'] = isset($params['auditName']) ? $this->onlineUserId : null;
  49. $data['auditName'] = isset($params['auditName']) ? $params['auditName'] : null;
  50. $data['warehouseName'] = isset($params['warehouseName']) ? $params['warehouseName'] : null;
  51. $data['inWarehouseName'] = isset($params['inWarehouseName']) ? $params['inWarehouseName'] : null;
  52. $data['deleteArray'] = isset($params['deleteArray']) ? $params['deleteArray'] : [];
  53. if(empty($params['details']) || !isset($params['details'])) parent::sendOutput('商品数据为空', ErrorCode::$paramError);
  54. $data['num'] = 0;
  55. $data['details'] = [];
  56. foreach ($params['details'] as $value) {
  57. $data['num']++;
  58. $data['details'][] = [
  59. 'id' => isset($value['id']) ? $value['id'] : '',
  60. 'materielId' => isset($value['materielId']) ? $value['materielId'] : '',
  61. 'materielName' => isset($value['materielName']) ? $value['materielName'] : '',
  62. 'materielCode' => isset($value['materielCode']) ? $value['materielCode'] : '',
  63. 'skuId' => isset($value['skuId']) ? $value['skuId'] : '',
  64. 'unitName' => isset($value['unitName']) ? $value['unitName'] : '',
  65. 'skuName' => isset($value['skuName']) ? $value['skuName'] : '',
  66. 'num' => isset($value['num']) ? $value['num'] : '',
  67. 'otherNum' => isset($value['otherNum']) ? $value['otherNum'] : '',
  68. 'inAreaId' => isset($value['inAreaId']) ? $value['inAreaId'] : 0,
  69. 'inAreaName' => isset($value['inAreaName']) ? $value['inAreaName'] : '',
  70. 'inAreaCode' => isset($value['inAreaCode']) ? $value['inAreaCode'] : '',
  71. 'inStorageLocationId' => isset($value['inStorageLocationId']) ? $value['inStorageLocationId'] : 0,
  72. 'inStorageLocationName' => isset($value['inStorageLocationName']) ? $value['inStorageLocationName'] : '',
  73. 'inStorageLocationCode' => isset($value['inStorageLocationCode']) ? $value['inStorageLocationCode'] : '',
  74. 'outAreaId' => isset($value['outAreaId']) ? $value['outAreaId'] : 0,
  75. 'outAreaName' => isset($value['outAreaName']) ? $value['outAreaName'] : '',
  76. 'outAreaCode' => isset($value['outAreaCode']) ? $value['outAreaCode'] : '',
  77. 'outStorageLocationId' => isset($value['outStorageLocationId']) ? $value['outStorageLocationId'] : 0,
  78. 'outStorageLocationName' => isset($value['outStorageLocationName']) ? $value['outStorageLocationName'] : '',
  79. 'outStorageLocationCode' => isset($value['outStorageLocationCode']) ? $value['outStorageLocationCode'] : '',
  80. 'costUnitPrice' => isset($value['costUnitPrice']) ? $value['costUnitPrice'] : '',
  81. 'isEq' => isset($value['isEq']) ? $value['isEq'] : 4,
  82. ];
  83. }
  84. return $data;
  85. }
  86. /**
  87. * 仓库调拨添加
  88. * @throws Exception
  89. */
  90. public function addAllocate()
  91. {
  92. $data = $this->commonFieldFilter();
  93. $result = $this->objMAllocate->addAllocate($data);
  94. if ($result->isSuccess()) {
  95. parent::sendOutput($result->getData());
  96. } else {
  97. parent::sendOutput($result->getData(), $result->getErrorCode());
  98. }
  99. }
  100. /**
  101. * 仓库调拨记录删除
  102. */
  103. public function deleteAllocate()
  104. {
  105. $params['id'] = $this->request->param('request_id');
  106. if (empty($params)) {
  107. $this->sendOutput('参数为空', ErrorCode::$paramError);
  108. }
  109. $result = $this->objMAllocate->deleteAllocate($params);
  110. if ($result->isSuccess()) {
  111. parent::sendOutput($result->getData());
  112. } else {
  113. parent::sendOutput($result->getData(), $result->getErrorCode());
  114. }
  115. }
  116. /**
  117. * 仓库调拨审核
  118. * @throws Exception
  119. */
  120. public function auditAllocate()
  121. {
  122. $params = $this->request->getRawJson();
  123. $id = $this->request->param('request_id');
  124. if (empty($id)) {
  125. $this->sendOutput('参数为空', ErrorCode::$paramError);
  126. }
  127. $updateData = [
  128. 'id' => $id,
  129. 'auditId' => $this->onlineUserId,
  130. 'auditName' => isset($params['auditName']) ? $params['auditName'] : '',
  131. ];
  132. foreach($updateData as $key => $value){
  133. if(empty($value) && $value !== 0){
  134. parent::sendOutput($key.'参数错误', ErrorCode::$paramError);
  135. }
  136. }
  137. $result = $this->objMAllocate->auditAllocate($updateData);
  138. if ($result->isSuccess()) {
  139. parent::sendOutput($result->getData());
  140. } else {
  141. parent::sendOutput($result->getData(), $result->getErrorCode());
  142. }
  143. }
  144. /**
  145. * 仓库仓库调拨修改
  146. */
  147. public function updateAllocate()
  148. {
  149. $updateData = self::commonFieldFilter();
  150. $param = $this->request->param('request_id');
  151. if(empty($param)){
  152. parent::sendOutput('参数为空', ErrorCode::$paramError);
  153. }
  154. $updateData['id'] = $param;
  155. $result = $this->objMAllocate->updateAllocate($updateData);
  156. if ($result->isSuccess()) {
  157. parent::sendOutput($result->getData());
  158. } else {
  159. parent::sendOutput($result->getData(), $result->getErrorCode());
  160. }
  161. }
  162. /**
  163. * 仓库调拨记录列表
  164. */
  165. public function getAllAllocate()
  166. {
  167. $params = $this->request->getRawJson();
  168. if (empty($params)) {
  169. parent::sendOutput('参数为空', ErrorCode::$paramError);
  170. }
  171. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  172. $selectParams['limit'] = $pageParams['limit'];
  173. $selectParams['offset'] = $pageParams['offset'];
  174. $export = isset($params['export']) ? $params['export'] : 0;
  175. $result = $this->objMAllocate->getAllAllocate($selectParams,$export);
  176. if ($result->isSuccess()) {
  177. $returnData = $result->getData();
  178. $pageData = [
  179. 'pageIndex' => $params['page'],
  180. 'pageSize' => $params['pageSize'],
  181. 'pageTotal' => $returnData['total'],
  182. ];
  183. parent::sendOutput($returnData['data'], 0, $pageData);
  184. } else {
  185. parent::sendOutput($result->getData(), ErrorCode::$dberror);
  186. }
  187. }
  188. /**
  189. * 调拨搜索
  190. */
  191. public function searchAllocate()
  192. {
  193. $params = $this->request->getRawJson();
  194. if( empty($params) ){
  195. $this->sendOutput('参数为空', ErrorCode::$paramError );
  196. }
  197. $selectParams = [
  198. 'warehouseId' => isset($params['warehouseId']) ? $params['warehouseId'] : '',
  199. 'inWarehouseId' => isset($params['inWarehouseId']) ? $params['inWarehouseId'] : '',
  200. 'auditStatus' => isset($params['auditStatus']) ? $params['auditStatus'] : '',
  201. 'start' => isset($params['start']) ? $params['start'] : '',
  202. 'end' => isset($params['end']) ? $params['end'] : '',
  203. 'search' => isset($params['search']) ? $params['search'] : '',
  204. ];
  205. $pageParams = pageToOffset($params['page'] ? : 1, $params['pageSize'] ? : 10);
  206. $selectParams['limit'] = $pageParams['limit'];
  207. $selectParams['offset'] = $pageParams['offset'];
  208. $result = $this->objMAllocate->getAllAllocate($selectParams);
  209. if($result->isSuccess()){
  210. $returnData = $result->getData();
  211. $pageData = [
  212. 'pageIndex' => $params['page'],
  213. 'pageSize' => $params['pageSize'],
  214. 'pageTotal' => $returnData['total'],
  215. ];
  216. parent::sendOutput($returnData['data'], 0, $pageData);
  217. }else{
  218. parent::sendOutput($result->getData(), $result->getErrorCode());
  219. }
  220. }
  221. /**
  222. * 仓库调拨详情
  223. */
  224. public function getAllocateInfo()
  225. {
  226. $params['id'] = $this->request->param('request_id');
  227. if (empty($params['id'])) {
  228. $this->sendOutput('参数为空', ErrorCode::$paramError);
  229. }
  230. $result = $this->objMAllocate->getAllocateInfo($params);
  231. if ($result->isSuccess()) {
  232. parent::sendOutput($result->getData());
  233. } else {
  234. parent::sendOutput($result->getData(), $result->getErrorCode());
  235. }
  236. }
  237. }