| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- <?php
- namespace App;
- use Illuminate\Database\Eloquent\Model;
- use App\Traits\ModelLogChanging;
- use Illuminate\Database\Eloquent\Relations\BelongsTo;
- class WorkOrderProcessLog extends Model
- {
- use ModelLogChanging;
- //
- protected $fillable = [
- 'work_order_id', // 工单
- 'type', // 处理类型 0 无 1宝时 2 承运商
- 'is_indemnity', // 是否赔偿 0 无 1否 2 是
- 'indemnity', // 赔偿金
- 'creator_id', // 创建人
- 'remark', // 描述
- ];
- static public $enums = [
- 'type' => [
- '' => 0,
- '宝时' => 1,
- '承运商' => 2,
- ],
- 'is_indemnity' => [
- '' => 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 getIsIndemnityAttribute($value)
- {
- if (!$value) return '';
- return self::$enums['is_indemnity'][$value];
- }
- public function setIsIndemnityAttribute($value)
- {
- if (!$value) return ;
- if (is_numeric($value)) {
- $this->attributes['is_indemnity'] = $value;
- } else {
- $this->attributes['is_indemnity'] = self::$enums['is_indemnity'][$value];
- }
- }
- public function workOrder(): BelongsTo
- {
- return $this->belongsTo(WorkOrder::class);
- }
- public function creator(): BelongsTo
- {
- return $this->belongsTo(User::class);
- }
- }
|