'json']; protected $dispatchesEvents = [ 'updated' => OrderUpdated::class, ]; public function scopeComplete($query) { return $query->where('status',OrderStatus::SUCCESS); } public function getCouponIdAttribute($value) { return explode(',', $value); } public function getStatusAttribute($value) { $this->append('status_text'); return $value; } public function getStatusTextAttribute() { return Status::array()[$this->attributes['status']] ?? '未知'; } public function getPayTypeAttribute($value) { $this->append('pay_type_text'); return $value; } public function getPayTypeTextAttribute() { return PayType::array()[$this->attributes['pay_type']] ?? '未知'; } //退款信息 public function getRefundInfoAttribute($value): array { $value = $value ? json_decode($value, true) : []; if (!empty($value['pictures']) && is_array($value['pictures'])) { $prefix = Storage::disk('public')->url(''); foreach ($value['pictures'] as &$v) { if ($v && strpos($v, $prefix) === false) { $v = $prefix . $v; } } } return $value ?? []; } public function getPictureAttribute($value): string { $prefix = Storage::disk('public')->url(''); return $value && substr($value, 0, 4) != 'http' ? $prefix . $value : ''; } public function setPictureAttribute($value) { //修改器里面$this->host变量为空 $this->attributes['picture'] = str_replace(env('APP_URL'), '', $value); } public function agentProduct() { return $this->belongsTo(AgentProduct::class); } public function product() { return $this->belongsTo(Product::class); } public function coupon() { return $this->belongsTo(Coupon::class); } public function agent() { return $this->belongsTo(Agent::class)->withTrashed(); } public function supplier() { return $this->belongsTo(Supplier::class)->withTrashed(); } public function user() { return $this->belongsTo(User::class)->withTrashed(); } public function agentProductItem() { return $this->hasMany(AgentProductItem::class, 'agent_product_id', 'agent_product_id'); } public function orderProductItem() { return $this->hasMany(OrderProductItem::class); } public function guide() { return $this->belongsTo(Guide::class)->withTrashed(); } //关联的计调云产品 public function agentCloud() { return $this->belongsTo(AgentProduct::class, 'agent_cloud_pid', 'id'); } public function statementAdmin() { return $this->hasMany(StatementAdmin::class,'order_id','id'); } public function statement() { return $this->morphMany(Statement::class,'access'); } }