HandInStorageController.php 9.2 KB

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