HandInStorageService.php 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841
  1. <?php
  2. namespace App\Services;
  3. use App\CommodityBarcode;
  4. use App\OracleActTransactionLog;
  5. use App\OracleBasCode;
  6. use App\OracleBasCustomer;
  7. use App\OracleBasForwardingLoc;
  8. use App\OracleBasLocation;
  9. use App\OracleBasLotId;
  10. use App\OracleBasSKU;
  11. use App\OracleDOCASNDetail;
  12. use App\OracleDOCASNHeader;
  13. use App\OracleInvLotAtt;
  14. use App\OracleInvLotLocId;
  15. use App\Traits\ServiceAppAop;
  16. use App\ValueStore;
  17. use Carbon\Carbon;
  18. use Doctrine\DBAL\Schema\AbstractAsset;
  19. use Illuminate\Database\Eloquent\Builder;
  20. use Illuminate\Database\Eloquent\Collection;
  21. use Illuminate\Database\Eloquent\Model;
  22. use Illuminate\Support\Facades\Auth;
  23. use Illuminate\Support\Facades\Cache;
  24. use Illuminate\Support\Facades\DB;
  25. use Monolog\Handler\IFTTTHandler;
  26. use phpDocumentor\Reflection\Types\Object_;
  27. class HandInStorageService
  28. {
  29. use ServiceAppAop;
  30. /**
  31. * @param $asnno
  32. * @return object
  33. * 根据asn单号获取 总预期数量 总已收数量
  34. */
  35. public function getAsnQty($asnno)
  36. {
  37. $asnQty=OracleDOCASNDetail::query()
  38. ->select('expectedqty','receivedqty')
  39. ->where('asnno',$asnno)
  40. ->get();
  41. $expectedqty=0;
  42. $receivedqty=0;
  43. foreach ($asnQty as $qty){
  44. $expectedqty+=$qty->expectedqty;
  45. $receivedqty+=$qty->receivedqty;
  46. }
  47. return (object)array('expectedqty'=>$expectedqty,'receivedqty'=>$receivedqty);
  48. }
  49. /**
  50. * @param array $info
  51. * @return bool|int
  52. * 校验货主拣货位
  53. */
  54. public function checkForwardingLoc(array $info)
  55. {
  56. $res=OracleBasCustomer::query()
  57. ->where('customerid',$info['customerid'])
  58. ->where('customer_type','OW')
  59. ->where('udf1','Y')->count(); //查询此货主是否必须有拣货位
  60. if ($res>0) {
  61. $amount=OracleBasForwardingLoc::query()
  62. ->where('customerid',$info['customerid'])
  63. ->where('sku',$info['sku'])
  64. ->count();
  65. if ($amount==0)return 1;//请维护拣货位!
  66. }
  67. return true;
  68. }
  69. /**
  70. * @param array $info
  71. * @return bool|int
  72. * 校验产品档案长宽高
  73. */
  74. public function checkWidthHeight(array $info)
  75. {
  76. $basSku=OracleBasSKU::query()->where('customerid',$info['customerid'])->where('sku',$info['sku'])->first();
  77. if (!$basSku)return 1;//需要维护产品档案
  78. if ($basSku->skulength<=0||$basSku->skuwidth<=0||$basSku->skuhigh<=0)return 2;//需要维护该产品档案中的长宽高
  79. return true;
  80. }
  81. /**
  82. * @param array $info
  83. * @return bool|int
  84. * 校验产品档案重量体积
  85. */
  86. public function checkCubicWeight(array $info)
  87. {
  88. $basSku=OracleBasSKU::query()->where('customerid',$info['customerid'])->where('sku',$info['sku'])->first();
  89. if (!$basSku)return 1;//需要维护产品档案
  90. if ($basSku->grossweight<=0||$basSku->cube<=0)return 2;//需要维护该产品档案中的重量体积
  91. return true;
  92. }
  93. /**
  94. * @param array $info
  95. * @param array $param
  96. * @return bool|int
  97. * 校验库位
  98. */
  99. public function checkLocation(array $info, array $param)
  100. {
  101. $location = OracleBasLocation::query()
  102. ->where('locationid', $info['location'])
  103. ->where('status', 'OK')
  104. ->first();
  105. if (!$location) return 1;//库位不存在
  106. if ($location['mix_flag'] == 'N' && $location['mix_lotflag'] == 'N') { // 库位:产品和批次都不可混放
  107. $inv = OracleInvLotLocId::query()->where('locationid', $info['location'])->first();
  108. if (!$inv) return true; //当前库位无库存余量 可直接入库
  109. if ($inv['customerid'] == $param['customerid'] && $inv['sku'] == $param['sku']
  110. && $inv['lotnum'] == $param['plantolotnum'])
  111. return true;
  112. else return 2; //库位:产品和批次不可混放
  113. }
  114. if ($location['mix_flag'] == 'Y' && $location['mix_lotflag'] == 'N') {//库位:产品可混放,批次不可
  115. $invs = OracleInvLotLocId::query()->where('locationid', $info['location'])->get();
  116. if ($invs->count() == 0) return true; //当前库位无库存余量 可直接入库
  117. $skuInvs = []; // 库位没有该商品
  118. foreach ($invs as $inv) {
  119. if ($inv['customerid'] != $param['customerid'] && $inv['sku'] != $param['sku']) { // 库位没有该商品
  120. $skuInvs[] = $inv;
  121. continue;
  122. }
  123. if ($inv['lotnum'] == $param['plantolotnum']) return true; // 批次相同
  124. return 3; //库位:产品相同,不能混放批次
  125. }
  126. if (count($skuInvs) == count($invs)) return true;
  127. }
  128. if ($location['mix_flag'] == 'N' && $location['mix_lotflag'] == 'Y') { //库位:产品不可混放,批次可混放
  129. $inv = OracleInvLotLocId::query()->where('locationid', $info['location'])->first();
  130. if (!$inv) return true; //当前库位无库存余量 可直接入库
  131. if ($inv['customerid'] == $param['customerid'] && $inv['sku'] == $param['sku']) return true;
  132. else return 4; //库位:产品不能混放
  133. }
  134. // 库位
  135. return true;
  136. }
  137. /**
  138. * @param array $info
  139. * @return int|mixed
  140. * 校验asn单号是否能收货
  141. */
  142. public function checkAsnOperation(array $info)
  143. {
  144. if (!$info['customerid'] || !$info['asntype']) {
  145. $asn = OracleDOCASNHeader::query()
  146. ->select(['asnno', 'asnreference1', 'asnstatus', 'addtime', 'customerid', 'asntype'])
  147. ->where('asnno', $info['asnno'])
  148. ->whereIn('asnstatus', ['00', '30'])
  149. ->first();
  150. if (!$asn) return 1; //无效asn单号
  151. return $this->whetherDeliver($asn);
  152. }
  153. return $this->whetherDeliver($info);
  154. }
  155. private function whetherDeliver($asn)
  156. {
  157. if ($asn['asntype'] != 'XNRK' && $asn['asntype'] != 'THRK' && $asn['asntype'] != 'F31') {
  158. $res = app(DeliveryAppointmentService::class)->checkOperableAsn($asn['asnno'], $asn['customerid']);
  159. if ($res) return $asn;
  160. else return 2; //当前asn单号无预约记录
  161. }
  162. return $asn;
  163. }
  164. /**
  165. * @param $asn
  166. * @return Builder[]|Collection
  167. * 获取富勒asn_header 根据货主,asn,或者条码
  168. *
  169. */
  170. public function selectAsn($asn)
  171. {
  172. if (!$asn) return OracleDOCASNHeader::query() //空扫
  173. ->select(['asnno', 'asnreference1', 'asnstatus', 'addtime', 'customerid', 'asntype','notes'])
  174. ->where('asnstatus', '00')
  175. ->orderByDesc('addtime')
  176. ->limit(50)
  177. ->get();
  178. if (strpos(strtoupper($asn), 'ASN') !== false) { //asn 单号
  179. return OracleDOCASNHeader::query()
  180. ->select(['asnno', 'asnreference1', 'asnstatus', 'addtime', 'customerid', 'asntype','notes'])
  181. ->where('asnno', $asn)
  182. ->whereIn('asnstatus', ['00', '30'])
  183. ->get();
  184. } else {
  185. $asns = OracleDOCASNHeader::query() //货主
  186. ->select(['asnno', 'asnreference1', 'asnstatus', 'addtime', 'customerid', 'asntype','notes'])
  187. ->where('customerid', strtoupper($asn))
  188. ->whereIn('asnstatus', ['00', '30'])
  189. ->get();
  190. if ($asns->count() > 0) {
  191. return $asns;
  192. } else { //商品条码
  193. $sql = <<<SQL
  194. SELECT DOC_ASN_HEADER.ASNNO,DOC_ASN_HEADER.addtime,DOC_ASN_HEADER.asnreference1,DOC_ASN_HEADER.customerid,DOC_ASN_HEADER.asnstatus,DOC_ASN_HEADER.asntype,DOC_ASN_HEADER.notes FROM DOC_ASN_HEADER
  195. LEFT JOIN DOC_ASN_DETAILS ON DOC_ASN_HEADER.ASNNO = DOC_ASN_DETAILS.ASNNO
  196. LEFT JOIN BAS_SKU ON DOC_ASN_DETAILS.CUSTOMERID = BAS_SKU.CUSTOMERID AND DOC_ASN_DETAILS.SKU = BAS_SKU.SKU
  197. WHERE DOC_ASN_HEADER.ASNSTATUS in ('00','30') and BAS_SKU.SKU in (select SKU from BAS_SKU where ALTERNATE_SKU1=? union
  198. select SKU from BAS_SKU where ALTERNATE_SKU2=? union
  199. select SKU from BAS_SKU where ALTERNATE_SKU3=? )
  200. group by DOC_ASN_HEADER.ASNNO,DOC_ASN_HEADER.addtime,DOC_ASN_HEADER.asnreference1,DOC_ASN_HEADER.customerid,DOC_ASN_HEADER.asnstatus,DOC_ASN_HEADER.asntype,DOC_ASN_HEADER.notes
  201. SQL;
  202. return DB::connection("oracle")->select(DB::raw($sql), [$asn, $asn, $asn]);
  203. }
  204. }
  205. }
  206. /**
  207. * @param $asnno
  208. * @return Builder[]|Collection
  209. * 获取富勒asn_detail (集合)
  210. */
  211. public function selectAsnDetails($asnno)
  212. {
  213. $sql = <<<sql
  214. SELECT DOC_ASN_DETAILS.sku,DOC_ASN_DETAILS.expectedqty,DOC_ASN_DETAILS.skudescrc,DOC_ASN_DETAILS.asnlineno,DOC_ASN_DETAILS.asnno,
  215. DOC_ASN_DETAILS.receivedqty,BAS_SKU.alternate_sku1
  216. FROM DOC_ASN_DETAILS LEFT JOIN BAS_SKU ON DOC_ASN_DETAILS.CUSTOMERID = BAS_SKU.CUSTOMERID AND DOC_ASN_DETAILS.SKU = BAS_SKU.SKU
  217. WHERE asnno = ? AND linestatus IN ('00','30')
  218. sql;
  219. $asn_details = DB::connection("oracle")->select(DB::raw($sql), [$asnno]);
  220. if (count($asn_details) > 0) return $asn_details;
  221. else return array();
  222. }
  223. /**
  224. * @param $asnno
  225. * @param $skuOrBarcode
  226. * @return Builder|Model|object|null
  227. *根据sku 或者条码获取asn_detail
  228. */
  229. public function getAsnDetail($asnno, $skuOrBarcode)
  230. {
  231. $sql = <<<sql
  232. SELECT DOC_ASN_DETAILS.sku,DOC_ASN_DETAILS.expectedqty,DOC_ASN_DETAILS.skudescrc,
  233. DOC_ASN_DETAILS.lotatt01, DOC_ASN_DETAILS.lotatt02, DOC_ASN_DETAILS.lotatt03, DOC_ASN_DETAILS.lotatt04,
  234. DOC_ASN_DETAILS.lotatt05, DOC_ASN_DETAILS.lotatt06, DOC_ASN_DETAILS.lotatt07, DOC_ASN_DETAILS.lotatt08,
  235. DOC_ASN_DETAILS.asnlineno,DOC_ASN_DETAILS.asnno,DOC_ASN_DETAILS.receivedqty FROM DOC_ASN_DETAILS
  236. LEFT JOIN BAS_SKU ON DOC_ASN_DETAILS.CUSTOMERID = BAS_SKU.CUSTOMERID AND DOC_ASN_DETAILS.SKU = BAS_SKU.SKU
  237. WHERE ASNNO = ? AND LINESTATUS IN ('00','30') AND (ALTERNATE_SKU1 = ? OR ALTERNATE_SKU2 = ? OR ALTERNATE_SKU3 = ?)
  238. sql;
  239. $asn_detail = DB::connection("oracle")->selectOne(DB::raw($sql), [$asnno, $skuOrBarcode, $skuOrBarcode, $skuOrBarcode]);
  240. if ($asn_detail) return $asn_detail;
  241. else return OracleDOCASNDetail::query()
  242. ->select(['sku', 'expectedqty', 'skudescrc', 'asnlineno', 'asnno', 'receivedqty',
  243. 'lotatt01','lotatt02','lotatt03','lotatt04','lotatt05','lotatt06','lotatt07','lotatt08'])
  244. ->where('asnno', $asnno)
  245. ->where('sku', $skuOrBarcode)
  246. ->whereIn('linestatus', ['00', '30'])
  247. ->first();
  248. }
  249. /**
  250. * @return mixed
  251. * 获取质量状态
  252. */
  253. public function getQualityStatus()
  254. {
  255. return Cache::remember('BAS_CODE_QLT_STS', 600, function () {
  256. return OracleBasCode::query()->select(['codeid', 'code', 'codename_c'])
  257. ->where('codeid', 'QLT_STS')
  258. ->get();
  259. });
  260. }
  261. /**
  262. * @return mixed
  263. * 获取属性仓
  264. */
  265. public function getAttributeLocation()
  266. {
  267. return Cache::remember('BAS_CODE_CUS_UDFPC', 600, function () {
  268. return OracleBasCode::query()->select(['codeid', 'code', 'codename_c'])
  269. ->where('codeid', 'CUS_UDFPC')
  270. ->get();
  271. });
  272. }
  273. /**
  274. * @param $customerid
  275. * @param $sku
  276. * @return mixed
  277. * 根据customerid和sku 查询商品关联的批次属性规则
  278. */
  279. public function getBasSkuLotId($customerid, $sku)
  280. {
  281. return Cache::remember('bas_sku_lot_' . $customerid . '_' . $sku, 600, function () use ($customerid, $sku) {
  282. return OracleBasSKU::query()->select(['customerid', 'sku', 'lotid'])
  283. ->where('customerid', $customerid)
  284. ->where('sku', $sku)
  285. ->with('lotId')
  286. ->first();
  287. });
  288. }
  289. /**
  290. * @param $barcode
  291. * @return array
  292. * 根据条码获取 库存
  293. */
  294. public function getInvotlocid($barcode): array
  295. {
  296. $sql=<<<sql
  297. select INV_LOT_LOC_ID.CUSTOMERID,BAS_SKU.ALTERNATE_SKU1,INV_LOT_LOC_ID.LOCATIONID,INV_LOT_ATT.LOTATT05,INV_LOT_ATT.LOTATT08,
  298. INV_LOT_ATT.LOTATT01,INV_LOT_ATT.LOTATT02,INV_LOT_ATT.LOTATT03,INV_LOT_ATT.LOTATT04,
  299. sum(INV_LOT_LOC_ID.QTY) AS QTY from INV_LOT_LOC_ID
  300. left join BAS_SKU on INV_LOT_LOC_ID.CUSTOMERID=BAS_SKU.CUSTOMERID and INV_LOT_LOC_ID.SKU =BAS_SKU.SKU
  301. left join INV_LOT_ATT on INV_LOT_ATT.LOTNUM=INV_LOT_LOC_ID.LOTNUM
  302. where BAS_SKU.SKU in (select SKU from BAS_SKU where ALTERNATE_SKU1=? union
  303. select SKU from BAS_SKU where ALTERNATE_SKU2=? union
  304. select SKU from BAS_SKU where ALTERNATE_SKU3=? )
  305. group by INV_LOT_LOC_ID.CUSTOMERID,BAS_SKU.ALTERNATE_SKU1,INV_LOT_LOC_ID.LOCATIONID,INV_LOT_ATT.LOTATT05,INV_LOT_ATT.LOTATT08,INV_LOT_ATT.LOTATT01,INV_LOT_ATT.LOTATT02,INV_LOT_ATT.LOTATT03,INV_LOT_ATT.LOTATT04
  306. sql;
  307. $invLots = DB::connection("oracle")->select(DB::raw($sql), [$barcode, $barcode, $barcode]);
  308. if (!$invLots)return [];
  309. else return $invLots;
  310. }
  311. /**
  312. * @param string $barCode
  313. * @return array|int
  314. * 根据商品条码 获取完全收货状态 部分收货状态的 PA任务
  315. */
  316. public function getTsk($trackNumber,$barCode): array
  317. {
  318. $sql = <<<sql
  319. select t.*, DOC_ASN_DETAILS.RECEIVEDQTY
  320. from (select TSK_TASKLISTS.CustomerID,
  321. TSK_TASKLISTS.DOCNO,
  322. TSK_TASKLISTS.Sku,
  323. TSK_TASKLISTS.PlanToLotNum,
  324. TSK_TASKLISTS.PlanToID,
  325. DOC_ASN_DETAILS.SKUDESCRC,
  326. TSK_TASKLISTS.DOCLINENO,
  327. sum(TSK_TASKLISTS.PlanToQty) as qty
  328. from TSK_TASKLISTS
  329. LEFT JOIN DOC_ASN_DETAILS ON DOC_ASN_DETAILS.ASNNO = TSK_TASKLISTS.DOCNO AND
  330. DOC_ASN_DETAILS.ASNLINENO = TSK_TASKLISTS.DOCLINENO
  331. where TSK_TASKLISTS.TASKTYPE = 'PA'
  332. AND TSK_TASKLISTS.TASKPROCESS = '00'
  333. sql;
  334. if (!$trackNumber){ //没有输入条件 空扫
  335. $owner_codes = app('OwnerService')->getIntersectPermitting(['code']);
  336. if (count($owner_codes)>0){
  337. $sql.=' AND TSK_TASKLISTS.CustomerID IN (';
  338. foreach ($owner_codes as $index => $no){
  339. if ($index==0){
  340. $sql.="'".$no->code."'";
  341. continue;
  342. }
  343. $sql.=",'".$no->code."'";
  344. }
  345. $sql.=')';
  346. }else{
  347. $sql .= ' AND TSK_TASKLISTS.CustomerID IS NULL ';
  348. }
  349. }else{
  350. if (strpos(strtoupper($trackNumber), 'ASN') !== false){
  351. $sql.='AND TSK_TASKLISTS.DOCNO= ?'; //输入条件为asn单号
  352. } else{ //不为asn号时 判断是否为货主
  353. if ($this->checkUserOwnerAuth($trackNumber)){ //输入条件为货主
  354. $sql.=' AND TSK_TASKLISTS.CustomerID= ?';
  355. }else{
  356. $sql.=' AND TSK_TASKLISTS.PlanToID= ?'; //不是货主 判断是否为跟踪号
  357. }
  358. }
  359. }
  360. if ($barCode)$sql.=" AND TSK_TASKLISTS.sku in (select SKU from BAS_SKU where ALTERNATE_SKU1='".$barCode."' union
  361. select SKU from BAS_SKU where ALTERNATE_SKU2='".$barCode."' union
  362. select SKU from BAS_SKU where ALTERNATE_SKU3='".$barCode."' )";
  363. $sql.=' group by TSK_TASKLISTS.CustomerID, TSK_TASKLISTS.DOCNO, TSK_TASKLISTS.Sku, TSK_TASKLISTS.PlanToLotNum,
  364. TSK_TASKLISTS.PlanToID, DOC_ASN_DETAILS.SKUDESCRC, TSK_TASKLISTS.DOCLINENO) t
  365. left join DOC_ASN_DETAILS on t.DOCLINENO = DOC_ASN_DETAILS.ASNLINENO and t.DOCNO = DOC_ASN_DETAILS.ASNNO';
  366. if ($trackNumber){
  367. if ($this->checkUserOwnerAuth($trackNumber))$tasks = DB::connection("oracle")->select(DB::raw($sql), [strtoupper($trackNumber)]);
  368. else $tasks = DB::connection("oracle")->select(DB::raw($sql), [$trackNumber]);
  369. }else {$tasks = DB::connection("oracle")->select(DB::raw($sql));}
  370. if (!$tasks) return [];
  371. else return $tasks;
  372. }
  373. /**
  374. * @param $owner_code
  375. * @return bool
  376. * 判断当前用户货主权限
  377. */
  378. public function checkUserOwnerAuth($owner_code): bool
  379. {
  380. $owner_codes = app('OwnerService')->getIntersectPermitting(['code']);
  381. $owner=$owner_codes->where('code','=',strtoupper($owner_code));
  382. if ($owner->count()>0)return true;
  383. else return false;
  384. }
  385. /**
  386. * @throws \Throwable
  387. * flux手持端 上架
  388. */
  389. public function fluxHandPa(array $info, array $taskParam): bool
  390. {
  391. $tasks = $this->selectFluxTask($taskParam, $info['amount']);
  392. if (!$tasks) return false; //获取任务失败
  393. return DB::connection("oracle")->transaction(function () use ($tasks, $info) { //单体嵌套事务 回滚FLUX失败任务
  394. foreach ($tasks as $task) {
  395. $res=$this->checkExpiryPa($task,$info['location']);
  396. if ($res!==true)return $res;
  397. if (!app("StorageService")->fluxPA($task, $info['location'])) {
  398. DB::connection("oracle")->rollBack();
  399. return false; //上架失败
  400. }
  401. }
  402. return true; //上架成功
  403. });
  404. }
  405. /**
  406. * @param $task
  407. * @param $location
  408. * @return bool|int
  409. * 上架校验效期
  410. */
  411. public function checkExpiryPa($task,$location)
  412. {
  413. if (!$task->taskid)return 0;//任务id不存在
  414. if (strpos($task->taskid,'MIX') !== false)return true;//合并拣货,不校验
  415. $sql = <<<sql
  416. select instr(DESCR,'拣货') as var_IsPickingArea from BAS_Zone where ZONE=(select PutawayZone from BAS_Location where LocationID = ?)
  417. sql;
  418. $basZone = DB::connection("oracle")->selectOne(DB::raw($sql), [$location]);
  419. if ($basZone&&$basZone->var_ispickingarea>0) return true; //不是存储区,不校验
  420. $sql1 = <<<sql
  421. select SKU,LotAtt02,CustomerID from INV_LOT_ATT WHERE LOTNUM=?
  422. sql;
  423. $invLotAtt = DB::connection("oracle")->selectOne(DB::raw($sql1), [$task->fmlotnum]);
  424. $sql2 = <<<sql
  425. select count(*) as var_amountOfDecaying from INV_LOT_LOC_ID store
  426. left join BAS_Location location on store.LocationID=location.locationId
  427. left join BAS_Zone zone on zone.zone=location.PickZone
  428. left join INV_LOT_ATT attres on store.LOTNUM=attres.LOTNUM
  429. where store.SKU=?
  430. and store.CustomerID=?
  431. and store.LOTNUM!=?
  432. and attres.LotAtt02 > ?
  433. and zone.DESCR like '%拣货%'
  434. sql;
  435. $invLotLocId=DB::connection("oracle")->selectOne(DB::raw($sql2), [$invLotAtt->sku,$invLotAtt->customerid,$task->fmlotnum,$invLotAtt->lotatt02]);
  436. if ($invLotLocId&&$invLotLocId->var_amountofdecaying>0)return 1;//拣货区找到效期更新的同样货品,不能上架至存储区
  437. return true;
  438. }
  439. /**
  440. * @param $taskParam
  441. * @param $amount
  442. * @return array
  443. * 根据跟踪号,货主,sku,批次 获取任务列表 再通过数量 进行任务的重组(拆分或选定)
  444. */
  445. public function selectFluxTask($taskParam, $amount): array
  446. {
  447. /** @var StorageService $storageService */
  448. $storageService = app('StorageService');
  449. $sql = <<<sql
  450. select * from TSK_TASKLISTS where customerid = ? AND sku = ? AND plantoid = ? AND plantolotnum = ? AND TASKPROCESS = '00' AND TASKTYPE = 'PA'
  451. sql;
  452. $tasks = DB::connection("oracle")->select(DB::raw($sql), [$taskParam['customerid'], $taskParam['sku'], $taskParam['plantoid'], $taskParam['plantolotnum']]);
  453. if (!$tasks) return [];
  454. $nums = [];
  455. $sum = 0;
  456. $maxIndex = null;
  457. foreach ($tasks as $i => $task) {
  458. if ((int)$task->fmqty == $amount) return [$task];
  459. $nums[] = (int)$task->fmqty;
  460. $sum += (int)$task->fmqty;
  461. if ((int)$task->fmqty > $amount) $maxIndex = $i;
  462. }
  463. if ($sum < $amount) return []; //上架数大于入库数
  464. $result = $storageService->getMatch($nums, $amount);
  465. if (!$result) return $storageService->splitTask($tasks, $maxIndex, $amount);
  466. $arr = [];
  467. foreach ($result as $index) $arr[] = $tasks[$index];
  468. return $arr;
  469. }
  470. /**
  471. * @throws \Throwable
  472. * fulx 手持收货
  473. */
  474. public function fluxHandIn(array $info)
  475. {
  476. $lotatt = array_filter($info, function ($key) {
  477. return strpos($key, 'lotatt') === 0;
  478. }, ARRAY_FILTER_USE_KEY);
  479. $invlotatt = [];
  480. for ($i = 1; $i <= 8; $i++) {
  481. $invlotatt["lotatt0{$i}"] = null;
  482. }
  483. foreach ($invlotatt as $key => &$item) {
  484. foreach ($lotatt as $key1 => $item1) {
  485. if ($key === $key1) $item = $item1;
  486. }
  487. }
  488. $who = 'WAS' . (Auth::user() ? '-' . Auth::user()["name"] : '');
  489. $time = Carbon::now()->toDateTimeString();
  490. return DB::connection("oracle")->transaction(function () use ($info, $invlotatt, $who, $time) {
  491. //flux 批次号
  492. $lotNum = $this->getOrCreateLotNum($info, $invlotatt, $who, $time);
  493. if (!$lotNum) return false;
  494. //flux 创建入库事务
  495. $actTransactionLog = $this->setFluxActTransactionLog($info, $lotNum, $who, $time);
  496. if (count($actTransactionLog)==0) return false;
  497. //flux 创建上架任务
  498. $this->setFluxTskTaskListPA($info, $invlotatt, $actTransactionLog, $who, $time);
  499. //flux 完善库存余量
  500. $this->updateFluxInv($info, $lotNum, $who, $time, $actTransactionLog);
  501. //flux 更新asn_detail 和 asn_header 状态
  502. return $this->updateFluxAsn($info, $invlotatt, $time, $who);
  503. });
  504. }
  505. /**
  506. * @throws \Throwable
  507. */
  508. public function updateFluxAsn(array $info, array $invlotatt, $time, $who): bool
  509. {
  510. $db = DB::connection("oracle");
  511. $asn = OracleDOCASNHeader::query()
  512. ->withCount('asnDetails')
  513. ->with('asnDetails')
  514. ->where('asnno', $info['asnno'])
  515. ->first();
  516. if (!$asn || !$asn->asnDetails || !$asn->asn_details_count) return false;
  517. $asnDetails = $asn->asnDetails;
  518. $receiveAsn = null;
  519. foreach ($asnDetails as $asnDetail) {
  520. if ($asnDetail['asnno'] == $info['asnno'] &&
  521. $asnDetail['asnlineno'] == $info['asnlineno'] &&
  522. $asnDetail['customerid'] == $info['customerid'] &&
  523. $asnDetail['sku'] == $info['sku']) $receiveAsn = $asnDetail;
  524. }
  525. return $db->transaction(function () use ($db, $info, $receiveAsn, $invlotatt, $time, $who, $asn) {
  526. if ($receiveAsn && (int)$receiveAsn['receivedqty'] + (int)$info['amount'] < (int)$receiveAsn['expectedqty']) {
  527. //asn_detail 收货数量+已收数量<预期数量
  528. $db->update(DB::raw("UPDATE DOC_ASN_DETAILS SET receivedqty = receivedqty + ?,receivedqty_each = receivedqty_each + ?,linestatus = '30',holdrejectcode ='OK',
  529. reserve_flag ='Y',edittime = TO_DATE(?,'yyyy-mm-dd hh24:mi:ss'),receivedtime = TO_DATE(?,'yyyy-mm-dd hh24:mi:ss'),editwho = ?,
  530. lotatt01 =?,lotatt02 =?,lotatt03 =?,lotatt04 =?,lotatt05 =?,lotatt06 =?,lotatt07 =?,lotatt08=? WHERE asnno = ? and asnlineno = ?"),
  531. [(int)$info['amount'], (int)$info['amount'], $time, $time, $who, $invlotatt['lotatt01'], $invlotatt['lotatt02'], $invlotatt['lotatt03'], $invlotatt['lotatt04'],
  532. $invlotatt['lotatt05'], $invlotatt['lotatt06'], $invlotatt['lotatt07'], $invlotatt['lotatt08'], $info['asnno'], $info['asnlineno']]);
  533. //asn_header 部分收货状态
  534. $db->update(DB::raw("UPDATE DOC_ASN_HEADER SET asnstatus = '30',edittime = TO_DATE(?,'yyyy-mm-dd hh24:mi:ss'),editwho = ? WHERE asnno = ?"),
  535. [$time, $who, $info['asnno']]);
  536. } elseif ($receiveAsn && (int)$receiveAsn['receivedqty'] + (int)$info['amount'] == (int)$receiveAsn['expectedqty']) {
  537. //asn_detail 收货数量+已收数量=预期数量
  538. $db->update(DB::raw("UPDATE DOC_ASN_DETAILS SET receivedqty=receivedqty+?,receivedqty_each=receivedqty_each+?,linestatus = '40',
  539. edittime = TO_DATE(?,'yyyy-mm-dd hh24:mi:ss'),receivedtime = TO_DATE(?,'yyyy-mm-dd hh24:mi:ss'),editwho = ?,holdrejectcode='OK',
  540. reserve_flag='Y',lotatt01=?,lotatt02=?,lotatt03=?,lotatt04=?,lotatt05=?,lotatt06=?,lotatt07=?,lotatt08=? WHERE asnno = ? and asnlineno = ?"),
  541. [(int)$info['amount'], (int)$info['amount'], $time, $time, $who, $invlotatt['lotatt01'], $invlotatt['lotatt02'], $invlotatt['lotatt03'], $invlotatt['lotatt04'],
  542. $invlotatt['lotatt05'], $invlotatt['lotatt06'], $invlotatt['lotatt07'], $invlotatt['lotatt08'], $info['asnno'], $info['asnlineno']]);
  543. //当asn_detail 所有状态都为完全收货是 asn_header 状态修改为 完全收货(asnstatus=40)
  544. if (OracleDOCASNDetail::query()->where('asnno', $info['asnno'])->where('linestatus', 40)->count() == $asn->asn_details_count) {
  545. $db->update(DB::raw("UPDATE DOC_ASN_HEADER SET asnstatus = '40',edittime = TO_DATE(?,'yyyy-mm-dd hh24:mi:ss'),editwho = ? WHERE asnno = ?"),
  546. [$time, $who, $info['asnno']]);
  547. } else {
  548. //asn_header 部分收货状态
  549. $db->update(DB::raw("UPDATE DOC_ASN_HEADER SET asnstatus = '30',edittime = TO_DATE(?,'yyyy-mm-dd hh24:mi:ss'),editwho = ? WHERE asnno = ?"),
  550. [$time, $who, $info['asnno']]);
  551. }
  552. }
  553. return true;
  554. });
  555. }
  556. /**
  557. * @throws \Throwable
  558. */
  559. public function updateFluxInv(array $info, $lotNum, $who, $time, array $actTransactionLog)
  560. {
  561. $db = DB::connection("oracle");
  562. $db->transaction(function () use ($db, $info, $lotNum, $actTransactionLog, $who, $time) {
  563. //更新 inv_lot 批次 库存表
  564. $invLot = $db->selectOne(DB::raw("SELECT * FROM INV_LOT WHERE lotnum = ? AND customerid = ? AND sku = ? "), [
  565. $lotNum, $info['customerid'], $info['sku']
  566. ]);
  567. if ($invLot) $db->update(DB::raw("UPDATE INV_LOT SET qty = qty+?,edittime=?,editwho=? WHERE lotnum = ? AND customerid = ? AND sku = ?"), [
  568. (int)$info['amount'], $time, $who, $lotNum, $info['customerid'], $info['sku'],
  569. ]);
  570. else $db->insert(DB::raw("INSERT INTO INV_LOT VALUES(?,?,?,?,0,0,0,0,0,0,0,TO_DATE(?,'yyyy-mm-dd hh24:mi:ss'),?,TO_DATE(?,'yyyy-mm-dd hh24:mi:ss'),?)"), [
  571. $lotNum, $info['customerid'], $info['sku'], $info['amount'], $time, $who, $time, $who
  572. ]);
  573. //更新 inv_lot_loc_id 批次/库位/跟踪号 库存表
  574. $invLotId = $db->selectOne(DB::raw("SELECT * FROM inv_lot_loc_id WHERE lotnum = ? AND locationid = ? AND customerid = ? AND sku = ? AND traceid = ? FOR UPDATE"), [
  575. $lotNum, $actTransactionLog['location'], $actTransactionLog['customerid'], $actTransactionLog['sku'], $actTransactionLog['trackid']
  576. ]);
  577. // if ($info['location']) { //存在目标库位
  578. // $invLotIdHasPreLocation = $db->selectOne(DB::raw("SELECT * FROM inv_lot_loc_id WHERE lotnum = ? AND locationid = ? AND customerid = ? AND sku = ? AND traceid = ? FOR UPDATE"), [
  579. // $lotNum, $info['location'], $actTransactionLog['customerid'], $actTransactionLog['sku'], $actTransactionLog['trackid']
  580. // ]);
  581. //
  582. // if ($invLotIdHasPreLocation) $db->update(DB::raw("UPDATE inv_lot_loc_id SET qtypa = qtypa+?,edittime=?,editwho=? WHERE lotnum = ? AND locationid = ? AND traceid = ?"), [
  583. // (int)$info['amount'], $time, $who, $lotNum, $info['location'], $actTransactionLog['trackid']
  584. // ]);
  585. // else $db->insert(DB::raw("INSERT INTO inv_lot_loc_id VALUES(?,?,?,?,?,?,0,0,0,0,0,0,TO_DATE(?,'yyyy-mm-dd hh24:mi:ss'),?,TO_DATE(?,'yyyy-mm-dd hh24:mi:ss'),?,0,0,0,0,0,'*',?,null)"), [
  586. // $lotNum, $info['location'], $actTransactionLog['trackid'], $actTransactionLog['customerid'], $actTransactionLog['sku'], 0, $time, $who, $time, $who, (int)$info['amount']
  587. // ]);
  588. //
  589. // if ($invLotId){
  590. // $db->update(DB::raw("UPDATE inv_lot_loc_id SET qty = qty+?,qtymvout = qtymvout+?,edittime=?,editwho=? WHERE lotnum = ? AND locationid = ? AND traceid = ?"), [
  591. // (int)$info['amount'], (int)$info['amount'], $time, $who, $lotNum, $actTransactionLog['location'], $actTransactionLog['trackid']
  592. // ]);
  593. // } else {
  594. // $db->insert(DB::raw("INSERT INTO inv_lot_loc_id VALUES(?,?,?,?,?,?,0,0,0,0,?,0,TO_DATE(?,'yyyy-mm-dd hh24:mi:ss'),?,TO_DATE(?,'yyyy-mm-dd hh24:mi:ss'),?,0,0,0,0,0,'*',0,null)"), [
  595. // $lotNum, $actTransactionLog['location'], $actTransactionLog['trackid'], $actTransactionLog['customerid'], $actTransactionLog['sku'], (int)$info['amount'], (int)$info['amount'],
  596. // $time, $who, $time, $who,
  597. // ]);
  598. // }
  599. //
  600. // }
  601. if ($invLotId) $db->update(DB::raw("UPDATE inv_lot_loc_id SET qty = qty+?,qtymvout = qtymvout+?,edittime=?,editwho=? WHERE lotnum = ? AND locationid = ? AND traceid = ?"), [
  602. (int)$info['amount'],(int)$info['amount'], $time, $who, $lotNum, $actTransactionLog['location'], $actTransactionLog['trackid']
  603. ]);
  604. else $db->insert(DB::raw("INSERT INTO inv_lot_loc_id VALUES(?,?,?,?,?,?,0,0,0,0,?,0,TO_DATE(?,'yyyy-mm-dd hh24:mi:ss'),?,TO_DATE(?,'yyyy-mm-dd hh24:mi:ss'),?,0,0,0,0,0,'*',0,null)"), [
  605. $lotNum, $actTransactionLog['location'], $actTransactionLog['trackid'], $actTransactionLog['customerid'], $actTransactionLog['sku'], (int)$info['amount'], (int)$info['amount'], $time, $who, $time, $who,
  606. ]);
  607. });
  608. }
  609. /**
  610. * @throws \Throwable
  611. */
  612. public function setFluxTskTaskListPA(array $info, array $invlotatt, $actTransactionLog, $who, $time)
  613. {
  614. $db = DB::connection("oracle");
  615. $db->transaction(function () use ($db, $info, $invlotatt, $actTransactionLog, $who, $time) {
  616. $sql = <<<sql
  617. INSERT INTO TSK_TASKLISTS VALUES(?,'1','PA',?,?,'ASN',?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,null,null,?,?,?,?,?,?,?,?,null,null,null,null,
  618. 0,0,0,0,null,?,null,null,null,?,TO_DATE(?,'yyyy-mm-dd hh24:mi:ss'),null,null,?,TO_DATE(?,'yyyy-mm-dd hh24:mi:ss'),?,TO_DATE(?,'yyyy-mm-dd hh24:mi:ss'),'N',null,null,
  619. ?,?,?,'N',null,?,'*',null,null,null,'N',null,null)
  620. sql;
  621. $db->insert(DB::raw($sql), [
  622. $actTransactionLog['tsid'], $actTransactionLog['customerid'], $actTransactionLog['sku'], $actTransactionLog['docno'], $actTransactionLog['doclineno'],
  623. $actTransactionLog['lotNum'], $actTransactionLog['packid'], 'EA', $info['amount'], $info['amount'], $actTransactionLog['location'], $actTransactionLog['location'],
  624. $actTransactionLog['trackid'], $actTransactionLog['lotNum'], $actTransactionLog['packid'], 'EA', $info['amount'], $info['amount'],
  625. $info['location'], $info['location'], $actTransactionLog['trackid'], '00', 'Putaway Task', '3', $invlotatt['lotatt01'], $invlotatt['lotatt02'], $invlotatt['lotatt03'], $invlotatt['lotatt04'],
  626. $invlotatt['lotatt05'], $invlotatt['lotatt06'], $invlotatt['lotatt07'], $invlotatt['lotatt08'], $actTransactionLog['trid'], $who, $time, null, null, null, null,
  627. $actTransactionLog['userdefine1'], $actTransactionLog['userdefine2'], $actTransactionLog['userdefine3'], $actTransactionLog['warehouseid']
  628. ]);
  629. });
  630. }
  631. /**
  632. * @param array $info
  633. * @param $lotNum
  634. * @param $who
  635. * @param $time
  636. * @return mixed
  637. * @throws \Throwable
  638. * 创建入库事务
  639. */
  640. public function setFluxActTransactionLog(array $info, $lotNum, $who, $time)
  641. {
  642. $db = DB::connection("oracle");
  643. return $db->transaction(function () use ($db, $info, $lotNum, $time, $who) {
  644. if ($info['trackNumber']) $trackNumber = $info['trackNumber'];
  645. else $trackNumber = substr(md5($time), 0, 30);
  646. $asnHeader = OracleDOCASNHeader::query()->where('asnno', $info['asnno'])->first();
  647. $asnDetail = OracleDOCASNDetail::query()->where('asnno', $info['asnno'])
  648. ->where('asnlineno',$info['asnlineno'])->where('sku', $info['sku'])->first();
  649. //添加超收判断
  650. $actTransactionLogQty=OracleActTransactionLog::query()->where('docno',$info['asnno'])
  651. ->where('doclineno',$info['asnlineno'])->where('fmsku', $info['sku'])->count('fmqty');
  652. if ((int)($info['amount']+$actTransactionLogQty)>(int)$asnDetail['expectedqty'])return [];
  653. $sql = <<<sql
  654. INSERT INTO ACT_TRANSACTION_LOG VALUES(?,'IN',?,?,?,?,'ASN',?,?,?,?,?,?,?,?,TO_DATE(?,'yyyy-mm-dd hh24:mi:ss'),?,
  655. TO_DATE(?,'yyyy-mm-dd hh24:mi:ss'),?,0,0,0,0,TO_DATE(?,'yyyy-mm-dd hh24:mi:ss'),?,?,null,null,null,?,?,?,?,?,?,?,?,
  656. ?,?,?,?,'1','Y',null,?,?,?,?,null,null,?,null,null)
  657. sql;
  658. list($trid, $max) = app('StorageService')->getTrNumber();
  659. list($tsid, $max) = $this->getTsNum();
  660. $db->insert(DB::raw($sql), [
  661. $trid, $asnDetail->customerid, $asnDetail->sku,
  662. $asnDetail->asnno, $asnDetail->asnlineno, $lotNum, $asnDetail->receivinglocation, '*', $asnDetail->packid, 'EA', $info['amount'], $info['amount'], '99', $time, $who,
  663. $time, $who, $time, $asnDetail->customerid, $asnDetail->sku, $trackNumber, $asnDetail->receivinglocation, $who, $asnDetail->packid, 'EA', $info['amount'], $info['amount'], $lotNum,
  664. '*', '0', 'N', $tsid, substr($asnDetail->receivinglocation, -4), $asnHeader->userdefine1, $asnHeader->userdefine2,
  665. $asnHeader->userdefine3, 'O'
  666. ]);
  667. app('StorageService')->setTrNumber();
  668. $this->setTsNum();
  669. $actTransactionLog = [
  670. 'trid' => $trid, 'docno' => $asnDetail->asnno, 'customerid' => $asnDetail->customerid, 'sku' => $asnDetail->sku, 'doclineno' => $asnDetail->asnlineno, 'lotNum' => $lotNum, 'location' => $asnDetail->receivinglocation,
  671. 'packid' => $asnDetail->packid, 'tsid' => $tsid, 'warehouseid' => substr($asnDetail->receivinglocation, -4), 'userdefine1' => $asnHeader->userdefine1, 'userdefine2' => $asnHeader->userdefine2,
  672. 'userdefine3' => $asnHeader->userdefine3, 'trackid' => $trackNumber
  673. ];
  674. return $actTransactionLog;
  675. });
  676. }
  677. /**
  678. * @param array $info
  679. * @return mixed
  680. * @throws \Throwable
  681. * 或去flux 批次号
  682. */
  683. public function getOrCreateLotNum(array $info, array $invlotatt, $who, $time)
  684. {
  685. $invlotatt['customerid'] = $info['customerid'];
  686. $invlotatt['sku'] = $info['sku'];
  687. //根据批次规则查询或新建批次
  688. $lotnum = OracleInvLotAtt::query()->where($invlotatt)->value('lotnum');
  689. if ($lotnum) return $lotnum;
  690. $db = DB::connection("oracle");
  691. list($num, $max) = $this->getLtNum();
  692. return $db->transaction(function () use ($db, $info, $invlotatt, $num, $who, $time) {
  693. $sql = <<<sql
  694. INSERT INTO INV_LOT_ATT VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,TO_DATE(?,'yyyy-mm-dd hh24:mi:ss'),?,
  695. TO_DATE(?,'yyyy-mm-dd hh24:mi:ss'),?,TO_DATE(?,'yyyy-mm-dd hh24:mi:ss'),?)
  696. sql;
  697. $db->insert(DB::raw($sql), [
  698. $num, $info['customerid'], $info['sku'], $invlotatt['lotatt01'], $invlotatt['lotatt02'], $invlotatt['lotatt03'], $invlotatt['lotatt04'],
  699. $invlotatt['lotatt05'], $invlotatt['lotatt06'], $invlotatt['lotatt07'], $invlotatt['lotatt08'], null, null, null, null, $time, $who, $time, $who, $time, null
  700. ]);
  701. $this->setLtNum();
  702. return $num;
  703. });
  704. }
  705. /**
  706. * 获取批次号
  707. * @return array
  708. */
  709. private function getLtNum(): array
  710. {
  711. $val = ValueStore::query()->select("value")->where("name", "flux_lt_number")->lockForUpdate()->first();
  712. if (!$val) $val = ValueStore::query()->create(["name" => "flux_lt_number", "value" => '0']);
  713. $max = $val->value + 1;
  714. $number = sprintf("%07d", $max);
  715. return array('WLT' . $number, $max);
  716. }
  717. /**
  718. * 设置批次号
  719. */
  720. private function setLtNum()
  721. {
  722. ValueStore::query()
  723. ->select("value")
  724. ->where("name", "flux_lt_number")
  725. ->update(["value" => DB::raw("value+1")]);
  726. }
  727. /**
  728. * 获取批次号
  729. * @return array
  730. */
  731. private function getTsNum(): array
  732. {
  733. $val = ValueStore::query()->select("value")->where("name", "flux_ts_number")->lockForUpdate()->first();
  734. if (!$val) $val = ValueStore::query()->create(["name" => "flux_ts_number", "value" => '0']);
  735. $max = $val->value + 1;
  736. $number = sprintf("%07d", $max);
  737. return array('WTS' . $number, $max);
  738. }
  739. /**
  740. * 设置批次号
  741. */
  742. private function setTsNum()
  743. {
  744. ValueStore::query()
  745. ->select("value")
  746. ->where("name", "flux_ts_number")
  747. ->update(["value" => DB::raw("value+1")]);
  748. }
  749. /**
  750. * @param $param
  751. * @return array
  752. * 获取库存信息
  753. */
  754. public function getInventoryInfos($param): array
  755. {
  756. $sql = <<<sql
  757. select BAS_SKU.SKU,INV_LOT_LOC_ID.CUSTOMERID,BAS_SKU.ALTERNATE_SKU1,INV_LOT_LOC_ID.LOCATIONID,INV_LOT_ATT.LOTATT05,INV_LOT_ATT.LOTATT08,
  758. INV_LOT_ATT.LOTATT01,INV_LOT_ATT.LOTATT02,INV_LOT_ATT.LOTATT03,INV_LOT_ATT.LOTATT04,
  759. sum(INV_LOT_LOC_ID.QTY) AS QTY from INV_LOT_LOC_ID
  760. left join BAS_SKU on INV_LOT_LOC_ID.CUSTOMERID=BAS_SKU.CUSTOMERID and INV_LOT_LOC_ID.SKU =BAS_SKU.SKU
  761. left join INV_LOT_ATT on INV_LOT_ATT.LOTNUM=INV_LOT_LOC_ID.LOTNUM where
  762. sql;
  763. if ($this->checkUserOwnerAuth($param)) { //输入条件为货主
  764. $sql .= ' INV_LOT_LOC_ID.CUSTOMERID= ?';
  765. } else if (preg_match('/^[A-Z]{1,3}[0-9]{2,3}[-][0-9]{2,3}[-][0-9]{2,3}$/', $param)) { //判断是否为库位
  766. $sql .= ' INV_LOT_LOC_ID.LOCATIONID= ?';
  767. } else {
  768. $sql .= " BAS_SKU.SKU in ( select SKU from BAS_SKU where ALTERNATE_SKU1=? union
  769. select SKU from BAS_SKU where ALTERNATE_SKU2=? union
  770. select SKU from BAS_SKU where ALTERNATE_SKU3=? union
  771. select SKU from BAS_SKU where SKU=? )";
  772. }
  773. $sql .= ' group by BAS_SKU.SKU,INV_LOT_LOC_ID.CUSTOMERID,BAS_SKU.ALTERNATE_SKU1,INV_LOT_LOC_ID.LOCATIONID,
  774. INV_LOT_ATT.LOTATT05,INV_LOT_ATT.LOTATT08,INV_LOT_ATT.LOTATT01,INV_LOT_ATT.LOTATT02,INV_LOT_ATT.LOTATT03,INV_LOT_ATT.LOTATT04';
  775. if ($this->checkUserOwnerAuth($param)){
  776. $invLots = DB::connection("oracle")->select(DB::raw($sql), [strtoupper($param)
  777. ]);
  778. }else if(preg_match('/^[A-Z]{1,3}[0-9]{2,3}[-][0-9]{2,3}[-][0-9]{2,3}$/', $param)){
  779. $invLots = DB::connection("oracle")->select(DB::raw($sql), [$param]);
  780. }else{
  781. $invLots = DB::connection("oracle")->select(DB::raw($sql), [$param,$param,$param,$param]);
  782. }
  783. if (!$invLots) return [];
  784. else return $invLots;
  785. }
  786. }