|
|
@@ -12,6 +12,7 @@ import org.apache.http.client.utils.DateUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
+import shop.alien.entity.result.R;
|
|
|
import shop.alien.entity.store.*;
|
|
|
import shop.alien.entity.store.dto.LifeDiscountCouponStoreFriendDto;
|
|
|
import shop.alien.entity.store.vo.LifeCouponStatusVo;
|
|
|
@@ -22,9 +23,14 @@ import shop.alien.util.common.UniqueRandomNumGenerator;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
+import java.time.DayOfWeek;
|
|
|
import java.time.LocalDate;
|
|
|
+import java.time.LocalDateTime;
|
|
|
import java.time.ZoneId;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.time.format.TextStyle;
|
|
|
import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 优惠券
|
|
|
@@ -51,6 +57,11 @@ public class LifeCouponServiceImpl extends ServiceImpl<LifeCouponMapper, LifeCou
|
|
|
|
|
|
private final StoreUserMapper storeUserMapper;
|
|
|
|
|
|
+ private final OrderCouponMiddleMapper orderCouponMiddleMapper;
|
|
|
+
|
|
|
+ private final LifeGroupBuyMainMapper lifeGroupBuyMainMapper;
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
public boolean addOrUpdateCoupon(LifeCoupon lifeCoupon) {
|
|
|
|
|
|
@@ -187,10 +198,10 @@ public class LifeCouponServiceImpl extends ServiceImpl<LifeCouponMapper, LifeCou
|
|
|
storeIncomeDetailsRecordMapper.insert(record);
|
|
|
// 店铺账户余额增加
|
|
|
UpdateWrapper<StoreUser> updateWrapper = new UpdateWrapper();
|
|
|
- updateWrapper.eq("store_id",storeId);
|
|
|
- updateWrapper.eq("delete_flag",0);
|
|
|
- updateWrapper.setSql("money = money + "+money);
|
|
|
- storeUserMapper.update(null,updateWrapper);
|
|
|
+ updateWrapper.eq("store_id", storeId);
|
|
|
+ updateWrapper.eq("delete_flag", 0);
|
|
|
+ updateWrapper.setSql("money = money + " + money);
|
|
|
+ storeUserMapper.update(null, updateWrapper);
|
|
|
//发放好友优惠券
|
|
|
LifeDiscountCouponStoreFriendDto lifeDiscountCouponStoreFriendDto = new LifeDiscountCouponStoreFriendDto();
|
|
|
lifeDiscountCouponStoreFriendDto.setOrderId(Integer.parseInt(order.getId()));
|
|
|
@@ -233,18 +244,18 @@ public class LifeCouponServiceImpl extends ServiceImpl<LifeCouponMapper, LifeCou
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public IPage<EssentialHolidayComparison> getHolidayList(int page, int size, String year,String openFlag,String holidayName) {
|
|
|
+ public IPage<EssentialHolidayComparison> getHolidayList(int page, int size, String year, String openFlag, String holidayName) {
|
|
|
if (StringUtils.isEmpty(year)) {
|
|
|
LambdaQueryWrapper<EssentialHolidayComparison> essentialHolidayComparisonLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
essentialHolidayComparisonLambdaQueryWrapper.eq(EssentialHolidayComparison::getDelFlag, 0).groupBy(EssentialHolidayComparison::getParticularYear).orderByDesc(EssentialHolidayComparison::getParticularYear);
|
|
|
IPage<EssentialHolidayComparison> essentialHolidayComparisonIPage = new Page<>(page, size);
|
|
|
return essentialHolidayComparisonMapper.selectPage(essentialHolidayComparisonIPage, essentialHolidayComparisonLambdaQueryWrapper);
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
LambdaQueryWrapper<EssentialHolidayComparison> essentialHolidayComparisonLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
essentialHolidayComparisonLambdaQueryWrapper.eq(EssentialHolidayComparison::getDelFlag, 0)
|
|
|
- .eq(com.baomidou.mybatisplus.core.toolkit.StringUtils.isNotEmpty(year),EssentialHolidayComparison::getParticularYear,year)
|
|
|
- .eq(com.baomidou.mybatisplus.core.toolkit.StringUtils.isNotEmpty(openFlag),EssentialHolidayComparison::getOpenFlag,openFlag)
|
|
|
- .like(com.baomidou.mybatisplus.core.toolkit.StringUtils.isNotEmpty(holidayName),EssentialHolidayComparison::getFestivalName,holidayName)
|
|
|
+ .eq(com.baomidou.mybatisplus.core.toolkit.StringUtils.isNotEmpty(year), EssentialHolidayComparison::getParticularYear, year)
|
|
|
+ .eq(com.baomidou.mybatisplus.core.toolkit.StringUtils.isNotEmpty(openFlag), EssentialHolidayComparison::getOpenFlag, openFlag)
|
|
|
+ .like(com.baomidou.mybatisplus.core.toolkit.StringUtils.isNotEmpty(holidayName), EssentialHolidayComparison::getFestivalName, holidayName)
|
|
|
.orderByAsc(EssentialHolidayComparison::getStartTime);
|
|
|
IPage<EssentialHolidayComparison> essentialHolidayComparisonIPage = new Page<>(page, size);
|
|
|
return essentialHolidayComparisonMapper.selectPage(essentialHolidayComparisonIPage, essentialHolidayComparisonLambdaQueryWrapper);
|
|
|
@@ -259,7 +270,7 @@ public class LifeCouponServiceImpl extends ServiceImpl<LifeCouponMapper, LifeCou
|
|
|
}
|
|
|
essentialHolidayComparisonMapper.updateById(essentialHolidayComparison);
|
|
|
return true;
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
if (ObjectUtils.isNotEmpty(essentialHolidayComparison.getStartTime())) {
|
|
|
essentialHolidayComparison.setFestivalDate(essentialHolidayComparison.getStartTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate());
|
|
|
}
|
|
|
@@ -291,4 +302,111 @@ public class LifeCouponServiceImpl extends ServiceImpl<LifeCouponMapper, LifeCou
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 核销订单前效验
|
|
|
+ *
|
|
|
+ * @param orderId
|
|
|
+ * @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) {
|
|
|
+ return R.fail("该劵不是待使用状态");
|
|
|
+ }
|
|
|
+ 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()));
|
|
|
+ LocalDateTime localDateTime = lifeUserOrder.getBuyTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
|
|
|
+ LocalDateTime validityPeriod = localDateTime.plusDays(Long.parseLong(lifeGroupBuyMain.getEffectiveDateValue()));
|
|
|
+ LocalDateTime nowDate = LocalDateTime.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 afterSemicolon = lifeGroupBuyMain.getDisableDateValue().split(";")[1];
|
|
|
+ if(!StringUtils.isEmpty(afterSemicolon)){
|
|
|
+ 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("该劵在不可用日期内");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return R.fail("效验通过");
|
|
|
+ }
|
|
|
+
|
|
|
+ public static boolean isCurrentDateInAnyRange(String[] dateRanges) {
|
|
|
+ // 获取当前日期
|
|
|
+ LocalDate currentDate = LocalDate.now();
|
|
|
+ // 定义日期格式
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
+
|
|
|
+ // 遍历数组中的每一对日期范围
|
|
|
+ for (String range : dateRanges) {
|
|
|
+ // 分割每一对日期(开始日期和结束日期)
|
|
|
+ String[] dates = range.split(",");
|
|
|
+ if (dates.length != 2) {
|
|
|
+ // 格式不正确,跳过这一对
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ // 解析开始日期和结束日期
|
|
|
+ LocalDate startDate = LocalDate.parse(dates[0], formatter);
|
|
|
+ LocalDate endDate = LocalDate.parse(dates[1], formatter);
|
|
|
+
|
|
|
+ // 检查当前日期是否在范围内(包括开始和结束日期)
|
|
|
+ if (!currentDate.isBefore(startDate) &&
|
|
|
+ !currentDate.isAfter(endDate)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 日期解析错误,跳过这一对
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 没有任何一对日期范围包含当前日期
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
}
|