HandInStorageController.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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. ->where('warehouse_id',3)//3 代表九干仓仓库id
  149. ->whereNull('deleted_at')
  150. ->get();
  151. foreach ($owners as $owner){
  152. if ($owner->code==$ownerCode){
  153. return true;
  154. }
  155. }
  156. return false;
  157. }
  158. /**
  159. * @param Request $request
  160. * 根据商品条码和跟踪号 获取要上架的任务列表
  161. */
  162. public function getTsk(Request $request)
  163. {
  164. $this->gate("入库管理-手持入库-上架");
  165. $barCode=$request->input('barCode');
  166. $trackNumber=$request->input('trackNumber');
  167. /** @var HandInStorageService $handInStorageService */
  168. $handInStorageService=app('HandInStorageService');
  169. $tasks=$handInStorageService->getTsk($trackNumber,$barCode);
  170. if (count($tasks)>0){
  171. $invLots=$handInStorageService->getInvotlocid($barCode);
  172. $collect= collect();
  173. foreach ($invLots as $invLot){
  174. if ($invLot->locationid=='STAGEWH01'||$invLot->locationid=='STAGEWH02')continue;
  175. $collect->push($invLot);
  176. }
  177. return json_encode(["success"=>true,'data'=>$tasks,'inv'=>$collect]);
  178. }
  179. else $this->error("该商品暂无上架任务");
  180. }
  181. /**
  182. * @param Request $request
  183. * 根据customerid,asnno,跟踪号 或空扫 获取待上架任务
  184. */
  185. public function getPaTaskByTraceInOrCustomerOrAsnOrNull(Request $request)
  186. {
  187. $this->gate("入库管理-手持入库-上架");
  188. $trackNumber=$request->input('trackNumber');
  189. $barCode=$request->input('barCode');
  190. /** @var HandInStorageService $handInStorageService */
  191. $handInStorageService=app('HandInStorageService');
  192. $tasks=$handInStorageService->getTsk($trackNumber,$barCode);
  193. if (count($tasks)>0)$this->success($tasks);
  194. else $this->error('暂无上架任务');
  195. }
  196. /**
  197. * @throws \Throwable
  198. * 上架
  199. */
  200. public function handFluxPa(Request $request)
  201. {
  202. $this->gate("入库管理-手持入库-上架");
  203. $info=$request->input('info');
  204. if (gettype($info['amount'])==='string')$info['amount']=(int)$info['amount'];
  205. if (!$info['location']||!$info['amount']||!$info['barCode'] || gettype($info['amount'])==='string') $this->error('参数错误');
  206. if (count($request->input('checkData'))==0) $this->error('请勾选要上架任务');
  207. $checkData=$request->input('checkData')[0];
  208. //九干仓禁止使用当前app上架
  209. $res=$this->screenWarehouseAndContrast($checkData['customerid']);
  210. if ($res)$this->error('禁止使用当前app上架,请换用新版app上架!');
  211. /** @var HandInStorageService $handInStorageService */
  212. $handInStorageService=app('HandInStorageService');
  213. //判断当前库位是否能放该商品
  214. $res=$handInStorageService->checkLocation($info,$checkData);
  215. if ($res===1)$this->error('库位不存在');
  216. if ($res===2)$this->error('库位:产品和批次不可混放');
  217. if ($res===3)$this->error('库位:不能混放批次');
  218. if ($res===4)$this->error('库位:产品不能混放');
  219. $key = $info['location'] . '_' . $info['barCode'] . '_' . Auth::id();
  220. $ttl = 10;
  221. try {
  222. //缓存校验操作
  223. if (Cache::has($key)){
  224. $this->error('当前已操作');
  225. }else{
  226. Cache::put($key,true, $ttl);
  227. }
  228. $result = $handInStorageService->fluxHandPa($info, $checkData);
  229. if ($result===true){
  230. if ($checkData['customerid']=="JIANSHANG"){
  231. $asn=OracleDOCASNHeader::query()
  232. ->where('asnno',$checkData['docno'])
  233. ->where('asnstatus','99')
  234. ->whereIn('asntype',['F10','F21','F31','F32'])
  235. ->first();
  236. if ($asn){$handInStorageService->verifyAsnStatusAndInsert($asn);}
  237. }
  238. $this->success("上架成功");
  239. }
  240. if ($result===false) $this->error("上架失败");
  241. if ($result===1)$this->error("拣货区找到效期更新的同样货品,不能上架至存储区");
  242. } catch (\Exception $e) {
  243. $this->error($e->getMessage());
  244. app('LogService')->log(__METHOD__,'error_'.__FUNCTION__,json_encode($info).'|catch:'.$e->getMessage());
  245. }finally {
  246. Cache::forget($key);
  247. }
  248. }
  249. public function getInventoryInfos(Request $request)
  250. {
  251. $this->gate("入库管理-手持入库-库存查询");
  252. $param=$request->input('location');
  253. /** @var HandInStorageService $handInStorageService */
  254. $handInStorageService=app('HandInStorageService');
  255. $invs=$handInStorageService->getInventoryInfos($param);
  256. if (count($invs)>0)$this->success($invs);
  257. else $this->error('未查询到库存信息');
  258. }
  259. }