HandInStorageController.php 9.2 KB

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