@@ -20,10 +20,10 @@ public class CouponEntity {
|
|||||||
//优惠券类型 0现金 1折扣
|
//优惠券类型 0现金 1折扣
|
||||||
private Integer couponType;
|
private Integer couponType;
|
||||||
|
|
||||||
//优惠卷范围 0无限制 1课程卷 2课程品类卷 3全部课程 4商品 5全部商品
|
//优惠卷范围 0无限制 1课程卷 2课程品类卷
|
||||||
private Integer couponRange;
|
private Integer couponRange;
|
||||||
|
|
||||||
//范围详情(课程卷是课程id,分割 课程品类卷是课程分类根id,分割;商品id,分割)
|
//范围详情(课程卷是课程id,分割;课程品类卷是课程分类根id)
|
||||||
private String rangeInfo;
|
private String rangeInfo;
|
||||||
|
|
||||||
//优惠券名称
|
//优惠券名称
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service("commonCouponService")
|
@Service("commonCouponService")
|
||||||
@@ -62,8 +61,12 @@ public class CouponServiceImpl extends ServiceImpl<CouponDao, CouponEntity> impl
|
|||||||
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()==4){
|
}else if(couponEntity.getCouponRange()==3){
|
||||||
list.add(shopProductDao.selectById(Integer.parseInt(str)));
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -132,18 +135,22 @@ public class CouponServiceImpl extends ServiceImpl<CouponDao, CouponEntity> impl
|
|||||||
couponHistory.setCanUseReason("优惠券使用时间未到");
|
couponHistory.setCanUseReason("优惠券使用时间未到");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Set<Integer> allProductIds = new HashSet<>();
|
couponHistory.setCouponEntity(couponEntity);
|
||||||
//校验订单门槛
|
if (couponEntity.getCouponRange()==0){
|
||||||
BigDecimal totalAmount = new BigDecimal(0);
|
//无限制
|
||||||
|
res.add(couponHistory);
|
||||||
|
}else {
|
||||||
|
//课程券和课程分类券
|
||||||
//"shopProductInfos":"1:69:1,2:79:1"//商品id:价格:数量
|
//"shopProductInfos":"1:69:1,2:79:1"//商品id:价格:数量
|
||||||
String shopProductInfos = params.get("shopProductInfos").toString();
|
String shopProductInfos = params.get("shopProductInfos").toString();
|
||||||
String[] infos = shopProductInfos.split(",");
|
String[] infos = shopProductInfos.split(",");
|
||||||
for (String shopProductInfo : infos) {
|
for (String shopProductInfo : infos) {
|
||||||
String[] info = shopProductInfo.split(":");
|
String[] info = shopProductInfo.split(":");
|
||||||
allProductIds.add(Integer.parseInt(info[0]));
|
//通过优惠卷获取商品
|
||||||
BigDecimal amount = new BigDecimal(info[1]).multiply(new BigDecimal(info[2]));
|
Set<Integer> set = getShopProductByCoupon(couponEntity);
|
||||||
totalAmount = totalAmount.add(amount);
|
//比对用户优惠卷是否有此商品
|
||||||
}
|
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){
|
if (new BigDecimal(couponEntity.getUseLevel()).compareTo(totalAmount)>0){
|
||||||
couponHistory.setCanUse(0);
|
couponHistory.setCanUse(0);
|
||||||
couponHistory.setCanUseReason("优惠券未到使用门槛");
|
couponHistory.setCanUseReason("优惠券未到使用门槛");
|
||||||
@@ -152,21 +159,13 @@ public class CouponServiceImpl extends ServiceImpl<CouponDao, CouponEntity> impl
|
|||||||
couponHistory.setCanUse(0);
|
couponHistory.setCanUse(0);
|
||||||
couponHistory.setCanUseReason("优惠券面额大于商品价值");
|
couponHistory.setCanUseReason("优惠券面额大于商品价值");
|
||||||
}
|
}
|
||||||
couponHistory.setCouponEntity(couponEntity);
|
|
||||||
if (couponEntity.getCouponRange()==0){
|
|
||||||
//无限制
|
|
||||||
res.add(couponHistory);
|
|
||||||
}else {
|
|
||||||
//通过优惠卷获取商品
|
|
||||||
Set<Integer> set = getShopProductByCoupon(couponEntity);
|
|
||||||
//比对用户优惠卷是否有此商品
|
|
||||||
if(!set.addAll(allProductIds)){
|
|
||||||
res.add(couponHistory);
|
res.add(couponHistory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -202,15 +201,6 @@ public class CouponServiceImpl extends ServiceImpl<CouponDao, CouponEntity> impl
|
|||||||
for (ShopProductCourseEntity shopProductCourseEntity : shopProductCourseList) {
|
for (ShopProductCourseEntity shopProductCourseEntity : shopProductCourseList) {
|
||||||
set.add(shopProductCourseEntity.getProductId());
|
set.add(shopProductCourseEntity.getProductId());
|
||||||
}
|
}
|
||||||
}else if (couponEntity.getCouponRange()==4) {
|
|
||||||
//4商品
|
|
||||||
String[] productIds = couponEntity.getRangeInfo().split(",");
|
|
||||||
for (String productId : productIds) {
|
|
||||||
set.add(Integer.parseInt(productId));
|
|
||||||
}
|
|
||||||
}else if (couponEntity.getCouponRange()==5) {
|
|
||||||
//5全部商品
|
|
||||||
set.addAll(shopProductDao.selectList(new LambdaQueryWrapper<>()).stream().map(ShopProduct::getProductId).collect(Collectors.toList()));
|
|
||||||
}
|
}
|
||||||
return set;
|
return set;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user