HandInStorageController.php 9.1 KB

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