调整利润计算
This commit is contained in:
@@ -485,7 +485,7 @@ class StockOrdersService
|
||||
$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, '利润');
|
||||
|
||||
// 累计到岸价
|
||||
@@ -539,67 +539,55 @@ class StockOrdersService
|
||||
];
|
||||
|
||||
foreach ($priceFields as $field => $description) {
|
||||
if (!empty($veh[$field]['amount'])) {
|
||||
$item->addMoney(
|
||||
$field,
|
||||
$veh[$field]['currency'],
|
||||
$veh[$field]['amount'],
|
||||
$veh[$field]['rate'],
|
||||
$description
|
||||
);
|
||||
}
|
||||
$item->addMoney(
|
||||
$field,
|
||||
$veh[$field]['currency'],
|
||||
(float)$veh[$field]['amount'],
|
||||
$veh[$field]['rate'],
|
||||
$description
|
||||
);
|
||||
}
|
||||
|
||||
// 根据里程处理新车或二手车价格
|
||||
if (!empty($veh['mileage']) && $veh['mileage'] > 0) {
|
||||
// 二手车
|
||||
if (!empty($veh['listing_price']['amount'])) {
|
||||
$item->addMoney(
|
||||
'listing_price',
|
||||
$veh['listing_price']['currency'],
|
||||
$veh['listing_price']['amount'],
|
||||
$veh['listing_price']['rate'],
|
||||
'二手挂牌价'
|
||||
);
|
||||
}
|
||||
|
||||
if (!empty($veh['reduction_price']['amount'])) {
|
||||
$item->addMoney(
|
||||
'reduction_price',
|
||||
$veh['reduction_price']['currency'],
|
||||
$veh['reduction_price']['amount'],
|
||||
$veh['reduction_price']['rate'],
|
||||
'二手减价'
|
||||
);
|
||||
}
|
||||
$item->addMoney(
|
||||
'listing_price',
|
||||
$veh['listing_price']['currency'],
|
||||
(float)$veh['listing_price']['amount'],
|
||||
$veh['listing_price']['rate'],
|
||||
'二手挂牌价'
|
||||
);
|
||||
$item->addMoney(
|
||||
'reduction_price',
|
||||
$veh['reduction_price']['currency'],
|
||||
(float)$veh['reduction_price']['amount'],
|
||||
$veh['reduction_price']['rate'],
|
||||
'二手减价'
|
||||
);
|
||||
} else {
|
||||
// 新车
|
||||
if (!empty($veh['official_price']['amount'])) {
|
||||
$item->addMoney(
|
||||
'official_price',
|
||||
$veh['official_price']['currency'],
|
||||
$veh['official_price']['amount'],
|
||||
$veh['official_price']['rate'],
|
||||
'官方指导价'
|
||||
);
|
||||
}
|
||||
|
||||
if (!empty($veh['discount_price']['amount'])) {
|
||||
$item->addMoney(
|
||||
'discount_price',
|
||||
$veh['discount_price']['currency'],
|
||||
$veh['discount_price']['amount'],
|
||||
$veh['discount_price']['rate'],
|
||||
'优惠价'
|
||||
);
|
||||
}
|
||||
$item->addMoney(
|
||||
'official_price',
|
||||
$veh['official_price']['currency'],
|
||||
(float)$veh['official_price']['amount'],
|
||||
$veh['official_price']['rate'],
|
||||
'官方指导价'
|
||||
);
|
||||
$item->addMoney(
|
||||
'discount_price',
|
||||
$veh['discount_price']['currency'],
|
||||
(float)$veh['discount_price']['amount'],
|
||||
$veh['discount_price']['rate'],
|
||||
'优惠价'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算利润
|
||||
*/
|
||||
private function calculateProfit(array $veh, $order): float
|
||||
private function calculateProfit(array $veh, int $mileage, $order): float
|
||||
{
|
||||
$contractExchangeRate = $order->contract_exchange_rate ?: 1;
|
||||
|
||||
@@ -612,7 +600,7 @@ class StockOrdersService
|
||||
}
|
||||
|
||||
// 处理主要价格字段,根据是否需要汇率转换来计算
|
||||
if (!empty($veh['mileage']) && $veh['mileage'] > 0) {
|
||||
if ($mileage > 0) {
|
||||
// 二手车
|
||||
$listingPriceRate = $veh['listing_price']['rate'] ?: 1;
|
||||
if ($listingPriceRate != $contractExchangeRate) {
|
||||
@@ -825,7 +813,7 @@ class StockOrdersService
|
||||
$modificationText = $this->getModificationText($v->options);
|
||||
|
||||
// 计算单项利润
|
||||
$itemProfit = $this->calculateProfit($moneyValues, $item);
|
||||
$itemProfit = $this->calculateProfit($moneyValues, $v->mileage, $item);
|
||||
|
||||
// 构建车辆信息
|
||||
$vehList[$v->unique_id] = [
|
||||
|
||||
Reference in New Issue
Block a user