|
@@ -198,22 +198,21 @@ public class OrderCalcServiceImpl implements OrderCalcService {
|
|
|
|
|
|
// 计算
|
|
|
// 计算利润: (价格 - 成本价格) * 产品数量
|
|
|
- BigDecimal profit = new BigDecimal("0");
|
|
|
+ final BigDecimal[] profit = {new BigDecimal("0")};
|
|
|
k.getOrderItemMessages().forEach(j -> {
|
|
|
- // 计算该订单的利润
|
|
|
BigDecimal onePrice = new BigDecimal(j.getPrice());
|
|
|
BigDecimal oneCostPrice = new BigDecimal(j.getCostPrice());
|
|
|
BigDecimal productCount = new BigDecimal(j.getCount());
|
|
|
BigDecimal oneGrossProfit = onePrice.subtract(oneCostPrice).multiply(productCount);
|
|
|
- profit.add(oneGrossProfit);
|
|
|
+ profit[0] = profit[0].add(oneGrossProfit); // 注意这里的改动
|
|
|
});
|
|
|
|
|
|
|
|
|
// 计算毛利: 利润 * 0.38
|
|
|
- BigDecimal grossProfit = profit.multiply(new BigDecimal(orderPercentageDO.getGrossProfitPerc())).setScale(4, RoundingMode.DOWN);
|
|
|
+ BigDecimal grossProfit = profit[0].multiply(new BigDecimal(orderPercentageDO.getGrossProfitPerc())).setScale(4, RoundingMode.DOWN);
|
|
|
|
|
|
// 计算平台收益
|
|
|
- BigDecimal grossProfitAfterBonus = profit.multiply(oneHundred.subtract(new BigDecimal(orderPercentageDO.getGrossProfitPerc()))).setScale(4, RoundingMode.DOWN);
|
|
|
+ BigDecimal grossProfitAfterBonus = profit[0].multiply(oneHundred.subtract(new BigDecimal(orderPercentageDO.getGrossProfitPerc()))).setScale(4, RoundingMode.DOWN);
|
|
|
|
|
|
if (otherOneHundred.compareTo(new BigDecimal(BigInteger.ZERO)) > 0) {
|
|
|
grossProfitAfterBonus = grossProfitAfterBonus.add(grossProfit.multiply(otherOneHundred).setScale(4, RoundingMode.DOWN));
|