调整利润计算
This commit is contained in:
@@ -601,25 +601,100 @@ class StockOrdersService
|
||||
*/
|
||||
private function calculateProfit(array $veh, $order): float
|
||||
{
|
||||
$unitPrice = (float)($veh['unit_price']['amount'] ?? 0);
|
||||
$contractExchangeRate = $order->contract_exchange_rate ?: 1;
|
||||
|
||||
if (!empty($veh['mileage']) && $veh['mileage'] > 0) {
|
||||
// 二手车
|
||||
$ttPrice = ($veh['listing_price']['amount'] ?? 0) / ($order->contract_exchange_rate ?: 1);
|
||||
$ddPrice = $veh['reduction_price']['amount'] ?? 0;
|
||||
// 提取单价并进行汇率转换(如果需要)
|
||||
$unitPriceRate = $veh['unit_price']['rate'] ?: 1;
|
||||
if ($unitPriceRate != $contractExchangeRate) {
|
||||
$unitPrice = (float)($veh['unit_price']['amount'] ?? 0) / $contractExchangeRate;
|
||||
} else {
|
||||
// 新车
|
||||
$ttPrice = ($veh['official_price']['amount'] ?? 0) / ($order->contract_exchange_rate ?: 1);
|
||||
$ddPrice = $veh['discount_price']['amount'] ?? 0;
|
||||
$unitPrice = (float)($veh['unit_price']['amount'] ?? 0);
|
||||
}
|
||||
|
||||
$handlingFee = (float)($veh['handling_fee']['amount'] ?? 0);
|
||||
$fobTransportFee = (float)($veh['fob_transport_fee']['amount'] ?? 0);
|
||||
$portMiscFee = (float)($veh['port_misc_fee']['amount'] ?? 0);
|
||||
$retrofitFee = (float)($veh['retrofit_fee']['amount'] ?? 0);
|
||||
$oceanFreight = (float)($veh['ocean_freight']['amount'] ?? 0);
|
||||
$commission = (float)($veh['commission']['amount'] ?? 0);
|
||||
$purchaseTax = (float)($veh['purchase_tax']['amount'] ?? 0);
|
||||
// 处理主要价格字段,根据是否需要汇率转换来计算
|
||||
if (!empty($veh['mileage']) && $veh['mileage'] > 0) {
|
||||
// 二手车
|
||||
$listingPriceRate = $veh['listing_price']['rate'] ?: 1;
|
||||
if ($listingPriceRate != $contractExchangeRate) {
|
||||
$ttPrice = ($veh['listing_price']['amount'] ?? 0) / $contractExchangeRate;
|
||||
} else {
|
||||
$ttPrice = $veh['listing_price']['amount'] ?? 0;
|
||||
}
|
||||
|
||||
$reductionPriceRate = $veh['reduction_price']['rate'] ?: 1;
|
||||
if ($reductionPriceRate != $contractExchangeRate) {
|
||||
$ddPrice = ($veh['reduction_price']['amount'] ?? 0) / $contractExchangeRate;
|
||||
} else {
|
||||
$ddPrice = $veh['reduction_price']['amount'] ?? 0;
|
||||
}
|
||||
} else {
|
||||
// 新车
|
||||
$officialPriceRate = $veh['official_price']['rate'] ?: 1;
|
||||
if ($officialPriceRate != $contractExchangeRate) {
|
||||
$ttPrice = ($veh['official_price']['amount'] ?? 0) / $contractExchangeRate;
|
||||
} else {
|
||||
$ttPrice = $veh['official_price']['amount'] ?? 0;
|
||||
}
|
||||
|
||||
$discountPriceRate = $veh['discount_price']['rate'] ?: 1;
|
||||
if ($discountPriceRate != $contractExchangeRate) {
|
||||
$ddPrice = ($veh['discount_price']['amount'] ?? 0) / $contractExchangeRate;
|
||||
} else {
|
||||
$ddPrice = $veh['discount_price']['amount'] ?? 0;
|
||||
}
|
||||
}
|
||||
|
||||
// 处理其他费用字段,根据是否需要汇率转换来计算
|
||||
$handlingFeeRate = $veh['handling_fee']['rate'] ?: 1;
|
||||
if ($handlingFeeRate != $contractExchangeRate) {
|
||||
$handlingFee = (float)($veh['handling_fee']['amount'] ?? 0) / $contractExchangeRate;
|
||||
} else {
|
||||
$handlingFee = (float)($veh['handling_fee']['amount'] ?? 0);
|
||||
}
|
||||
|
||||
$fobTransportFeeRate = $veh['fob_transport_fee']['rate'] ?: 1;
|
||||
if ($fobTransportFeeRate != $contractExchangeRate) {
|
||||
$fobTransportFee = (float)($veh['fob_transport_fee']['amount'] ?? 0) / $contractExchangeRate;
|
||||
} else {
|
||||
$fobTransportFee = (float)($veh['fob_transport_fee']['amount'] ?? 0);
|
||||
}
|
||||
|
||||
$portMiscFeeRate = $veh['port_misc_fee']['rate'] ?: 1;
|
||||
if ($portMiscFeeRate != $contractExchangeRate) {
|
||||
$portMiscFee = (float)($veh['port_misc_fee']['amount'] ?? 0) / $contractExchangeRate;
|
||||
} else {
|
||||
$portMiscFee = (float)($veh['port_misc_fee']['amount'] ?? 0);
|
||||
}
|
||||
|
||||
$retrofitFeeRate = $veh['retrofit_fee']['rate'] ?: 1;
|
||||
if ($retrofitFeeRate != $contractExchangeRate) {
|
||||
$retrofitFee = (float)($veh['retrofit_fee']['amount'] ?? 0) / $contractExchangeRate;
|
||||
} else {
|
||||
$retrofitFee = (float)($veh['retrofit_fee']['amount'] ?? 0);
|
||||
}
|
||||
|
||||
$oceanFreightRate = $veh['ocean_freight']['rate'] ?: 1;
|
||||
if ($oceanFreightRate != $contractExchangeRate) {
|
||||
$oceanFreight = (float)($veh['ocean_freight']['amount'] ?? 0) / $contractExchangeRate;
|
||||
} else {
|
||||
$oceanFreight = (float)($veh['ocean_freight']['amount'] ?? 0);
|
||||
}
|
||||
|
||||
$commissionRate = $veh['commission']['rate'] ?: 1;
|
||||
if ($commissionRate != $contractExchangeRate) {
|
||||
$commission = (float)($veh['commission']['amount'] ?? 0) / $contractExchangeRate;
|
||||
} else {
|
||||
$commission = (float)($veh['commission']['amount'] ?? 0);
|
||||
}
|
||||
|
||||
$purchaseTaxRate = $veh['purchase_tax']['rate'] ?: 1;
|
||||
if ($purchaseTaxRate != $contractExchangeRate) {
|
||||
$purchaseTax = (float)($veh['purchase_tax']['amount'] ?? 0) / $contractExchangeRate;
|
||||
} else {
|
||||
$purchaseTax = (float)($veh['purchase_tax']['amount'] ?? 0);
|
||||
}
|
||||
|
||||
// 预估退税不需要参与汇率转换计算,前端已经计算过了
|
||||
$taxRefund = (float)($veh['tax_refund']['amount'] ?? 0);
|
||||
|
||||
// 退税额 是增加利润
|
||||
|
||||
Reference in New Issue
Block a user