| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- <?php
- namespace App;
- use App\Traits\ModelTimeFormat;
- use Illuminate\Database\Eloquent\Model;
- use App\Traits\ModelLogChanging;
- use Illuminate\Database\Eloquent\Relations\BelongsTo;
- use Illuminate\Database\Eloquent\Relations\HasMany;
- class WorkOrderDetail extends Model
- {
- use ModelLogChanging;
- use ModelTimeFormat;
- protected $fillable = [
- 'work_order_id',
- 'order_issue_type_id', // 工单异常类型
- 'price', // 商品价值
- 'sku_amount', // 破损sku数
- 'receive_address', // 收方信息
- 'reissue_logistic_number', // 补发单号
- 'return_logistic_number', // 退回单号
- 'logistic_number', // 快递单号
- 'status', // 当前状态
- 'remark', // 创建工单时的问题标记
- 'tag', // 标记当前工单是否为历史标记
- ];
- static public $enums = [
- 'status' => [
- '' => 0,
- '宝时处理' => 1,
- '货主处理' => 2,
- '承运商处理' => 3,
- '宝时终审' => 4,
- '完成' => 5,
- '待货主完结' => 6,
- ],
- 'tag' => [
- '创建' => 0,
- '完成' => 1,
- '标记' => 2,
- ],
- ];
- function __construct(array $attributes = [])
- {
- foreach (self::$enums as &$enum) {
- $enum = $enum + array_flip($enum);
- }
- parent::__construct($attributes);
- }
- public function getStatusAttribute($value)
- {
- if (!$value) return '';
- return self::$enums['status'][$value];
- }
- public function setStatusAttribute($value)
- {
- if (!$value) return;
- if (is_numeric($value)) {
- $this->attributes['status'] = $value;
- } else {
- $this->attributes['status'] = self::$enums['status'][$value];
- }
- }
- public function getTagAttribute($value)
- {
- if (is_numeric($value)) return self::$enums['tag'][$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 workOrder(): BelongsTo
- {
- return $this->belongsTo(WorkOrder::class);
- }
- public function issueType(): BelongsTo
- {
- return $this->belongsTo(OrderIssueType::class,'order_issue_type_id');
- }
- // 图片
- public function images(): HasMany
- {
- return $this->hasMany(WorkOrderImage::class);
- }
- public function getPackageImagesAttribute()
- {
- return $this->images->where('type', 1);
- }
- public function getCommodityImagesAttribute()
- {
- return $this->images->where('type', 2);
- }
- public function getDealImagesAttribute()
- {
- return $this->images->where('type', 3);
- }
- public function getRefundImagesAttribute()
- {
- return $this->images->where('type', 4);
- }
- public function logs(): HasMany
- {
- return $this->hasMany(WorkOrderLog::class);
- }
- public function commodities(): HasMany
- {
- return $this->hasMany(WorkOrderCommodities::class);
- }
- // 未完成历史标记
- public function undoneTag(){
- if ($this->tag != '完成'){
- $this->update(['tag' => 2]);
- }
- }
- // 完成标记
- public function end(){
- $this->status = 5;
- $this->tag = 1;
- $this->update();
- }
- public function changeStatus($status)
- {
- $this->status = $status;
- $this->update();
- }
- }
|