HandInStorageController.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Components\AsyncResponse;
  4. use App\OracleDOCASNHeader;
  5. use App\Owner;
  6. use App\Services\HandInStorageService;
  7. use Carbon\Carbon;
  8. use Doctrine\DBAL\Exception;
  9. use Illuminate\Http\Request;
  10. use Illuminate\Support\Facades\Auth;
  11. use Illuminate\Support\Facades\Cache;
  12. use Illuminate\Support\Facades\Log;
  13. class HandInStorageController extends Controller
  14. {
  15. use AsyncResponse;
  16. /**
  17. * 搜索查詢asn
  18. */
  19. public function selectAsn(Request $request)
  20. {
  21. $this->gate("入库管理-手持入库-收货");
  22. /** @var HandInStorageService $handInStorageService */
  23. $handInStorageService=app('HandInStorageService');
  24. $asnno= $request->input('asnno');
  25. $asns =$handInStorageService->selectAsn($asnno);
  26. if (count($asns)>0){
  27. foreach ($asns as $asn){
  28. $asn->asnDetails=array();
  29. }
  30. $this->success($asns);
  31. }else{
  32. $this->error('无有效的ASN的订单');
  33. }
  34. }
  35. public function checkAsnOperation(Request $request)
  36. {
  37. $this->gate("入库管理-手持入库-收货");
  38. /** @var HandInStorageService $handInStorageService */
  39. $handInStorageService=app('HandInStorageService');
  40. $info= $request->input('info');
  41. $res=$handInStorageService->checkAsnOperation($info);
  42. if ($res===1)$this->error('无有效的ASN的订单');
  43. elseif ($res===2)$this->error('该asn无预约,暂不可收货');
  44. else $this->success($res);
  45. }
  46. /**
  47. * @param $asnno
  48. * 跳转到收货明细页面
  49. */
  50. public function receiveDetailPage($asnno,$customerid)
  51. {
  52. $this->gate("入库管理-手持入库-收货");
  53. /** @var HandInStorageService $handInStorageService */
  54. $handInStorageService=app('HandInStorageService');
  55. if (!$customerid||$customerid=='undefined')
  56. $customerid=OracleDOCASNHeader::query()->where('asnno',$asnno)->value('customerid');
  57. $qualityStatus=$handInStorageService->getQualityStatus();
  58. $attributeLocations=$handInStorageService->getAttributeLocation();
  59. $asnQty=$handInStorageService->getAsnQty($asnno);
  60. return view('store.handInStorage.receiveDetailPage')
  61. ->with(['asn_expectedqty'=>$asnQty->expectedqty,'asn_receivedqty'=>$asnQty->receivedqty,
  62. 'asnno'=>$asnno,'customerid'=>$customerid,
  63. 'qualityStatus'=>$qualityStatus,'attributeLocations'=>$attributeLocations]);
  64. }
  65. /**
  66. * @param Request $request
  67. * 查询富勒asn_detail(集合)
  68. */
  69. public function selectAsnDetails(Request $request)
  70. {
  71. $this->gate("入库管理-手持入库-收货");
  72. $asnno= $request->input('asnno');
  73. $asnDetails =app('HandInStorageService')->selectAsnDetails($asnno);
  74. if (count($asnDetails)>0)$this->success($asnDetails);
  75. else $this->error('未查询到相应的asn明细');
  76. }
  77. /**
  78. * @param Request $request
  79. * 查询富勒bas_sku 并关联 bas_lotid
  80. */
  81. public function getBasSkuWithLot(Request $request): array
  82. {
  83. $customerid= $request->input('customerid');
  84. $skuOrBarcode= $request->input('sku');
  85. $asnno= $request->input('asnno');
  86. $asnDetail=app('HandInStorageService')->getAsnDetail($asnno,$skuOrBarcode);
  87. if (!$asnDetail)$this->error('无效条码');
  88. $basSku =app('HandInStorageService')->getBasSkuLotId($customerid,$asnDetail->sku);
  89. if (isset($basSku)&&isset($asnDetail))return ['success'=>true,'basSku'=>$basSku,'asnDetail'=>$asnDetail];
  90. else $this->error('无效条码');
  91. }
  92. /**
  93. * @throws \Throwable
  94. * 收货
  95. */
  96. public function fluxHandIn(Request $request)
  97. {
  98. $this->gate("入库管理-手持入库-收货");
  99. $info=$request->input('info');
  100. $isReceivedqty=$info['receivedqty']??false;
  101. $isExpectedqty=$info['expectedqty']??false;
  102. $isSku=$info['sku']??false;
  103. if ($info['lotatt02']&&Carbon::now()->gt($info['lotatt02']))$this->error('失效日期超过入库效期');
  104. if (!$info['customerid']||$isSku===false||!$info['asnno']||$isReceivedqty===false||$isExpectedqty===false) $this->error('参数错误');
  105. if ($info['amount'] + $info['receivedqty'] > $info['expectedqty']) $this->error('收货数大于预期数');
  106. //九干仓禁止使用当前app收货
  107. $res=$this->screenWarehouseAndContrast($info['customerid']);
  108. if ($res)$this->error('禁止使用当前app收货,请换用新版app收货!');
  109. /** @var HandInStorageService $handInStorageService */
  110. $handInStorageService=app('HandInStorageService');
  111. if ($info['customerid']=='ONKYO'||$info['customerid']=='ANMEILAI'||$info['customerid']=='FEIHE'){
  112. $res=$handInStorageService->checkWidthHeight($info);
  113. if ($res===1)$this->error('需要维护产品档案');
  114. if ($res===2)$this->error('需要维护该产品档案中的长宽高');
  115. }
  116. if ($info['customerid']=='TANGENBEI'||$info['customerid']=='ANMEILAI'){
  117. $result=$handInStorageService->checkCubicWeight($info);
  118. if ($result===1)$this->error('需要维护产品档案');
  119. if ($result===2)$this->error('需要维护该产品档案中的重量体积');
  120. }
  121. if ($info['customerid']=='JIANSHANG'&&$handInStorageService->checkForwardingLoc($info)===1)$this->error('请维护拣货位');
  122. $key = $info['asnno'] . '_' . $info['sku'] . '_' . Auth::id();
  123. $ttl = 10;
  124. try {
  125. //缓存校验操作
  126. if (Cache::has($key)){
  127. $this->error('当前已操作');
  128. }else{
  129. Cache::put($key,true, $ttl);
  130. }
  131. //收货操作
  132. $resultIn = $handInStorageService->fluxHandIn($info);
  133. if ($resultIn===1)$this->error("超收");
  134. if ($resultIn){
  135. $asnQty=$handInStorageService->getAsnQty($info['asnno']);
  136. $this->success($asnQty);
  137. } else $this->error("收货失败");
  138. } catch (\Exception $e) {
  139. app('LogService')->log(__METHOD__,'error_'.__FUNCTION__,json_encode($info).'|catch:'.$e->getMessage());
  140. } finally {
  141. Cache::forget($key);
  142. }
  143. }
  144. public function screenWarehouseAndContrast($ownerCode): bool
  145. {
  146. $owners=Owner::query()
  147. ->select('code')
  148. ->whereIn('warehouse_id',[2,3])//3 代表九干仓仓库id 2代表泗砖仓id
  149. ->whereNull('deleted_at')
  150. ->where('id','<>',400) //排除GM货主
  151. ->get();
  152. foreach ($owners as $owner){
  153. if ($owner->code==$ownerCode){
  154. return true;
  155. }
  156. }
  157. return false;
  158. }
  159. /**
  160. * @param Request $request
  161. * 根据商品条码和跟踪号 获取要上架的任务列表
  162. */
  163. public function getTsk(Request $request)
  164. {
  165. $this->gate("入库管理-手持入库-上架");
  166. $barCode=$request->input('barCode');
  167. $trackNumber=$request->input('trackNumber');
  168. /** @var HandInStorageService $handInStorageService */
  169. $handInStorageService=app('HandInStorageService');
  170. $tasks=$handInStorageService->getTsk($trackNumber,$barCode);
  171. if (count($tasks)>0){
  172. $invLots=$handInStorageService->getInvotlocid($barCode);
  173. $collect= collect();
  174. foreach ($invLots as $invLot){
  175. if ($invLot->locationid=='STAGEWH01'||$invLot->locationid=='STAGEWH02')continue;
  176. $collect->push($invLot);
  177. }
  178. return json_encode(["success"=>true,'data'=>$tasks,'inv'=>$collect]);
  179. }
  180. else $this->error("该商品暂无上架任务");
  181. }
  182. /**
  183. * @param Request $request
  184. * 根据customerid,asnno,跟踪号 或空扫 获取待上架任务
  185. */
  186. public function getPaTaskByTraceInOrCustomerOrAsnOrNull(Request $request)
  187. {
  188. $this->gate("入库管理-手持入库-上架");
  189. $trackNumber=$request->input('trackNumber');
  190. $barCode=$request->input('barCode');
  191. /** @var HandInStorageService $handInStorageService */
  192. $handInStorageService=app('HandInStorageService');
  193. $tasks=$handInStorageService->getTsk($trackNumber,$barCode);
  194. if (count($tasks)>0)$this->success($tasks);
  195. else $this->error('暂无上架任务');
  196. }
  197. /**
  198. * @throws \Throwable
  199. * 上架
  200. */
  201. public function handFluxPa(Request $request)
  202. {
  203. $this->gate("入库管理-手持入库-上架");
  204. $info=$request->input('info');
  205. if (gettype($info['amount'])==='string')$info['amount']=(int)$info['amount'];
  206. if (!$info['location']||!$info['amount']||!$info['barCode'] || gettype($info['amount'])==='string') $this->error('参数错误');
  207. if (count($request->input('checkData'))==0) $this->error('请勾选要上架任务');
  208. $checkData=$request->input('checkData')[0];
  209. //九干仓禁止使用当前app上架
  210. $res=$this->screenWarehouseAndContrast($checkData['customerid']);
  211. if ($res)$this->error('禁止使用当前app上架,请换用新版app上架!');
  212. /** @var HandInStorageService $handInStorageService */
  213. $handInStorageService=app('HandInStorageService');
  214. //判断当前库位是否能放该商品
  215. $res=$handInStorageService->checkLocation($info,$checkData);
  216. if ($res===1)$this->error('库位不存在');
  217. if ($res===2)$this->error('库位:产品和批次不可混放');
  218. if ($res===3)$this->error('库位:不能混放批次');
  219. if ($res===4)$this->error('库位:产品不能混放');
  220. $key = $info['location'] . '_' . $info['barCode'] . '_' . Auth::id();
  221. $ttl = 10;
  222. try {
  223. //缓存校验操作
  224. if (Cache::has($key)){
  225. $this->error('当前已操作');
  226. }else{
  227. Cache::put($key,true, $ttl);
  228. }
  229. $result = $handInStorageService->fluxHandPa($info, $checkData);
  230. if ($result===true){
  231. if ($checkData['customerid']=="JIANSHANG"){
  232. $asn=OracleDOCASNHeader::query()
  233. ->where('asnno',$checkData['docno'])
  234. ->where('asnstatus','99')
  235. ->whereIn('asntype',['F10','F21','F31','F32'])
  236. ->first();
  237. if ($asn){$handInStorageService->verifyAsnStatusAndInsert($asn);}
  238. }
  239. $this->success("上架成功");
  240. }
  241. if ($result===false) $this->error("上架失败");
  242. if ($result===1)$this->error("拣货区找到效期更新的同样货品,不能上架至存储区");
  243. } catch (\Exception $e) {
  244. $this->error($e->getMessage());
  245. app('LogService')->log(__METHOD__,'error_'.__FUNCTION__,json_encode($info).'|catch:'.$e->getMessage());
  246. }finally {
  247. Cache::forget($key);
  248. }
  249. }
  250. public function getInventoryInfos(Request $request)
  251. {
  252. $this->gate("入库管理-手持入库-库存查询");
  253. $param=$request->input('location');
  254. /** @var HandInStorageService $handInStorageService */
  255. $handInStorageService=app('HandInStorageService');
  256. $invs=$handInStorageService->getInventoryInfos($param);
  257. if (count($invs)>0)$this->success($invs);
  258. else $this->error('未查询到库存信息');
  259. }
  260. }