6
0
Fork 0
jiqu-library-server/app/Models/OrderPackage.php

111 lines
2.8 KiB
PHP

<?php
namespace App\Models;
use Dcat\Admin\Traits\HasDateTimeFormatter;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class OrderPackage extends Model
{
use HasFactory;
use HasDateTimeFormatter;
public const STATUS_WAIT = 1;//揽收
public const STATUS_ONTHEWAY = 0;//途中
public const STATUS_DISTRIBUTE = 5;//派送
public const STATUS_CHECK = 3;//签收
public const STATUS_QUESTION = 2;//疑难:问题包裹
public const STATUS_REFUND = 4;//退签
public const STATUS_REFUSE = 6;//拒签
public const STATUS_OTHER = 10;//其他
public const STATUS_AUTOCHECK = 11;//自动签收
public static $shippingCompanyTexts = [
'圆通速递'=>'圆通速递',
'韵达快递'=>'韵达快递',
'中通快递'=>'中通快递',
'申通快递'=>'申通快递',
'百世快递'=>'百世快递',
'EMS'=>'EMS',
'顺丰速运'=>'顺丰速运',
'德邦快递'=>'德邦快递',
];
public static $kuaidi100StatusMap = [
'wait' => self::STATUS_WAIT,
'on_the_way' => self::STATUS_ONTHEWAY,
'distribute' => self::STATUS_DISTRIBUTE,
'check' => self::STATUS_CHECK,
'refund' => self::STATUS_REFUND,
'refuse' => self::STATUS_REFUSE,
'questions'=> self::STATUS_QUESTION,
];
protected $attributes = [
'status' => self::STATUS_WAIT,
'is_failed'=> false,
];
protected $casts = [
'checked_at' => 'datetime',
'is_failed' => 'bool',
];
protected $fillable = [
'remarks', 'status', 'is_failed', 'checked_at', 'last_news',
];
/**
* 未签收的包裹
*/
public function scopeUnchecked($query)
{
return $query->whereNotIn('status', [static::STATUS_CHECK, static::STATUS_AUTOCHECK]);
}
/**
* 订单
*/
public function order()
{
return $this->belongsTo(Order::class, 'order_id');
}
/**
* 货运单商品
*
*/
public function packageProducts()
{
return $this->hasMany(OrderPackageProduct::class, 'order_package_id');
}
/**
* 关联的订单商品
*
*/
public function orderProducts()
{
return $this->belongsToMany(OrderProduct::class, 'order_package_products', 'order_package_id', 'order_product_id');
}
/**
* 属于此货运单单的标签
*/
public function tags()
{
return $this->belongsToMany(Tag::class, 'taggables', 'taggable_id', 'tag_id')->wherePivot('taggable_type', self::class)->withTimestamps();
}
/**
* 确认此包裹是否已签收
*
* @return bool
*/
public function isChecked()
{
return in_array($this->status, [static::STATUS_CHECK, static::STATUS_AUTOCHECK]);
}
}