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.
102 lines
3.0 KiB
102 lines
3.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 ViolationParkingEquipment extends Model |
|
{ |
|
use HasFactory, SoftDeletes; |
|
protected $table = 'violationparking_equipment'; |
|
protected $dates = ['deleted_at']; |
|
protected $fillable = [ |
|
'serialnumber', |
|
'brand', |
|
'model', |
|
'custodyunit_id', |
|
'assetownership_id', |
|
'buydate', |
|
'activatedate', |
|
'locationid', |
|
'location', |
|
'comment', |
|
'precinct', |
|
'station', |
|
]; |
|
// append fields |
|
protected $appends = [ |
|
'custodyunit_name', |
|
'assetownership_name', |
|
]; |
|
|
|
// custome fields |
|
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; |
|
} |
|
}
|
|
|