Finish mzl_dev
This commit is contained in:
@@ -485,7 +485,7 @@ class StockOrdersService
|
|||||||
$this->processVehiclePrices($item, $veh);
|
$this->processVehiclePrices($item, $veh);
|
||||||
|
|
||||||
// 计算利润
|
// 计算利润
|
||||||
$profit = $this->calculateProfit($veh, $order);
|
$profit = $this->calculateProfit($veh, $item->mileage, $order);
|
||||||
$item->addMoney('profit', $order->settlement_currency, $profit, $order->contract_exchange_rate, '利润');
|
$item->addMoney('profit', $order->settlement_currency, $profit, $order->contract_exchange_rate, '利润');
|
||||||
|
|
||||||
// 累计到岸价
|
// 累计到岸价
|
||||||
@@ -539,87 +539,150 @@ class StockOrdersService
|
|||||||
];
|
];
|
||||||
|
|
||||||
foreach ($priceFields as $field => $description) {
|
foreach ($priceFields as $field => $description) {
|
||||||
if (!empty($veh[$field]['amount'])) {
|
$item->addMoney(
|
||||||
$item->addMoney(
|
$field,
|
||||||
$field,
|
$veh[$field]['currency'],
|
||||||
$veh[$field]['currency'],
|
(float)$veh[$field]['amount'],
|
||||||
$veh[$field]['amount'],
|
$veh[$field]['rate'],
|
||||||
$veh[$field]['rate'],
|
$description
|
||||||
$description
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据里程处理新车或二手车价格
|
// 根据里程处理新车或二手车价格
|
||||||
if (!empty($veh['mileage']) && $veh['mileage'] > 0) {
|
if (!empty($veh['mileage']) && $veh['mileage'] > 0) {
|
||||||
// 二手车
|
// 二手车
|
||||||
if (!empty($veh['listing_price']['amount'])) {
|
$item->addMoney(
|
||||||
$item->addMoney(
|
'listing_price',
|
||||||
'listing_price',
|
$veh['listing_price']['currency'],
|
||||||
$veh['listing_price']['currency'],
|
(float)$veh['listing_price']['amount'],
|
||||||
$veh['listing_price']['amount'],
|
$veh['listing_price']['rate'],
|
||||||
$veh['listing_price']['rate'],
|
'二手挂牌价'
|
||||||
'二手挂牌价'
|
);
|
||||||
);
|
$item->addMoney(
|
||||||
}
|
'reduction_price',
|
||||||
|
$veh['reduction_price']['currency'],
|
||||||
if (!empty($veh['reduction_price']['amount'])) {
|
(float)$veh['reduction_price']['amount'],
|
||||||
$item->addMoney(
|
$veh['reduction_price']['rate'],
|
||||||
'reduction_price',
|
'二手减价'
|
||||||
$veh['reduction_price']['currency'],
|
);
|
||||||
$veh['reduction_price']['amount'],
|
|
||||||
$veh['reduction_price']['rate'],
|
|
||||||
'二手减价'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// 新车
|
// 新车
|
||||||
if (!empty($veh['official_price']['amount'])) {
|
$item->addMoney(
|
||||||
$item->addMoney(
|
'official_price',
|
||||||
'official_price',
|
$veh['official_price']['currency'],
|
||||||
$veh['official_price']['currency'],
|
(float)$veh['official_price']['amount'],
|
||||||
$veh['official_price']['amount'],
|
$veh['official_price']['rate'],
|
||||||
$veh['official_price']['rate'],
|
'官方指导价'
|
||||||
'官方指导价'
|
);
|
||||||
);
|
$item->addMoney(
|
||||||
}
|
'discount_price',
|
||||||
|
$veh['discount_price']['currency'],
|
||||||
if (!empty($veh['discount_price']['amount'])) {
|
(float)$veh['discount_price']['amount'],
|
||||||
$item->addMoney(
|
$veh['discount_price']['rate'],
|
||||||
'discount_price',
|
'优惠价'
|
||||||
$veh['discount_price']['currency'],
|
);
|
||||||
$veh['discount_price']['amount'],
|
|
||||||
$veh['discount_price']['rate'],
|
|
||||||
'优惠价'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 计算利润
|
* 计算利润
|
||||||
*/
|
*/
|
||||||
private function calculateProfit(array $veh, $order): float
|
private function calculateProfit(array $veh, int $mileage, $order): float
|
||||||
{
|
{
|
||||||
$unitPrice = (float)($veh['unit_price']['amount'] ?? 0);
|
$contractExchangeRate = $order->contract_exchange_rate ?: 1;
|
||||||
|
|
||||||
if (!empty($veh['mileage']) && $veh['mileage'] > 0) {
|
// 提取单价并进行汇率转换(如果需要)
|
||||||
// 二手车
|
$unitPriceRate = $veh['unit_price']['rate'] ?: 1;
|
||||||
$ttPrice = ($veh['listing_price']['amount'] ?? 0) / ($order->contract_exchange_rate ?: 1);
|
if ($unitPriceRate != $contractExchangeRate) {
|
||||||
$ddPrice = $veh['reduction_price']['amount'] ?? 0;
|
$unitPrice = (float)($veh['unit_price']['amount'] ?? 0) / $contractExchangeRate;
|
||||||
} else {
|
} else {
|
||||||
// 新车
|
$unitPrice = (float)($veh['unit_price']['amount'] ?? 0);
|
||||||
$ttPrice = ($veh['official_price']['amount'] ?? 0) / ($order->contract_exchange_rate ?: 1);
|
|
||||||
$ddPrice = $veh['discount_price']['amount'] ?? 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$handlingFee = (float)($veh['handling_fee']['amount'] ?? 0);
|
// 处理主要价格字段,根据是否需要汇率转换来计算
|
||||||
$fobTransportFee = (float)($veh['fob_transport_fee']['amount'] ?? 0);
|
if ($mileage > 0) {
|
||||||
$portMiscFee = (float)($veh['port_misc_fee']['amount'] ?? 0);
|
// 二手车
|
||||||
$retrofitFee = (float)($veh['retrofit_fee']['amount'] ?? 0);
|
$listingPriceRate = $veh['listing_price']['rate'] ?: 1;
|
||||||
$oceanFreight = (float)($veh['ocean_freight']['amount'] ?? 0);
|
if ($listingPriceRate != $contractExchangeRate) {
|
||||||
$commission = (float)($veh['commission']['amount'] ?? 0);
|
$ttPrice = ($veh['listing_price']['amount'] ?? 0) / $contractExchangeRate;
|
||||||
$purchaseTax = (float)($veh['purchase_tax']['amount'] ?? 0);
|
} 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);
|
$taxRefund = (float)($veh['tax_refund']['amount'] ?? 0);
|
||||||
|
|
||||||
// 退税额 是增加利润
|
// 退税额 是增加利润
|
||||||
@@ -750,7 +813,7 @@ class StockOrdersService
|
|||||||
$modificationText = $this->getModificationText($v->options);
|
$modificationText = $this->getModificationText($v->options);
|
||||||
|
|
||||||
// 计算单项利润
|
// 计算单项利润
|
||||||
$itemProfit = $this->calculateProfit($moneyValues, $item);
|
$itemProfit = $this->calculateProfit($moneyValues, $v->mileage, $item);
|
||||||
|
|
||||||
// 构建车辆信息
|
// 构建车辆信息
|
||||||
$vehList[$v->unique_id] = [
|
$vehList[$v->unique_id] = [
|
||||||
|
|||||||
Reference in New Issue
Block a user