You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
122 lines
4.0 KiB
122 lines
4.0 KiB
<?php |
|
|
|
namespace App\Models; |
|
|
|
use COM; |
|
use Illuminate\Database\Eloquent\Factories\HasFactory; |
|
use Illuminate\Database\Eloquent\Model; |
|
use Illuminate\Database\Eloquent\SoftDeletes; |
|
|
|
class MultisysEquipment extends Model |
|
{ |
|
use HasFactory, SoftDeletes; |
|
protected $table = 'multisys_equipment'; |
|
protected $dates = ['deleted_at']; |
|
protected $fillable = [ |
|
'serialnumber', |
|
'brand', |
|
'model', |
|
'custodyunit_id', |
|
'assetownership_id', |
|
'buydate', |
|
'activatedate', |
|
'locationid', |
|
'location', |
|
'comment', |
|
'map', |
|
'precinct', |
|
'station', |
|
]; |
|
// append fields |
|
protected $appends = [ |
|
'custodyunit_name', |
|
'assetownership_name', |
|
'short_name', |
|
]; |
|
|
|
// custome fields |
|
public function getShortNameAttribute() |
|
{ |
|
$match = [ |
|
'桃園區國際路二段與大興西路三段路口' => '國際路二段與大興西三段', |
|
'桃園區復興路與民生路口' => '復興路與民生路', |
|
'桃園區三民路二段與春日路口' => '三民二段與春日路', |
|
'桃園區中山路與上海路口' => '中山路與上海路', |
|
'桃園區三民路二段與民生路口' => '三民路二段與民生路', |
|
'桃園區春日路與民光東路口' => '春日路與民光東路', |
|
'桃園區三民路三段與永安路口' => '三民路三段與永安路', |
|
'蘆竹區中正路與南山路一段路口' => '蘆竹中正路與南山路一段', |
|
'八德區中華路與永豐路口' => '八德中華路與永豐路', |
|
'八德區建德路與豐德路口' => '八德建德路與豐德路', |
|
]; |
|
$name = $match[$this->location] ?? $this->location; |
|
return $name; |
|
} |
|
public function getCustodyunitNameAttribute() |
|
{ |
|
$name = CustodyUnit::find($this->custodyunit_id)->name ?? '無'; |
|
return $name; |
|
} |
|
|
|
public function getAssetownershipNameAttribute() |
|
{ |
|
$name = AssetOwnership::find($this->assetownership_id)->name ?? '無'; |
|
return $name; |
|
} |
|
|
|
// 有關聯到設備保管單位 |
|
public function custodyunit() |
|
{ |
|
return $this->belongsTo(CustodyUnit::class, 'custodyunit_id', 'id'); |
|
} |
|
|
|
// 有關聯到設備財產權屬 |
|
public function assetownership() |
|
{ |
|
return $this->belongsTo(AssetOwnership::class, 'assetownership_id', 'id'); |
|
} |
|
|
|
// 有關聯到 |
|
public static function getTypeStation($options = []) |
|
{ |
|
// 获取所有的类型 |
|
$types = self::select('station')->distinct()->pluck('station')->toArray(); |
|
|
|
// 构建一个关联数组来存储每个类型对应的代码 |
|
$typeCodes = []; |
|
foreach ($types as $type) { |
|
if ($options != []){ |
|
if (in_array($type, $options)) { |
|
$codes = self::where('station', $type)->pluck('serialnumber')->toArray(); |
|
$typeCodes[$type] = $codes; |
|
} |
|
}else{ |
|
$codes = self::where('station', $type)->pluck('serialnumber')->toArray(); |
|
$typeCodes[$type] = $codes; |
|
} |
|
} |
|
|
|
return $typeCodes; |
|
} |
|
public static function getTypePrecinct($options = []) |
|
{ |
|
// 获取所有的类型 |
|
$types = self::select('precinct')->distinct()->pluck('precinct')->toArray(); |
|
|
|
// 构建一个关联数组来存储每个类型对应的代码 |
|
$typeCodes = []; |
|
foreach ($types as $type) { |
|
// $type in $options |
|
if ($options != []){ |
|
if (in_array($type, $options)) { |
|
$codes = self::where('precinct', $type)->pluck('serialnumber')->toArray(); |
|
$typeCodes[$type] = $codes; |
|
} |
|
}else{ |
|
$codes = self::where('precinct', $type)->pluck('serialnumber')->toArray(); |
|
$typeCodes[$type] = $codes; |
|
} |
|
} |
|
return $typeCodes; |
|
} |
|
}
|
|
|