|
|
@@ -46,7 +46,7 @@ import com.ruoyi.system.service.IPromotionCalcService;
|
|
|
@Service
|
|
|
public class PromotionCalcServiceImpl implements IPromotionCalcService
|
|
|
{
|
|
|
- private static final BigDecimal MIN_AMOUNT = new BigDecimal("0.01");
|
|
|
+ private static final BigDecimal MIN_AMOUNT = new BigDecimal("1");
|
|
|
|
|
|
@Autowired
|
|
|
private PromotionActivityMapper activityMapper;
|
|
|
@@ -122,7 +122,7 @@ public class PromotionCalcServiceImpl implements IPromotionCalcService
|
|
|
ip.put("name", nameMap.getOrDefault(productId, ""));
|
|
|
itemsWithPrice.add(ip);
|
|
|
}
|
|
|
- originalAmount = originalAmount.setScale(2, RoundingMode.HALF_UP);
|
|
|
+ originalAmount = originalAmount.setScale(0, RoundingMode.HALF_UP);
|
|
|
|
|
|
// ---- 2. 查询门店生效的促销活动 ----
|
|
|
List<PromotionActivity> activeActivities = activityMapper.selectActiveByStoreId(storeId);
|
|
|
@@ -271,7 +271,7 @@ public class PromotionCalcServiceImpl implements IPromotionCalcService
|
|
|
|
|
|
// ---- 8. 最终金额 ----
|
|
|
BigDecimal finalAmount = afterPromotion.subtract(newCustomerReduce).subtract(couponReduce);
|
|
|
- finalAmount = finalAmount.max(MIN_AMOUNT).setScale(2, RoundingMode.HALF_UP);
|
|
|
+ finalAmount = finalAmount.max(MIN_AMOUNT).setScale(0, RoundingMode.HALF_UP);
|
|
|
|
|
|
// ---- 9. 构建响应DTO ----
|
|
|
PromotionCalcResponse response = new PromotionCalcResponse();
|
|
|
@@ -490,7 +490,7 @@ public class PromotionCalcServiceImpl implements IPromotionCalcService
|
|
|
pathResult.put("promotionReduce",
|
|
|
discountResult.containsKey("originalRef")
|
|
|
? ((BigDecimal) discountResult.get("originalRef")).subtract(halfPriceSubtotal)
|
|
|
- .setScale(2, RoundingMode.HALF_UP) : BigDecimal.ZERO);
|
|
|
+ .setScale(0, RoundingMode.HALF_UP) : BigDecimal.ZERO);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
@@ -499,7 +499,7 @@ public class PromotionCalcServiceImpl implements IPromotionCalcService
|
|
|
pathResult.put("promotionReduce",
|
|
|
discountResult.containsKey("originalRef")
|
|
|
? ((BigDecimal) discountResult.get("originalRef")).subtract(discountSubtotal)
|
|
|
- .setScale(2, RoundingMode.HALF_UP) : BigDecimal.ZERO);
|
|
|
+ .setScale(0, RoundingMode.HALF_UP) : BigDecimal.ZERO);
|
|
|
}
|
|
|
|
|
|
return pathResult;
|
|
|
@@ -541,7 +541,7 @@ public class PromotionCalcServiceImpl implements IPromotionCalcService
|
|
|
{
|
|
|
BigDecimal discounted = unitPrice.multiply(rule.getDiscountRate())
|
|
|
.multiply(BigDecimal.valueOf(quantity))
|
|
|
- .setScale(2, RoundingMode.HALF_UP);
|
|
|
+ .setScale(0, RoundingMode.HALF_UP);
|
|
|
if (discounted.compareTo(finalPrice) < 0)
|
|
|
{
|
|
|
finalPrice = discounted;
|
|
|
@@ -556,8 +556,8 @@ public class PromotionCalcServiceImpl implements IPromotionCalcService
|
|
|
lineItem.put("productId", productId);
|
|
|
lineItem.put("quantity", quantity);
|
|
|
lineItem.put("unitPrice", unitPrice);
|
|
|
- lineItem.put("originalLineTotal", lineOriginal.setScale(2, RoundingMode.HALF_UP));
|
|
|
- lineItem.put("finalLineTotal", finalPrice.setScale(2, RoundingMode.HALF_UP));
|
|
|
+ lineItem.put("originalLineTotal", lineOriginal.setScale(0, RoundingMode.HALF_UP));
|
|
|
+ lineItem.put("finalLineTotal", finalPrice.setScale(0, RoundingMode.HALF_UP));
|
|
|
lineItem.put("name", item.get("name"));
|
|
|
if (matchedRule != null)
|
|
|
{
|
|
|
@@ -568,8 +568,8 @@ public class PromotionCalcServiceImpl implements IPromotionCalcService
|
|
|
}
|
|
|
|
|
|
result.put("items", itemList);
|
|
|
- result.put("subtotal", subtotal.setScale(2, RoundingMode.HALF_UP));
|
|
|
- result.put("originalRef", originalRef.setScale(2, RoundingMode.HALF_UP));
|
|
|
+ result.put("subtotal", subtotal.setScale(0, RoundingMode.HALF_UP));
|
|
|
+ result.put("originalRef", originalRef.setScale(0, RoundingMode.HALF_UP));
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
@@ -612,7 +612,7 @@ public class PromotionCalcServiceImpl implements IPromotionCalcService
|
|
|
BigDecimal halfPriceTotal = unitPrice.multiply(BigDecimal.valueOf(pairs))
|
|
|
.multiply(new BigDecimal("1.5"))
|
|
|
.add(unitPrice.multiply(BigDecimal.valueOf(remainder)))
|
|
|
- .setScale(2, RoundingMode.HALF_UP);
|
|
|
+ .setScale(0, RoundingMode.HALF_UP);
|
|
|
if (halfPriceTotal.compareTo(finalPrice) < 0)
|
|
|
{
|
|
|
finalPrice = halfPriceTotal;
|
|
|
@@ -627,8 +627,8 @@ public class PromotionCalcServiceImpl implements IPromotionCalcService
|
|
|
lineItem.put("productId", productId);
|
|
|
lineItem.put("quantity", quantity);
|
|
|
lineItem.put("unitPrice", unitPrice);
|
|
|
- lineItem.put("originalLineTotal", lineOriginal.setScale(2, RoundingMode.HALF_UP));
|
|
|
- lineItem.put("finalLineTotal", finalPrice.setScale(2, RoundingMode.HALF_UP));
|
|
|
+ lineItem.put("originalLineTotal", lineOriginal.setScale(0, RoundingMode.HALF_UP));
|
|
|
+ lineItem.put("finalLineTotal", finalPrice.setScale(0, RoundingMode.HALF_UP));
|
|
|
lineItem.put("name", item.get("name"));
|
|
|
if (matchedRule != null)
|
|
|
{
|
|
|
@@ -639,8 +639,8 @@ public class PromotionCalcServiceImpl implements IPromotionCalcService
|
|
|
}
|
|
|
|
|
|
result.put("items", itemList);
|
|
|
- result.put("subtotal", subtotal.setScale(2, RoundingMode.HALF_UP));
|
|
|
- result.put("originalRef", originalRef.setScale(2, RoundingMode.HALF_UP));
|
|
|
+ result.put("subtotal", subtotal.setScale(0, RoundingMode.HALF_UP));
|
|
|
+ result.put("originalRef", originalRef.setScale(0, RoundingMode.HALF_UP));
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
@@ -665,7 +665,7 @@ public class PromotionCalcServiceImpl implements IPromotionCalcService
|
|
|
lineItem.put("unitPrice", item.get("unitPrice"));
|
|
|
BigDecimal lineTotal = ((BigDecimal) item.get("unitPrice"))
|
|
|
.multiply(BigDecimal.valueOf(toInt(item.get("quantity"))))
|
|
|
- .setScale(2, RoundingMode.HALF_UP);
|
|
|
+ .setScale(0, RoundingMode.HALF_UP);
|
|
|
lineItem.put("originalLineTotal", lineTotal);
|
|
|
lineItem.put("finalLineTotal", lineTotal);
|
|
|
lineItem.put("name", item.get("name"));
|
|
|
@@ -702,7 +702,7 @@ public class PromotionCalcServiceImpl implements IPromotionCalcService
|
|
|
if (bestMatch != null)
|
|
|
{
|
|
|
BigDecimal subtotal = originalAmount.subtract(bestMatch.getReduceAmount())
|
|
|
- .max(MIN_AMOUNT).setScale(2, RoundingMode.HALF_UP);
|
|
|
+ .max(MIN_AMOUNT).setScale(0, RoundingMode.HALF_UP);
|
|
|
pathResult.put("subtotal", subtotal);
|
|
|
pathResult.put("promotionReduce", bestMatch.getReduceAmount());
|
|
|
Map<String, Object> matchedRuleInfo = new LinkedHashMap<>();
|
|
|
@@ -751,12 +751,12 @@ public class PromotionCalcServiceImpl implements IPromotionCalcService
|
|
|
{
|
|
|
BigDecimal reduction = totalProductPrice.multiply(BigDecimal.ONE.subtract(couponRule.getDiscountRate()));
|
|
|
return reduction.max(BigDecimal.ZERO).min(totalProductPrice)
|
|
|
- .setScale(2, RoundingMode.HALF_UP);
|
|
|
+ .setScale(0, RoundingMode.HALF_UP);
|
|
|
}
|
|
|
else if (couponRule.getAmount() != null)
|
|
|
{
|
|
|
return couponRule.getAmount().min(totalProductPrice)
|
|
|
- .setScale(2, RoundingMode.HALF_UP);
|
|
|
+ .setScale(0, RoundingMode.HALF_UP);
|
|
|
}
|
|
|
}
|
|
|
return BigDecimal.ZERO;
|
|
|
@@ -765,7 +765,7 @@ public class PromotionCalcServiceImpl implements IPromotionCalcService
|
|
|
{
|
|
|
if (couponRule.getAmount() != null)
|
|
|
{
|
|
|
- return couponRule.getAmount().min(baseAmount).setScale(2, RoundingMode.HALF_UP);
|
|
|
+ return couponRule.getAmount().min(baseAmount).setScale(0, RoundingMode.HALF_UP);
|
|
|
}
|
|
|
}
|
|
|
return BigDecimal.ZERO;
|