128 lines
2.9 KiB
PHP
128 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Casts\JsonArray;
|
|
use App\Enums\DealerOrderSettleState;
|
|
use App\Enums\DealerOrderStatus;
|
|
use Dcat\Admin\Traits\HasDateTimeFormatter;
|
|
use EloquentFilter\Filterable;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class DealerOrder extends Model
|
|
{
|
|
use Filterable;
|
|
use HasDateTimeFormatter;
|
|
|
|
/**
|
|
* 订单状态
|
|
*/
|
|
public const STATUS_PENDING = 0; // 待确认
|
|
public const STATUS_PENDINGED = 1; // 已确认 待付款
|
|
public const STATUS_PAY = 2; // 已付款 待收款
|
|
public const STATUS_PAID = 3; // 已收款 待发货
|
|
public const STATUS_SHIPPING = 4; // 已发货 待收货
|
|
public const STATUS_COMPLETED = 9; // 已完成
|
|
public const STATUS_CANCELLED = 10; // 已取消
|
|
|
|
protected $attributes = [
|
|
'status' => DealerOrderStatus::Pending,
|
|
'settle_state' => DealerOrderSettleState::Pending,
|
|
];
|
|
|
|
protected $casts = [
|
|
'status' => DealerOrderStatus::class,
|
|
'settle_state' => DealerOrderSettleState::class,
|
|
'pay_info'=>JsonArray::class,
|
|
];
|
|
|
|
/**
|
|
* 获取待确认订单
|
|
*/
|
|
public function scopeOnlyPending($query)
|
|
{
|
|
return $query->where('status', static::STATUS_PENDING);
|
|
}
|
|
|
|
/**
|
|
* 已确认/待付款
|
|
*/
|
|
public function scopeOnlyPendinged($query)
|
|
{
|
|
return $query->where('status', static::STATUS_PENDINGED);
|
|
}
|
|
|
|
/**
|
|
* 已收款/待发货
|
|
*/
|
|
public function scopeOnlyPaid($query)
|
|
{
|
|
return $query->where('status', static::STATUS_PAID);
|
|
}
|
|
|
|
/**
|
|
* 已发货/待收货
|
|
*/
|
|
public function scopeOnlyShipping($query)
|
|
{
|
|
return $query->where('status', static::STATUS_SHIPPING);
|
|
}
|
|
|
|
/**
|
|
* 已完成
|
|
*/
|
|
public function scopeOnlyCompleted($query)
|
|
{
|
|
return $query->where('status', static::STATUS_COMPLETED);
|
|
}
|
|
|
|
/**
|
|
* 已取消
|
|
*/
|
|
public function scopeOnlyCancelled($query)
|
|
{
|
|
return $query->where('status', static::STATUS_CANCELLED);
|
|
}
|
|
|
|
/**
|
|
* 此订单所属的用户的信息
|
|
*/
|
|
public function userInfo()
|
|
{
|
|
return $this->belongsTo(UserInfo::class, 'user_id', 'user_id');
|
|
}
|
|
|
|
/**
|
|
* 属于此订单的商品
|
|
*/
|
|
public function products()
|
|
{
|
|
return $this->hasMany(DealerOrderProduct::class, 'order_id');
|
|
}
|
|
|
|
public function user()
|
|
{
|
|
return $this->belongsTo(User::class, 'user_id');
|
|
}
|
|
|
|
public function consignor()
|
|
{
|
|
return $this->belongsTo(User::class, 'consignor_id');
|
|
}
|
|
|
|
public function isUser($userId)
|
|
{
|
|
return $this->user_id == $userId;
|
|
}
|
|
|
|
public function isConsignor($userId)
|
|
{
|
|
return $this->consignor_id == $userId;
|
|
}
|
|
|
|
public function canCurd($userId)
|
|
{
|
|
return $this->isUser($userId) || $this->isConsignor($userId);
|
|
}
|
|
}
|