|
|
@@ -227,6 +227,73 @@ public class LifeCouponServiceImpl extends ServiceImpl<LifeCouponMapper, LifeCou
|
|
|
return resultMap;
|
|
|
}
|
|
|
|
|
|
+ @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()));
|
|
|
+ //CouponType 类型为 1:代金券 2:团购套餐
|
|
|
+ if(lifeUserOrder.getCouponType()==1){
|
|
|
+ orderCouponMiddle.setStatus(2);
|
|
|
+ orderCouponMiddle.setUsedTime(new Date());
|
|
|
+ orderCouponMiddleMapper.updateById(orderCouponMiddle);
|
|
|
+ // TODO 抽成比例应该从商户里取
|
|
|
+ BigDecimal amounts = new BigDecimal(lifeUserOrder.getFinalPrice()).multiply(new BigDecimal(100));
|
|
|
+ BigDecimal commission = amounts.multiply(new BigDecimal(0.04)).setScale(0, RoundingMode.HALF_UP);
|
|
|
+ BigDecimal money = amounts.subtract(commission);
|
|
|
+
|
|
|
+ // 插入收入明细表数据
|
|
|
+ StoreIncomeDetailsRecord record = new StoreIncomeDetailsRecord();
|
|
|
+ record.setStoreId(Integer.parseInt(storeId));
|
|
|
+ record.setUserOrderId(orderCouponMiddle.getId());
|
|
|
+ record.setIncomeType(lifeUserOrder.getCouponType());
|
|
|
+ record.setBusinessId(orderCouponMiddle.getCouponId());
|
|
|
+ record.setCommission(commission.intValue());
|
|
|
+ record.setMoney(money.intValue());
|
|
|
+ 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);
|
|
|
+ resultMap.put("code", "true");
|
|
|
+ resultMap.put("message", "核销成功");
|
|
|
+
|
|
|
+ }else if(lifeUserOrder.getCouponType()==2){
|
|
|
+ orderCouponMiddle.setStatus(2);
|
|
|
+ orderCouponMiddle.setUsedTime(new Date());
|
|
|
+ orderCouponMiddleMapper.updateById(orderCouponMiddle);
|
|
|
+ // TODO 抽成比例应该从商户里取
|
|
|
+ BigDecimal amounts = new BigDecimal(lifeUserOrder.getFinalPrice()).multiply(new BigDecimal(100));
|
|
|
+ BigDecimal commission = amounts.multiply(new BigDecimal(0.04)).setScale(0, RoundingMode.HALF_UP);
|
|
|
+ BigDecimal money = amounts.subtract(commission);
|
|
|
+
|
|
|
+ // 插入收入明细表数据
|
|
|
+ StoreIncomeDetailsRecord record = new StoreIncomeDetailsRecord();
|
|
|
+ record.setStoreId(Integer.parseInt(storeId));
|
|
|
+ record.setUserOrderId(orderCouponMiddle.getId());
|
|
|
+ record.setIncomeType(lifeUserOrder.getCouponType());
|
|
|
+ record.setBusinessId(orderCouponMiddle.getCouponId());
|
|
|
+ record.setCommission(commission.intValue());
|
|
|
+ record.setMoney(money.intValue());
|
|
|
+ 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);
|
|
|
+ resultMap.put("code", "true");
|
|
|
+ resultMap.put("message", "核销成功");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return resultMap;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* <p>
|
|
|
* 获取代金券状态
|
|
|
@@ -327,69 +394,71 @@ public class LifeCouponServiceImpl extends ServiceImpl<LifeCouponMapper, LifeCou
|
|
|
@Override
|
|
|
public R<String> orderVerify(Integer orderId) {
|
|
|
OrderCouponMiddle orderCouponMiddle = orderCouponMiddleMapper.selectOne(new LambdaQueryWrapper<OrderCouponMiddle>().eq(OrderCouponMiddle::getId, orderId));
|
|
|
- if (StringUtils.isEmpty(orderCouponMiddle) && orderCouponMiddle.getStatus() != 5) {
|
|
|
- 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 (!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("该劵在不可用日期内");
|
|
|
+ //判断订单是否在不可用日期内
|
|
|
+ //判断当前日期是否在不可用星期
|
|
|
+ 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("该劵在不可用日期内");
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- //判断当前日期是否在不可用节日
|
|
|
- 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(lifeGroupBuyMain.getDisableDateType() == 2){
|
|
|
+ String [] customDate = lifeGroupBuyMain.getDisableDateValue().split(";");
|
|
|
+ boolean isExist = isCurrentDateInAnyRange(customDate);
|
|
|
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("该劵不是待使用状态");
|
|
|
}
|
|
|
- return R.fail("效验通过");
|
|
|
+ return R.success("效验通过");
|
|
|
}
|
|
|
|
|
|
public static boolean isCurrentDateInAnyRange(String[] dateRanges) {
|