|
|
|
|
@@ -1177,33 +1177,32 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private BigDecimal calcCartPriceWithCoupon(List<TbCashierCart> newCashierCarts, OrderCouponInfoDTO couponInfoDTO, Integer memberId, TbOrderInfo orderInfo) {
|
|
|
|
|
ArrayList<TbCashierCart> balanceCartList = new ArrayList<>();
|
|
|
|
|
BigDecimal discountAmount = BigDecimal.ZERO;
|
|
|
|
|
HashMap<String, TbUserCouponVo> couponMap = new HashMap<>();
|
|
|
|
|
couponInfoDTO.getProductCouponMap().values().forEach(item -> {
|
|
|
|
|
couponMap.put(item.getProId().toString(), item);
|
|
|
|
|
});
|
|
|
|
|
HashMap<Integer, TbUserCouponVo> usedCouponMap = new HashMap<>();
|
|
|
|
|
ArrayList<TbActivateOutRecord> outRecords = new ArrayList<>();
|
|
|
|
|
for (TbCashierCart cashierCart : newCashierCarts) {
|
|
|
|
|
TbUserCouponVo couponVo = couponMap.get(cashierCart.getProductId());
|
|
|
|
|
boolean useCoupon;
|
|
|
|
|
private TbUserCouponVo getCanUseCoupon(HashMap<String, List<TbUserCouponVo>> couponMap, String productId) {
|
|
|
|
|
List<TbUserCouponVo> tbUserCouponVos = couponMap.get(productId);
|
|
|
|
|
if (tbUserCouponVos == null || tbUserCouponVos.isEmpty()) return null;
|
|
|
|
|
for (TbUserCouponVo tbUserCouponVo : tbUserCouponVos) {
|
|
|
|
|
if (tbUserCouponVo.getCurrentUseNum() > 0) {
|
|
|
|
|
return tbUserCouponVo;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private BigDecimal reduceProCoupon(HashMap<String, List<TbUserCouponVo>> couponMap, TbCashierCart cashierCart, HashMap<Integer,
|
|
|
|
|
List<TbUserCouponVo>> usedCouponMap, BigDecimal discountAmount, ArrayList<TbCashierCart> balanceCartList,
|
|
|
|
|
ArrayList<TbActivateOutRecord> outRecords, Integer memberId) {
|
|
|
|
|
TbUserCouponVo couponVo = getCanUseCoupon(couponMap, cashierCart.getProductId());
|
|
|
|
|
if (couponVo != null && couponVo.getCurrentUseNum() > 0) {
|
|
|
|
|
BigDecimal currentUseNum = BigDecimal.ZERO;
|
|
|
|
|
BigDecimal currentUseNum;
|
|
|
|
|
if (cashierCart.getNumber() < couponVo.getCurrentUseNum()) {
|
|
|
|
|
currentUseNum = BigDecimal.valueOf(couponVo.getCurrentUseNum());
|
|
|
|
|
BigDecimal cartNum = BigDecimal.valueOf(cashierCart.getNumber());
|
|
|
|
|
BigDecimal singlePackFee = cashierCart.getPackFee().divide(cartNum, RoundingMode.HALF_UP);
|
|
|
|
|
cashierCart.setPackFee(singlePackFee.multiply(currentUseNum));
|
|
|
|
|
cashierCart.setTotalAmount(cashierCart.getSalePrice().multiply(currentUseNum).add(singlePackFee.multiply(currentUseNum)));
|
|
|
|
|
cashierCart.setNumber(couponVo.getCurrentUseNum());
|
|
|
|
|
cashierCart.setTotalNumber(couponVo.getCurrentUseNum());
|
|
|
|
|
cashierCart.setUserCouponId(couponVo.getId());
|
|
|
|
|
discountAmount = discountAmount.add(cashierCart.getTotalAmount());
|
|
|
|
|
discountAmount = discountAmount.add(cashierCart.getTotalAmountByNum(null));
|
|
|
|
|
couponVo.setCurrentUseNum(couponVo.getCurrentUseNum() - cashierCart.getNumber());
|
|
|
|
|
}
|
|
|
|
|
usedCouponMap.put(Integer.valueOf(cashierCart.getProductId()), couponVo);
|
|
|
|
|
List<TbUserCouponVo> tbUserCouponVos = usedCouponMap.computeIfAbsent(Integer.valueOf(cashierCart.getProductId()), k -> new ArrayList<>());
|
|
|
|
|
tbUserCouponVos.add(couponVo);
|
|
|
|
|
|
|
|
|
|
TbCashierCart balanceCart = null;
|
|
|
|
|
// 优惠券数量小于购物车数量,分割购物车数据
|
|
|
|
|
if (cashierCart.getNumber() > couponVo.getCurrentUseNum()) {
|
|
|
|
|
currentUseNum = BigDecimal.valueOf(couponVo.getCurrentUseNum());
|
|
|
|
|
@@ -1211,16 +1210,17 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|
|
|
|
int balanceNum = cashierCart.getTotalNumber() - couponVo.getCurrentUseNum();
|
|
|
|
|
BigDecimal singlePackFee = cashierCart.getPackFee().divide(cartNum, RoundingMode.HALF_UP);
|
|
|
|
|
cashierCart.setPackFee(singlePackFee.multiply(currentUseNum));
|
|
|
|
|
cashierCart.setTotalAmount(cashierCart.getSalePrice().multiply(currentUseNum).add(singlePackFee.multiply(currentUseNum)));
|
|
|
|
|
BigDecimal totalAmountByNum = cashierCart.getTotalAmountByNum(couponVo.getCurrentUseNum());
|
|
|
|
|
cashierCart.setTotalAmount(totalAmountByNum.add(singlePackFee.multiply(currentUseNum)));
|
|
|
|
|
cashierCart.setNumber(couponVo.getCurrentUseNum());
|
|
|
|
|
cashierCart.setTotalNumber(couponVo.getCurrentUseNum());
|
|
|
|
|
cashierCart.setUserCouponId(couponVo.getId());
|
|
|
|
|
discountAmount = discountAmount.add(cashierCart.getTotalAmount());
|
|
|
|
|
discountAmount = discountAmount.add(totalAmountByNum);
|
|
|
|
|
couponVo.setCurrentUseNum(couponVo.getCurrentUseNum() - cashierCart.getNumber());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 创建结余购物车
|
|
|
|
|
TbCashierCart balanceCart = BeanUtil.copyProperties(cashierCart, TbCashierCart.class);
|
|
|
|
|
balanceCart = BeanUtil.copyProperties(cashierCart, TbCashierCart.class);
|
|
|
|
|
BigDecimal num = BigDecimal.valueOf(balanceNum);
|
|
|
|
|
balanceCart.setUserCouponId(null);
|
|
|
|
|
balanceCart.setId(null);
|
|
|
|
|
@@ -1231,7 +1231,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|
|
|
|
balanceCartList.add(balanceCart);
|
|
|
|
|
} else {
|
|
|
|
|
currentUseNum = BigDecimal.valueOf(cashierCart.getNumber());
|
|
|
|
|
discountAmount = discountAmount.add(cashierCart.getTotalAmount());
|
|
|
|
|
discountAmount = discountAmount.add(cashierCart.getTotalAmount().divide(BigDecimal.valueOf(cashierCart.getTotalNumber()), RoundingMode.HALF_UP).multiply(currentUseNum));
|
|
|
|
|
cashierCart.setUserCouponId(couponVo.getId());
|
|
|
|
|
couponVo.setCurrentUseNum(couponVo.getCurrentUseNum() - cashierCart.getNumber());
|
|
|
|
|
}
|
|
|
|
|
@@ -1247,7 +1247,37 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|
|
|
|
tbActivateOutRecord.setCreateTime(DateUtil.date());
|
|
|
|
|
tbActivateOutRecord.setRefNum(0);
|
|
|
|
|
outRecords.add(tbActivateOutRecord);
|
|
|
|
|
|
|
|
|
|
// 优惠券未消耗完毕
|
|
|
|
|
if (balanceCart != null && getCanUseCoupon(couponMap, balanceCart.getProductId()) != null) {
|
|
|
|
|
discountAmount = reduceProCoupon(couponMap, balanceCart, usedCouponMap, discountAmount, balanceCartList, outRecords, memberId);
|
|
|
|
|
}
|
|
|
|
|
return discountAmount;
|
|
|
|
|
}
|
|
|
|
|
return discountAmount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private BigDecimal calcCartPriceWithCoupon(List<TbCashierCart> newCashierCarts, OrderCouponInfoDTO couponInfoDTO, Integer memberId, TbOrderInfo orderInfo) {
|
|
|
|
|
ArrayList<TbCashierCart> balanceCartList = new ArrayList<>();
|
|
|
|
|
BigDecimal discountAmount = BigDecimal.ZERO;
|
|
|
|
|
HashMap<String, List<TbUserCouponVo>> couponMap = new HashMap<>();
|
|
|
|
|
couponInfoDTO.getProductCouponMap().values().forEach(item -> {
|
|
|
|
|
if (item.getCurrentUseNum() <= 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
List<TbUserCouponVo> tbUserCouponVos = couponMap.get(item.getProId().toString());
|
|
|
|
|
if (tbUserCouponVos == null) {
|
|
|
|
|
tbUserCouponVos = new ArrayList<>();
|
|
|
|
|
tbUserCouponVos.add(item);
|
|
|
|
|
couponMap.put(item.getProId().toString(), tbUserCouponVos);
|
|
|
|
|
}else {
|
|
|
|
|
tbUserCouponVos.add(item);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
HashMap<Integer, List<TbUserCouponVo>> usedCouponMap = new HashMap<>();
|
|
|
|
|
ArrayList<TbActivateOutRecord> outRecords = new ArrayList<>();
|
|
|
|
|
for (TbCashierCart cashierCart : newCashierCarts) {
|
|
|
|
|
discountAmount = reduceProCoupon(couponMap, cashierCart, usedCouponMap, discountAmount, balanceCartList, outRecords, memberId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!balanceCartList.isEmpty()) {
|
|
|
|
|
@@ -1258,7 +1288,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|
|
|
|
mpCashierCartService.updateBatchById(newCashierCarts);
|
|
|
|
|
|
|
|
|
|
couponInfoDTO.setOutRecordList(outRecords);
|
|
|
|
|
couponInfoDTO.setProductCouponMap(usedCouponMap);
|
|
|
|
|
couponInfoDTO.setCouponMap(usedCouponMap);
|
|
|
|
|
|
|
|
|
|
return discountAmount;
|
|
|
|
|
}
|
|
|
|
|
@@ -1939,7 +1969,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|
|
|
|
returnCoupon(orderInfo);
|
|
|
|
|
|
|
|
|
|
Set<String> productIdSet = new HashSet<>();
|
|
|
|
|
List<TbCashierCart> cashierCarts = mpCashierCartService.selectByOrderIdAndState(orderInfo.getId(), null);
|
|
|
|
|
List<TbCashierCart> cashierCarts = mpCashierCartService.selectByOrderIdAndState(orderInfo.getId());
|
|
|
|
|
ArrayList<TbCashierCart> activateCartInfo = new ArrayList<>();
|
|
|
|
|
for (TbCashierCart cashierCart : cashierCarts) {
|
|
|
|
|
productIdSet.add(cashierCart.getProductId());
|
|
|
|
|
|