| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- <?php
- namespace App;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Database\Eloquent\Relations\BelongsTo;
- use App\Traits\ModelLogChanging;
- class StationCacheShelfGrid extends Model
- {
- use ModelLogChanging;
- protected $fillable = ['station_id', 'material_box_id', 'grid_id', 'status'];
- public static $status = [
- '0' => '无',
- '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 = [];
- $bool = preg_match_all('/^HAI([\w]+)-[0]([0-9]+)-[0]([0-9]+)/',$code,$arr);
- if(!$bool)return [false,false];
- $stationCode =$arr[1][0] ?? false;
- $col = $arr[2][0] ?? 0; // 列
- $row = $arr[3][0] ?? 0; // 行
- $gridId = ($row-1)*3 + $col;
- return [$stationCode,$gridId,$row,$col];
- }
- }
|