StoreCountGoodsAndReceiveController.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Components\AsyncResponse;
  4. use App\Exports\InventoryBlindReceiveExcelExport;
  5. use App\InventoryBlindReceiveExcel;
  6. use App\OracleDOCASNDetail;
  7. use App\Services\HandInStorageService;
  8. use Carbon\Carbon;
  9. use Doctrine\DBAL\Exception;
  10. use Doctrine\DBAL\Exception\DatabaseObjectExistsException;
  11. use Illuminate\Http\Request;
  12. use Illuminate\Support\Facades\Auth;
  13. use Illuminate\Support\Facades\Cache;
  14. use Maatwebsite\Excel\Facades\Excel;
  15. class StoreCountGoodsAndReceiveController extends Controller
  16. {
  17. use AsyncResponse;
  18. public function index()
  19. {
  20. /** @var HandInStorageService $handInStorageService */
  21. $handInStorageService=app('HandInStorageService');
  22. $qualityStatus=$handInStorageService->getQualityStatus();
  23. $attributeLocations=$handInStorageService->getAttributeLocation();
  24. return view('store.countGoodsAndReceive.index',
  25. compact('qualityStatus','attributeLocations'));
  26. }
  27. public function excel()
  28. {
  29. $excels=InventoryBlindReceiveExcel::query()
  30. ->where('name','like','清点%')
  31. ->orderByDesc('id')->get();
  32. return view('store.countGoodsAndReceive.excel',['excels'=>$excels]);
  33. }
  34. public function createExcel(Request $request): array
  35. {
  36. $goodses=$request->input('goodses')??'';
  37. $excelFileName=$request->input('filename')??'';
  38. if(!$goodses||!is_array($goodses)||count($goodses)==0){
  39. return ['result'=>'failure','fail_info'=>'没有数据提交!'];
  40. }
  41. $goodsExcelArray=[['条码','数量','箱号']];
  42. foreach ($goodses as $goods){
  43. array_push($goodsExcelArray,[$goods['barcode'],$goods['amount'],$goods['cast_number']]);
  44. }
  45. $fileName=Carbon::now()->toDateTimeLocalString().'.xlsx';
  46. $fileName = str_replace( ':', '_',$fileName);
  47. $goodsNeateningExcel = new InventoryBlindReceiveExcel(['file' => $fileName, 'goods_amount' => count($goodses), 'name'=>'清点_'.$excelFileName]);
  48. $goodsNeateningExcel->save();
  49. Excel::store(new InventoryBlindReceiveExcelExport($goodsExcelArray),$fileName,'public');
  50. $this->removeExpiredExcel();
  51. return ['result'=>'success'];
  52. }
  53. private function removeExpiredExcel(){
  54. $excels=InventoryBlindReceiveExcel::query()->where('created_at','<',Carbon::now()->subDays(100)->toDateTimeString())->get();
  55. $excels->each(
  56. /** @throws \Exception */
  57. function(InventoryBlindReceiveExcel $excel){
  58. $excel->delete();
  59. });
  60. }
  61. public function getReceiveTaskByAsnNoAndBarcodes(Request $request)
  62. {
  63. $asnno=$request->input('asnno');
  64. $goods=$request->input('goods');
  65. $asnDetails=OracleDOCASNDetail::query()
  66. ->select('asnno','asnlineno','customerid','sku','expectedqty','receivedqty_each',
  67. 'lotatt01','lotatt02','lotatt03','lotatt04','lotatt05','lotatt08')
  68. ->with('basSku.lotId')
  69. ->where('asnno',$asnno)
  70. ->whereIn('linestatus', ['00', '30'])
  71. ->get();
  72. $status=false;
  73. foreach ($goods as &$good){
  74. foreach ($asnDetails as $asnDetail){
  75. if (!$asnDetail['basSku']??false)continue;
  76. if ($good['sku']==$asnDetail['basSku']['alternate_sku1']
  77. ||$good['sku']==$asnDetail['basSku']['alternate_sku2']
  78. ||$good['sku']==$asnDetail['basSku']['alternate_sku3']){
  79. $good['basSku']=$asnDetail['basSku'];
  80. $good['customerid']=$asnDetail['customerid'];
  81. $good['asn_amount']=($asnDetail['expectedqty']-$asnDetail['receivedqty_each']);
  82. $good['diff_val']=($good['asn_amount']-$good['amount']);
  83. $good['receiveStatus']=true;
  84. $status=true;
  85. $good['asnlineno']=$asnDetail['asnlineno'];
  86. $good['lotatt01']=$asnDetail['lotatt01'];
  87. $good['lotatt02']=$asnDetail['lotatt02'];
  88. $good['lotatt03']=$asnDetail['lotatt03'];
  89. $good['lotatt04']=$asnDetail['lotatt04'];
  90. $good['lotatt05']=$asnDetail['lotatt05'];
  91. $good['lotatt08']=$asnDetail['lotatt08'];
  92. }
  93. }
  94. }
  95. if ($status)$this->success($goods);
  96. else $this->error('当前ASN单号未查询到下述商品信息!');
  97. }
  98. public function fluxReceive(Request $request)
  99. {
  100. $info=$request->input('good');
  101. $isSku=$info['sku']??false;
  102. if ($info['lotatt02']&&Carbon::now()->gt($info['lotatt02']))$this->error('失效日期超过入库效期');
  103. if (!$info['customerid']||$isSku===false||!$info['asnno']) $this->error('参数错误');
  104. /** @var HandInStorageService $handInStorageService */
  105. $handInStorageService=app('HandInStorageService');
  106. if ($info['customerid']=='ONKYO'||$info['customerid']=='ANMEILAI'||$info['customerid']=='FEIHE'){
  107. $res=$handInStorageService->checkWidthHeight($info);
  108. if ($res===1)$this->error('需要维护产品档案');
  109. if ($res===2)$this->error('需要维护该产品档案中的长宽高');
  110. }
  111. if ($info['customerid']=='TANGENBEI'||$info['customerid']=='ANMEILAI'){
  112. $result=$handInStorageService->checkCubicWeight($info);
  113. if ($result===1)$this->error('需要维护产品档案');
  114. if ($result===2)$this->error('需要维护该产品档案中的重量体积');
  115. }
  116. if ($info['customerid']=='JIANSHANG'&&$handInStorageService->checkForwardingLoc($info)===1)$this->error('请维护拣货位');
  117. $key = $info['asnno'] . '_' . $info['sku'] . '_' . Auth::id();
  118. $ttl = 10;
  119. try {
  120. //缓存校验操作
  121. if (Cache::has($key)){
  122. $this->error('当前已操作');
  123. }else{
  124. Cache::put($key,true, $ttl);
  125. }
  126. //收货操作
  127. $resultIn = $handInStorageService->fluxHandIn($info);
  128. if ($resultIn===1)$this->error("超收");
  129. if ($resultIn){
  130. $this->success('收货成功');
  131. } else $this->error("收货失败");
  132. } catch (\Exception $e) {
  133. app('LogService')->log(__METHOD__,'error_'.__FUNCTION__,json_encode($info).'|catch:'.$e->getMessage());
  134. } finally {
  135. Cache::forget($key);
  136. }
  137. }
  138. }