Files
xin-procurement/app/Models/StoreOrderModel.php
T
2026-08-12 17:30:46 +08:00

82 lines
2.2 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;
protected $table = 'store_order';
protected $primaryKey = 'id';
protected $fillable = [
'order_no',
'store_id',
'order_date',
'total_quantity',
'total_weight',
'total_amount',
'product_amount',
'added_amount',
'box_num',
'tray_num',
'status',
'remark',
'purchase_id',
];
protected $casts = [
'store_id' => 'integer',
'purchase_id' => 'integer',
'statement_id' => 'integer',
'order_date' => 'date:Y-m-d',
'total_quantity' => 'integer',
'total_weight' => 'decimal:3',
'total_amount' => 'decimal:2',
'product_amount' => 'decimal:2',
'added_amount' => 'decimal:2',
'box_num' => 'integer',
'tray_num' => 'integer',
'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');
}
}