109 lines
2.0 KiB
PHP
109 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace app\common\model;
|
|
|
|
use support\Model;
|
|
|
|
class UsedCarDetailAudit extends Model
|
|
{
|
|
/**
|
|
* The connection name for the model.
|
|
*
|
|
* @var string|null
|
|
*/
|
|
protected $connection = 'mysql';
|
|
|
|
/**
|
|
* The table associated with the model.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $table = 'used_car_detail_audit';
|
|
|
|
/**
|
|
* The primary key associated with the table.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $primaryKey = 'id';
|
|
|
|
/**
|
|
* Indicates if the model should be timestamped.
|
|
*
|
|
* @var bool
|
|
*/
|
|
public $timestamps = true;
|
|
|
|
protected $dateFormat = 'U';
|
|
|
|
/**
|
|
* 允许自动填充模型字段
|
|
*/
|
|
protected $fillable = [
|
|
'id', 'car_id', 'auditor_id', 'audit_status', 'audit_reason',
|
|
'before_status', 'after_status', 'created_at', 'updated_at'
|
|
];
|
|
|
|
/**
|
|
* 不允许自动填充模型字段
|
|
*/
|
|
protected $guarded = [];
|
|
|
|
/**
|
|
* 审核状态文本
|
|
*/
|
|
public static $statusText = [
|
|
0 => '待审核',
|
|
1 => '审核通过',
|
|
2 => '审核拒绝',
|
|
];
|
|
|
|
/**
|
|
* 关联车辆
|
|
*/
|
|
public function car()
|
|
{
|
|
return $this->belongsTo(UsedCarDetail::class, 'car_id', 'id');
|
|
}
|
|
|
|
/**
|
|
* 关联审核人
|
|
*/
|
|
public function auditor()
|
|
{
|
|
return $this->belongsTo(\app\common\model\User::class, 'auditor_id', 'id');
|
|
}
|
|
|
|
/**
|
|
* 获取审核状态文本
|
|
*/
|
|
public function getAuditStatusTextAttribute()
|
|
{
|
|
return self::$statusText[$this->audit_status] ?? '未知';
|
|
}
|
|
|
|
/**
|
|
* 作用域:通过审核
|
|
*/
|
|
public function scopeApproved($query)
|
|
{
|
|
return $query->where('audit_status', 1);
|
|
}
|
|
|
|
/**
|
|
* 作用域:拒绝审核
|
|
*/
|
|
public function scopeRejected($query)
|
|
{
|
|
return $query->where('audit_status', 2);
|
|
}
|
|
|
|
/**
|
|
* 作用域:待审核
|
|
*/
|
|
public function scopePending($query)
|
|
{
|
|
return $query->where('audit_status', 0);
|
|
}
|
|
}
|