2026-08-31 13:16:46 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace plugin\produce\app\model;
|
|
|
|
|
|
2026-09-01 19:17:09 +08:00
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
|
|
2026-08-31 13:16:46 +08:00
|
|
|
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',
|
2026-09-01 19:17:09 +08:00
|
|
|
'process_id',
|
|
|
|
|
'step_id',
|
2026-08-31 13:16:46 +08:00
|
|
|
'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',
|
2026-09-01 19:17:09 +08:00
|
|
|
'process_id' => 'integer',
|
|
|
|
|
'step_id' => 'integer',
|
2026-08-31 13:16:46 +08:00
|
|
|
'status' => 'integer',
|
|
|
|
|
'handled_at' => 'integer',
|
|
|
|
|
'reported_at' => 'integer',
|
|
|
|
|
'created_by' => 'integer',
|
|
|
|
|
'updated_by' => 'integer',
|
|
|
|
|
'created_at' => 'integer',
|
|
|
|
|
'updated_at' => 'integer',
|
|
|
|
|
'deleted_at' => 'integer',
|
|
|
|
|
];
|
|
|
|
|
|
2026-09-01 19:17:09 +08:00
|
|
|
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 ?? '');
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-31 13:16:46 +08:00
|
|
|
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 => '待处理',
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|