Files
fdesk/app/common/model/StockOrderItems.php
T
2025-09-02 17:22:56 +08:00

83 lines
3.2 KiB
PHP

<?php
namespace app\common\model;
use support\Model;
class StockOrderItems extends Model
{
/**
* The connection name for the model.
*
* @var string|null
*/
protected $connection = 'mysql';
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'stock_order_items';
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'id';
/**
* Indicates if the model should be timestamped.
*
* @var bool
*/
public $timestamps = true;
protected $dateFormat = 'U';
/**
* 允许自动填充模型字段
*/
protected $fillable = ['id', 'order_id', 'product_code', 'sku_id', 'sku_snapshot', 'model_snapshot', 'quantity', 'color_interior_id', 'color_interior_snapshot', 'color_exterior_id', 'color_exterior_snapshot', 'remark', 'unit_price', 'handling_fee', 'fob_transport_fee', 'port_misc_fee', 'retrofit_fee', 'total_price', 'created_at', 'updated_at', 'unit_price_value_id', 'handling_fee_value_id', 'fob_transport_fee_value_id', 'port_misc_fee_value_id', 'retrofit_fee_value_id', 'total_price_value_id'];
/**
* 不允许自动填充模型字段
*/
protected $guarded = [];
public function unitPrice() { return $this->belongsTo(VehMoneyValue::class, 'unit_price_value_id'); }
public function handlingFee() { return $this->belongsTo(VehMoneyValue::class, 'handling_fee_value_id'); }
public function fobTransportFee() { return $this->belongsTo(VehMoneyValue::class, 'fob_transport_fee_value_id'); }
public function portMiscFee() { return $this->belongsTo(VehMoneyValue::class, 'port_misc_fee_value_id'); }
public function retrofitFee() { return $this->belongsTo(VehMoneyValue::class, 'retrofit_fee_value_id'); }
public function totalPrice() { return $this->belongsTo(VehMoneyValue::class, 'total_price_value_id'); }
// 便捷访问器(原币种的金额)
public function getUnitPriceAmountAttribute() { return $this->unitPrice?->amount; }
public function getHandlingFeeAmountAttribute() { return $this->handlingFee?->amount; }
public function getFobTransportFeeAmountAttribute() { return $this->fobTransportFee?->amount; }
public function getPortMiscFeeAmountAttribute() { return $this->portMiscFee?->amount; }
public function getRetrofitFeeAmountAttribute() { return $this->retrofitFee?->amount; }
public function getTotalPriceAmountAttribute() { return $this->totalPrice?->amount; }
// 便捷:按“各自 exchange_rate”换到结算币后相加(无 rate 的跳过)
public function sumToSettlement(): string
{
$list = array_filter([
$this->unitPrice?->amountInSettlement(),
$this->handlingFee?->amountInSettlement(),
$this->fobTransportFee?->amountInSettlement(),
$this->portMiscFee?->amountInSettlement(),
$this->retrofitFee?->amountInSettlement(),
], fn($v) => $v !== null);
$sum = '0.00';
foreach ($list as $v) {
$sum = bcadd($sum, (string)$v, 2);
}
return $sum;
}
}