HandInStorageService.php 42 KB

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