101 lines
2.7 KiB
PHP
101 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
/**
|
|
* 门店订单模型(小程序下单,快照等级价;软删除,仅已取消订单可由后台删除)
|
|
*/
|
|
class StoreOrderModel extends Model
|
|
{
|
|
use HasFactory, SoftDeletes;
|
|
|
|
/** 状态:待接单(可被采购单生成归集、可取消) */
|
|
public const int STATUS_PENDING = 0;
|
|
/** 状态:已接单(已生成采购单) */
|
|
public const int STATUS_SUMMARIZED = 1;
|
|
/** 状态:采购中 */
|
|
public const int STATUS_DELIVERING = 2;
|
|
/** 状态:配送中 */
|
|
public const int STATUS_DISTRIBUTION = 3;
|
|
/** 状态:已完成 */
|
|
public const int STATUS_COMPLETED = 4;
|
|
/** 状态:已取消 */
|
|
public const int STATUS_CANCELLED = 9;
|
|
|
|
/** 状态中文名(后台文案/订单通知用) */
|
|
public const array STATUS_NAMES = [
|
|
self::STATUS_PENDING => '待接单',
|
|
self::STATUS_SUMMARIZED => '已接单',
|
|
self::STATUS_DELIVERING => '采购中',
|
|
self::STATUS_DISTRIBUTION => '配送中',
|
|
self::STATUS_COMPLETED => '已完成',
|
|
self::STATUS_CANCELLED => '已取消',
|
|
];
|
|
|
|
protected $table = 'store_order';
|
|
protected $primaryKey = 'id';
|
|
|
|
protected $fillable = [
|
|
'order_no',
|
|
'store_id',
|
|
'order_date',
|
|
'total_quantity',
|
|
'total_weight',
|
|
'total_amount',
|
|
'status',
|
|
'remark',
|
|
'purchase_id',
|
|
'bill_id',
|
|
];
|
|
|
|
protected $casts = [
|
|
'store_id' => 'integer',
|
|
'purchase_id' => 'integer',
|
|
'bill_id' => 'integer',
|
|
'order_date' => 'date:Y-m-d',
|
|
'total_quantity' => 'integer',
|
|
'total_weight' => 'decimal:3',
|
|
'total_amount' => 'decimal:2',
|
|
'status' => 'integer',
|
|
'created_at' => 'datetime:Y-m-d H:i:s',
|
|
];
|
|
|
|
/**
|
|
* 下单门店
|
|
*/
|
|
public function store(): BelongsTo
|
|
{
|
|
return $this->belongsTo(StoreModel::class, 'store_id', 'id');
|
|
}
|
|
|
|
/**
|
|
* 订单明细
|
|
*/
|
|
public function items(): HasMany
|
|
{
|
|
return $this->hasMany(StoreOrderItemModel::class, 'order_id', 'id');
|
|
}
|
|
|
|
/**
|
|
* 采购单
|
|
*/
|
|
public function purchase(): BelongsTo
|
|
{
|
|
return $this->belongsTo(PurchaseOrderModel::class, 'purchase_id', 'id');
|
|
}
|
|
|
|
/**
|
|
* 关联账单(采购单完成后按门店生成)
|
|
*/
|
|
public function bill(): BelongsTo
|
|
{
|
|
return $this->belongsTo(BillModel::class, 'bill_id', 'id');
|
|
}
|
|
}
|