where('parent_id', $id)->with('storage.materialBox')->get(); } /** * 拍灯触发任务 * @param $locCode * * @return array|bool[] * @throws \Exception */ public function lightOffTask($locCode): array { $station = Station::query()->with('materialBox')->where('code', $locCode)->first(); if (Cache::has("CACHE_SHELF_OCCUPANCY_{$station->id}")){ //缓存存在 不允许灭灯 灭了再点开 app("CacheShelfService")->lightUp($station->code,'3','0',["title"=>"机器人取箱中,禁止操作"]); return ['success' => true]; } //站存在 站为缓存架 if (app("StationService")->isHalfBoxLocation($station)){ $result = app("StorageService")->checkStorage($station); if ($result===false){//任务存在且失败 红灯 $this->lightUp($station->code,'0','1',["title"=>"上架失败,联系管理员"]); return ['success' => false,'errMsg' => '上架任务失败']; }; if ($result===true){//任务存在且成功 绿灯 $this->lightUp($station->code,'1','0',['title'=>"操作完成,等待入库"]); return ['success' => true]; } } try { $bool = $this->putBinToStore($station); // 推送任务 if ($bool) { LogService::log(__CLASS__, 'lightOffTask', 'code' . ' true' . $locCode . json_encode($station)); return ['success' => true]; }else return ['success' => false, 'errMsg' => '机器人推送失败']; } catch (ErrorException $e) { LogService::log(__FUNCTION__, '缓存架推送任务失败', json_encode($e->getMessage())); return ['success' => false, 'errMsg' => $e->getMessage()]; } } /** * 推任务至海柔机器人 * @param $station * @return bool * @throws ErrorException * @throws \Exception */ public function putBinToStore($station): bool { $this->instant($this->foreignHaiRoboticsService, 'ForeignHaiRoboticsService'); $this->instant($this->stationService, 'StationService'); if (!$station->materialBox)return false; /** @var StationTaskMaterialBox $stationTaskMaterialBox */ $stationTaskMaterialBox = app("StorageService")->createWarehousingTask($this->stationService->getStation_byType('立库')["id"],$station->materialBox->id); $this->lightUp($station->code,'3','0',['title'=>"等待机器人拿走,请勿操作"]); Cache::forever("CACHE_SHELF_OCCUPANCY_{$station->id}",true); return $this->foreignHaiRoboticsService->putBinToStore_fromCacheShelf($stationTaskMaterialBox, $station); } /** * 站亮灯 * * @param string $stationCode * @param string $color explain: 0-red 1-green 2-blue 3-yellow * @param string $frequency explain: 0-常亮 1-一次 2-两次 3-三次 4-四次 5-五次 (均为/秒) * @param array $info * @return bool */ public function lightUp(string $stationCode, string $color = '1', string $frequency = '0',array $info = []):bool { $default = [ "detail01" => '', "detail02" => "", "detail03" => "", "qrCode" => "", "qty00" => "", "qty01" => "", "qty02" => "", "title" => '', "uomDesc01" => "", "uomDesc02" => "" ]; foreach ($info as $key=>$item)$default[$key] = $item; $params = [ "areaCode" => "1004", 'locCode' => $stationCode, 'PTLAction' => 1, 'PTLSettings' => ['color' => $color, 'frequency' => $frequency], "displayInfo" => $default, ]; $response = Http::post(config('api.haiq.storage.light'), $params); return $response->status()==200; } /** * 控制格口灭灯 * @param $locCode * @return mixed */ public function _stationCacheLightOff($locCode) { if (!$locCode) return null; $params = [ "areaCode" => "1004", 'locCode' => $locCode, 'PTLAction' => 0, ]; $response = Http::post(config('api.haiq.storage.light'), $params); return json_decode($response->body()); } /** * 广播 type success成功 error 异常 * @param $locCode * @param $PTLAction * @param string $type */ public function _stationCacheBroadCast($locCode, $PTLAction, string $type = 'success') { if (!$locCode) return; if ($PTLAction == 0) { $station = Station::query()->with('parent')->where('code', $locCode)->first(); $json = json_encode([ 'station_id' => $station['parent']['id'], 'code' => $station['parent']['code'], 'gird_id' => $station['id'], 'grid_code' => $station['code'], 'type' => $type, 'status' => 0 ]); broadcast(new BroadcastToStation($station['parent_id'], $json)); } } /** * 取消任务 * @param $stationCode * @return array * @throws \Exception */ public function clearTask($stationCode): array { $station = Station::query()->with('storage')->where('code', $stationCode)->first(); if (!$station) return ['success' => false, 'message' => '传入参数异常,找不到对应的缓存架记录']; $stationTaskMaterialBox = StationTaskMaterialBox::query()->where('material_box_id',$station['material_box_id'])->first(); if($stationTaskMaterialBox ){ if($stationTaskMaterialBox->status == '处理中') return ['success' => false, 'message' => '当前缓存架任务正在处理中']; else{ $stationTaskMaterialBox->delete(); } } $station->update(['status' => 0,'material_box_id' => null]); return ['success' => true]; } /** * 料箱被取走 * * @param Station|\stdClass $station */ public function boxHasBeenTaken($station) { app("StationService")->locationFreed($station->code); //释放库位,解除绑定料箱 $available=Cache::get("CACHE_SHELF_AVAILABLE",0)+1;//获取可用缓存架数量 plus当前 Cache::forever("CACHE_SHELF_AVAILABLE",$available); $this->_stationCacheLightOff($station->code); CacheShelfTaskJob::dispatch("CACHE_SHELF_AVAILABLE",$available)->delay(now()->addSeconds(config("haiRou.cacheShelf.outBinAwait",3))); } }