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; } }