89 lines
2.0 KiB
PHP
89 lines
2.0 KiB
PHP
<?php
|
|||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
namespace plugin\produce\app\model;
|
||
|
|
|
||
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||
|
|
|
||
|
|
class ScanData extends BaseModel
|
||
|
|
{
|
||
|
|
protected $table = 'produce_scan_data';
|
||
|
|
|
||
|
|
protected $appends = ['scan_date', 'process_name', 'step_name', 'status_name'];
|
||
|
|
|
||
|
|
protected static function booted(): void
|
||
|
|
{
|
||
|
|
static::creating(function (self $model) {
|
||
|
|
if (empty($model->scan_time)) {
|
||
|
|
$model->scan_time = time();
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
protected $fillable = [
|
||
|
|
'id',
|
||
|
|
'order_no',
|
||
|
|
'quantity',
|
||
|
|
'user_code',
|
||
|
|
'operator',
|
||
|
|
'operator_id',
|
||
|
|
'process_id',
|
||
|
|
'step_id',
|
||
|
|
'status_id',
|
||
|
|
'scan_result',
|
||
|
|
'scan_time',
|
||
|
|
'remark',
|
||
|
|
'created_by',
|
||
|
|
'updated_by',
|
||
|
|
'created_at',
|
||
|
|
'updated_at',
|
||
|
|
'deleted_at',
|
||
|
|
];
|
||
|
|
|
||
|
|
protected $casts = [
|
||
|
|
'quantity' => 'integer',
|
||
|
|
'scan_result' => 'integer',
|
||
|
|
'scan_time' => '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 status(): BelongsTo
|
||
|
|
{
|
||
|
|
return $this->belongsTo(StepStatus::class, 'status_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 getStatusNameAttribute(): string
|
||
|
|
{
|
||
|
|
return (string) ($this->status?->status_name ?? '');
|
||
|
|
}
|
||
|
|
|
||
|
|
public function getScanDateAttribute(): ?string
|
||
|
|
{
|
||
|
|
return $this->scan_time ? date('Y-m-d H:i:s', (int) $this->scan_time) : null;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|