| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- <?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否
- 'indemnitor', // 赔偿人 0 无 1宝时 2承运商
- 'indemnity', // 赔偿金
- 'creator_id', // 创建人
- 'remark', // 描述
- ];
- static public $enums = [
- 'type' => [
- '' => 0,
- '宝时' => 1,
- '承运商' => 2,
- ],
- 'is_indemnity' => [
- '' => 0,
- '是' => 1,
- '否' => 2,
- ],
- 'indemnitor'=> [
- '' => 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 getIndemnitorAttribute($value)
- {
- if (!$value) return '';
- return self::$enums['indemnitor'][$value];
- }
- public function setIndemnitorAttribute($value)
- {
- if (!$value) return ;
- if (is_numeric($value)) {
- $this->attributes['indemnitor'] = $value;
- } else {
- $this->attributes['indemnitor'] = self::$enums['indemnitor'][$value];
- }
- }
- public function workOrder(): BelongsTo
- {
- return $this->belongsTo(WorkOrder::class);
- }
- public function creator(): BelongsTo
- {
- return $this->belongsTo(User::class);
- }
- public function isLogisticLog(): bool
- {
- return $this->type == "承运商";
- }
- public function isBaoShiLog(): bool
- {
- return $this->type == "宝时";
- }
- }
|