data["active_test"] = "active"; } public function method(Request $request, $method) { return call_user_func([$this, $method], $request); } public function lightUp() { app("CacheShelfService")->lightUp('HAIB1-02-02','3','0'); } public function lightOff() { $params = [ "areaCode" => "1004", 'locCode' => "HAIB1-02-02", 'PTLAction' => 0, ]; $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 = << 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]); } } } //快递称重 生成历史数据 public function addRecord(Request $request) { ini_set('max_execution_time',-1); OrderPackageCountingRecord::query()->truncate(); $start = Carbon::parse(request("month"))->startOfMonth(); $end = Carbon::parse(request('month'))->endOfMonth(); foreach (CarbonPeriod::create($start,$end) as $date){ /** @var $date Carbon */ $yesterday = $date->format("Y-m-d"); $sql = << $yesterday, "un_weigh_count" => 0, "total_count" => 0, "measuring_machine_id" => 0, "owner_id" => 0 ]; $model = OrderPackageCountingRecord::query()->create($obj); Cache::put("weight.".$yesterday, $obj); }else{ $objs = []; foreach ($result as $v){ $obj = [ "targeted_at" => $v->date, "un_weigh_count" => $v->count, "total_count" => $v->total, "measuring_machine_id" => $v->measuring_machine_id, "owner_id" => $v->owner_id ]; $model = OrderPackageCountingRecord::query()->create($obj); array_push($objs, $obj); } Cache::put("weight.".$yesterday, $objs); } } } public function redis() { $start = 1606752000;$end = 1627747200; $len = ($end - $start) / 86400; for ($i=0; $i <= $len ; $i ++){ $date = date("Y-m-d", $start + $i * 86400); Cache::pull('weight.'.$date); } } }