Files
MrleeAdmin/backend/plugin/produce/app/model/ExceptionRecord.php
T

108 lines
2.5 KiB
PHP

<?php
declare(strict_types=1);
namespace plugin\produce\app\model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class ExceptionRecord extends BaseModel
{
protected $table = 'produce_exception_record';
protected $appends = ['reported_date', 'handled_date', 'status_name'];
protected static function booted(): void
{
static::creating(function (self $model) {
if (empty($model->reported_at)) {
$model->reported_at = time();
}
});
}
protected $fillable = [
'id',
'order_no',
'process_id',
'step_id',
'user_code',
'reporter',
'reporter_id',
'type_id',
'type_code',
'type_name',
'reason_id',
'reason_code',
'reason_name',
'issue_id',
'issue_code',
'issue_name',
'images',
'remark',
'status',
'handler',
'handler_id',
'handled_at',
'reported_at',
'created_by',
'updated_by',
'created_at',
'updated_at',
'deleted_at',
];
protected $casts = [
'images' => 'array',
'process_id' => 'integer',
'step_id' => 'integer',
'status' => 'integer',
'handled_at' => 'integer',
'reported_at' => 'integer',
'created_by' => 'integer',
'updated_by' => 'integer',
'created_at' => 'integer',
'updated_at' => 'integer',
'deleted_at' => 'integer',
];
public function process(): BelongsTo
{
return $this->belongsTo(Process::class, 'process_id', 'id')->withTrashed();
}
public function step(): BelongsTo
{
return $this->belongsTo(ProcessStep::class, 'step_id', 'id')->withTrashed();
}
public function getProcessNameAttribute(): string
{
return (string) ($this->process?->process_name ?? '');
}
public function getStepNameAttribute(): string
{
return (string) ($this->step?->step_name ?? '');
}
public function getReportedDateAttribute(): ?string
{
return $this->reported_at ? date('Y-m-d H:i:s', (int) $this->reported_at) : null;
}
public function getHandledDateAttribute(): ?string
{
return $this->handled_at ? date('Y-m-d H:i:s', (int) $this->handled_at) : null;
}
public function getStatusNameAttribute(): string
{
return match ((int) $this->status) {
1 => '处理中',
2 => '已处理',
default => '待处理',
};
}
}