StorageController.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Commodity;
  4. use App\CommodityMaterialBoxModel;
  5. use App\Components\AsyncResponse;
  6. use App\MaterialBox;
  7. use App\MaterialBoxCommodity;
  8. use App\MaterialBoxModel;
  9. use App\Owner;
  10. use App\Services\LogService;
  11. use App\Station;
  12. use App\StationTask;
  13. use App\StationTaskMaterialBox;
  14. use App\Store;
  15. use App\StoreItem;
  16. use App\TaskTransaction;
  17. use Illuminate\Database\Eloquent\Builder;
  18. use Illuminate\Foundation\Auth\AuthenticatesUsers;
  19. use Illuminate\Support\Collection;
  20. use Illuminate\Support\Facades\Auth;
  21. use Illuminate\Support\Facades\Cache;
  22. use Illuminate\Support\Facades\DB;
  23. use Illuminate\Support\Facades\Gate;
  24. use Illuminate\Support\Facades\Validator;
  25. class StorageController extends Controller
  26. {
  27. use AsyncResponse;
  28. use AuthenticatesUsers;
  29. public function putShelf()
  30. {
  31. $this->error("停用缓存架上架,联系管理员开启");
  32. $this->gate("入库管理-入库-缓存架入库");
  33. $asn = \request("asn");
  34. $ide = \request("ide");
  35. $barCode = \request("barCode");
  36. $amount = (int)\request("amount");
  37. //check info
  38. if (!$asn || !$ide || !$barCode || !$amount)$this->error("信息不完整");
  39. $box = MaterialBox::query()->with("station")->where("code",$ide)->first();
  40. if (!$box)$this->error("WAS无此料箱");
  41. if (!$box->station)$this->error("WAS无此库位信息");
  42. if (!app("StationService")->isCacheShelfLocation($box->station))$this->error("非缓存架库位");
  43. $fromLocation = $box->station->code; //源库位
  44. $item = StoreItem::query()->whereHas("store",function (Builder $query){
  45. $query->where("asn_code",request("asn"));
  46. })->whereHas("commodity",function (Builder $query)use($barCode){
  47. $query->whereHas("barcodes",function (Builder $query)use($barCode){
  48. $query->where("code",$barCode);
  49. });
  50. })->first();
  51. if (!$item)$this->error("WAS无此ASN单信息");
  52. //get flux
  53. $tasks = app("StorageService")->getFluxTask($asn,$barCode,$amount);
  54. if (!$tasks)$this->error("该单无上架任务或不存在");
  55. //此处嵌套三层事务 以最高层级为准
  56. DB::beginTransaction(); //总体事务 回滚WAS错误操作
  57. try{
  58. //库存记录
  59. if (!app("StorageService")->enterWarehouse( $box->id, $item->commodity_id, $amount, $box->material_box_model_id))$this->error("库存异常");
  60. DB::connection("oracle")->transaction(function ()use($tasks,$ide){ //单体嵌套事务 回滚FLUX失败任务
  61. foreach ($tasks as $task)if (!app("StorageService")->fluxPA($task,$ide)){
  62. DB::connection("oracle")->rollBack();
  63. $this->error("FLUX上架失败");
  64. };
  65. });
  66. DB::commit();
  67. }catch (\Exception $e){
  68. DB::rollBack();
  69. $this->error($e->getMessage());
  70. }
  71. //亮灯
  72. app("CacheShelfService")->lightUp($fromLocation,'1','0',["detail01"=>$ide,"qty01"=>$amount]);
  73. $maximum = app("CommodityMaterialBoxModelService")->getMaximum($box->material_box_model_id,$item->commodity_id);
  74. $this->success(["model" => $box->material_box_model_id,"commodity" => $item->commodity_id, "maximum" => $maximum]);
  75. }
  76. public function setMaximum()
  77. {
  78. app("CommodityMaterialBoxModelService")->setMaximum(request("model"),request("commodity"),request("maximum"));
  79. $this->success();
  80. }
  81. /**
  82. * 检查最大限值并返回
  83. *
  84. */
  85. public function checkMaximum()
  86. {
  87. $lotNum = request("lotNum");
  88. $sql = <<<SQL
  89. SELECT * FROM INV_LOT_ATT WHERE LOTNUM = '{$lotNum}'
  90. SQL;
  91. $lot = DB::connection("oracle")->selectOne(DB::raw($sql));
  92. if (!$lot)$this->error("批次丢失");
  93. $commodity = Commodity::query()->whereHas("owner",function ($query)use($lot){
  94. $query->where("code",$lot->customerid);
  95. })->where("sku",$lot->sku)->first();
  96. if (!$commodity)$this->error("WAS无此商品信息");
  97. $models = CommodityMaterialBoxModel::query()->where("commodity_id",$commodity->id)->get();
  98. if ($models->count()==0)$this->success(["material_box_model_id"=>null,"commodity_id"=>$commodity->id]);
  99. $map = [];
  100. foreach ($models as $model)$map[$model->material_box_model_id] = $model;
  101. $models = app("MaterialBoxModelService")->getModelSortedByOwner($commodity->owner_id);
  102. $m = null;
  103. foreach ($models as $model){
  104. if (!isset($map[$model->id]))continue;
  105. $model->maximum = $map[$model->id]->maximum;
  106. $boxCodes = app("MaterialBoxService")->getModelAvailableBox($model->id,true);
  107. if (!$boxCodes)continue;
  108. if (!$m)$m = $model;
  109. $sql = <<<SQL
  110. SELECT LOCATIONID,({$model->maximum}-QTY) AS QTY FROM INV_LOT_LOC_ID WHERE LOTNUM = '{$lotNum}'
  111. AND LOCATIONID IN ({$boxCodes}) AND TRACEID = '*' AND {$model->maximum}-QTY > 0 ORDER BY (CASE QTY WHEN 0 THEN 1 ELSE 0 END),{$model->maximum}-QTY
  112. SQL;
  113. $res = DB::connection("oracle")->selectOne(DB::raw($sql));
  114. if ($res){
  115. $m = $model;
  116. $m->maximum = $res->qty;
  117. $m->location = $res->locationid;
  118. break;
  119. }
  120. }
  121. if (!$m)$this->error("没有可用料箱");
  122. $this->success(["need"=>$m->maximum,"material_box_model_id"=>$m->id,"commodity_id"=>$commodity->id,"location"=>$m->locationid]);
  123. }
  124. /**
  125. * 检查ASN可上架总数
  126. */
  127. public function checkAsnAmount()
  128. {
  129. $sql = <<<sql
  130. SELECT sum(fmqty) amount FROM DOC_ASN_DETAILS LEFT JOIN BAS_SKU ON DOC_ASN_DETAILS.CUSTOMERID = BAS_SKU.CUSTOMERID AND DOC_ASN_DETAILS.SKU = BAS_SKU.SKU
  131. LEFT JOIN TSK_TASKLISTS ON DOC_ASN_DETAILS.ASNNO = TSK_TASKLISTS.DOCNO AND DOC_ASN_DETAILS.ASNLINENO = TSK_TASKLISTS.DOCLINENO
  132. WHERE ASNNO = ? AND (ALTERNATE_SKU1 = ? OR ALTERNATE_SKU2 = ? OR ALTERNATE_SKU3 = ?)
  133. AND TASKPROCESS = '00' AND TASKTYPE = 'PA'
  134. sql;
  135. $task = DB::connection("oracle")->selectOne(DB::raw($sql),[request("asn"),request("barCode"),request("barCode"),request("barCode")]);
  136. $this->success($task->amount ?? 0);
  137. }
  138. /**
  139. * 重置缓存架指定格口
  140. */
  141. public function resetCacheShelf()
  142. {
  143. $this->gate("入库管理-入库-缓存架入库");
  144. $boxes = request("boxes");
  145. //清理任务
  146. $data = '';
  147. //剔除准备执行任务但没有真正开始执行的待定库位
  148. $occupy = Station::query()->select("id")->whereIn("code",$boxes)->where("status",1)->get();
  149. foreach ($occupy as $item){
  150. unset($boxes[array_search($item->code,$boxes)]);
  151. $data .= '“'.$item->code.'”,';
  152. }
  153. if ($occupy->count()>0){
  154. $data .= "存在任务待处理,无法调取 ";
  155. $boxes = array_values($boxes);
  156. }
  157. //剔除存在任务的库位
  158. $tasks = StationTaskMaterialBox::query()->with("station:id,code")
  159. ->whereIn("station_id",Station::query()->select("id")->whereIn("code",$boxes))
  160. ->whereNotIn("status",["完成","取消"])->get();
  161. foreach ($tasks as $task){
  162. unset($boxes[array_search($task->station->code,$boxes)]);
  163. $data .= '“'.$task->station->code.'”,';
  164. };
  165. if ($tasks->count()>0){
  166. $data .= "任务排队中,无法调取";
  167. $boxes = array_values($boxes);
  168. }
  169. //重新调取料箱
  170. $result = app("ForeignHaiRoboticsService")->paddingCacheShelf(Station::query()->whereIn("code",$boxes)->get());
  171. if ($result===null)$this->error("任务下发错误,检查日志");
  172. if ($result===false)$this->error("已无可用料箱,部分库位填充失败");
  173. $this->success(["data"=>$data,"boxes"=>$boxes]);
  174. }
  175. /**
  176. * 取得料箱
  177. */
  178. public function acquireBox()
  179. {
  180. $this->gate("入库管理-入库-半箱补货入库");
  181. $boxId = request("material_box_id");
  182. $modelId = request("material_box_model_id");
  183. if (!$modelId)$this->error("商品未设定库存上限");
  184. //获取目标库位
  185. $station = app("StationService")->getMirrorMappingLocation(request("station"));
  186. if (!$station)$this->error("未知库位");
  187. $isAvailable = app("StationService")->isAvailable($station);
  188. if (!$isAvailable)$this->error("库存被占用或存在任务未处理");
  189. $amount = app("StorageService")->checkPutAmount(request("track"),request("barCode"),request("lotNum"));
  190. if ($amount<request("amount"))$this->error("待上架数量不足,最大可上数量为{$amount}");
  191. //发起取箱任务
  192. $exe = function ($boxId)use($station,$amount){
  193. DB::beginTransaction();
  194. try{
  195. $collection = new Collection();
  196. $task = StationTask::query()->create([
  197. 'status' => "待处理",
  198. 'station_id' => $station->id,
  199. ]);
  200. $collection->add(StationTaskMaterialBox::query()->create([
  201. 'station_id' => $station->id,
  202. 'material_box_id'=>$boxId,
  203. 'status'=>"待处理",
  204. 'type' => '取',
  205. 'station_task_id' => $task->id,
  206. ]));
  207. if (!app("ForeignHaiRoboticsService")->fetchGroup($station->code,$collection,'','立架出至缓存架'))$this->error("呼叫机器人失败");
  208. //生成临时任务事务
  209. TaskTransaction::query()->create([
  210. //"doc_code" => request("asn"),
  211. "bar_code" => request("barCode"),
  212. "fm_station_id" => $station->id,
  213. "material_box_id" => $boxId,
  214. "commodity_id" => request("commodity_id"),
  215. "amount" => request("amount"),
  216. "type" => "入库",
  217. "user_id" => Auth::id(),
  218. "mark" => 1,
  219. "lot_num" => request("lotNum"),
  220. "track_num" => request("track"),
  221. ]);
  222. //亮灯
  223. app("CacheShelfService")->lightUp($station->code,'3','2');
  224. app("StationService")->locationOccupy($station->code);//占用库位
  225. Cache::forever("CACHE_SHELF_OCCUPANCY_{$station->id}",true);
  226. DB::commit();
  227. return true;
  228. }catch (\Exception $e){
  229. DB::rollBack();
  230. return false;
  231. }
  232. };
  233. //检查获取的料箱仍然可用
  234. if ($boxId && app("MaterialBoxService")->checkUsableBox($boxId))$this->success(["status"=>$exe($boxId),"amount"=>$amount-request("amount")]);
  235. $commodity = Commodity::query()->find(request("commodity_id"));
  236. if (!$commodity)$this->error("商品在WAS丢失");
  237. $models = app("MaterialBoxModelService")->getModelSortedByOwner($commodity->owner_id);
  238. $models->load(["commodity"=>function($query)use($commodity){
  239. $query->where("commodity_id",$commodity->id);
  240. }]);
  241. //获取料箱
  242. if ($boxId){
  243. $blacklist = [$boxId];
  244. $boxId = null;
  245. //料箱存在且不可用
  246. /** @var \Illuminate\Database\Eloquent\Collection $models */
  247. foreach ($models as $model){
  248. if (!$model->commodity)continue;
  249. //料箱不可用寻找新料箱
  250. $result = app("StorageService")->getMaxAvailableHalfBoxLocation($model->commodity, request("lotNum"), $blacklist);
  251. while ($result){
  252. $materialBox = MaterialBox::query()->where("code",$result->locationid)->first();
  253. //料箱可用并且数量符合本次半箱数量 跳出
  254. if ($materialBox && app("MaterialBoxService")->checkUsableBox($materialBox->id)
  255. && $result->qty>=request("amount"))$this->success(["status"=>$exe($materialBox->id),"amount"=>$amount-request("amount")]);
  256. else if ($materialBox)$blacklist[] = $materialBox->id;
  257. //否则黑名单此料箱继续查找 直至料箱为空
  258. $result = app("StorageService")->getMaxAvailableHalfBoxLocation($model->commodity, request("lotNum"), $blacklist);
  259. }
  260. }
  261. }
  262. //料箱不存在且该商品有过入库记录 拿取空箱
  263. if (!$modelId){
  264. $box = null;
  265. foreach ($models as $model){
  266. if (!$model->commodity)continue;
  267. $box = app("MaterialBoxService")->getAnEmptyBox($model);
  268. if($box)break;
  269. }
  270. }else $box = app("MaterialBoxService")->getAnEmptyBox(MaterialBoxModel::query()->find($modelId));
  271. if (!$box)$this->error("无可用料箱");
  272. $this->success(["status"=>$exe($box->id),"amount"=>$amount-request("amount")]);
  273. }
  274. /**
  275. * 溢出校正
  276. */
  277. public function overflowRevision()
  278. {
  279. $this->gate("入库管理-入库-半箱补货入库");
  280. $station = request("station");
  281. $amount = request("amount");
  282. //获取目标库位
  283. $station = app("StationService")->getMirrorMappingLocation($station);
  284. if (!$station)$this->error("未知库位");
  285. $task = TaskTransaction::query()->with("materialBox")->where("fm_station_id",$station->id)->where("amount",">",$amount)
  286. ->where("type","入库")->where("mark",1)->where("status",0)->first();
  287. if (!$task)$this->error("无任务存在");
  288. $task->update(["amount" => DB::raw("amount - {$amount}")]);
  289. $storage = MaterialBoxCommodity::query()->where("material_box_id",$task->material_box_id)
  290. ->where("commodity_id",$task->commodity_id)->first();
  291. $maximum = (($storage->amount ?? 0)+$task->amount)-$amount;
  292. CommodityMaterialBoxModel::query()->where("material_box_model_id",$task->materialBox->material_box_model_id)
  293. ->where("commodity_id",$task->commodity_id)->update(["maximum"=>$maximum]);
  294. $this->success("校正成功");
  295. }
  296. public function syncStorage()
  297. {
  298. ini_set('max_execution_time', 0);
  299. $model = MaterialBoxModel::query()->create([
  300. "code" => "common"
  301. ]);
  302. $sql = <<<sql
  303. select * from INV_LOT_LOC_ID where traceid = '*' and locationid like 'IDE%'
  304. sql;
  305. DB::beginTransaction();
  306. foreach (DB::connection("oracle")->select(DB::raw($sql)) as $inv){
  307. $materialBox = MaterialBox::query()->firstOrCreate(["code"=>$inv->locationid],[
  308. "code" => $inv->locationid,
  309. "material_box_model_id"=>$model
  310. ]);
  311. $owner = Owner::query()->firstOrCreate([
  312. "code" => $inv->customerid
  313. ],[
  314. "code" => $inv->customerid,
  315. "name" => $inv->customerid,
  316. ]);
  317. $commodity = Commodity::query()->where("owner_id",$owner->id)->where("sku",$inv->sku)->first();
  318. $s = MaterialBoxCommodity::query()->where("material_box_id",$materialBox->id)
  319. ->where("commodity_id",$commodity->id)->first();
  320. if (!$s)MaterialBoxCommodity::query()->create([
  321. "material_box_id" => $materialBox->id,
  322. "commodity_id" => $commodity->id,
  323. "amount" => $inv->qty,
  324. ]);else $s->update(["amount" => $inv->qty]);
  325. }
  326. DB::commit();
  327. $this->success();
  328. }
  329. /**
  330. * 在安卓端的个体登录鉴权
  331. *
  332. */
  333. public function androidLogin()
  334. {
  335. $errors=Validator::make(request()->input(),[
  336. "name" => 'required|string',
  337. 'password' => 'required|string'])->errors();
  338. if($errors->count()>0){return ['success'=>false,'errors'=>$errors];}
  339. request()->offsetSet("remember",true);
  340. if (!$this->attemptLogin(request()))return ['success'=>false,'errors'=>['name'=>['登录信息验证失败']]];
  341. if (!Gate::allows("入库管理-入库-缓存架入库") && !Gate::allows("入库管理-入库-半箱补货入库"))return ['success'=>false,'errors'=>['name'=>['用户无权操作入库']]];
  342. return ['success'=>true,'url'=>url("store/inStorage/android.index")];
  343. }
  344. public function username(): string
  345. {
  346. return 'name';
  347. }
  348. /**
  349. * 库外箱绑定至库位
  350. */
  351. public function bindBox()
  352. {
  353. $location = request("location");
  354. $box = request("ide");
  355. if (!$location || !$box)$this->error("参数传递错误");
  356. $task = StationTaskMaterialBox::query()->select("id")->where(function ($query)use($location,$box){
  357. /** @var Builder $query */
  358. $query->whereHas("station",function ($query)use($location){
  359. /** @var Builder $query */
  360. $query->where("code",$location);
  361. })->orWhereHas("materialBox",function ($query)use($box){
  362. /** @var Builder $query */
  363. $query->where("code",$box);
  364. });
  365. })->whereNotIn("status",["完成","取消"])->first();
  366. if ($task)$this->error("库位或料箱存在任务待执行,无法放置料箱");
  367. $ks = DB::connection("mysql_haiRobotics")->table("ks_bin")->select(DB::raw("1"))
  368. ->where("ks_bin_code",$box)->where("status",4)->first();
  369. if (!$ks)$this->error("海柔料箱状态异常");
  370. DB::beginTransaction();
  371. try {
  372. $station = Station::query()->where("code",$location)->where("status",0)->first();
  373. $box = MaterialBox::query()->where("code",$box)->first();
  374. if (!$station || !$box)$this->error("库位或料箱未在WAS记录");
  375. $station->update(["material_box_id"=>$box->id]);
  376. DB::commit();
  377. $this->success();
  378. }catch (\Exception $e){
  379. DB::rollBack();
  380. $this->error($e->getMessage());
  381. }
  382. }
  383. public function bindModelIndex(){
  384. $models = MaterialBoxModel::query()->get();
  385. return view("store.inStorage.boxBindModel",compact("models"));
  386. }
  387. public function searchIde()
  388. {
  389. $ide = request("ide");
  390. $box = MaterialBox::query()->where("code",$ide)->first();
  391. if (!$box)$this->error("料箱不存在");
  392. $this->success($box->material_box_model_id);
  393. }
  394. public function boxBindModel()
  395. {
  396. $this->success(MaterialBox::query()->where("code",request("ide"))
  397. ->update(["material_box_model_id"=>request("material_box_model_id")]));
  398. }
  399. public function commodityBindModel()
  400. {
  401. $models = MaterialBoxModel::query()->get();
  402. return view("store.inStorage.commodityBindModel",compact("models"));
  403. }
  404. public function getModels()
  405. {
  406. $this->success(MaterialBoxModel::query()->select("id","code","description","maximum_kind")->get());
  407. }
  408. /**
  409. * 设定料箱最大
  410. */
  411. public function settingModelMaximum()
  412. {
  413. $insert = function ($commodityId){
  414. $in = [];
  415. $ids = [];
  416. foreach (request("models") as $model){
  417. $in[] = [
  418. "commodity_id" => $commodityId,
  419. "material_box_model_id" => $model["id"],
  420. "maximum" => $model["maximum"]
  421. ];
  422. $ids[] = $model["id"];
  423. }
  424. return array($in,$ids);
  425. };
  426. list($in,$ids) = $insert(request("commodityId"));
  427. if ($ids){
  428. $map = array_flip($ids);
  429. foreach (CommodityMaterialBoxModel::query()->where("commodity_id",request("commodityId"))
  430. ->lockForUpdate()->get() as $model){
  431. $index = $map[$model->material_box_model_id];
  432. if ($model->maximum != $in[$index]["maximum"]){
  433. CommodityMaterialBoxModel::query()->where("commodity_id",request("commodityId"))
  434. ->where("material_box_model_id",$model->material_box_model_id)
  435. ->update(["maximum"=>$in[$index]["maximum"]]);
  436. }
  437. unset($in[$index]);
  438. }
  439. $in = array_values($in);
  440. }
  441. if ($in){
  442. LogService::log(__CLASS__,__METHOD__,json_encode($in));
  443. CommodityMaterialBoxModel::query()->insert($in);
  444. }
  445. $this->success();
  446. }
  447. /**
  448. * 根据条码检索商品
  449. */
  450. public function searchBarCode()
  451. {
  452. $commodities = Commodity::query()->with("owner")->whereHas("barcodes",function (Builder $query){
  453. $query->where("code",request("barCode"));
  454. })->get();
  455. if (!$commodities->count())$this->error("库内无此商品信息");
  456. if ($commodities->count()>1)$commodities->load("owner");
  457. $this->success($commodities);
  458. }
  459. /**
  460. * 根据商品ID检索已存在的上限设定
  461. */
  462. public function searchModel()
  463. {
  464. $mapping = [];
  465. foreach (CommodityMaterialBoxModel::query()->where("commodity_id",request("id"))->get() as $model){
  466. $mapping[$model->material_box_model_id] = $model->maximum;
  467. }
  468. $this->success($mapping);
  469. }
  470. /**
  471. * 根据ASN号检索未设定商品型号上限的信息
  472. */
  473. public function searchAsn()
  474. {
  475. $sql = <<<SQL
  476. SELECT CUSTOMERID,SKU FROM TSK_TASKLISTS WHERE DOCNO = ? AND TASKPROCESS = '00' AND TASKTYPE = 'PA' GROUP BY CUSTOMERID,SKU
  477. SQL;
  478. $store = Store::query()->select("owner_id")->where("asn_code",request("asn"))->first();
  479. if (!$store || !$store->owner_id)$this->error("WAS内无此ASN单信息");
  480. $tasks = DB::connection("oracle")->select(DB::raw($sql),[request("asn")]);
  481. $codes = array_column($tasks,"sku");
  482. $model = MaterialBoxModel::query()->where("maximum_kind",1)->first();
  483. if (!$model)$this->error("单品型号缺失");
  484. $commodities = Commodity::query()->with("model")->where("owner_id",$store->owner_id)
  485. ->whereIn("sku",$codes)->get()->toArray();
  486. if (count($codes)!=count($commodities))$this->error("WAS商品信息不全");
  487. foreach ($commodities as $index=>$commodity){
  488. if ($commodity->model)unset($commodities[$index]);
  489. }
  490. $this->success(["commodities"=>array_values($commodities),"model"=>$model]);
  491. }
  492. /**
  493. * 设置商品上限
  494. */
  495. public function settingCommodityMaximum()
  496. {
  497. $modelId = request("modelId");
  498. $insert = [];
  499. $date = date("Y-m-d H:i:s");
  500. foreach (request("commodities") as $commodity){
  501. $insert[] = [
  502. "commodity_id" => $commodity["id"],
  503. "material_box_model_id" => $modelId,
  504. "maximum" => $commodity->maximum,
  505. "created_at" => $date,
  506. "updated_at" => $date,
  507. ];
  508. }
  509. $this->success(CommodityMaterialBoxModel::query()->insert($insert));
  510. }
  511. /**
  512. * 检查任务获取多批次
  513. */
  514. public function checkTask()
  515. {
  516. $track = request("track");
  517. $barCode = request("barCode");
  518. $sql = <<<SQL
  519. SELECT TSK_TASKLISTS.FMLOTNUM FROM TSK_TASKLISTS LEFT JOIN BAS_SKU ON TSK_TASKLISTS.CUSTOMERID = BAS_SKU.CUSTOMERID
  520. AND TSK_TASKLISTS.SKU = BAS_SKU.SKU
  521. WHERE FMID = ? AND (ALTERNATE_SKU1 = ? OR ALTERNATE_SKU2 = ? OR ALTERNATE_SKU3 = ?)
  522. AND TASKPROCESS = '00' AND TASKTYPE = 'PA' GROUP BY FMID,FMLOTNUM
  523. SQL;
  524. $tasks = DB::connection("oracle")->select(DB::raw($sql),[$track,$barCode,$barCode,$barCode]);
  525. $result = ["count"=>count($tasks)];
  526. if (count($tasks)>1){
  527. $lotNums = "";
  528. foreach ($tasks as $task)$lotNums .= "'".$task->fmlotnum."',";
  529. $lotNums = rtrim($lotNums,",");
  530. $sql = <<<SQL
  531. SELECT * FROM INV_LOT_ATT WHERE LOTNUM IN ({$lotNums});
  532. SQL;
  533. $result["lots"] = DB::connection("oracle")->select(DB::raw($sql));
  534. }
  535. if (count($tasks)==1)$result["lots"] = $tasks[0]->fmlotnum;
  536. $this->success($result);
  537. }
  538. }