|
|
@@ -8,6 +8,7 @@ use App\Components\AsyncResponse;
|
|
|
use App\Components\ErrorPush;
|
|
|
use App\ErrorTemp;
|
|
|
use App\Feature;
|
|
|
+use App\Jobs\CacheShelfTaskJob;
|
|
|
use App\Jobs\OrderCreateWaybill;
|
|
|
use App\MaterialBox;
|
|
|
use App\MaterialBoxModel;
|
|
|
@@ -65,86 +66,85 @@ class TestController extends Controller
|
|
|
$response = Http::post(config('api.haiq.storage.light'), $params);
|
|
|
return json_decode($response->body());
|
|
|
}
|
|
|
- private function checkHaiQ(array $boxCodes)
|
|
|
- {
|
|
|
- $haiBoxes = DB::connection("mysql_haiRobotics")->table("ks_bin")
|
|
|
- ->where("status",1)->whereIn("ks_bin_code",$boxCodes)->get();
|
|
|
- if ($haiBoxes->count()==0)return array(null,null);
|
|
|
- $codes = [];
|
|
|
- $haiBoxes->each(function ($haiBox)use(&$codes){$codes[$haiBox->ks_bin_code] = true;});
|
|
|
- $haiBoxes = DB::connection("mysql_haiRobotics_ess")->table("ks_ess_task_detail")
|
|
|
- ->whereIn("bin_code",$boxCodes)
|
|
|
- ->whereNotIn("status",[0,4])->get();
|
|
|
- $notCodes = [];
|
|
|
- $haiBoxes->each(function ($haiBox)use(&$notCodes){$notCodes[$haiBox->bin_code] = true;});
|
|
|
- return array($codes,$notCodes);
|
|
|
- }
|
|
|
- public function getModelAvailableBox(int $modelId, bool $sqlQuery = false, array $blacklist = [])
|
|
|
- {
|
|
|
- $query = MaterialBox::query()->where("material_box_model_id",$modelId);
|
|
|
- $boxes = $query->whereNotIn("id",MaterialBox::query()->where("material_box_model_id",$modelId)->select("id")
|
|
|
- ->whereHas("performTask"));
|
|
|
- if ($blacklist)$boxes = $boxes->whereNotIn("id",$blacklist);
|
|
|
- $boxes = $boxes->get();
|
|
|
- //筛选下海柔可用箱
|
|
|
- list($codes,$notCodes) = $this->checkHaiQ(array_column($boxes->toArray(),"code"));
|
|
|
- if (!$codes)$boxes = new \Illuminate\Database\Eloquent\Collection();
|
|
|
- $boxes = $boxes->filter(function ($box)use($codes,$notCodes){
|
|
|
- if (!isset($codes[$box->code]) || isset($notCodes[$box->code]))return false;
|
|
|
- return true;
|
|
|
- });
|
|
|
|
|
|
- if (!$sqlQuery)return $boxes;
|
|
|
- if ($boxes->count()==0)return array(null,null);
|
|
|
- $boxCodes = "";
|
|
|
- $map = [];
|
|
|
- foreach ($boxes as $box){
|
|
|
- $boxCodes .= "'".$box->code."',";
|
|
|
- $map[$box->code] = $box->id;
|
|
|
- }
|
|
|
- return array(rtrim($boxCodes,","),$map);
|
|
|
- }
|
|
|
public function test()
|
|
|
{
|
|
|
- $a = collect(["a"]);
|
|
|
- $b = collect(["b"]);
|
|
|
- dd($a->merge($b));
|
|
|
- $lotNum = 'LT00551703';
|
|
|
- $commodity = Commodity::query()->find(593292);
|
|
|
- /** @var \Illuminate\Database\Eloquent\Collection $models */
|
|
|
- $models = app("MaterialBoxModelService")->getModelSortedByOwner($commodity->owner_id);
|
|
|
- $models->load(["commodity"=>function($query)use($commodity){
|
|
|
- $query->where("commodity_id",$commodity->id);
|
|
|
- }]);
|
|
|
- $models = $models->whereNotNull("commodity");
|
|
|
- if ($models->count()==0)$this->success(["status"=>false,"commodityId"=>$commodity->id]);
|
|
|
-
|
|
|
-
|
|
|
- $sql = <<<SQL
|
|
|
-SELECT LOCATIONID,QTY FROM INV_LOT_LOC_ID WHERE LOTNUM = '{$lotNum}'
|
|
|
-AND LOCATIONID LIKE 'IDE%' AND SKU = '{$commodity->sku}' AND TRACEID = '*' AND QTY > 0 AND QTY > 0 ORDER BY QTY
|
|
|
-SQL;
|
|
|
- $invs = DB::connection("oracle")->select(DB::raw($sql));
|
|
|
- if ($invs){
|
|
|
- $map = [];
|
|
|
- $codes = [];
|
|
|
- foreach ($invs as $inv){
|
|
|
- $map[$inv->locationid] = $inv->qty;
|
|
|
- $codes[] = $inv->locationid;
|
|
|
- }
|
|
|
- $modelMap = [];
|
|
|
- $orderBy = "CASE material_box_model_id ";
|
|
|
- foreach ($models as $key=>$model){
|
|
|
- $orderBy .= 'WHEN '.$model->id." THEN ".$key;
|
|
|
- $modelMap[$model->id] = $model->commodity->maximum;
|
|
|
- }
|
|
|
- $orderBy.= " END";
|
|
|
- $boxes = MaterialBox::query()->whereIn("code",$codes)->orderByRaw($orderBy)->get();
|
|
|
- foreach ($boxes as $box){
|
|
|
- if ($modelMap[$box->material_box_model_id]<=$map[$box->code])continue;
|
|
|
- $num = $modelMap[$box->material_box_model_id]-$map[$box->code];
|
|
|
- dump([$box,$num]);
|
|
|
- }
|
|
|
+ app("CacheShelfService")->_stationCacheLightOff("HAIB1-01-01");
|
|
|
+ app("CacheShelfService")->_stationCacheLightOff("HAIB1-01-02");
|
|
|
+ app("CacheShelfService")->_stationCacheLightOff("HAIB1-02-02");
|
|
|
+ dd(1);
|
|
|
+ $stationTaskMaterialBox = StationTaskMaterialBox::query()->find(70370);
|
|
|
+ DB::beginTransaction();
|
|
|
+ try{
|
|
|
+ $stationTaskMaterialBox->loadMissing("station");
|
|
|
+ //如果为半箱位置 清理原有任务
|
|
|
+ if (!$stationTaskMaterialBox->station)return;
|
|
|
+ if (app("StationService")->isHalfBoxLocation($stationTaskMaterialBox->station)){
|
|
|
+ app("StationService")->locationOccupy($stationTaskMaterialBox->station->code,$stationTaskMaterialBox->material_box_id);
|
|
|
+ //清除海柔库位信息
|
|
|
+ app("StorageService")->clearTask([$stationTaskMaterialBox->station->code]);
|
|
|
+ $stationId = $stationTaskMaterialBox->station_id;
|
|
|
+ $tasks = TaskTransaction::query()->with("materialBox")->where(function ($query)use($stationId){
|
|
|
+ $query->where("fm_station_id",$stationId)->orWhere("to_station_id",$stationId);
|
|
|
+ })->where("status",0)->get();
|
|
|
+ if ($tasks->count()!=0){
|
|
|
+ $options = [];
|
|
|
+ switch ($tasks[0]->mark){
|
|
|
+ case 1:
|
|
|
+ $options["title"] = '上架任务';
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ $options["title"] = '出库任务';
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ $options["title"] = '未知类型';
|
|
|
+ }
|
|
|
+ switch ($tasks->count()){
|
|
|
+ case 1:
|
|
|
+ $task = $tasks[0];
|
|
|
+ $options["detail01"] = $task->materialBox->code ?? '';
|
|
|
+ $options["detail02"] = $task->doc_code ?: '跟踪:‘'.$task->track_num."’ 批次:‘".$task->lot_num."’";
|
|
|
+ $options["detail03"] = $task->bar_code;
|
|
|
+ $options["qty01"] = $task->amount;
|
|
|
+ $options["uomDesc01"] = '件';
|
|
|
+ $options["qty02"] = $task->bin_number;
|
|
|
+ $options["uomDesc02"] = '号';
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ $count = count(array_unique(array_column($tasks->toArray(),"commodity_id")));
|
|
|
+ if ($count==1){
|
|
|
+ $options["detail01"] = $tasks[0]->bar_code;
|
|
|
+ $options["detail02"] = "";
|
|
|
+ $options["detail03"] = "";
|
|
|
+ $amount = 0;
|
|
|
+ foreach ($tasks as $task){
|
|
|
+ if (mb_strlen($options["detail02"])>20){
|
|
|
+ $options["detail03"] .= $task->bin_number."号-".$task->amount."件,";
|
|
|
+ }else $options["detail02"] .= $task->bin_number."号-".$task->amount."件,";
|
|
|
+ $amount += $task->amount;
|
|
|
+ }
|
|
|
+ $options["detail02"] = rtrim($options["detail02"],",");
|
|
|
+ $options["detail03"] = rtrim($options["detail03"],",");
|
|
|
+ $options["qty02"] = $amount;
|
|
|
+ $options["uomDesc02"] = '件';
|
|
|
+ }else{
|
|
|
+ $task = $tasks[0];
|
|
|
+ $options["detail01"] = $task->materialBox->code ?? '';
|
|
|
+ $options["detail02"] = "货品过多请自行核对";
|
|
|
+ $options["detail03"] = "波次:".$task->doc_code ?
|
|
|
+ (Order::query()->with("batch")->where("code",$task->doc_code)->first()->batch->code ?? '无') : '无';
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ app("CacheShelfService")->lightUp($stationTaskMaterialBox->station->code,'2','0',$options);
|
|
|
+ Cache::forget("CACHE_SHELF_OCCUPANCY_{$stationTaskMaterialBox->station->id}");//关闭无限亮灯
|
|
|
+ }
|
|
|
+ }else app("StationService")->locationFreed($stationTaskMaterialBox->station->code); //释放库位占用
|
|
|
+ DB::commit();
|
|
|
+ dd("OK");
|
|
|
+ }catch (\Exception $e){
|
|
|
+ DB::rollBack();
|
|
|
+ dd($e->getTrace());
|
|
|
}
|
|
|
|
|
|
|