|
|
@@ -1,4 +1,3 @@
|
|
|
-
|
|
|
package shop.alien.store.service.impl;
|
|
|
|
|
|
import com.alibaba.nacos.common.utils.CollectionUtils;
|
|
|
@@ -345,79 +344,81 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
|
|
|
@Override
|
|
|
public List<LifeDiscountCouponVo> getStoreUserCouponList(String storeId, UserLoginInfo userLoginInfo) {
|
|
|
List<LifeDiscountCouponVo> lifeDiscountCouponVos = new ArrayList<>();
|
|
|
- LocalDate now = LocalDate.now();
|
|
|
- LocalDateTime now1 = now.atStartOfDay();
|
|
|
- //根据店铺id查询该店铺的优惠券,状态是开启领取的券
|
|
|
- List<LifeDiscountCoupon> lifeDiscountCoupons = lifeDiscountCouponMapper.selectList(new LambdaQueryWrapper<LifeDiscountCoupon>().eq(LifeDiscountCoupon::getStoreId, storeId).eq(LifeDiscountCoupon::getGetStatus, "1").gt(LifeDiscountCoupon::getSingleQty, 0) //还有库存
|
|
|
- .ge(LifeDiscountCoupon::getEndGetDate, now).orderByDesc(LifeDiscountCoupon::getCreatedTime));
|
|
|
- //根据优惠券列表查询该优惠券是否领取过
|
|
|
- for (LifeDiscountCoupon lifeDiscountCoupon : lifeDiscountCoupons) {
|
|
|
- LifeDiscountCouponVo lifeDiscountCouponVo = new LifeDiscountCouponVo();
|
|
|
- lifeDiscountCouponVo.setCouponId(lifeDiscountCoupon.getId());
|
|
|
- BeanUtils.copyProperties(lifeDiscountCoupon, lifeDiscountCouponVo);
|
|
|
- //查询该人员该卡券是否达到限领数量
|
|
|
- LambdaQueryWrapper<LifeDiscountCouponUser> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
- queryWrapper.eq(LifeDiscountCouponUser::getCouponId, lifeDiscountCoupon.getId());
|
|
|
- queryWrapper.eq(LifeDiscountCouponUser::getUserId, userLoginInfo.getUserId());
|
|
|
- queryWrapper.orderByDesc(LifeDiscountCouponUser::getReceiveTime);
|
|
|
- List<LifeDiscountCouponUser> lifeDiscountCouponUsers = lifeDiscountCouponUserMapper.selectList(queryWrapper);
|
|
|
- String specifiedDay = lifeDiscountCoupon.getSpecifiedDay();
|
|
|
- Date receiveDay = null;
|
|
|
-
|
|
|
- //判断是否已经全部领取
|
|
|
- if (lifeDiscountCoupon.getRestrictedQuantity() != 0 && lifeDiscountCouponUsers.size() >= lifeDiscountCoupon.getRestrictedQuantity()) {
|
|
|
- receiveDay = lifeDiscountCouponUsers.get(0).getReceiveTime();
|
|
|
- lifeDiscountCouponVo.setExpirationTime(lifeDiscountCouponUsers.get(0).getExpirationTime());
|
|
|
- lifeDiscountCouponVo.setCanReceived(false);
|
|
|
- } else {
|
|
|
- //判断一下领取规则
|
|
|
- LambdaQueryWrapper<LifeDiscountCouponUnavailableRules> rulesLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
- rulesLambdaQueryWrapper.eq(LifeDiscountCouponUnavailableRules::getDiscountCouponId, lifeDiscountCoupon.getId());
|
|
|
- rulesLambdaQueryWrapper.eq(LifeDiscountCouponUnavailableRules::getUnavailableRuleType, DiscountCouponEnum.CLAIM_RULE.getValue());
|
|
|
- LifeDiscountCouponUnavailableRules lifeDiscountCouponUnavailableRules = lifeDiscountCouponUnavailableRulesMapper.selectOne(rulesLambdaQueryWrapper);
|
|
|
- //获取一下当前人员领取的最近一次领取
|
|
|
- if (lifeDiscountCouponUsers.size() == 0) {
|
|
|
- lifeDiscountCouponVo.setCanReceived(true);
|
|
|
+ try{
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+ //根据店铺id查询该店铺的优惠券,状态是开启领取的券
|
|
|
+ List<LifeDiscountCoupon> lifeDiscountCoupons = lifeDiscountCouponMapper.selectList(new LambdaQueryWrapper<LifeDiscountCoupon>().eq(LifeDiscountCoupon::getStoreId, storeId).eq(LifeDiscountCoupon::getGetStatus, "1") //还有库存
|
|
|
+ .ge(LifeDiscountCoupon::getEndGetDate, LocalDate.now()).orderByDesc(LifeDiscountCoupon::getCreatedTime));
|
|
|
+ //根据优惠券列表查询该优惠券是否领取过
|
|
|
+ for (LifeDiscountCoupon lifeDiscountCoupon : lifeDiscountCoupons) {
|
|
|
+ LifeDiscountCouponVo lifeDiscountCouponVo = new LifeDiscountCouponVo();
|
|
|
+ lifeDiscountCouponVo.setCouponId(lifeDiscountCoupon.getId());
|
|
|
+ BeanUtils.copyProperties(lifeDiscountCoupon, lifeDiscountCouponVo);
|
|
|
+ //查询该人员该卡券是否达到限领数量
|
|
|
+ LambdaQueryWrapper<LifeDiscountCouponUser> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(LifeDiscountCouponUser::getCouponId, lifeDiscountCoupon.getId());
|
|
|
+ queryWrapper.eq(LifeDiscountCouponUser::getUserId, userLoginInfo.getUserId());
|
|
|
+ queryWrapper.orderByDesc(LifeDiscountCouponUser::getReceiveTime);
|
|
|
+ List<LifeDiscountCouponUser> lifeDiscountCouponUsers = lifeDiscountCouponUserMapper.selectList(queryWrapper);
|
|
|
+ String specifiedDay = lifeDiscountCoupon.getSpecifiedDay();
|
|
|
+ Date receiveDay = null;
|
|
|
+
|
|
|
+ //判断是否已经全部领取
|
|
|
+ if (lifeDiscountCoupon.getRestrictedQuantity() != 0 && lifeDiscountCouponUsers.size() >= lifeDiscountCoupon.getRestrictedQuantity()) {
|
|
|
+ receiveDay = lifeDiscountCouponUsers.get(0).getReceiveTime();
|
|
|
+ lifeDiscountCouponVo.setExpirationTime(lifeDiscountCouponUsers.get(0).getExpirationTime());
|
|
|
+ lifeDiscountCouponVo.setCanReceived(false);
|
|
|
} else {
|
|
|
- LifeDiscountCouponUser lifeDiscountCouponUser = lifeDiscountCouponUsers.get(0);
|
|
|
- Date receiveTime = lifeDiscountCouponUser.getReceiveTime();
|
|
|
- receiveDay = lifeDiscountCouponUser.getReceiveTime();
|
|
|
-
|
|
|
- // 将 Date 转换为 Instant
|
|
|
- Instant instant = receiveTime.toInstant();
|
|
|
- // 获取系统默认时区
|
|
|
- ZoneId zoneId = ZoneId.systemDefault();
|
|
|
- // 将 Instant 转换为 LocalDateTime
|
|
|
- LocalDateTime localDateTime = instant.atZone(zoneId).toLocalDateTime();
|
|
|
-
|
|
|
- String unavailableRuleValue = lifeDiscountCouponUnavailableRules.getUnavailableRuleValue();
|
|
|
- long confineTo = 0L;
|
|
|
- if (DiscountCouponEnum.DAY.getValue().equals(unavailableRuleValue)) {//如果规则限制一天一张
|
|
|
- confineTo = ChronoUnit.DAYS.between(localDateTime, now1);
|
|
|
- } else if (DiscountCouponEnum.WEEK.getValue().equals(unavailableRuleValue)) {//如果规则限制一周一张
|
|
|
- confineTo = ChronoUnit.WEEKS.between(localDateTime, now1);
|
|
|
- } else if (DiscountCouponEnum.MONTH.getValue().equals(unavailableRuleValue)) {//如果规则限制一月一张
|
|
|
- confineTo = ChronoUnit.MONTHS.between(localDateTime, now1);
|
|
|
- } else if (DiscountCouponEnum.YEAR.getValue().equals(unavailableRuleValue)) {//如果规则限制一年一张
|
|
|
- confineTo = ChronoUnit.YEARS.between(localDateTime, now1);
|
|
|
+ //判断一下领取规则
|
|
|
+ LambdaQueryWrapper<LifeDiscountCouponUnavailableRules> rulesLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ rulesLambdaQueryWrapper.eq(LifeDiscountCouponUnavailableRules::getDiscountCouponId, lifeDiscountCoupon.getId());
|
|
|
+ rulesLambdaQueryWrapper.eq(LifeDiscountCouponUnavailableRules::getUnavailableRuleType, DiscountCouponEnum.CLAIM_RULE.getValue());
|
|
|
+ LifeDiscountCouponUnavailableRules lifeDiscountCouponUnavailableRules = lifeDiscountCouponUnavailableRulesMapper.selectOne(rulesLambdaQueryWrapper);
|
|
|
+ //获取一下当前人员领取的最近一次领取
|
|
|
+ if (lifeDiscountCouponUsers.size() == 0) {
|
|
|
+ lifeDiscountCouponVo.setCanReceived(true);
|
|
|
+ } else {
|
|
|
+ LifeDiscountCouponUser lifeDiscountCouponUser = lifeDiscountCouponUsers.get(0);
|
|
|
+ Date receiveTime = lifeDiscountCouponUser.getReceiveTime();
|
|
|
+ receiveDay = lifeDiscountCouponUser.getReceiveTime();
|
|
|
+
|
|
|
+ // 将 Date 转换为 Instant
|
|
|
+ Instant instant = receiveTime.toInstant();
|
|
|
+ // 获取系统默认时区
|
|
|
+ ZoneId zoneId = ZoneId.systemDefault();
|
|
|
+ // 将 Instant 转换为 LocalDateTime
|
|
|
+ LocalDateTime localDateTime = instant.atZone(zoneId).toLocalDateTime();
|
|
|
+ String unavailableRuleValue = lifeDiscountCouponUnavailableRules.getUnavailableRuleValue();
|
|
|
+ long confineTo = 0L;
|
|
|
+ if (DiscountCouponEnum.DAY.getValue().equals(unavailableRuleValue)) {//如果规则限制一天一张
|
|
|
+ confineTo = ChronoUnit.DAYS.between(localDateTime, now);
|
|
|
+ } else if (DiscountCouponEnum.WEEK.getValue().equals(unavailableRuleValue)) {//如果规则限制一周一张
|
|
|
+ confineTo = ChronoUnit.WEEKS.between(localDateTime, now);
|
|
|
+ } else if (DiscountCouponEnum.MONTH.getValue().equals(unavailableRuleValue)) {//如果规则限制一月一张
|
|
|
+ confineTo = ChronoUnit.MONTHS.between(localDateTime, now);
|
|
|
+ } else if (DiscountCouponEnum.YEAR.getValue().equals(unavailableRuleValue)) {//如果规则限制一年一张
|
|
|
+ confineTo = ChronoUnit.YEARS.between(localDateTime, now);
|
|
|
+ }
|
|
|
+ //如果在规则范围内,则不允许领取,范围外,则可以领取
|
|
|
+ lifeDiscountCouponVo.setCanReceived(confineTo >= 1);
|
|
|
+ lifeDiscountCouponVo.setExpirationTime(lifeDiscountCouponUser.getExpirationTime());
|
|
|
}
|
|
|
- //如果在规则范围内,则不允许领取,范围外,则可以领取
|
|
|
- lifeDiscountCouponVo.setCanReceived(confineTo >= 1);
|
|
|
- lifeDiscountCouponVo.setExpirationTime(lifeDiscountCouponUser.getExpirationTime());
|
|
|
}
|
|
|
- }
|
|
|
- if (!StringUtils.isEmpty(specifiedDay)) {
|
|
|
- int sDay = Integer.parseInt(specifiedDay);
|
|
|
- if (sDay > 0 && receiveDay != null) {
|
|
|
- Date validDate = addDaysToDateJava8(receiveDay, sDay);
|
|
|
- LocalDate validDateLocalDate = validDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
|
|
|
- lifeDiscountCouponVo.setValidDate(validDateLocalDate);
|
|
|
- } else {
|
|
|
- lifeDiscountCouponVo.setValidDate(null);
|
|
|
+ if (!StringUtils.isEmpty(specifiedDay)) {
|
|
|
+ int sDay = Integer.parseInt(specifiedDay);
|
|
|
+ if (sDay > 0 && receiveDay != null) {
|
|
|
+ Date validDate = addDaysToDateJava8(receiveDay, sDay);
|
|
|
+ LocalDate validDateLocalDate = validDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
|
|
|
+ lifeDiscountCouponVo.setValidDate(validDateLocalDate);
|
|
|
+ } else {
|
|
|
+ lifeDiscountCouponVo.setValidDate(null);
|
|
|
+ }
|
|
|
}
|
|
|
+ lifeDiscountCouponVo.setQuantityClaimed(lifeDiscountCouponUsers.size());
|
|
|
+ lifeDiscountCouponVos.add(lifeDiscountCouponVo);
|
|
|
}
|
|
|
- lifeDiscountCouponVo.setQuantityClaimed(lifeDiscountCouponUsers.size());
|
|
|
- lifeDiscountCouponVos.add(lifeDiscountCouponVo);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("LifeDiscountCouponServiceImpl.getStoreUserUsableCouponList ERROR Msg={}", e);
|
|
|
}
|
|
|
return lifeDiscountCouponVos;
|
|
|
}
|