HandInStorageController.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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 Doctrine\DBAL\Exception;
  8. use Illuminate\Http\Request;
  9. use Illuminate\Support\Facades\Auth;
  10. use Illuminate\Support\Facades\Cache;
  11. use Illuminate\Support\Facades\Log;
  12. class HandInStorageController extends Controller
  13. {
  14. use AsyncResponse;
  15. /**
  16. * 搜索查詢asn
  17. */
  18. public function selectAsn(Request $request)
  19. {
  20. $this->gate("入库管理-手持入库-收货");
  21. /** @var HandInStorageService $handInStorageService */
  22. $handInStorageService=app('HandInStorageService');
  23. $asnno= $request->input('asnno');
  24. $asns =$handInStorageService->selectAsn($asnno);
  25. if (count($asns)>0){
  26. foreach ($asns as $asn){
  27. $asn->asnDetails=array();
  28. }
  29. $this->success($asns);
  30. }else{
  31. $this->error('无有效的ASN的订单');
  32. }
  33. }
  34. public function checkAsnOperation(Request $request)
  35. {
  36. $this->gate("入库管理-手持入库-收货");
  37. /** @var HandInStorageService $handInStorageService */
  38. $handInStorageService=app('HandInStorageService');
  39. $info= $request->input('info');
  40. $res=$handInStorageService->checkAsnOperation($info);
  41. if ($res===1)$this->error('无有效的ASN的订单');
  42. elseif ($res===2)$this->error('该asn无预约,暂不可收货');
  43. else $this->success($res);
  44. }
  45. /**
  46. * @param $asnno
  47. * 跳转到收货明细页面
  48. */
  49. public function receiveDetailPage($asnno,$customerid)
  50. {
  51. $this->gate("入库管理-手持入库-收货");
  52. /** @var HandInStorageService $handInStorageService */
  53. $handInStorageService=app('HandInStorageService');
  54. if (!$customerid||$customerid=='undefined')
  55. $customerid=OracleDOCASNHeader::query()->where('asnno',$asnno)->value('customerid');
  56. $qualityStatus=$handInStorageService->getQualityStatus();
  57. $attributeLocations=$handInStorageService->getAttributeLocation();
  58. $asnQty=$handInStorageService->getAsnQty($asnno);
  59. return view('store.handInStorage.receiveDetailPage')
  60. ->with(['asn_expectedqty'=>$asnQty->expectedqty,'asn_receivedqty'=>$asnQty->receivedqty,
  61. 'asnno'=>$asnno,'customerid'=>$customerid,
  62. 'qualityStatus'=>$qualityStatus,'attributeLocations'=>$attributeLocations]);
  63. }
  64. /**
  65. * @param Request $request
  66. * 查询富勒asn_detail(集合)
  67. */
  68. public function selectAsnDetails(Request $request)
  69. {
  70. $this->gate("入库管理-手持入库-收货");
  71. $asnno= $request->input('asnno');
  72. $asnDetails =app('HandInStorageService')->selectAsnDetails($asnno);
  73. if (count($asnDetails)>0)$this->success($asnDetails);
  74. else $this->error('未查询到相应的asn明细');
  75. }
  76. /**
  77. * @param Request $request
  78. * 查询富勒bas_sku 并关联 bas_lotid
  79. */
  80. public function getBasSkuWithLot(Request $request): array
  81. {
  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. 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. $this->gate("入库管理-手持入库-收货");
  98. $info=$request->input('info');
  99. $isReceivedqty=$info['receivedqty']??false;
  100. $isExpectedqty=$info['expectedqty']??false;
  101. $isSku=$info['sku']??false;
  102. if ($info['lotatt02']&&Carbon::now()->gt($info['lotatt02']))$this->error('失效日期超过入库效期');
  103. if (!$info['customerid']||$isSku===false||!$info['asnno']||$isReceivedqty===false||$isExpectedqty===false) $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. $key = $info['asnno'] . '_' . $info['sku'] . '_' . Auth::id();
  119. $ttl = 10;
  120. try {
  121. //缓存校验操作
  122. if (Cache::has($key)){
  123. $this->error('当前已操作');
  124. }else{
  125. Cache::put($key,true, $ttl);
  126. }
  127. //收货操作
  128. $resultIn = $handInStorageService->fluxHandIn($info);
  129. if ($resultIn===1)$this->error("超收");
  130. if ($resultIn){
  131. $asnQty=$handInStorageService->getAsnQty($info['asnno']);
  132. $this->success($asnQty);
  133. } else $this->error("收货失败");
  134. } catch (\Exception $e) {
  135. app('LogService')->log(__METHOD__,'error_'.__FUNCTION__,json_encode($info).'|catch:'.$e->getMessage());
  136. } finally {
  137. Cache::forget($key);
  138. }
  139. }
  140. /**
  141. * @param Request $request
  142. * 根据商品条码和跟踪号 获取要上架的任务列表
  143. */
  144. public function getTsk(Request $request)
  145. {
  146. $this->gate("入库管理-手持入库-上架");
  147. $barCode=$request->input('barCode');
  148. $trackNumber=$request->input('trackNumber');
  149. /** @var HandInStorageService $handInStorageService */
  150. $handInStorageService=app('HandInStorageService');
  151. $tasks=$handInStorageService->getTsk($trackNumber,$barCode);
  152. if (count($tasks)>0){
  153. $invLots=$handInStorageService->getInvotlocid($barCode);
  154. $collect= collect();
  155. foreach ($invLots as $invLot){
  156. if ($invLot->locationid=='STAGEWH01'||$invLot->locationid=='STAGEWH02')continue;
  157. $collect->push($invLot);
  158. }
  159. return json_encode(["success"=>true,'data'=>$tasks,'inv'=>$collect]);
  160. }
  161. else $this->error("该商品暂无上架任务");
  162. }
  163. /**
  164. * @param Request $request
  165. * 根据customerid,asnno,跟踪号 或空扫 获取待上架任务
  166. */
  167. public function getPaTaskByTraceInOrCustomerOrAsnOrNull(Request $request)
  168. {
  169. $this->gate("入库管理-手持入库-上架");
  170. $trackNumber=$request->input('trackNumber');
  171. $barCode=$request->input('barCode');
  172. /** @var HandInStorageService $handInStorageService */
  173. $handInStorageService=app('HandInStorageService');
  174. $tasks=$handInStorageService->getTsk($trackNumber,$barCode);
  175. if (count($tasks)>0)$this->success($tasks);
  176. else $this->error('暂无上架任务');
  177. }
  178. /**
  179. * @throws \Throwable
  180. * 上架
  181. */
  182. public function handFluxPa(Request $request)
  183. {
  184. $this->gate("入库管理-手持入库-上架");
  185. $info=$request->input('info');
  186. if (gettype($info['amount'])==='string')$info['amount']=(int)$info['amount'];
  187. if (!$info['location']||!$info['amount']||!$info['barCode'] || gettype($info['amount'])==='string') $this->error('参数错误');
  188. if (count($request->input('checkData'))==0) $this->error('请勾选要上架任务');
  189. $checkData=$request->input('checkData')[0];
  190. /** @var HandInStorageService $handInStorageService */
  191. $handInStorageService=app('HandInStorageService');
  192. //判断当前库位是否能放该商品
  193. $res=$handInStorageService->checkLocation($info,$checkData);
  194. if ($res===1)$this->error('库位不存在');
  195. if ($res===2)$this->error('库位:产品和批次不可混放');
  196. if ($res===3)$this->error('库位:不能混放批次');
  197. if ($res===4)$this->error('库位:产品不能混放');
  198. $key = $info['location'] . '_' . $info['barCode'] . '_' . Auth::id();
  199. $ttl = 10;
  200. try {
  201. //缓存校验操作
  202. if (Cache::has($key)){
  203. $this->error('当前已操作');
  204. }else{
  205. Cache::put($key,true, $ttl);
  206. }
  207. $result = $handInStorageService->fluxHandPa($info, $checkData);
  208. if ($result===true){
  209. if ($checkData['customerid']=="JIANSHANG"){
  210. $asn=OracleDOCASNHeader::query()
  211. ->where('asnno',$checkData['docno'])
  212. ->where('asnstatus','99')
  213. ->whereIn('asntype',['F10','F21','F31','F32'])
  214. ->first();
  215. if ($asn){$handInStorageService->verifyAsnStatusAndInsert($asn);}
  216. }
  217. $this->success("上架成功");
  218. }
  219. if ($result===false) $this->error("上架失败");
  220. if ($result===1)$this->error("拣货区找到效期更新的同样货品,不能上架至存储区");
  221. } catch (\Exception $e) {
  222. $this->error($e->getMessage());
  223. app('LogService')->log(__METHOD__,'error_'.__FUNCTION__,json_encode($info).'|catch:'.$e->getMessage());
  224. }finally {
  225. Cache::forget($key);
  226. }
  227. }
  228. public function getInventoryInfos(Request $request)
  229. {
  230. $this->gate("入库管理-手持入库-库存查询");
  231. $param=$request->input('location');
  232. /** @var HandInStorageService $handInStorageService */
  233. $handInStorageService=app('HandInStorageService');
  234. $invs=$handInStorageService->getInventoryInfos($param);
  235. if (count($invs)>0)$this->success($invs);
  236. else $this->error('未查询到库存信息');
  237. }
  238. }