88 lines
2.1 KiB
PHP
88 lines
2.1 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;
|
|
|
|
/**
|
|
* 采购单明细模型(按商品+供应商聚合,快照品名/规格;实际金额录入后用于分摊)
|
|
*/
|
|
class PurchaseOrderItemModel extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
/** 未发送供应商 */
|
|
public const NOT_SENT = 0;
|
|
/** 已发送供应商 */
|
|
public const SENT = 1;
|
|
|
|
protected $table = 'purchase_order_item';
|
|
protected $primaryKey = 'id';
|
|
|
|
protected $fillable = [
|
|
'purchase_id',
|
|
'product_id',
|
|
'supplier_id',
|
|
'product_name',
|
|
'product_spec',
|
|
'price',
|
|
'quantity',
|
|
'weight',
|
|
'amount',
|
|
'sort',
|
|
'is_sent',
|
|
'sent_at',
|
|
'supplier_confirmed_at',
|
|
'remark',
|
|
];
|
|
|
|
protected $casts = [
|
|
'purchase_id' => 'integer',
|
|
'product_id' => 'integer',
|
|
'supplier_id' => 'integer',
|
|
'price' => 'decimal:2',
|
|
'quantity' => 'decimal:2',
|
|
'weight' => 'decimal:3',
|
|
'amount' => 'decimal:2',
|
|
'sort' => 'integer',
|
|
'is_sent' => 'integer',
|
|
'sent_at' => 'datetime',
|
|
'supplier_confirmed_at' => 'datetime',
|
|
];
|
|
|
|
/**
|
|
* 所属采购单
|
|
*/
|
|
public function purchase(): BelongsTo
|
|
{
|
|
return $this->belongsTo(PurchaseOrderModel::class, 'purchase_id', 'id');
|
|
}
|
|
|
|
/**
|
|
* 采购商品
|
|
*/
|
|
public function product(): BelongsTo
|
|
{
|
|
return $this->belongsTo(ProductModel::class, 'product_id', 'id');
|
|
}
|
|
|
|
/**
|
|
* 供货供应商
|
|
*/
|
|
public function supplier(): BelongsTo
|
|
{
|
|
return $this->belongsTo(SupplierModel::class, 'supplier_id', 'id');
|
|
}
|
|
|
|
/**
|
|
* 金额分摊记录(按订货比例摊到门店/单品)
|
|
*/
|
|
public function allocations(): HasMany
|
|
{
|
|
return $this->hasMany(PurchaseAllocationModel::class, 'purchase_item_id', 'id');
|
|
}
|
|
}
|