StoreCountGoodsAndReceiveController.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 Doctrine\DBAL\Schema\AbstractAsset;
  12. use Illuminate\Http\Request;
  13. use Illuminate\Support\Facades\Auth;
  14. use Illuminate\Support\Facades\Cache;
  15. use Maatwebsite\Excel\Facades\Excel;
  16. class StoreCountGoodsAndReceiveController extends Controller
  17. {
  18. use AsyncResponse;
  19. public function index()
  20. {
  21. /** @var HandInStorageService $handInStorageService */
  22. $handInStorageService=app('HandInStorageService');
  23. $qualityStatus=$handInStorageService->getQualityStatus();
  24. $attributeLocations=$handInStorageService->getAttributeLocation();
  25. return view('store.countGoodsAndReceive.index',
  26. compact('qualityStatus','attributeLocations'));
  27. }
  28. public function excel()
  29. {
  30. $excels=InventoryBlindReceiveExcel::query()
  31. ->where('name','like','清点%')
  32. ->orderByDesc('id')->get();
  33. return view('store.countGoodsAndReceive.excel',['excels'=>$excels]);
  34. }
  35. public function createExcel(Request $request): array
  36. {
  37. $goodses=$request->input('goodses')??'';
  38. $excelFileName=$request->input('filename')??'';
  39. if(!$goodses||!is_array($goodses)||count($goodses)==0){
  40. return ['result'=>'failure','fail_info'=>'没有数据提交!'];
  41. }
  42. $goodsExcelArray=[['条码','数量','箱号']];
  43. foreach ($goodses as $goods){
  44. array_push($goodsExcelArray,[$goods['barcode'],$goods['amount'],$goods['cast_number']]);
  45. }
  46. $fileName=Carbon::now()->toDateTimeLocalString().'.xlsx';
  47. $fileName = str_replace( ':', '_',$fileName);
  48. $goodsNeateningExcel = new InventoryBlindReceiveExcel(['file' => $fileName, 'goods_amount' => count($goodses), 'name'=>'清点_'.$excelFileName]);
  49. $goodsNeateningExcel->save();
  50. Excel::store(new InventoryBlindReceiveExcelExport($goodsExcelArray),$fileName,'public');
  51. $this->removeExpiredExcel();
  52. return ['result'=>'success'];
  53. }
  54. private function removeExpiredExcel(){
  55. $excels=InventoryBlindReceiveExcel::query()->where('created_at','<',Carbon::now()->subDays(100)->toDateTimeString())->get();
  56. $excels->each(
  57. /** @throws \Exception */
  58. function(InventoryBlindReceiveExcel $excel){
  59. $excel->delete();
  60. });
  61. }
  62. public function getReceiveTaskByAsnNoAndBarcodes(Request $request)
  63. {
  64. $asnno=$request->input('asnno');
  65. $goods=$request->input('goods');
  66. $asnDetails=OracleDOCASNDetail::query()
  67. ->select('asnno','asnlineno','customerid','sku','expectedqty','receivedqty_each',
  68. 'lotatt01','lotatt02','lotatt03','lotatt04','lotatt05','lotatt08')
  69. ->with('basSku.lotId')
  70. ->where('asnno',$asnno)
  71. ->whereIn('linestatus', ['00', '30'])
  72. ->get();
  73. $status=false;
  74. foreach ($goods as &$good){
  75. foreach ($asnDetails as $asnDetail){
  76. if (!$asnDetail['basSku']??false)continue;
  77. if ($good['sku']==$asnDetail['basSku']['alternate_sku1']
  78. ||$good['sku']==$asnDetail['basSku']['alternate_sku2']
  79. ||$good['sku']==$asnDetail['basSku']['alternate_sku3']){
  80. $good['basSku']=$asnDetail['basSku'];
  81. $good['customerid']=$asnDetail['customerid'];
  82. $good['asn_amount']=($asnDetail['expectedqty']-$asnDetail['receivedqty_each']);
  83. $good['diff_val']=($good['asn_amount']-$good['amount']);
  84. $good['receiveStatus']=true;
  85. $status=true;
  86. $good['asnlineno']=$asnDetail['asnlineno'];
  87. $good['lotatt01']=$asnDetail['lotatt01'];
  88. $good['lotatt02']=$asnDetail['lotatt02'];
  89. $good['lotatt03']=$asnDetail['lotatt03'];
  90. $good['lotatt04']=$asnDetail['lotatt04'];
  91. $good['lotatt05']=$asnDetail['lotatt05'];
  92. $good['lotatt08']=$asnDetail['lotatt08'];
  93. }
  94. }
  95. }
  96. if ($status)$this->success($goods);
  97. else $this->error('当前ASN单号未查询到下述商品信息!');
  98. }
  99. public function fluxReceive(Request $request)
  100. {
  101. $info=$request->input('good');
  102. $isSku=$info['sku']??false;
  103. if ($info['lotatt02']&&Carbon::now()->gt($info['lotatt02']))$this->error('失效日期超过入库效期');
  104. if (!$info['customerid']||$isSku===false||!$info['asnno']) $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. $this->success('收货成功');
  132. } else $this->error("收货失败");
  133. } catch (\Exception $e) {
  134. app('LogService')->log(__METHOD__,'error_'.__FUNCTION__,json_encode($info).'|catch:'.$e->getMessage());
  135. } finally {
  136. Cache::forget($key);
  137. }
  138. }
  139. }