InventoryOut.Class.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. <?php
  2. /**
  3. * 出库管理Controller
  4. * Created by PhpStorm.
  5. * User: 小威
  6. * Date: 2019/11/11
  7. * Time: 16:00
  8. */
  9. namespace JinDouYun\Controller\Stock;
  10. use Exception;
  11. use Jindouyun\Cache\EnterpriseCache;
  12. use Mall\Framework\Core\ErrorCode;
  13. use Mall\Framework\Core\StatusCode;
  14. use JinDouYun\Controller\BaseController;
  15. use JinDouYun\Model\Stock\MInventoryOut;
  16. class InventoryOut extends BaseController
  17. {
  18. private $objMInventoryOut;
  19. public function __construct($isCheckAcl = true, $isMustLogin = true)
  20. {
  21. parent::__construct($isCheckAcl, $isMustLogin);
  22. $this->objMInventoryOut = new MInventoryOut($this->onlineEnterpriseId, $this->onlineUserId);
  23. }
  24. /**
  25. * 出库审核
  26. * @throws Exception
  27. */
  28. public function updateInventoryOutStatus()
  29. {
  30. $paramsData = $this->request->getRawJson();
  31. if (empty($paramsData)) {
  32. $this->sendOutput('参数为空', ErrorCode::$paramError);
  33. }
  34. $params = [
  35. 'id' => isset($paramsData['id']) ? $paramsData['id'] : '',//出库id
  36. 'auditId' => $this->onlineUserId,//操作人id
  37. 'auditName' => isset($paramsData['auditName']) ? $paramsData['auditName'] : '',//操作人姓名
  38. 'outWarehouseData' => isset($paramsData['outWarehouseData']) ? $paramsData['outWarehouseData'] : [],
  39. ];
  40. foreach ($params as $key => $value) {
  41. if (empty($value) && $value !== 0) {
  42. $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
  43. }
  44. }
  45. $objEnterpriseCache = new EnterpriseCache();
  46. $enterSettingData = $objEnterpriseCache->getEnterpriseSetting($this->onlineEnterpriseId);
  47. // 判断负库存是否允许出库
  48. // foreach ($params['outWarehouseData'] as $k => $v){
  49. // foreach ($v['details'] as $k1 => $v1){
  50. // if( $enterSettingData['distributionExamine'] == StatusCode::$delete && $v1['isDistribution'] == StatusCode::$standard && $v1['warehouseInventoryNum'] < $v1['num'] ){ //不开启,不允许负库存出库
  51. // $this->sendOutput($v1['materielName'] . '库存不足,不允许出库', ErrorCode::$notAllowAccess);
  52. // }
  53. // }
  54. // }
  55. $params['logisticsData'] = isset($paramsData['logisticsData']) ? $paramsData['logisticsData'] : null;
  56. $params['deliveryNo'] = isset($paramsData['deliveryNo']) ? $paramsData['deliveryNo'] : '';
  57. $params['expressName'] = isset($paramsData['expressName']) ? $paramsData['expressName'] : '';
  58. $params['expressId'] = isset($paramsData['expressId']) ? $paramsData['expressId'] : 0;
  59. $params['UnassignedSkuData'] = isset($paramsData['UnassignedSkuData']) ? $paramsData['UnassignedSkuData'] : [];
  60. $params['autoAudit'] = StatusCode::$delete;
  61. $result = $this->objMInventoryOut->updateInventoryOutStatus($params);
  62. if ($result->isSuccess()) {
  63. parent::sendOutput($result->getData());
  64. }
  65. parent::sendOutput($result->getData(), $result->getErrorCode());
  66. }
  67. /**
  68. * 出库单分配仓库
  69. */
  70. public function saveOutInventory()
  71. {
  72. $id = $this->request->param('request_id');
  73. if (empty($id)) {
  74. $this->sendOutput('id参数为空', ErrorCode::$paramError);
  75. }
  76. $params = $this->request->getRawJson();
  77. if (empty($params)) {
  78. $this->sendOutput('参数为空', ErrorCode::$paramError);
  79. }
  80. $data = [
  81. 'outWarehouseData' => isset($params['outWarehouseData']) ? $params['outWarehouseData'] : [],
  82. 'UnassignedSkuData' => isset($params['UnassignedSkuData']) ? $params['UnassignedSkuData'] : [],
  83. ];
  84. $result = $this->objMInventoryOut->saveOutInventory($data, ['id' => $id]);
  85. if (!$result->isSuccess()) {
  86. parent::sendOutput($result->getData(), $result->getErrorCode());
  87. }
  88. parent::sendOutput($result->getData());
  89. }
  90. /**
  91. * 出库列表
  92. */
  93. public function getAllInventoryOut()
  94. {
  95. $params = $this->request->getRawJson();
  96. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  97. $selectParams['limit'] = $pageParams['limit'];
  98. $selectParams['offset'] = $pageParams['offset'];
  99. (isset($params['auditStatus']) && !empty($params['auditStatus'])) && $selectParams['auditStatus'] = $params['auditStatus'];
  100. if(isset($params['type']) && !empty($params['type'])){
  101. $selectParams['type'] = $params['type'];
  102. }
  103. if(isset($params['start']) && !empty($params['start']) && isset($params['end']) && !empty($params['end'])){
  104. $selectParams['createTime'] = ['start' => $params['start'], 'end' => $params['end']];
  105. }
  106. if(isset($params['search']) && !empty($params['search'])){
  107. $selectParams['search']['no'] = $params['search'];
  108. $selectParams['search']['auditName'] = $params['search'];
  109. }
  110. if(!empty($this->shopId)){
  111. $selectParams['shopId'] = $this->shopId;
  112. }else{
  113. if(isset($params['shopId']) && !empty($params['shopId'])){
  114. $selectParams['shopId'] = $params['shopId'];
  115. }
  116. }
  117. $export = isset($params['export']) ? $params['export'] : 0;
  118. $result = $this->objMInventoryOut->getAllInventoryOut($selectParams,$export);
  119. if ($result->isSuccess()) {
  120. $returnData = $result->getData();
  121. $pageData = [
  122. 'pageIndex' => $params['page'],
  123. 'pageSize' => $params['pageSize'],
  124. 'pageTotal' => $returnData['total'],
  125. ];
  126. parent::sendOutput($returnData['data'], 0, $pageData);
  127. }
  128. parent::sendOutput($result->getData(), ErrorCode::$dberror);
  129. }
  130. /**
  131. * 出库列表搜索
  132. */
  133. public function searchAllInventoryOut()
  134. {
  135. $params = $this->request->getRawJson();
  136. if (empty($params)) {
  137. $this->sendOutput('参数为空', ErrorCode::$paramError);
  138. }
  139. $selectParams = [
  140. 'warehouseId' => isset($params['warehouseId']) ? $params['warehouseId'] : '',
  141. 'type' => isset($params['type']) ? $params['type'] : '',
  142. 'auditStatus' => isset($params['auditStatus']) ? $params['auditStatus'] : '',
  143. 'start' => isset($params['start']) ? $params['start'] : '',
  144. 'end' => isset($params['end']) ? $params['end'] : '',
  145. 'search' => isset($params['search']) ? $params['search'] : '',
  146. ];
  147. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  148. $selectParams['limit'] = $pageParams['limit'];
  149. $selectParams['offset'] = $pageParams['offset'];
  150. $selectParams['shopId'] = $this->shopId;
  151. $result = $this->objMInventoryOut->searchAllInventoryOut($selectParams);
  152. if ($result->isSuccess()) {
  153. $returnData = $result->getData();
  154. $pageData = [
  155. 'pageIndex' => $params['page'],
  156. 'pageSize' => $params['pageSize'],
  157. 'pageTotal' => $returnData['total'],
  158. ];
  159. parent::sendOutput($returnData['data'], 0, $pageData);
  160. }
  161. parent::sendOutput($result->getData(), $result->getErrorCode());
  162. }
  163. /**
  164. * 出库统计
  165. * @throws Exception
  166. */
  167. public function statisticsAllInventoryOut()
  168. {
  169. $params = $this->request->getRawJson();
  170. if (empty($params)) {
  171. parent::sendOutput('参数为空', ErrorCode::$paramError);
  172. }
  173. $type = $params['type'];
  174. $modelResult = $this->objMInventoryOut->statisticsAllInventoryOut($type, $this->shopId);
  175. if (!$modelResult->isSuccess()) {
  176. parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
  177. }
  178. parent::sendOutput($modelResult->getData());
  179. }
  180. /**
  181. * 出库详情
  182. * @throws Exception
  183. */
  184. public function getInventoryOutInfo()
  185. {
  186. $params['id'] = $this->request->param('request_id');
  187. $data = $this->request->getRawJson();
  188. $params['originId'] = isset($data['originId']) ? $data['originId'] : '';
  189. $params['source'] = isset($data['source']) ? $data['source'] : '';
  190. $where = [];
  191. if(isset($params['id']) && !empty($params['id'])){
  192. $where['id'] = $params['id'];
  193. }else{
  194. if(isset($params['originId']) && !empty($params['originId'])){
  195. $where['originId'] = $params['originId'];
  196. if(isset($params['source']) && !empty($params['source'])){
  197. $where['source'] = $params['source'];
  198. }else{
  199. $this->sendOutput('source参数为空', ErrorCode::$paramError);
  200. }
  201. }
  202. }
  203. if (empty($where)) {
  204. $this->sendOutput('参数为空', ErrorCode::$paramError);
  205. }
  206. $result = $this->objMInventoryOut->getInventoryOutInfo($where);
  207. if ($result->isSuccess()) {
  208. parent::sendOutput($result->getData());
  209. }
  210. parent::sendOutput($result->getData(), $result->getErrorCode());
  211. }
  212. /**
  213. * 出库详情
  214. * @throws Exception
  215. */
  216. public function getInventoryOutByOriginId()
  217. {
  218. $data = $this->request->getRawJson();
  219. $result = $this->objMInventoryOut->getInventoryOutByOriginId($data['originId'], StatusCode::$orderType['saleOrder']);
  220. if ($result->isSuccess()) {
  221. parent::sendOutput($result->getData());
  222. }
  223. parent::sendOutput($result->getData(), $result->getErrorCode());
  224. }
  225. /**
  226. * 格式化出库es
  227. */
  228. public function formatInventoryOutEsData()
  229. {
  230. $params = $this->request->getRawJson();
  231. if (!isset($params['key']) || md5('123456123456') != $params['key']) {
  232. $this->sendOutput('参数校验失败', ErrorCode::$paramError);
  233. }
  234. $result = $this->objMInventoryOut->formatInventoryOutEsData();
  235. if ($result->isSuccess()) {
  236. parent::sendOutput($result->getData(),$result->getErrorCode());
  237. }
  238. parent::sendOutput($result->getData());
  239. }
  240. /**
  241. * 设置物流信息
  242. */
  243. public function addLogistics()
  244. {
  245. $params = $this->request->getRawJson();
  246. if( empty($params) ){
  247. parent::sendOutput('请求参数错误', ErrorCode::$paramError);
  248. }
  249. $result = $this->objMInventoryOut->addLogistics($params);
  250. if ($result->isSuccess()) {
  251. parent::sendOutput($result->getData(),$result->getErrorCode());
  252. }
  253. parent::sendOutput($result->getData());
  254. }
  255. /**
  256. * 扫条码加载出库单商品数据
  257. */
  258. public function getDetailByGoodsCode()
  259. {
  260. $params = $this->request->getRawJson();
  261. if( empty($params) ){
  262. parent::sendOutput('参数为空', ErrorCode::$paramError);
  263. }
  264. $selectParams = [
  265. 'id' => getArrayItem($params, 'id'),
  266. 'barCode' => getArrayItem($params, 'barCode'),
  267. ];
  268. //必填项
  269. foreach ($selectParams as $key => $value) {
  270. if (empty($value) && $value !== 0) {
  271. $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
  272. }
  273. }
  274. $result = $this->objMInventoryOut->getDetailByGoodsCode($selectParams);
  275. if ($result->isSuccess()) {
  276. parent::sendOutput($result->getData(),$result->getErrorCode());
  277. }
  278. parent::sendOutput($result->getData());
  279. }
  280. }