Files
xin-procurement/app/Models/PurchaseAllocationModel.php
T
2026-07-23 20:41:25 +08:00

68 lines
1.5 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* 采购金额分摊模型(实际采购金额按订货比例分摊到门店/单品,尾差修正保证金额守恒)
*/
class PurchaseAllocationModel extends Model
{
protected $table = 'purchase_allocation';
protected $primaryKey = 'id';
protected $fillable = [
'purchase_item_id',
'order_item_id',
'store_id',
'product_id',
'quantity',
'weight',
'amount',
];
protected $casts = [
'purchase_item_id' => 'integer',
'order_item_id' => 'integer',
'store_id' => 'integer',
'product_id' => 'integer',
'quantity' => 'decimal:2',
'weight' => 'decimal:3',
'amount' => 'decimal:2',
];
/**
* 来源采购明细
*/
public function purchaseItem(): BelongsTo
{
return $this->belongsTo(PurchaseOrderItemModel::class, 'purchase_item_id', 'id');
}
/**
* 溯源订货明细
*/
public function orderItem(): BelongsTo
{
return $this->belongsTo(StoreOrderItemModel::class, 'order_item_id', 'id');
}
/**
* 分摊门店
*/
public function store(): BelongsTo
{
return $this->belongsTo(StoreModel::class, 'store_id', 'id');
}
/**
* 分摊商品
*/
public function product(): BelongsTo
{
return $this->belongsTo(ProductModel::class, 'product_id', 'id');
}
}