HandInStorageController.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Components\AsyncResponse;
  4. use App\OracleDOCASNDetail;
  5. use App\OracleDOCASNHeader;
  6. use App\Services\HandInStorageService;
  7. use Carbon\Carbon;
  8. use Illuminate\Http\Request;
  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. $customerid= $request->input('customerid');
  80. $skuOrBarcode= $request->input('sku');
  81. $asnno= $request->input('asnno');
  82. $asnDetail=app('HandInStorageService')->getAsnDetail($asnno,$skuOrBarcode);
  83. if (!$asnDetail)$this->error('无效条码');
  84. $basSku =app('HandInStorageService')->getBasSkuLotId($customerid,$asnDetail->sku);
  85. if (isset($basSku)&&isset($asnDetail))return ['success'=>true,'basSku'=>$basSku,'asnDetail'=>$asnDetail];
  86. else $this->error('无效条码');
  87. }
  88. /**
  89. * @throws \Throwable
  90. * 收货
  91. */
  92. public function fluxHandIn(Request $request)
  93. {
  94. $this->gate("入库管理-手持入库-收货");
  95. $info=$request->input('info');
  96. if ($info['lotatt02']&&Carbon::now()->gt($info['lotatt02']))$this->error('失效日期超过入库效期');
  97. if (!$info['customerid']||!$info['sku']||!$info['asnno']) $this->error('参数错误');
  98. if ($info['amount']+$info['receivedqty']>$info['expectedqty'])$this->error('收货数大于预期数');
  99. /** @var HandInStorageService $handInStorageService */
  100. $handInStorageService=app('HandInStorageService');
  101. if ($info['customerid']=='ONKYO'||$info['customerid']=='ANMEILAI'||$info['customerid']=='FEIHE'){
  102. $res=$handInStorageService->checkWidthHeight($info);
  103. if ($res===1)$this->error('需要维护产品档案');
  104. if ($res===2)$this->error('需要维护该产品档案中的长宽高');
  105. }
  106. if ($info['customerid']=='TANGENBEI'||$info['customerid']=='ANMEILAI'){
  107. $result=$handInStorageService->checkCubicWeight($info);
  108. if ($result===1)$this->error('需要维护产品档案');
  109. if ($result===2)$this->error('需要维护该产品档案中的重量体积');
  110. }
  111. if ($handInStorageService->checkForwardingLoc($info)===1)$this->error('请维护拣货位');
  112. try {
  113. $result = $handInStorageService->fluxHandIn($info);
  114. if ($result){
  115. $asnQty=$handInStorageService->getAsnQty($info['asnno']);
  116. $this->success($asnQty);
  117. } else $this->error("收货失败");
  118. } catch (\Exception $e) {
  119. app('LogService')->log(__METHOD__,'error_'.__FUNCTION__,json_encode($info).'|catch:'.$e->getMessage());
  120. }
  121. }
  122. /**
  123. * @param Request $request
  124. * 根据商品条码和跟踪号 获取要上架的任务列表
  125. */
  126. public function getTsk(Request $request)
  127. {
  128. $this->gate("入库管理-手持入库-上架");
  129. $barCode=$request->input('barCode');
  130. $trackNumber=$request->input('trackNumber');
  131. /** @var HandInStorageService $handInStorageService */
  132. $handInStorageService=app('HandInStorageService');
  133. $tasks=$handInStorageService->getTsk($trackNumber,$barCode);
  134. if (count($tasks)>0){
  135. $invLots=$handInStorageService->getInvotlocid($barCode);
  136. $collect= collect();
  137. foreach ($invLots as $invLot){
  138. if ($invLot->locationid=='STAGEWH01'||$invLot->locationid=='STAGEWH02')continue;
  139. $collect->push($invLot);
  140. }
  141. return json_encode(["success"=>true,'data'=>$tasks,'inv'=>$collect]);
  142. }
  143. else $this->error("该商品暂无上架任务");
  144. }
  145. /**
  146. * @param Request $request
  147. * 根据customerid,asnno,跟踪号 或空扫 获取待上架任务
  148. */
  149. public function getPaTaskByTraceInOrCustomerOrAsnOrNull(Request $request)
  150. {
  151. $this->gate("入库管理-手持入库-上架");
  152. $trackNumber=$request->input('trackNumber');
  153. $barCode=$request->input('barCode');
  154. /** @var HandInStorageService $handInStorageService */
  155. $handInStorageService=app('HandInStorageService');
  156. $tasks=$handInStorageService->getTsk($trackNumber,$barCode);
  157. if (count($tasks)>0)$this->success($tasks);
  158. else $this->error('暂无上架任务');
  159. }
  160. /**
  161. * @throws \Throwable
  162. * 上架
  163. */
  164. public function handFluxPa(Request $request)
  165. {
  166. $this->gate("入库管理-手持入库-上架");
  167. $info=$request->input('info');
  168. if (!$info['location']||!$info['amount']||!$info['barCode']) $this->error('参数错误');
  169. if (count($request->input('checkData'))==0) $this->error('请勾选要上架任务');
  170. $checkData=$request->input('checkData')[0];
  171. /** @var HandInStorageService $handInStorageService */
  172. $handInStorageService=app('HandInStorageService');
  173. //判断当前库位是否能放该商品
  174. $res=$handInStorageService->checkLocation($info,$checkData);
  175. if ($res===1)$this->error('库位不存在');
  176. if ($res===2)$this->error('库位:产品和批次不可混放');
  177. if ($res===3)$this->error('库位:不能混放批次');
  178. if ($res===4)$this->error('库位:产品不能混放');
  179. try {
  180. $result = $handInStorageService->fluxHandPa($info, $checkData);
  181. if ($result===true)$this->success("上架成功");
  182. if ($result===false) $this->error("上架失败");
  183. if ($result===1)$this->error("拣货区找到效期更新的同样货品,不能上架至存储区");
  184. } catch (\Exception $e) {
  185. app('LogService')->log(__METHOD__,'error_'.__FUNCTION__,json_encode($info).'|catch:'.$e->getMessage());
  186. }
  187. }
  188. }