| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- <?php
- namespace App;
- use App\Traits\ModelTimeFormat;
- use Illuminate\Database\Eloquent\Model;
- use App\Traits\ModelLogChanging;
- use Illuminate\Database\Eloquent\Relations\BelongsTo;
- class WorkOrderLog extends Model
- {
- use ModelTimeFormat;
- protected $fillable = [
- 'work_order_id',
- 'work_order_detail_id',
- 'content',
- 'type', // 记录类型
- 'creator_id', // 创建人
- 'tag', // 标记
- ];
- static public $enums = [
- 'type' => [
- '' => 0,
- '创建' => 1,
- '处理' => 2,
- '终审' => 3,
- '完结' => 4,
- ],
- 'tag' => [
- '创建' => 0,
- '完结' => 1,
- '标记' => 2,
- ],
- ];
- function __construct(array $attributes = [])
- {
- foreach (self::$enums as &$enum) {
- $enum = $enum + array_flip($enum);
- }
- parent::__construct($attributes);
- }
- public function getTypeAttribute($value)
- {
- if (!$value) return '';
- return self::$enums['type'][$value];
- }
- public function setTypeAttribute($value)
- {
- if (!$value) return;
- if (is_numeric($value)) {
- $this->attributes['type'] = $value;
- } else {
- $this->attributes['type'] = self::$enums['type'][$value];
- }
- }
- public function getTagAttribute($value)
- {
- if (!$value) return '';
- return self::$enums['tag'][$value];
- }
- public function setTagAttribute($value)
- {
- if (!$value) return;
- if (is_numeric($value)) {
- $this->attributes['tag'] = $value;
- } else {
- $this->attributes['tag'] = self::$enums['tag'][$value];
- }
- }
- public function creator(): BelongsTo
- {
- return $this->belongsTo(User::class);
- }
- }
|