You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							77 lines
						
					
					
						
							1.5 KiB
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							77 lines
						
					
					
						
							1.5 KiB
						
					
					
				
								<?php
							 | 
						|
								
							 | 
						|
								namespace App\Models;
							 | 
						|
								
							 | 
						|
								use Illuminate\Database\Eloquent\Factories\HasFactory;
							 | 
						|
								use Illuminate\Database\Eloquent\SoftDeletes;
							 | 
						|
								use App\Common\OrderStatus as Status;
							 | 
						|
								
							 | 
						|
								class Order extends BaseModel
							 | 
						|
								{
							 | 
						|
								    use HasFactory, SoftDeletes;
							 | 
						|
									protected $guarded = ['created_at', 'updated_at']; //不可批量赋值的属性
							 | 
						|
								
							 | 
						|
									public function getCouponIdAttribute($value)
							 | 
						|
									{
							 | 
						|
										return explode(',', $value);
							 | 
						|
									}
							 | 
						|
								
							 | 
						|
									public function getStatusAttribute($value)
							 | 
						|
									{
							 | 
						|
										$this->append('status_text');
							 | 
						|
										return $value;
							 | 
						|
									}
							 | 
						|
								
							 | 
						|
									public function getStatusTextAttribute()
							 | 
						|
									{
							 | 
						|
										return Status::array()[$this->status] ?? '未知';
							 | 
						|
									}
							 | 
						|
								
							 | 
						|
									//退款信息
							 | 
						|
									public function getRefundInfoAttribute($value): array
							 | 
						|
									{
							 | 
						|
										$value = $value ? json_decode($value, true) : [];
							 | 
						|
										if (!empty($value['pictures']) && is_array($value['pictures'])) {
							 | 
						|
											foreach ($value['pictures'] as &$v) {
							 | 
						|
												$v = $this->host . $v;
							 | 
						|
											}
							 | 
						|
										}
							 | 
						|
										return $value ?? [];
							 | 
						|
									}
							 | 
						|
								
							 | 
						|
									public function getPictureAttribute($value): string
							 | 
						|
									{
							 | 
						|
										return $value ? $this->host . $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);
							 | 
						|
									}
							 | 
						|
								
							 | 
						|
									public function supplier()
							 | 
						|
									{
							 | 
						|
										return $this->belongsTo(Supplier::class);
							 | 
						|
									}
							 | 
						|
								}
							 |