Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -673,9 +673,21 @@ private void handleCouponAmount(List<OmsOrderItem> orderItemList, SmsCouponHisto
*/
private void calcPerCouponAmount(List<OmsOrderItem> orderItemList, SmsCoupon coupon) {
BigDecimal totalAmount = calcTotalAmount(orderItemList);
for (OmsOrderItem orderItem : orderItemList) {
//(商品价格/可用商品总价)*优惠券面额
BigDecimal couponAmount = orderItem.getProductPrice().divide(totalAmount, 3, RoundingMode.HALF_EVEN).multiply(coupon.getAmount());
BigDecimal couponAmountTotal = coupon.getAmount();
BigDecimal remainingAmount = couponAmountTotal;
int size = orderItemList.size();
for (int i = 0; i < size; i++) {
OmsOrderItem orderItem = orderItemList.get(i);
BigDecimal couponAmount;
if (i < size - 1) {
//(商品价格/可用商品总价)*优惠券面额
couponAmount = orderItem.getProductPrice().divide(totalAmount, 3, RoundingMode.HALF_EVEN).multiply(couponAmountTotal);
remainingAmount = remainingAmount.subtract(couponAmount);
} else {
// last item gets the remainder to ensure total equals coupon amount
couponAmount = remainingAmount;
}
couponAmount = couponAmount.setScale(2, RoundingMode.HALF_UP);
orderItem.setCouponAmount(couponAmount);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ public List<CartPromotionItem> calcCartPromotion(List<OmsCartItem> cartItemList)
BeanUtils.copyProperties(item,cartPromotionItem);
String message = getFullReductionPromotionMessage(fullReduction);
cartPromotionItem.setPromotionMessage(message);
//(商品原价/总价)*满减金额
//(商品原价/总价)*满减金额,使用 multiply-divide 顺序避免 divide 精度损失
PmsSkuStock skuStock= getOriginalPrice(promotionProduct, item.getProductSkuId());
BigDecimal originalPrice = skuStock.getPrice();
BigDecimal reduceAmount = originalPrice.divide(totalAmount,RoundingMode.HALF_EVEN).multiply(fullReduction.getReducePrice());
BigDecimal reduceAmount = originalPrice.multiply(fullReduction.getReducePrice()).divide(totalAmount, 2, RoundingMode.HALF_EVEN);
cartPromotionItem.setReduceAmount(reduceAmount);
cartPromotionItem.setRealStock(skuStock.getStock()-skuStock.getLockStock());
cartPromotionItem.setIntegration(promotionProduct.getGiftPoint());
Expand Down