|
|
@@ -230,11 +230,11 @@ public class LifeCouponServiceImpl extends ServiceImpl<LifeCouponMapper, LifeCou
|
|
|
@Override
|
|
|
public Map<String, String> newCouponVerify(String storeId, String quanCode) {
|
|
|
Map<String, String> resultMap = new HashMap<>();
|
|
|
- OrderCouponMiddle orderCouponMiddle = orderCouponMiddleMapper.selectOne(new LambdaQueryWrapper<OrderCouponMiddle>().eq(OrderCouponMiddle::getCouponCode,quanCode));
|
|
|
- if(!StringUtils.isEmpty(orderCouponMiddle)){
|
|
|
- LifeUserOrder lifeUserOrder = lifeUserOrderMapper.selectOne(new LambdaQueryWrapper<LifeUserOrder>().eq(LifeUserOrder::getId,orderCouponMiddle.getOrderId()));
|
|
|
+ OrderCouponMiddle orderCouponMiddle = orderCouponMiddleMapper.selectOne(new LambdaQueryWrapper<OrderCouponMiddle>().eq(OrderCouponMiddle::getCouponCode, quanCode));
|
|
|
+ if (!StringUtils.isEmpty(orderCouponMiddle)) {
|
|
|
+ LifeUserOrder lifeUserOrder = lifeUserOrderMapper.selectOne(new LambdaQueryWrapper<LifeUserOrder>().eq(LifeUserOrder::getId, orderCouponMiddle.getOrderId()));
|
|
|
//CouponType 类型为 1:代金券 2:团购套餐
|
|
|
- if(lifeUserOrder.getCouponType()==1){
|
|
|
+ if (lifeUserOrder.getCouponType() == 1) {
|
|
|
orderCouponMiddle.setStatus(2);
|
|
|
orderCouponMiddle.setUsedTime(new Date());
|
|
|
orderCouponMiddleMapper.updateById(orderCouponMiddle);
|
|
|
@@ -262,10 +262,20 @@ public class LifeCouponServiceImpl extends ServiceImpl<LifeCouponMapper, LifeCou
|
|
|
resultMap.put("code", "true");
|
|
|
resultMap.put("message", "核销成功");
|
|
|
|
|
|
- }else if(lifeUserOrder.getCouponType()==2){
|
|
|
+ } else if (lifeUserOrder.getCouponType() == 2) {
|
|
|
orderCouponMiddle.setStatus(2);
|
|
|
orderCouponMiddle.setUsedTime(new Date());
|
|
|
orderCouponMiddleMapper.updateById(orderCouponMiddle);
|
|
|
+ //通过订单id查询中间表 如果该订单下所有劵都为已核销状态更改订单表状态为已核销
|
|
|
+ List<OrderCouponMiddle> couponMiddleList = orderCouponMiddleMapper.selectList(new LambdaQueryWrapper<OrderCouponMiddle>()
|
|
|
+ .eq(OrderCouponMiddle::getOrderId,lifeUserOrder.getId()));
|
|
|
+ boolean isExist = couponMiddleList.stream()
|
|
|
+ .allMatch(str -> str.getStatus()==2);
|
|
|
+ if(isExist){
|
|
|
+ lifeUserOrder.setStatus(2);
|
|
|
+ lifeUserOrderMapper.updateById(lifeUserOrder);
|
|
|
+ }
|
|
|
+
|
|
|
// TODO 抽成比例应该从商户里取
|
|
|
BigDecimal amounts = new BigDecimal(lifeUserOrder.getFinalPrice()).multiply(new BigDecimal(100));
|
|
|
BigDecimal commission = amounts.multiply(new BigDecimal(0.04)).setScale(0, RoundingMode.HALF_UP);
|
|
|
@@ -290,6 +300,9 @@ public class LifeCouponServiceImpl extends ServiceImpl<LifeCouponMapper, LifeCou
|
|
|
resultMap.put("code", "true");
|
|
|
resultMap.put("message", "核销成功");
|
|
|
}
|
|
|
+ } else {
|
|
|
+ resultMap.put("code", "false");
|
|
|
+ resultMap.put("message", "核销失败");
|
|
|
}
|
|
|
return resultMap;
|
|
|
}
|
|
|
@@ -388,77 +401,23 @@ public class LifeCouponServiceImpl extends ServiceImpl<LifeCouponMapper, LifeCou
|
|
|
/**
|
|
|
* 核销订单前效验
|
|
|
*
|
|
|
- * @param orderId
|
|
|
+ * @param orderCode
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
- public R<String> orderVerify(Integer orderId) {
|
|
|
- OrderCouponMiddle orderCouponMiddle = orderCouponMiddleMapper.selectOne(new LambdaQueryWrapper<OrderCouponMiddle>().eq(OrderCouponMiddle::getId, orderId));
|
|
|
- if (!StringUtils.isEmpty(orderCouponMiddle) && orderCouponMiddle.getStatus() == 1) {
|
|
|
- if (!StringUtils.isEmpty(orderCouponMiddle)) {
|
|
|
- LifeGroupBuyMain lifeGroupBuyMain = lifeGroupBuyMainMapper.selectOne(new LambdaQueryWrapper<LifeGroupBuyMain>().eq(LifeGroupBuyMain::getId, orderCouponMiddle.getCouponId()));
|
|
|
- //团购有效期类型为:0 指定天数
|
|
|
- if (lifeGroupBuyMain.getEffectiveDateType() == 0) {
|
|
|
- //订单支付时间加上指定天数 为团购劵有效期
|
|
|
- LifeUserOrder lifeUserOrder = lifeUserOrderMapper.selectOne(new LambdaQueryWrapper<LifeUserOrder>().eq(LifeUserOrder::getId, orderCouponMiddle.getOrderId()));
|
|
|
- LocalDate localDate = lifeUserOrder.getPayTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
|
|
|
- LocalDate validityPeriod = localDate.plusDays(Long.parseLong(lifeGroupBuyMain.getEffectiveDateValue()));
|
|
|
- LocalDate nowDate = LocalDate.now(); // 获取当前时间
|
|
|
- if (nowDate.isAfter(validityPeriod)) {
|
|
|
- return R.fail("该劵不在有效期内");
|
|
|
- }
|
|
|
- } else if (lifeGroupBuyMain.getEffectiveDateType() == 1) {//类型为:1 指定时间段
|
|
|
- String[] strings = lifeGroupBuyMain.getEffectiveDateValue().split(",");
|
|
|
- String startDate = strings[0];
|
|
|
- String endDate = strings[1];
|
|
|
- LocalDate localStartDate = LocalDate.parse(startDate);
|
|
|
- LocalDate localEndDate = LocalDate.parse(endDate);
|
|
|
- LocalDate nowDate = LocalDate.now(); // 获取当前时间
|
|
|
- if (nowDate.isAfter(localEndDate) || nowDate.isBefore(localStartDate)) {
|
|
|
- return R.fail("该劵不在有效期内");
|
|
|
- }
|
|
|
- }
|
|
|
- //判断订单是否在不可用日期内
|
|
|
- //判断当前日期是否在不可用星期
|
|
|
- if(lifeGroupBuyMain.getDisableDateType() == 1){//限制日期: 1234567;节日id
|
|
|
- LocalDate nowDate = LocalDate.now(); // 获取当前时间
|
|
|
- DayOfWeek dayOfWeek = nowDate.getDayOfWeek();
|
|
|
- String week = dayOfWeek.getDisplayName(TextStyle.FULL, Locale.CHINA);
|
|
|
- String beforeSemicolon = lifeGroupBuyMain.getDisableDateValue().split(";")[0];
|
|
|
- if (!StringUtils.isEmpty(beforeSemicolon)) {
|
|
|
- List<String> collectUnavailableDate = Arrays.stream(beforeSemicolon.split(",")).map(String::trim).collect(Collectors.toList());
|
|
|
- boolean isExist = collectUnavailableDate.stream().anyMatch(s -> s.equals(week));
|
|
|
- if(isExist){
|
|
|
- return R.fail("该劵在不可用日期内");
|
|
|
- }
|
|
|
- }
|
|
|
- //判断当前日期是否在不可用节日
|
|
|
- String [] strings = lifeGroupBuyMain.getDisableDateValue().split(";");
|
|
|
- if(strings.length>1){
|
|
|
- String afterSemicolon = lifeGroupBuyMain.getDisableDateValue().split(";")[1];
|
|
|
- List<String> collectUnavailableDate = Arrays.stream(afterSemicolon.split(",")).map(String::trim).collect(Collectors.toList());
|
|
|
- List<EssentialHolidayComparison> essentialHolidayComparisons = essentialHolidayComparisonMapper.
|
|
|
- selectList(new LambdaQueryWrapper<EssentialHolidayComparison>().in(EssentialHolidayComparison::getId, collectUnavailableDate));
|
|
|
- boolean isExist = essentialHolidayComparisons.stream().anyMatch(s -> nowDate.isAfter(s.getStartTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate())
|
|
|
- && nowDate.isBefore(s.getEndTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate()));
|
|
|
- if(isExist){
|
|
|
- return R.fail("该劵在不可用日期内");
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- //判断当前日期是否在自定义不可用日期内
|
|
|
- if(lifeGroupBuyMain.getDisableDateType() == 2){
|
|
|
- String [] customDate = lifeGroupBuyMain.getDisableDateValue().split(";");
|
|
|
- boolean isExist = isCurrentDateInAnyRange(customDate);
|
|
|
- if(isExist){
|
|
|
- return R.fail("该劵在不可用日期内");
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }else{
|
|
|
- return R.fail("该劵不是待使用状态");
|
|
|
+ public R<String> orderVerify(String orderCode) {
|
|
|
+ OrderCouponMiddle orderCouponMiddle = orderCouponMiddleMapper.selectOne(new LambdaQueryWrapper<OrderCouponMiddle>().eq(OrderCouponMiddle::getCouponCode, orderCode));
|
|
|
+ if (!StringUtils.isEmpty(orderCouponMiddle) && orderCouponMiddle.getStatus() == 1) {
|
|
|
+ LifeUserOrder lifeUserOrder = lifeUserOrderMapper.selectOne(new LambdaQueryWrapper<LifeUserOrder>().eq(LifeUserOrder::getId, orderCouponMiddle.getOrderId()));
|
|
|
+ //类型为:1 代金券订单
|
|
|
+ if (lifeUserOrder.getCouponType() == 1) {
|
|
|
+ return couponVerification(orderCouponMiddle);
|
|
|
+ } else if (lifeUserOrder.getCouponType() == 2) {//类型为:2 团购订单
|
|
|
+ return groupVerification(orderCouponMiddle);
|
|
|
}
|
|
|
- return R.success("效验通过");
|
|
|
+ }
|
|
|
+ return R.fail("该劵不是待使用状态");
|
|
|
+
|
|
|
}
|
|
|
|
|
|
public static boolean isCurrentDateInAnyRange(String[] dateRanges) {
|
|
|
@@ -494,4 +453,127 @@ public class LifeCouponServiceImpl extends ServiceImpl<LifeCouponMapper, LifeCou
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+ public R<String> groupVerification(OrderCouponMiddle orderCouponMiddle) {
|
|
|
+ LifeGroupBuyMain lifeGroupBuyMain = lifeGroupBuyMainMapper.selectOne(new LambdaQueryWrapper<LifeGroupBuyMain>().eq(LifeGroupBuyMain::getId, orderCouponMiddle.getCouponId()));
|
|
|
+ //团购有效期类型为:0 指定天数
|
|
|
+ if (lifeGroupBuyMain.getEffectiveDateType() == 0) {
|
|
|
+ //订单支付时间加上指定天数 为团购劵有效期
|
|
|
+ LifeUserOrder lifeUserOrder = lifeUserOrderMapper.selectOne(new LambdaQueryWrapper<LifeUserOrder>().eq(LifeUserOrder::getId, orderCouponMiddle.getOrderId()));
|
|
|
+ LocalDate localDate = lifeUserOrder.getPayTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
|
|
|
+ LocalDate validityPeriod = localDate.plusDays(Long.parseLong(lifeGroupBuyMain.getEffectiveDateValue()));
|
|
|
+ LocalDate nowDate = LocalDate.now(); // 获取当前时间
|
|
|
+ if (nowDate.isAfter(validityPeriod)) {
|
|
|
+ return R.fail("该劵不在有效期内");
|
|
|
+ }
|
|
|
+ } else if (lifeGroupBuyMain.getEffectiveDateType() == 1) {//类型为:1 指定时间段
|
|
|
+ String[] strings = lifeGroupBuyMain.getEffectiveDateValue().split(",");
|
|
|
+ String startDate = strings[0];
|
|
|
+ String endDate = strings[1];
|
|
|
+ LocalDate localStartDate = LocalDate.parse(startDate);
|
|
|
+ LocalDate localEndDate = LocalDate.parse(endDate);
|
|
|
+ LocalDate nowDate = LocalDate.now(); // 获取当前时间
|
|
|
+ if (nowDate.isAfter(localEndDate) || nowDate.isBefore(localStartDate)) {
|
|
|
+ return R.fail("该劵不在有效期内");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //判断订单是否在不可用日期内
|
|
|
+ //判断当前日期是否在不可用星期
|
|
|
+ if (lifeGroupBuyMain.getDisableDateType() == 1) {//限制日期: 1234567;节日id
|
|
|
+ LocalDate nowDate = LocalDate.now(); // 获取当前时间
|
|
|
+ DayOfWeek dayOfWeek = nowDate.getDayOfWeek();
|
|
|
+ String week = dayOfWeek.getDisplayName(TextStyle.FULL, Locale.CHINA);
|
|
|
+ String beforeSemicolon = lifeGroupBuyMain.getDisableDateValue().split(";")[0];
|
|
|
+ if (!StringUtils.isEmpty(beforeSemicolon)) {
|
|
|
+ List<String> collectUnavailableDate = Arrays.stream(beforeSemicolon.split(",")).map(String::trim).collect(Collectors.toList());
|
|
|
+ boolean isExist = collectUnavailableDate.stream().anyMatch(s -> s.equals(week));
|
|
|
+ if (isExist) {
|
|
|
+ return R.fail("该劵在不可用日期内");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //判断当前日期是否在不可用节日
|
|
|
+ String[] strings = lifeGroupBuyMain.getDisableDateValue().split(";");
|
|
|
+ if (strings.length > 1) {
|
|
|
+ String afterSemicolon = lifeGroupBuyMain.getDisableDateValue().split(";")[1];
|
|
|
+ List<String> collectUnavailableDate = Arrays.stream(afterSemicolon.split(",")).map(String::trim).collect(Collectors.toList());
|
|
|
+ List<EssentialHolidayComparison> essentialHolidayComparisons = essentialHolidayComparisonMapper.
|
|
|
+ selectList(new LambdaQueryWrapper<EssentialHolidayComparison>().in(EssentialHolidayComparison::getId, collectUnavailableDate));
|
|
|
+ boolean isExist = essentialHolidayComparisons.stream().anyMatch(s -> !nowDate.isBefore(s.getStartTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate())
|
|
|
+ && !nowDate.isAfter(s.getEndTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate()));
|
|
|
+ if (isExist) {
|
|
|
+ return R.fail("该劵在不可用日期内");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //判断当前日期是否在自定义不可用日期内
|
|
|
+ if (lifeGroupBuyMain.getDisableDateType() == 2) {
|
|
|
+ String[] customDate = lifeGroupBuyMain.getDisableDateValue().split(";");
|
|
|
+ boolean isExist = isCurrentDateInAnyRange(customDate);
|
|
|
+ if (isExist) {
|
|
|
+ return R.fail("该劵在不可用日期内");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return R.success("效验通过");
|
|
|
+ }
|
|
|
+
|
|
|
+ public R<String> couponVerification(OrderCouponMiddle orderCouponMiddle) {
|
|
|
+ LifeCoupon lifeCoupon = lifeCouponMapper.selectOne(new LambdaQueryWrapper<LifeCoupon>().eq(LifeCoupon::getId, orderCouponMiddle.getCouponId()));
|
|
|
+ //代金券有效期类型为:1 指定天数
|
|
|
+ if (lifeCoupon.getExpirationType().equals("1")) {
|
|
|
+ //订单支付时间加上指定天数 为团购劵有效期
|
|
|
+ LifeUserOrder lifeUserOrder = lifeUserOrderMapper.selectOne(new LambdaQueryWrapper<LifeUserOrder>().eq(LifeUserOrder::getId, orderCouponMiddle.getOrderId()));
|
|
|
+ LocalDate localDate = lifeUserOrder.getPayTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
|
|
|
+ LocalDate validityPeriod = localDate.plusDays(lifeCoupon.getExpirationDate());
|
|
|
+ LocalDate nowDate = LocalDate.now(); // 获取当前时间
|
|
|
+ if (nowDate.isAfter(validityPeriod)) {
|
|
|
+ return R.fail("该劵不在有效期内");
|
|
|
+ }
|
|
|
+ } else if (lifeCoupon.getExpirationType().equals("2")) {//类型为:2 指定时间段
|
|
|
+ LocalDate localStartDate = lifeCoupon.getStartDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
|
|
|
+ LocalDate localEndDate = lifeCoupon.getEndDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
|
|
|
+ LocalDate nowDate = LocalDate.now(); // 获取当前时间
|
|
|
+ if (nowDate.isAfter(localEndDate) || nowDate.isBefore(localStartDate)) {
|
|
|
+ return R.fail("该劵不在有效期内");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //判断代金券订单是否在不可用日期内
|
|
|
+ //判断当前日期是否在不可用星期
|
|
|
+ if (lifeCoupon.getUnusedType().equals("2")) {//限制日期: 1234567;节日id
|
|
|
+ LocalDate nowDate = LocalDate.now(); // 获取当前时间
|
|
|
+ DayOfWeek dayOfWeek = nowDate.getDayOfWeek();
|
|
|
+ String week = dayOfWeek.getDisplayName(TextStyle.FULL, Locale.CHINA);
|
|
|
+ String beforeSemicolon = lifeCoupon.getUnusedDate().split(";")[0];
|
|
|
+ if (!StringUtils.isEmpty(beforeSemicolon)) {
|
|
|
+ List<String> collectUnavailableDate = Arrays.stream(beforeSemicolon.split(",")).map(String::trim).collect(Collectors.toList());
|
|
|
+ boolean isExist = collectUnavailableDate.stream().anyMatch(s -> s.equals(week));
|
|
|
+ if (isExist) {
|
|
|
+ return R.fail("该劵在不可用日期内");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //判断当前日期是否在不可用节日
|
|
|
+ String[] strings = lifeCoupon.getUnusedDate().split(";");
|
|
|
+ if (strings.length > 1) {
|
|
|
+ String afterSemicolon = lifeCoupon.getUnusedDate().split(";")[1];
|
|
|
+ List<String> collectUnavailableDate = Arrays.stream(afterSemicolon.split(",")).map(String::trim).collect(Collectors.toList());
|
|
|
+ List<EssentialHolidayComparison> essentialHolidayComparisons = essentialHolidayComparisonMapper.
|
|
|
+ selectList(new LambdaQueryWrapper<EssentialHolidayComparison>().in(EssentialHolidayComparison::getId, collectUnavailableDate));
|
|
|
+ boolean isExist = essentialHolidayComparisons.stream().anyMatch(s -> !nowDate.isBefore(s.getStartTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate())
|
|
|
+ && !nowDate.isAfter(s.getEndTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate()));
|
|
|
+ if (isExist) {
|
|
|
+ return R.fail("该劵在不可用日期内");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //判断当前日期是否在自定义不可用日期内
|
|
|
+ if (lifeCoupon.getUnusedType().equals("3")) {
|
|
|
+ String[] customDate = lifeCoupon.getUnusedDate().split(";");
|
|
|
+ boolean isExist = isCurrentDateInAnyRange(customDate);
|
|
|
+ if (isExist) {
|
|
|
+ return R.fail("该劵在不可用日期内");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return R.success("效验通过");
|
|
|
+ }
|
|
|
+
|
|
|
}
|