83 lines
2.2 KiB
PHP
83 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 Modules\SystemUser\Models\SysUserModel;
|
||
|
||
/**
|
||
* 采购单模型(按门店订单汇总生成;无独立明细表,明细直接溯源订货明细 store_order_item.purchase_id)
|
||
*/
|
||
class PurchaseOrderModel extends Model
|
||
{
|
||
use HasFactory;
|
||
|
||
/** 状态:进行中(已生成,待完成) */
|
||
public const int STATUS_PENDING = 0;
|
||
/** 状态:已完成 */
|
||
public const int STATUS_COMPLETED = 3;
|
||
|
||
protected $table = 'purchase_order';
|
||
protected $primaryKey = 'id';
|
||
|
||
protected $fillable = [
|
||
'purchase_no',
|
||
'purchase_date',
|
||
'status',
|
||
'total_quantity',
|
||
'total_weight',
|
||
'estimate_amount',
|
||
'actual_amount',
|
||
'operator_id',
|
||
'remark',
|
||
];
|
||
|
||
protected $casts = [
|
||
'purchase_date' => 'date:Y-m-d',
|
||
'status' => 'integer',
|
||
'total_quantity' => 'decimal:2',
|
||
'total_weight' => 'decimal:3',
|
||
'estimate_amount' => 'decimal:2',
|
||
'actual_amount' => 'decimal:2',
|
||
'operator_id' => 'integer',
|
||
'created_at' => 'datetime:Y-m-d H:i:s',
|
||
// 列表 withSum 聚合属性(应付商品金额;无账单时保持 null)
|
||
'bill_product_amount' => 'decimal:2',
|
||
];
|
||
|
||
/**
|
||
* 制单人(后台系统用户)
|
||
*/
|
||
public function operator(): BelongsTo
|
||
{
|
||
return $this->belongsTo(SysUserModel::class, 'operator_id', 'id');
|
||
}
|
||
|
||
/**
|
||
* 本采购单归集的门店订货明细
|
||
*/
|
||
public function orderItems(): HasMany
|
||
{
|
||
return $this->hasMany(StoreOrderItemModel::class, 'purchase_id', 'id');
|
||
}
|
||
|
||
/**
|
||
* 本采购单合并的门店订单
|
||
*/
|
||
public function orders(): HasMany
|
||
{
|
||
return $this->hasMany(StoreOrderModel::class, 'purchase_id', 'id');
|
||
}
|
||
|
||
/**
|
||
* 本采购单生成的门店账单
|
||
*/
|
||
public function bills(): HasMany
|
||
{
|
||
return $this->hasMany(BillModel::class, 'purchase_id', 'id');
|
||
}
|
||
}
|