Files
usedcar/app/apis/model/VehicleDataModel.php
T
2025-05-14 13:19:23 +08:00

129 lines
2.7 KiB
PHP

<?php
namespace app\apis\model;
use support\Model;
/**
* VehicleDataModel
*/
class VehicleDataModel extends Model
{
/**
* The connection name for the model.
*
* @var string|null
*/
protected $connection = 'mysql';
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'hs_vehicle_data';
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'id';
/**
* Indicates if the model should be timestamped.
*
* @var bool
*/
public $timestamps = true;
/**
* 模型的数据字段的保存格式。
*
* @var string
*/
protected $dateFormat = 'U';
/**
* 允许自动填充模型字段
*/
protected $fillable = ['id', 'vin', 'user_id', 'name', 'cover', 'brand', 'price', 'type', 'energy', 'model', 'mileage', 'vehicle_age', 'condition_desc', 'info_status', 'is_saled', 'store_status', 'start_use', 'end_use', 'location', 'views', 'created_at', 'updated_at'];
/**
* 不允许自动填充模型字段
*/
protected $guarded = [];
public function user()
{
return $this->belongsTo(UsersModel::class, 'user_id', 'id');
}
public function brand()
{
return $this->belongsTo(BrandModel::class, 'brand', 'id');
}
public function types()
{
return $this->belongsTo(TypesModel::class, 'type', 'id');
}
public function energy()
{
return $this->belongsTo(EnergyModel::class, 'energy', 'id');
}
public function models()
{
return $this->belongsTo(ModelModel::class, 'model', 'id');
}
public function album()
{
return $this->hasOne(VehicleAlbumModel::class, 'vehicle_data_id', 'id');
}
public function thumb()
{
return $this->belongsTo(VehicleAlbumModel::class, 'vehicle_id', 'id')->select('front_45_degree');
}
public function location()
{
return $this->belongsTo(LocationModel::class, 'location');
}
/**
* 单条翻译
*/
public function translation()
{
return $this->hasOne(VehicleDataTranslationModel::class, 'vehicle_id')->where('locale', locale());
}
/**
* 多条翻译
*/
public function translations()
{
return $this->hasMany(VehicleDataTranslationModel::class, 'vehicle_id');
}
const TRANS_FIELDS = [
'name', 'condition_desc'
];
const STORE_STATUS = [
1 => '现货',
2 => '在途',
3 => '订购',
];
const STORE_STATUS_VALUE = [
1 => 'in_stock',
2 => 'in_transit',
3 => 'in_order',
];
}