HandInStorageController.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Components\AsyncResponse;
  4. use App\Log;
  5. use App\OracleDOCASNDetail;
  6. use App\OracleDOCASNHeader;
  7. use App\Services\HandInStorageService;
  8. use Carbon\Carbon;
  9. use Illuminate\Http\Request;
  10. class HandInStorageController extends Controller
  11. {
  12. use AsyncResponse;
  13. /**
  14. * 搜索查詢asn
  15. */
  16. public function selectAsn(Request $request)
  17. {
  18. $this->gate("入库管理-手持入库-收货");
  19. /** @var HandInStorageService $handInStorageService */
  20. $handInStorageService=app('HandInStorageService');
  21. $asnno= $request->input('asnno');
  22. $asns =$handInStorageService->selectAsn($asnno);
  23. if (count($asns)>0){
  24. foreach ($asns as $asn){
  25. $asn->asnDetails=array();
  26. }
  27. $this->success($asns);
  28. }else{
  29. $this->error('无有效的ASN的订单');
  30. }
  31. }
  32. public function checkAsnOperation(Request $request)
  33. {
  34. $this->gate("入库管理-手持入库-收货");
  35. /** @var HandInStorageService $handInStorageService */
  36. $handInStorageService=app('HandInStorageService');
  37. $info= $request->input('info');
  38. $res=$handInStorageService->checkAsnOperation($info);
  39. if ($res===1)$this->error('无有效的ASN的订单');
  40. elseif ($res===2)$this->error('该asn无预约,暂不可收货');
  41. else $this->success($res);
  42. }
  43. /**
  44. * @param $asnno
  45. * 跳转到收货明细页面
  46. */
  47. public function receiveDetailPage($asnno,$customerid)
  48. {
  49. $this->gate("入库管理-手持入库-收货");
  50. /** @var HandInStorageService $handInStorageService */
  51. $handInStorageService=app('HandInStorageService');
  52. if (!$customerid||$customerid=='undefined')
  53. $customerid=OracleDOCASNHeader::query()->where('asnno',$asnno)->value('customerid');
  54. $qualityStatus=$handInStorageService->getQualityStatus();
  55. $attributeLocations=$handInStorageService->getAttributeLocation();
  56. $asnQty=$handInStorageService->getAsnQty($asnno);
  57. return view('store.handInStorage.receiveDetailPage')
  58. ->with(['asn_expectedqty'=>$asnQty->expectedqty,'asn_receivedqty'=>$asnQty->receivedqty,
  59. 'asnno'=>$asnno,'customerid'=>$customerid,
  60. 'qualityStatus'=>$qualityStatus,'attributeLocations'=>$attributeLocations]);
  61. }
  62. /**
  63. * @param Request $request
  64. * 查询富勒asn_detail(集合)
  65. */
  66. public function selectAsnDetails(Request $request)
  67. {
  68. $this->gate("入库管理-手持入库-收货");
  69. $asnno= $request->input('asnno');
  70. $asnDetails =app('HandInStorageService')->selectAsnDetails($asnno);
  71. if (count($asnDetails)>0)$this->success($asnDetails);
  72. else $this->error('未查询到相应的asn明细');
  73. }
  74. /**
  75. * @param Request $request
  76. * 查询富勒bas_sku 并关联 bas_lotid
  77. */
  78. public function getBasSkuWithLot(Request $request): array
  79. {
  80. $customerid= $request->input('customerid');
  81. $skuOrBarcode= $request->input('sku');
  82. $asnno= $request->input('asnno');
  83. $asnDetail=app('HandInStorageService')->getAsnDetail($asnno,$skuOrBarcode);
  84. if (!$asnDetail)$this->error('无效条码');
  85. $basSku =app('HandInStorageService')->getBasSkuLotId($customerid,$asnDetail->sku);
  86. if (isset($basSku)&&isset($asnDetail))return ['success'=>true,'basSku'=>$basSku,'asnDetail'=>$asnDetail];
  87. else $this->error('无效条码');
  88. }
  89. /**
  90. * @throws \Throwable
  91. * 收货
  92. */
  93. public function fluxHandIn(Request $request)
  94. {
  95. $this->gate("入库管理-手持入库-收货");
  96. $info=$request->input('info');
  97. if ($info['lotatt02']&&Carbon::now()->gt($info['lotatt02']))$this->error('失效日期超过入库效期');
  98. if (!$info['customerid']||!$info['sku']||!$info['asnno']) $this->error('参数错误');
  99. if ($info['amount']+$info['receivedqty']>$info['expectedqty'])$this->error('收货数大于预期数');
  100. /** @var HandInStorageService $handInStorageService */
  101. $handInStorageService=app('HandInStorageService');
  102. if ($info['customerid']=='ONKYO'||$info['customerid']=='ANMEILAI'||$info['customerid']=='FEIHE'){
  103. $res=$handInStorageService->checkWidthHeight($info);
  104. if ($res===1)$this->error('需要维护产品档案');
  105. if ($res===2)$this->error('需要维护该产品档案中的长宽高');
  106. }
  107. if ($info['customerid']=='TANGENBEI'||$info['customerid']=='ANMEILAI'){
  108. $result=$handInStorageService->checkCubicWeight($info);
  109. if ($result===1)$this->error('需要维护产品档案');
  110. if ($result===2)$this->error('需要维护该产品档案中的重量体积');
  111. }
  112. if ($info['customerid']=='JIANSHANG'&&$handInStorageService->checkForwardingLoc($info)===1)$this->error('请维护拣货位');
  113. try {
  114. $result = $handInStorageService->fluxHandIn($info);
  115. if ($result){
  116. $asnQty=$handInStorageService->getAsnQty($info['asnno']);
  117. $this->success($asnQty);
  118. } else $this->error("收货失败");
  119. } catch (\Exception $e) {
  120. app('LogService')->log(__METHOD__,'error_'.__FUNCTION__,json_encode($info).'|catch:'.$e->getMessage());
  121. }
  122. }
  123. /**
  124. * @param Request $request
  125. * 根据商品条码和跟踪号 获取要上架的任务列表
  126. */
  127. public function getTsk(Request $request)
  128. {
  129. $this->gate("入库管理-手持入库-上架");
  130. $barCode=$request->input('barCode');
  131. $trackNumber=$request->input('trackNumber');
  132. /** @var HandInStorageService $handInStorageService */
  133. $handInStorageService=app('HandInStorageService');
  134. $tasks=$handInStorageService->getTsk($trackNumber,$barCode);
  135. if (count($tasks)>0){
  136. $invLots=$handInStorageService->getInvotlocid($barCode);
  137. $collect= collect();
  138. foreach ($invLots as $invLot){
  139. if ($invLot->locationid=='STAGEWH01'||$invLot->locationid=='STAGEWH02')continue;
  140. $collect->push($invLot);
  141. }
  142. return json_encode(["success"=>true,'data'=>$tasks,'inv'=>$collect]);
  143. }
  144. else $this->error("该商品暂无上架任务");
  145. }
  146. /**
  147. * @param Request $request
  148. * 根据customerid,asnno,跟踪号 或空扫 获取待上架任务
  149. */
  150. public function getPaTaskByTraceInOrCustomerOrAsnOrNull(Request $request)
  151. {
  152. $this->gate("入库管理-手持入库-上架");
  153. $trackNumber=$request->input('trackNumber');
  154. $barCode=$request->input('barCode');
  155. /** @var HandInStorageService $handInStorageService */
  156. $handInStorageService=app('HandInStorageService');
  157. $tasks=$handInStorageService->getTsk($trackNumber,$barCode);
  158. if (count($tasks)>0)$this->success($tasks);
  159. else $this->error('暂无上架任务');
  160. }
  161. /**
  162. * @throws \Throwable
  163. * 上架
  164. */
  165. public function handFluxPa(Request $request)
  166. {
  167. $this->gate("入库管理-手持入库-上架");
  168. $info=$request->input('info');
  169. if (!$info['location']||!$info['amount']||!$info['barCode']) $this->error('参数错误');
  170. if (count($request->input('checkData'))==0) $this->error('请勾选要上架任务');
  171. $checkData=$request->input('checkData')[0];
  172. /** @var HandInStorageService $handInStorageService */
  173. $handInStorageService=app('HandInStorageService');
  174. //判断当前库位是否能放该商品
  175. $res=$handInStorageService->checkLocation($info,$checkData);
  176. if ($res===1)$this->error('库位不存在');
  177. if ($res===2)$this->error('库位:产品和批次不可混放');
  178. if ($res===3)$this->error('库位:不能混放批次');
  179. if ($res===4)$this->error('库位:产品不能混放');
  180. try {
  181. $result = $handInStorageService->fluxHandPa($info, $checkData);
  182. if ($result===true)$this->success("上架成功");
  183. if ($result===false) $this->error("上架失败");
  184. if ($result===1)$this->error("拣货区找到效期更新的同样货品,不能上架至存储区");
  185. } catch (\Exception $e) {
  186. $this->error($e->getMessage());
  187. app('LogService')->log(__METHOD__,'error_'.__FUNCTION__,json_encode($info).'|catch:'.$e->getMessage());
  188. }
  189. }
  190. public function getInventoryInfos(Request $request)
  191. {
  192. $this->gate("入库管理-手持入库-库存查询");
  193. $param=$request->input('location');
  194. /** @var HandInStorageService $handInStorageService */
  195. $handInStorageService=app('HandInStorageService');
  196. $invs=$handInStorageService->getInventoryInfos($param);
  197. if (count($invs)>0)$this->success($invs);
  198. else $this->error('未查询到库存信息');
  199. }
  200. }