| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265 |
- <?php
- namespace App;
- use App\Traits\ModelTimeFormat;
- use App\Traits\ModelLogChanging;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Database\Eloquent\Relations\BelongsTo;
- use Illuminate\Database\Eloquent\Relations\BelongsToMany;
- use Illuminate\Database\Eloquent\Relations\HasMany;
- use Illuminate\Support\Facades\Auth;
- class WorkOrderDetail extends Model
- {
- use ModelLogChanging;
- use ModelTimeFormat;
- protected $fillable = [
- 'work_order_id',
- 'order_issue_type_id', // 工单异常类型
- 'price', // 商品价值
- 'sku_amount', // 破损sku数
- 'type', // 快递异常填写:在途异常,签收未收到
- 'last_handler_id', // 上一个处理人
- 'reissue_logistic_number', // 补发单号
- 'return_logistic_number', // 退回单号 (错漏发:商家填写) (破损:创建时填写)
- 'process_progress', // 处理进度
- 'logistic_number', // 快递单号
- 'status', // 当前状态
- 'remark', // 创建工单时的问题标记
- 'tag', // 标记当前工单是否为历史标记
- 'receive_address', // 收方信息
- 'return_address', // 退回单 寄件人地址
- 'return_phone', // 退回单 寄件人联系号码
- 'return_name', // 退回单 寄件人姓名
- 'logistic_handle_tag', // 承运商在处理标记
- ];
- static public $enums = [
- 'status' => [
- '' => 0,
- '宝时处理' => 1,
- '货主处理' => 2,
- '承运商处理' => 3,
- '宝时终审' => 4,
- '完成' => 5,
- '待货主完结' => 6,
- ],
- 'last_status' => [
- '' => 0,
- '宝时处理' => 1,
- '货主处理' => 2,
- '承运商处理' => 3,
- '宝时终审' => 4,
- '完成' => 5,
- '待货主完结' => 6,
- ],
- 'tag' => [
- '创建' => 0,
- '完成' => 1,
- '标记' => 2,
- ],
- 'last_handler' => [
- '' => 0,
- '商家' => 1,
- '承运商' => 2,
- '宝时' => 3,
- ],
- 'logistic_handle_tag' => [
- '' => 0,
- '承运商处理中' => 1,
- '取消标记' => 2
- ],
- ];
- function __construct(array $attributes = [])
- {
- foreach (self::$enums as &$enum) {
- $enum = $enum + array_flip($enum);
- }
- parent::__construct($attributes);
- }
- public function getLogisticHandleTagAttribute($value)
- {
- if (!$value) return '';
- return self::$enums['logistic_handle_tag'][$value];
- }
- public function setLogisticHandleTagAttribute($value)
- {
- if (!$value) return;
- if (is_numeric($value)) {
- $this->attributes['logistic_handle_tag'] = $value;
- } else {
- $this->attributes['logistic_handle_tag'] = self::$enums['logistic_handle_tag'][$value];
- }
- }
- 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 getLastStatusAttribute($value)
- {
- if (!$value) return '';
- return self::$enums['last_status'][$value];
- }
- public function setLastStatusAttribute($value)
- {
- if (!$value) return;
- if (is_numeric($value)) {
- $this->attributes['last_status'] = $value;
- } else {
- $this->attributes['last_status'] = self::$enums['last_status'][$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 processLogs(): HasMany
- {
- return $this->hasMany(WorkOrderProcessLog::class,'work_order_detail_id','id');
- }
- public function userOwnerGroup(): BelongsTo
- {
- return $this->belongsTo(UserOwnerGroup::class);
- }
- public function userWorkgroups(): BelongsToMany
- {
- return $this->belongsToMany(UserWorkgroup::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();
- }
- public function changeProcessProgress($process_progress)
- {
- $this->update(['process_progress' => $process_progress]);
- }
- /**
- * 工单状态 and 处理状态
- * @param $status
- * @param $process_progress
- * @param $last_status
- */
- public function change($status, $process_progress, $last_status)
- {
- $user = Auth::user();
- $this->status = $status;
- $this->last_status = $last_status;
- $this->process_progress = $process_progress;
- $this->last_handler_id = $user['id'] ?? '';
- $this->update();
- }
- public function logisticTagHandle()
- {
- $this->update(['logistic_handle_tag' => 1]);
- }
- public function cancelLogisticTagHandle()
- {
- $this->logistic_handle_tag = '取消标记';
- $this->update();
- }
- }
|