HandInStorageService.php 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843
  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 (
  361. select SKU from BAS_SKU where ALTERNATE_SKU1='".$barCode."' union
  362. select SKU from BAS_SKU where ALTERNATE_SKU2='".$barCode."' union
  363. select SKU from BAS_SKU where ALTERNATE_SKU3='".$barCode."' union
  364. select SKU from BAS_SKU where SKU='".$barCode."' )";
  365. $sql.=' group by TSK_TASKLISTS.CustomerID, TSK_TASKLISTS.DOCNO, TSK_TASKLISTS.Sku, TSK_TASKLISTS.PlanToLotNum,
  366. TSK_TASKLISTS.PlanToID, DOC_ASN_DETAILS.SKUDESCRC, TSK_TASKLISTS.DOCLINENO) t
  367. left join DOC_ASN_DETAILS on t.DOCLINENO = DOC_ASN_DETAILS.ASNLINENO and t.DOCNO = DOC_ASN_DETAILS.ASNNO';
  368. if ($trackNumber){
  369. if ($this->checkUserOwnerAuth($trackNumber))$tasks = DB::connection("oracle")->select(DB::raw($sql), [strtoupper($trackNumber)]);
  370. else $tasks = DB::connection("oracle")->select(DB::raw($sql), [$trackNumber]);
  371. }else {$tasks = DB::connection("oracle")->select(DB::raw($sql));}
  372. if (!$tasks) return [];
  373. else return $tasks;
  374. }
  375. /**
  376. * @param $owner_code
  377. * @return bool
  378. * 判断当前用户货主权限
  379. */
  380. public function checkUserOwnerAuth($owner_code): bool
  381. {
  382. $owner_codes = app('OwnerService')->getIntersectPermitting(['code']);
  383. $owner=$owner_codes->where('code','=',strtoupper($owner_code));
  384. if ($owner->count()>0)return true;
  385. else return false;
  386. }
  387. /**
  388. * @throws \Throwable
  389. * flux手持端 上架
  390. */
  391. public function fluxHandPa(array $info, array $taskParam): bool
  392. {
  393. $tasks = $this->selectFluxTask($taskParam, $info['amount']);
  394. if (!$tasks) return false; //获取任务失败
  395. return DB::connection("oracle")->transaction(function () use ($tasks, $info) { //单体嵌套事务 回滚FLUX失败任务
  396. foreach ($tasks as $task) {
  397. $res=$this->checkExpiryPa($task,$info['location']);
  398. if ($res!==true)return $res;
  399. if (!app("StorageService")->fluxPA($task, $info['location'])) {
  400. DB::connection("oracle")->rollBack();
  401. return false; //上架失败
  402. }
  403. }
  404. return true; //上架成功
  405. });
  406. }
  407. /**
  408. * @param $task
  409. * @param $location
  410. * @return bool|int
  411. * 上架校验效期
  412. */
  413. public function checkExpiryPa($task,$location)
  414. {
  415. if (!$task->taskid)return 0;//任务id不存在
  416. if (strpos($task->taskid,'MIX') !== false)return true;//合并拣货,不校验
  417. $sql = <<<sql
  418. select instr(DESCR,'拣货') as var_IsPickingArea from BAS_Zone where ZONE=(select PutawayZone from BAS_Location where LocationID = ?)
  419. sql;
  420. $basZone = DB::connection("oracle")->selectOne(DB::raw($sql), [$location]);
  421. if ($basZone&&$basZone->var_ispickingarea>0) return true; //不是存储区,不校验
  422. $sql1 = <<<sql
  423. select SKU,LotAtt02,CustomerID from INV_LOT_ATT WHERE LOTNUM=?
  424. sql;
  425. $invLotAtt = DB::connection("oracle")->selectOne(DB::raw($sql1), [$task->fmlotnum]);
  426. $sql2 = <<<sql
  427. select count(*) as var_amountOfDecaying from INV_LOT_LOC_ID store
  428. left join BAS_Location location on store.LocationID=location.locationId
  429. left join BAS_Zone zone on zone.zone=location.PickZone
  430. left join INV_LOT_ATT attres on store.LOTNUM=attres.LOTNUM
  431. where store.SKU=?
  432. and store.CustomerID=?
  433. and store.LOTNUM!=?
  434. and attres.LotAtt02 > ?
  435. and zone.DESCR like '%拣货%'
  436. sql;
  437. $invLotLocId=DB::connection("oracle")->selectOne(DB::raw($sql2), [$invLotAtt->sku,$invLotAtt->customerid,$task->fmlotnum,$invLotAtt->lotatt02]);
  438. if ($invLotLocId&&$invLotLocId->var_amountofdecaying>0)return 1;//拣货区找到效期更新的同样货品,不能上架至存储区
  439. return true;
  440. }
  441. /**
  442. * @param $taskParam
  443. * @param $amount
  444. * @return array
  445. * 根据跟踪号,货主,sku,批次 获取任务列表 再通过数量 进行任务的重组(拆分或选定)
  446. */
  447. public function selectFluxTask($taskParam, $amount): array
  448. {
  449. /** @var StorageService $storageService */
  450. $storageService = app('StorageService');
  451. $sql = <<<sql
  452. select * from TSK_TASKLISTS where customerid = ? AND sku = ? AND plantoid = ? AND plantolotnum = ? AND TASKPROCESS = '00' AND TASKTYPE = 'PA'
  453. sql;
  454. $tasks = DB::connection("oracle")->select(DB::raw($sql), [$taskParam['customerid'], $taskParam['sku'], $taskParam['plantoid'], $taskParam['plantolotnum']]);
  455. if (!$tasks) return [];
  456. $nums = [];
  457. $sum = 0;
  458. $maxIndex = null;
  459. foreach ($tasks as $i => $task) {
  460. if ((int)$task->fmqty == $amount) return [$task];
  461. $nums[] = (int)$task->fmqty;
  462. $sum += (int)$task->fmqty;
  463. if ((int)$task->fmqty > $amount) $maxIndex = $i;
  464. }
  465. if ($sum < $amount) return []; //上架数大于入库数
  466. $result = $storageService->getMatch($nums, $amount);
  467. if (!$result) return $storageService->splitTask($tasks, $maxIndex, $amount);
  468. $arr = [];
  469. foreach ($result as $index) $arr[] = $tasks[$index];
  470. return $arr;
  471. }
  472. /**
  473. * @throws \Throwable
  474. * fulx 手持收货
  475. */
  476. public function fluxHandIn(array $info)
  477. {
  478. $lotatt = array_filter($info, function ($key) {
  479. return strpos($key, 'lotatt') === 0;
  480. }, ARRAY_FILTER_USE_KEY);
  481. $invlotatt = [];
  482. for ($i = 1; $i <= 8; $i++) {
  483. $invlotatt["lotatt0{$i}"] = null;
  484. }
  485. foreach ($invlotatt as $key => &$item) {
  486. foreach ($lotatt as $key1 => $item1) {
  487. if ($key === $key1) $item = $item1;
  488. }
  489. }
  490. $who = 'WAS' . (Auth::user() ? '-' . Auth::user()["name"] : '');
  491. $time = Carbon::now()->toDateTimeString();
  492. return DB::connection("oracle")->transaction(function () use ($info, $invlotatt, $who, $time) {
  493. //flux 批次号
  494. $lotNum = $this->getOrCreateLotNum($info, $invlotatt, $who, $time);
  495. if (!$lotNum) return false;
  496. //flux 创建入库事务
  497. $actTransactionLog = $this->setFluxActTransactionLog($info, $lotNum, $who, $time);
  498. if (count($actTransactionLog)==0) return false;
  499. //flux 创建上架任务
  500. $this->setFluxTskTaskListPA($info, $invlotatt, $actTransactionLog, $who, $time);
  501. //flux 完善库存余量
  502. $this->updateFluxInv($info, $lotNum, $who, $time, $actTransactionLog);
  503. //flux 更新asn_detail 和 asn_header 状态
  504. return $this->updateFluxAsn($info, $invlotatt, $time, $who);
  505. });
  506. }
  507. /**
  508. * @throws \Throwable
  509. */
  510. public function updateFluxAsn(array $info, array $invlotatt, $time, $who): bool
  511. {
  512. $db = DB::connection("oracle");
  513. $asn = OracleDOCASNHeader::query()
  514. ->withCount('asnDetails')
  515. ->with('asnDetails')
  516. ->where('asnno', $info['asnno'])
  517. ->first();
  518. if (!$asn || !$asn->asnDetails || !$asn->asn_details_count) return false;
  519. $asnDetails = $asn->asnDetails;
  520. $receiveAsn = null;
  521. foreach ($asnDetails as $asnDetail) {
  522. if ($asnDetail['asnno'] == $info['asnno'] &&
  523. $asnDetail['asnlineno'] == $info['asnlineno'] &&
  524. $asnDetail['customerid'] == $info['customerid'] &&
  525. $asnDetail['sku'] == $info['sku']) $receiveAsn = $asnDetail;
  526. }
  527. return $db->transaction(function () use ($db, $info, $receiveAsn, $invlotatt, $time, $who, $asn) {
  528. if ($receiveAsn && (int)$receiveAsn['receivedqty'] + (int)$info['amount'] < (int)$receiveAsn['expectedqty']) {
  529. //asn_detail 收货数量+已收数量<预期数量
  530. $db->update(DB::raw("UPDATE DOC_ASN_DETAILS SET receivedqty = receivedqty + ?,receivedqty_each = receivedqty_each + ?,linestatus = '30',holdrejectcode ='OK',
  531. reserve_flag ='Y',edittime = TO_DATE(?,'yyyy-mm-dd hh24:mi:ss'),receivedtime = TO_DATE(?,'yyyy-mm-dd hh24:mi:ss'),editwho = ?,
  532. lotatt01 =?,lotatt02 =?,lotatt03 =?,lotatt04 =?,lotatt05 =?,lotatt06 =?,lotatt07 =?,lotatt08=? WHERE asnno = ? and asnlineno = ?"),
  533. [(int)$info['amount'], (int)$info['amount'], $time, $time, $who, $invlotatt['lotatt01'], $invlotatt['lotatt02'], $invlotatt['lotatt03'], $invlotatt['lotatt04'],
  534. $invlotatt['lotatt05'], $invlotatt['lotatt06'], $invlotatt['lotatt07'], $invlotatt['lotatt08'], $info['asnno'], $info['asnlineno']]);
  535. //asn_header 部分收货状态
  536. $db->update(DB::raw("UPDATE DOC_ASN_HEADER SET asnstatus = '30',edittime = TO_DATE(?,'yyyy-mm-dd hh24:mi:ss'),editwho = ? WHERE asnno = ?"),
  537. [$time, $who, $info['asnno']]);
  538. } elseif ($receiveAsn && (int)$receiveAsn['receivedqty'] + (int)$info['amount'] == (int)$receiveAsn['expectedqty']) {
  539. //asn_detail 收货数量+已收数量=预期数量
  540. $db->update(DB::raw("UPDATE DOC_ASN_DETAILS SET receivedqty=receivedqty+?,receivedqty_each=receivedqty_each+?,linestatus = '40',
  541. edittime = TO_DATE(?,'yyyy-mm-dd hh24:mi:ss'),receivedtime = TO_DATE(?,'yyyy-mm-dd hh24:mi:ss'),editwho = ?,holdrejectcode='OK',
  542. reserve_flag='Y',lotatt01=?,lotatt02=?,lotatt03=?,lotatt04=?,lotatt05=?,lotatt06=?,lotatt07=?,lotatt08=? WHERE asnno = ? and asnlineno = ?"),
  543. [(int)$info['amount'], (int)$info['amount'], $time, $time, $who, $invlotatt['lotatt01'], $invlotatt['lotatt02'], $invlotatt['lotatt03'], $invlotatt['lotatt04'],
  544. $invlotatt['lotatt05'], $invlotatt['lotatt06'], $invlotatt['lotatt07'], $invlotatt['lotatt08'], $info['asnno'], $info['asnlineno']]);
  545. //当asn_detail 所有状态都为完全收货是 asn_header 状态修改为 完全收货(asnstatus=40)
  546. if (OracleDOCASNDetail::query()->where('asnno', $info['asnno'])->where('linestatus', 40)->count() == $asn->asn_details_count) {
  547. $db->update(DB::raw("UPDATE DOC_ASN_HEADER SET asnstatus = '40',edittime = TO_DATE(?,'yyyy-mm-dd hh24:mi:ss'),editwho = ? WHERE asnno = ?"),
  548. [$time, $who, $info['asnno']]);
  549. } else {
  550. //asn_header 部分收货状态
  551. $db->update(DB::raw("UPDATE DOC_ASN_HEADER SET asnstatus = '30',edittime = TO_DATE(?,'yyyy-mm-dd hh24:mi:ss'),editwho = ? WHERE asnno = ?"),
  552. [$time, $who, $info['asnno']]);
  553. }
  554. }
  555. return true;
  556. });
  557. }
  558. /**
  559. * @throws \Throwable
  560. */
  561. public function updateFluxInv(array $info, $lotNum, $who, $time, array $actTransactionLog)
  562. {
  563. $db = DB::connection("oracle");
  564. $db->transaction(function () use ($db, $info, $lotNum, $actTransactionLog, $who, $time) {
  565. //更新 inv_lot 批次 库存表
  566. $invLot = $db->selectOne(DB::raw("SELECT * FROM INV_LOT WHERE lotnum = ? AND customerid = ? AND sku = ? "), [
  567. $lotNum, $info['customerid'], $info['sku']
  568. ]);
  569. if ($invLot) $db->update(DB::raw("UPDATE INV_LOT SET qty = qty+?,edittime=?,editwho=? WHERE lotnum = ? AND customerid = ? AND sku = ?"), [
  570. (int)$info['amount'], $time, $who, $lotNum, $info['customerid'], $info['sku'],
  571. ]);
  572. 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'),?)"), [
  573. $lotNum, $info['customerid'], $info['sku'], $info['amount'], $time, $who, $time, $who
  574. ]);
  575. //更新 inv_lot_loc_id 批次/库位/跟踪号 库存表
  576. $invLotId = $db->selectOne(DB::raw("SELECT * FROM inv_lot_loc_id WHERE lotnum = ? AND locationid = ? AND customerid = ? AND sku = ? AND traceid = ? FOR UPDATE"), [
  577. $lotNum, $actTransactionLog['location'], $actTransactionLog['customerid'], $actTransactionLog['sku'], $actTransactionLog['trackid']
  578. ]);
  579. // if ($info['location']) { //存在目标库位
  580. // $invLotIdHasPreLocation = $db->selectOne(DB::raw("SELECT * FROM inv_lot_loc_id WHERE lotnum = ? AND locationid = ? AND customerid = ? AND sku = ? AND traceid = ? FOR UPDATE"), [
  581. // $lotNum, $info['location'], $actTransactionLog['customerid'], $actTransactionLog['sku'], $actTransactionLog['trackid']
  582. // ]);
  583. //
  584. // if ($invLotIdHasPreLocation) $db->update(DB::raw("UPDATE inv_lot_loc_id SET qtypa = qtypa+?,edittime=?,editwho=? WHERE lotnum = ? AND locationid = ? AND traceid = ?"), [
  585. // (int)$info['amount'], $time, $who, $lotNum, $info['location'], $actTransactionLog['trackid']
  586. // ]);
  587. // 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)"), [
  588. // $lotNum, $info['location'], $actTransactionLog['trackid'], $actTransactionLog['customerid'], $actTransactionLog['sku'], 0, $time, $who, $time, $who, (int)$info['amount']
  589. // ]);
  590. //
  591. // if ($invLotId){
  592. // $db->update(DB::raw("UPDATE inv_lot_loc_id SET qty = qty+?,qtymvout = qtymvout+?,edittime=?,editwho=? WHERE lotnum = ? AND locationid = ? AND traceid = ?"), [
  593. // (int)$info['amount'], (int)$info['amount'], $time, $who, $lotNum, $actTransactionLog['location'], $actTransactionLog['trackid']
  594. // ]);
  595. // } else {
  596. // $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)"), [
  597. // $lotNum, $actTransactionLog['location'], $actTransactionLog['trackid'], $actTransactionLog['customerid'], $actTransactionLog['sku'], (int)$info['amount'], (int)$info['amount'],
  598. // $time, $who, $time, $who,
  599. // ]);
  600. // }
  601. //
  602. // }
  603. if ($invLotId) $db->update(DB::raw("UPDATE inv_lot_loc_id SET qty = qty+?,qtymvout = qtymvout+?,edittime=?,editwho=? WHERE lotnum = ? AND locationid = ? AND traceid = ?"), [
  604. (int)$info['amount'],(int)$info['amount'], $time, $who, $lotNum, $actTransactionLog['location'], $actTransactionLog['trackid']
  605. ]);
  606. 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)"), [
  607. $lotNum, $actTransactionLog['location'], $actTransactionLog['trackid'], $actTransactionLog['customerid'], $actTransactionLog['sku'], (int)$info['amount'], (int)$info['amount'], $time, $who, $time, $who,
  608. ]);
  609. });
  610. }
  611. /**
  612. * @throws \Throwable
  613. */
  614. public function setFluxTskTaskListPA(array $info, array $invlotatt, $actTransactionLog, $who, $time)
  615. {
  616. $db = DB::connection("oracle");
  617. $db->transaction(function () use ($db, $info, $invlotatt, $actTransactionLog, $who, $time) {
  618. $sql = <<<sql
  619. INSERT INTO TSK_TASKLISTS VALUES(?,'1','PA',?,?,'ASN',?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,null,null,?,?,?,?,?,?,?,?,null,null,null,null,
  620. 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,
  621. ?,?,?,'N',null,?,'*',null,null,null,'N',null,null)
  622. sql;
  623. $db->insert(DB::raw($sql), [
  624. $actTransactionLog['tsid'], $actTransactionLog['customerid'], $actTransactionLog['sku'], $actTransactionLog['docno'], $actTransactionLog['doclineno'],
  625. $actTransactionLog['lotNum'], $actTransactionLog['packid'], 'EA', $info['amount'], $info['amount'], $actTransactionLog['location'], $actTransactionLog['location'],
  626. $actTransactionLog['trackid'], $actTransactionLog['lotNum'], $actTransactionLog['packid'], 'EA', $info['amount'], $info['amount'],
  627. $info['location'], $info['location'], $actTransactionLog['trackid'], '00', 'Putaway Task', '3', $invlotatt['lotatt01'], $invlotatt['lotatt02'], $invlotatt['lotatt03'], $invlotatt['lotatt04'],
  628. $invlotatt['lotatt05'], $invlotatt['lotatt06'], $invlotatt['lotatt07'], $invlotatt['lotatt08'], $actTransactionLog['trid'], $who, $time, null, null, null, null,
  629. $actTransactionLog['userdefine1'], $actTransactionLog['userdefine2'], $actTransactionLog['userdefine3'], $actTransactionLog['warehouseid']
  630. ]);
  631. });
  632. }
  633. /**
  634. * @param array $info
  635. * @param $lotNum
  636. * @param $who
  637. * @param $time
  638. * @return mixed
  639. * @throws \Throwable
  640. * 创建入库事务
  641. */
  642. public function setFluxActTransactionLog(array $info, $lotNum, $who, $time)
  643. {
  644. $db = DB::connection("oracle");
  645. return $db->transaction(function () use ($db, $info, $lotNum, $time, $who) {
  646. if ($info['trackNumber']) $trackNumber = $info['trackNumber'];
  647. else $trackNumber = substr(md5($time), 0, 30);
  648. $asnHeader = OracleDOCASNHeader::query()->where('asnno', $info['asnno'])->first();
  649. $asnDetail = OracleDOCASNDetail::query()->where('asnno', $info['asnno'])
  650. ->where('asnlineno',$info['asnlineno'])->where('sku', $info['sku'])->first();
  651. //添加超收判断
  652. $actTransactionLogQty=OracleActTransactionLog::query()->where('docno',$info['asnno'])
  653. ->where('doclineno',$info['asnlineno'])->where('fmsku', $info['sku'])->count('fmqty');
  654. if ((int)($info['amount']+$actTransactionLogQty)>(int)$asnDetail['expectedqty'])return [];
  655. $sql = <<<sql
  656. INSERT INTO ACT_TRANSACTION_LOG VALUES(?,'IN',?,?,?,?,'ASN',?,?,?,?,?,?,?,?,TO_DATE(?,'yyyy-mm-dd hh24:mi:ss'),?,
  657. TO_DATE(?,'yyyy-mm-dd hh24:mi:ss'),?,0,0,0,0,TO_DATE(?,'yyyy-mm-dd hh24:mi:ss'),?,?,null,null,null,?,?,?,?,?,?,?,?,
  658. ?,?,?,?,'1','Y',null,?,?,?,?,null,null,?,null,null)
  659. sql;
  660. list($trid, $max) = app('StorageService')->getTrNumber();
  661. list($tsid, $max) = $this->getTsNum();
  662. $db->insert(DB::raw($sql), [
  663. $trid, $asnDetail->customerid, $asnDetail->sku,
  664. $asnDetail->asnno, $asnDetail->asnlineno, $lotNum, $asnDetail->receivinglocation, '*', $asnDetail->packid, 'EA', $info['amount'], $info['amount'], '99', $time, $who,
  665. $time, $who, $time, $asnDetail->customerid, $asnDetail->sku, $trackNumber, $asnDetail->receivinglocation, $who, $asnDetail->packid, 'EA', $info['amount'], $info['amount'], $lotNum,
  666. '*', '0', 'N', $tsid, substr($asnDetail->receivinglocation, -4), $asnHeader->userdefine1, $asnHeader->userdefine2,
  667. $asnHeader->userdefine3, 'O'
  668. ]);
  669. app('StorageService')->setTrNumber();
  670. $this->setTsNum();
  671. $actTransactionLog = [
  672. 'trid' => $trid, 'docno' => $asnDetail->asnno, 'customerid' => $asnDetail->customerid, 'sku' => $asnDetail->sku, 'doclineno' => $asnDetail->asnlineno, 'lotNum' => $lotNum, 'location' => $asnDetail->receivinglocation,
  673. 'packid' => $asnDetail->packid, 'tsid' => $tsid, 'warehouseid' => substr($asnDetail->receivinglocation, -4), 'userdefine1' => $asnHeader->userdefine1, 'userdefine2' => $asnHeader->userdefine2,
  674. 'userdefine3' => $asnHeader->userdefine3, 'trackid' => $trackNumber
  675. ];
  676. return $actTransactionLog;
  677. });
  678. }
  679. /**
  680. * @param array $info
  681. * @return mixed
  682. * @throws \Throwable
  683. * 或去flux 批次号
  684. */
  685. public function getOrCreateLotNum(array $info, array $invlotatt, $who, $time)
  686. {
  687. $invlotatt['customerid'] = $info['customerid'];
  688. $invlotatt['sku'] = $info['sku'];
  689. //根据批次规则查询或新建批次
  690. $lotnum = OracleInvLotAtt::query()->where($invlotatt)->value('lotnum');
  691. if ($lotnum) return $lotnum;
  692. $db = DB::connection("oracle");
  693. list($num, $max) = $this->getLtNum();
  694. return $db->transaction(function () use ($db, $info, $invlotatt, $num, $who, $time) {
  695. $sql = <<<sql
  696. INSERT INTO INV_LOT_ATT VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,TO_DATE(?,'yyyy-mm-dd hh24:mi:ss'),?,
  697. TO_DATE(?,'yyyy-mm-dd hh24:mi:ss'),?,TO_DATE(?,'yyyy-mm-dd hh24:mi:ss'),?)
  698. sql;
  699. $db->insert(DB::raw($sql), [
  700. $num, $info['customerid'], $info['sku'], $invlotatt['lotatt01'], $invlotatt['lotatt02'], $invlotatt['lotatt03'], $invlotatt['lotatt04'],
  701. $invlotatt['lotatt05'], $invlotatt['lotatt06'], $invlotatt['lotatt07'], $invlotatt['lotatt08'], null, null, null, null, $time, $who, $time, $who, $time, null
  702. ]);
  703. $this->setLtNum();
  704. return $num;
  705. });
  706. }
  707. /**
  708. * 获取批次号
  709. * @return array
  710. */
  711. private function getLtNum(): array
  712. {
  713. $val = ValueStore::query()->select("value")->where("name", "flux_lt_number")->lockForUpdate()->first();
  714. if (!$val) $val = ValueStore::query()->create(["name" => "flux_lt_number", "value" => '0']);
  715. $max = $val->value + 1;
  716. $number = sprintf("%07d", $max);
  717. return array('WLT' . $number, $max);
  718. }
  719. /**
  720. * 设置批次号
  721. */
  722. private function setLtNum()
  723. {
  724. ValueStore::query()
  725. ->select("value")
  726. ->where("name", "flux_lt_number")
  727. ->update(["value" => DB::raw("value+1")]);
  728. }
  729. /**
  730. * 获取批次号
  731. * @return array
  732. */
  733. private function getTsNum(): array
  734. {
  735. $val = ValueStore::query()->select("value")->where("name", "flux_ts_number")->lockForUpdate()->first();
  736. if (!$val) $val = ValueStore::query()->create(["name" => "flux_ts_number", "value" => '0']);
  737. $max = $val->value + 1;
  738. $number = sprintf("%07d", $max);
  739. return array('WTS' . $number, $max);
  740. }
  741. /**
  742. * 设置批次号
  743. */
  744. private function setTsNum()
  745. {
  746. ValueStore::query()
  747. ->select("value")
  748. ->where("name", "flux_ts_number")
  749. ->update(["value" => DB::raw("value+1")]);
  750. }
  751. /**
  752. * @param $param
  753. * @return array
  754. * 获取库存信息
  755. */
  756. public function getInventoryInfos($param): array
  757. {
  758. $sql = <<<sql
  759. 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,
  760. INV_LOT_ATT.LOTATT01,INV_LOT_ATT.LOTATT02,INV_LOT_ATT.LOTATT03,INV_LOT_ATT.LOTATT04,
  761. sum(INV_LOT_LOC_ID.QTY) AS QTY from INV_LOT_LOC_ID
  762. left join BAS_SKU on INV_LOT_LOC_ID.CUSTOMERID=BAS_SKU.CUSTOMERID and INV_LOT_LOC_ID.SKU =BAS_SKU.SKU
  763. left join INV_LOT_ATT on INV_LOT_ATT.LOTNUM=INV_LOT_LOC_ID.LOTNUM where
  764. sql;
  765. if ($this->checkUserOwnerAuth($param)) { //输入条件为货主
  766. $sql .= ' INV_LOT_LOC_ID.CUSTOMERID= ?';
  767. } else if (preg_match('/^[A-Z]{1,3}[0-9]{2,3}[-][0-9]{2,3}[-][0-9]{2,3}$/', $param)) { //判断是否为库位
  768. $sql .= ' INV_LOT_LOC_ID.LOCATIONID= ?';
  769. } else {
  770. $sql .= " BAS_SKU.SKU in ( select SKU from BAS_SKU where ALTERNATE_SKU1=? union
  771. select SKU from BAS_SKU where ALTERNATE_SKU2=? union
  772. select SKU from BAS_SKU where ALTERNATE_SKU3=? union
  773. select SKU from BAS_SKU where SKU=? )";
  774. }
  775. $sql .= ' group by BAS_SKU.SKU,INV_LOT_LOC_ID.CUSTOMERID,BAS_SKU.ALTERNATE_SKU1,INV_LOT_LOC_ID.LOCATIONID,
  776. INV_LOT_ATT.LOTATT05,INV_LOT_ATT.LOTATT08,INV_LOT_ATT.LOTATT01,INV_LOT_ATT.LOTATT02,INV_LOT_ATT.LOTATT03,INV_LOT_ATT.LOTATT04';
  777. if ($this->checkUserOwnerAuth($param)){
  778. $invLots = DB::connection("oracle")->select(DB::raw($sql), [strtoupper($param)
  779. ]);
  780. }else if(preg_match('/^[A-Z]{1,3}[0-9]{2,3}[-][0-9]{2,3}[-][0-9]{2,3}$/', $param)){
  781. $invLots = DB::connection("oracle")->select(DB::raw($sql), [$param]);
  782. }else{
  783. $invLots = DB::connection("oracle")->select(DB::raw($sql), [$param,$param,$param,$param]);
  784. }
  785. if (!$invLots) return [];
  786. else return $invLots;
  787. }
  788. }