优惠券添加全部课程类型

This commit is contained in:
wuchunlei
2024-11-01 11:32:05 +08:00
parent ae85ae8109
commit f31342fb0a
2 changed files with 32 additions and 17 deletions

View File

@@ -257,9 +257,6 @@ public class BuyOrderController {
} }
CouponEntity coupon = couponService.getById(couponHistory.getCouponId()); CouponEntity coupon = couponService.getById(couponHistory.getCouponId());
if (coupon != null){ if (coupon != null){
if (new BigDecimal(coupon.getUseLevel()).compareTo(totalPrice)>0){
return R.error("未达到优惠券使用门槛");
}
couponHistory.setOrderId(buyOrder.getOrderId()); couponHistory.setOrderId(buyOrder.getOrderId());
couponService.useCouponAmount(couponHistory); couponService.useCouponAmount(couponHistory);
totalPrice = totalPrice.subtract(coupon.getCouponAmount()); totalPrice = totalPrice.subtract(coupon.getCouponAmount());

View File

@@ -32,7 +32,7 @@ public class CouponServiceImpl extends ServiceImpl<CouponDao, CouponEntity> impl
@Autowired @Autowired
private CourseMedicineDao courseMedicineDao; private CourseMedicineDao courseMedicineDao;
@Autowired @Autowired
private RabbitTemplate rabbitTemplate; private CourseToMedicineDao courseToMedicineDao;
@Autowired @Autowired
private ShopProductCourseDao shopProductCourseDao; private ShopProductCourseDao shopProductCourseDao;
@Autowired @Autowired
@@ -56,11 +56,17 @@ public class CouponServiceImpl extends ServiceImpl<CouponDao, CouponEntity> impl
if (couponEntity.getCouponRange()==1){ if (couponEntity.getCouponRange()==1){
list.add(courseDao.selectOne(new LambdaQueryWrapper<CourseEntity>() list.add(courseDao.selectOne(new LambdaQueryWrapper<CourseEntity>()
.eq(CourseEntity::getId,Integer.parseInt(str)) .eq(CourseEntity::getId,Integer.parseInt(str))
.select(CourseEntity::getId,CourseEntity::getTitle))); .select(CourseEntity::getId,CourseEntity::getTitle,CourseEntity::getImage)));
}else if(couponEntity.getCouponRange()==2){ }else if(couponEntity.getCouponRange()==2){
list.add(courseMedicineDao.selectOne(new LambdaQueryWrapper<CourseMedicine>() list.add(courseMedicineDao.selectOne(new LambdaQueryWrapper<CourseMedicine>()
.eq(CourseMedicine::getId,Integer.parseInt(str)) .eq(CourseMedicine::getId,Integer.parseInt(str))
.select(CourseMedicine::getId,CourseMedicine::getTitle))); .select(CourseMedicine::getId,CourseMedicine::getTitle)));
}else if(couponEntity.getCouponRange()==3){
MPJLambdaWrapper<CourseToMedicine> wrapper = new MPJLambdaWrapper();
wrapper.leftJoin(CourseEntity.class,CourseEntity::getId,CourseToMedicine::getCourseId);
wrapper.selectAll(CourseEntity.class);
wrapper.select(CourseEntity::getId,CourseEntity::getTitle,CourseEntity::getImage);
list.addAll(courseToMedicineDao.selectJoinList(CourseEntity.class,wrapper));
} }
} }
} }
@@ -107,12 +113,6 @@ public class CouponServiceImpl extends ServiceImpl<CouponDao, CouponEntity> impl
return R.error("优惠券暂未开始发放"); return R.error("优惠券暂未开始发放");
} }
} }
private MessagePostProcessor messagePostProcessor(long date) {
return message -> {
message.getMessageProperties().setDelay((int)date);
return message;
};
}
@Override @Override
public List<CouponHistory> getCouponListPayment(Map<String, Object> params) { public List<CouponHistory> getCouponListPayment(Map<String, Object> params) {
@@ -128,8 +128,8 @@ public class CouponServiceImpl extends ServiceImpl<CouponDao, CouponEntity> impl
couponHistory.setCanUse(1); couponHistory.setCanUse(1);
couponHistory.setCanUseReason(""); couponHistory.setCanUseReason("");
if (couponHistory.getEffectType()!=0){ if (couponHistory.getEffectType()!=0){
if (couponHistory.getStartTime().getTime() < new Date().getTime() && if (couponHistory.getStartTime().getTime() <= new Date().getTime() &&
couponHistory.getEndTime().getTime() > new Date().getTime()) { couponHistory.getEndTime().getTime() >= new Date().getTime()) {
}else { }else {
couponHistory.setCanUse(0); couponHistory.setCanUse(0);
couponHistory.setCanUseReason("优惠券使用时间未到"); couponHistory.setCanUseReason("优惠券使用时间未到");
@@ -140,13 +140,25 @@ public class CouponServiceImpl extends ServiceImpl<CouponDao, CouponEntity> impl
//无限制 //无限制
res.add(couponHistory); res.add(couponHistory);
}else { }else {
String shopProductIds = params.get("shopProductIds").toString(); //课程券和课程分类券
String[] ids = shopProductIds.split(","); //"shopProductInfos":"1:69:1,2:79:1"//商品id价格数量
for (String shopProductId : ids) { String shopProductInfos = params.get("shopProductInfos").toString();
String[] infos = shopProductInfos.split(",");
for (String shopProductInfo : infos) {
String[] info = shopProductInfo.split(":");
//通过优惠卷获取商品 //通过优惠卷获取商品
Set<Integer> set = getShopProductByCoupon(couponEntity); Set<Integer> set = getShopProductByCoupon(couponEntity);
//比对用户优惠卷是否有此商品 //比对用户优惠卷是否有此商品
if(!set.add(Integer.parseInt(shopProductId))){ if(!set.add(Integer.parseInt(info[0]))){
BigDecimal totalAmount = new BigDecimal(info[1]).multiply(new BigDecimal(info[2]));
if (new BigDecimal(couponEntity.getUseLevel()).compareTo(totalAmount)>0){
couponHistory.setCanUse(0);
couponHistory.setCanUseReason("优惠券未到使用门槛");
}
if (couponEntity.getCouponAmount().compareTo(totalAmount)>0){
couponHistory.setCanUse(0);
couponHistory.setCanUseReason("优惠券面额大于商品价值");
}
res.add(couponHistory); res.add(couponHistory);
} }
} }
@@ -183,6 +195,12 @@ public class CouponServiceImpl extends ServiceImpl<CouponDao, CouponEntity> impl
set.add(shopProductCourseEntity.getProductId()); set.add(shopProductCourseEntity.getProductId());
} }
} }
}else if (couponEntity.getCouponRange()==3) {
//3全部课程商品
List<ShopProductCourseEntity> shopProductCourseList = shopProductCourseDao.selectList(new LambdaQueryWrapper<>());
for (ShopProductCourseEntity shopProductCourseEntity : shopProductCourseList) {
set.add(shopProductCourseEntity.getProductId());
}
} }
return set; return set;
} }