指定2023预售书只有妇幼生殖vip送积分,其他vip送优惠券

This commit is contained in:
wyn
2026-06-03 15:27:02 +08:00
parent 13b32ccd55
commit 5b77220ae5

View File

@@ -304,6 +304,19 @@ public class CouponServiceImpl extends ServiceImpl<CouponDao, CouponEntity> impl
@Override @Override
public void refundZSCouponHistoryByOrder(BuyOrder order){ public void refundZSCouponHistoryByOrder(BuyOrder order){
MyUserEntity userEntity = userDao.selectById(order.getUserId());
BigDecimal refundAllJF = BigDecimal.ZERO;
List<JfTransactionDetails> grantJfList = jfTransactionDetailsDao.selectList(new LambdaQueryWrapper<JfTransactionDetails>()
.eq(JfTransactionDetails::getRelationId, order.getOrderId())
.eq(JfTransactionDetails::getUserId, order.getUserId())
.eq(JfTransactionDetails::getActType, 0)
.gt(JfTransactionDetails::getChangeAmount, BigDecimal.ZERO)
.like(JfTransactionDetails::getRemark, "优惠券换积分"));
for (JfTransactionDetails grantJf : grantJfList) {
refundAllJF = refundAllJF.add(grantJf.getChangeAmount());
}
boolean orderGrantedJf = refundAllJF.compareTo(BigDecimal.ZERO) > 0;
MPJLambdaWrapper<CouponToProduct> wrapper = new MPJLambdaWrapper(); MPJLambdaWrapper<CouponToProduct> wrapper = new MPJLambdaWrapper();
wrapper.leftJoin(BuyOrderProduct.class,BuyOrderProduct::getProductId,CouponToProduct::getProductId); wrapper.leftJoin(BuyOrderProduct.class,BuyOrderProduct::getProductId,CouponToProduct::getProductId);
wrapper.leftJoin(CouponEntity.class,CouponEntity::getId,CouponToProduct::getCouponId); wrapper.leftJoin(CouponEntity.class,CouponEntity::getId,CouponToProduct::getCouponId);
@@ -314,49 +327,37 @@ public class CouponServiceImpl extends ServiceImpl<CouponDao, CouponEntity> impl
wrapper.select(BuyOrderProduct::getQuantity); wrapper.select(BuyOrderProduct::getQuantity);
List<Map<String,Object>> buyOrderProducts = couponToProductDao.selectJoinMaps(wrapper); List<Map<String,Object>> buyOrderProducts = couponToProductDao.selectJoinMaps(wrapper);
MyUserEntity userEntity = userDao.selectById(order.getUserId());
List<UserVip> userVipList = userVipDao.selectList(new LambdaQueryWrapper<UserVip>()
.eq(UserVip::getUserId, userEntity.getId())
.eq(UserVip::getState,0)
.lt(UserVip::getStartTime,order.getPaymentDate()));
boolean isVip = false;
if (userVipList.size() > 0) {
isVip = true;
}
System.out.println("isVip:"+isVip);
boolean isFyszVip = userVipList.stream().anyMatch(userVip -> Integer.valueOf(10).equals(userVip.getType()));
BigDecimal refundAllJF = BigDecimal.ZERO;
Boolean isRefundCoupon = false; Boolean isRefundCoupon = false;
for (Map<String,Object> map : buyOrderProducts) { for (Map<String,Object> map : buyOrderProducts) {
ShopProduct shopProduct = shopProductDao.selectById(map.get("product_id").toString()); ShopProduct shopProduct = shopProductDao.selectById(map.get("product_id").toString());
System.out.println("goodsType:"+shopProduct.getGoodsType());
if ("03".equals(shopProduct.getGoodsType())) { if ("03".equals(shopProduct.getGoodsType())) {
int productId = Integer.parseInt(map.get("product_id").toString()); if (!orderGrantedJf) {
int couponId = Integer.parseInt(map.get("coupon_id").toString()); isRefundCoupon = true;
CouponEntity couponEntity = couponDao.selectById(couponId); }
boolean shouldRefundJf = couponEntity.getCouponType()==0 && ((productId == 2023 && isFyszVip) || (productId != 2023 && isVip)); } else {
//现金券 isRefundCoupon = true;
if (shouldRefundJf){ }
BigDecimal quantity = new BigDecimal(map.get("quantity").toString()); }
BigDecimal sumRefundJF = couponEntity.getCouponAmount().multiply(quantity);
refundAllJF = refundAllJF.add(sumRefundJF);
if (orderGrantedJf) {
BigDecimal userJf = userEntity.getJf() == null ? BigDecimal.ZERO : userEntity.getJf();
BigDecimal actualDeduct;
if (userJf.compareTo(refundAllJF) >= 0) {
actualDeduct = refundAllJF;
} else if (userJf.compareTo(BigDecimal.ZERO) > 0) {
actualDeduct = userJf;
} else {
actualDeduct = BigDecimal.ZERO;
}
if (actualDeduct.compareTo(BigDecimal.ZERO) > 0) {
userEntity.setJf(userJf.subtract(actualDeduct));
userDao.updateById(userEntity);
jfTransactionDetailsService.recordZsJfTransaction(order, userEntity, actualDeduct);
QueryWrapper<CouponHistory> couponHistoryRemoveWrapper = new QueryWrapper<>(); QueryWrapper<CouponHistory> couponHistoryRemoveWrapper = new QueryWrapper<>();
couponHistoryRemoveWrapper.eq("order_id", order.getOrderId()); couponHistoryRemoveWrapper.eq("order_id", order.getOrderId());
couponHistoryRemoveWrapper.eq("status", 1); couponHistoryRemoveWrapper.eq("status", 1);
couponHistoryService.remove(couponHistoryRemoveWrapper); couponHistoryService.remove(couponHistoryRemoveWrapper);
}else{
isRefundCoupon = true;
} }
}else{
isRefundCoupon = true;
}
}
if(refundAllJF.compareTo(BigDecimal.ZERO)>0 && userEntity.getJf().compareTo(refundAllJF)>=0){
BigDecimal userJF = userEntity.getJf().subtract(refundAllJF);
userEntity.setJf(userJF.compareTo(BigDecimal.ZERO)>=0?userJF:BigDecimal.ZERO);
userDao.updateById(userEntity);
jfTransactionDetailsService.recordZsJfTransaction(order,userEntity, refundAllJF);
} }
if (isRefundCoupon) { if (isRefundCoupon) {
QueryWrapper<CouponHistory> couponHistoryRemoveWrapper = new QueryWrapper<>(); QueryWrapper<CouponHistory> couponHistoryRemoveWrapper = new QueryWrapper<>();
@@ -379,9 +380,7 @@ public class CouponServiceImpl extends ServiceImpl<CouponDao, CouponEntity> impl
List<Map<String,Object>> buyOrderProducts = couponToProductDao.selectJoinMaps(wrapper); List<Map<String,Object>> buyOrderProducts = couponToProductDao.selectJoinMaps(wrapper);
for (Map<String,Object> map : buyOrderProducts) { for (Map<String,Object> map : buyOrderProducts) {
ShopProduct shopProduct = shopProductDao.selectById(map.get("product_id").toString()); ShopProduct shopProduct = shopProductDao.selectById(map.get("product_id").toString());
//预售书赠送规则: //预售书+赠送现金券VIP用户将券额转为积分仅产品id=2023时需为妇幼生殖vip(type=10)
//1) 指定预售书(2023)仅妇幼生殖vip(type=10)且现金券时,改为送积分
//2) 其他预售书保持原规则任意vip且现金券时改为送积分
if ("03".equals(shopProduct.getGoodsType())){ if ("03".equals(shopProduct.getGoodsType())){
MyUserEntity userEntity = userDao.selectById(order.getUserId()); MyUserEntity userEntity = userDao.selectById(order.getUserId());
List<UserVip> userVipList = userVipDao.selectList(new LambdaQueryWrapper<UserVip>() List<UserVip> userVipList = userVipDao.selectList(new LambdaQueryWrapper<UserVip>()
@@ -391,7 +390,7 @@ public class CouponServiceImpl extends ServiceImpl<CouponDao, CouponEntity> impl
int couponId = Integer.parseInt(map.get("coupon_id").toString()); int couponId = Integer.parseInt(map.get("coupon_id").toString());
CouponEntity couponEntity = couponDao.selectById(couponId); CouponEntity couponEntity = couponDao.selectById(couponId);
boolean isFyszVip = userVipList.stream().anyMatch(userVip -> Integer.valueOf(10).equals(userVip.getType())); boolean isFyszVip = userVipList.stream().anyMatch(userVip -> Integer.valueOf(10).equals(userVip.getType()));
boolean couponToJf = couponEntity.getCouponType() == 0 && ((productId == 2023 && isFyszVip) || (productId != 2023 && userVipList.size() > 0)); boolean couponToJf = couponEntity.getCouponType() == 0 && (productId == 2023 ? isFyszVip : userVipList.size() > 0);
if (couponToJf){ if (couponToJf){
BigDecimal jf = BigDecimal.ZERO; BigDecimal jf = BigDecimal.ZERO;
for (int i=0;i<Integer.parseInt(map.get("quantity").toString());i++){ for (int i=0;i<Integer.parseInt(map.get("quantity").toString());i++){