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.
 
 
 

62 lines
1.9 KiB

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class EquipmentView extends Model
{
use HasFactory;
protected $table = 'equipment_view';
protected $fillable = [
'serialnumber',
'location',
'precinct',
'station',
];
// 有關聯到
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;
}
}