HandInStorageController.php 12 KB

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