'无', '1' => '待处理', ]; public function station(): BelongsTo { return $this->belongsTo(Station::class); } public function materialBox(): BelongsTo { return $this->belongsTo(MaterialBox::class); } /** * 根据格口计算位置 * @param Station $station * @param StationCacheShelfGrid $grid * @return string */ public static function getLocation(Station $station, StationCacheShelfGrid $grid): string { $code = $station['code']; $grid_id = $grid['grid_id']; $row = 2 - round($grid_id / 3) + 1; $col = 2 - ($grid_id % 3) + 1; return 'HAI' . $code . '-0' . $col . '-0' . $row; } /** * 根据位置计算 grid_id 和 station code * @param $code * @return array|false[] */ public static function getGridByCode($code): array { $arr = []; preg_match('/^HAI([\w\.\ ]+)-0([0-9]+)-0([0-9]+)/',$code,$arr); if(count($arr)==0)return [false,false,null,null]; $stationCode =$arr[1] ?? false; $col = $arr[2] ?? 0; // 列 $row = $arr[3] ?? 0; // 行 $gridId = ($row-1)*3 + (3-$col); return [$stationCode,$gridId,$row,$col]; } }