Jelajahi Sumber

Merge branch 'ticket_notify'

zoujiajian 2 tahun lalu
induk
melakukan
3d3fe2b6d5

+ 2 - 0
netflix-service/src/main/java/com/cyksj/redis/RedisService.java

@@ -831,6 +831,8 @@ public class RedisService {
         CHATGPT_CAR_SCORES("chatgpt:car:scores","chatGpt 车队分数", 48 * 60 * 60L),
         CHATGPT_CAR_HIGH_CHAT("chatgpt:car:high:chat:","chatGpt gpt4 对话次数", 48 * 60 * 60L),
         CHATGPT_CAR_LOW_CHAT("chatgpt:car:low:chat:","chatGpt 3.5 对话次数", 48 * 60 * 60L),
+        //车票到期前每日通知key
+        TICKET_EXPIRY_NOTIFY_DAY("ticket_expiry_notify_day:%s:%s", "车票到期前每日通知key", 60 * 60 * 24L),
         ;
 
         private String name;

+ 18 - 15
netflix-service/src/main/java/com/cyksj/service/order/impl/OrderDonServiceImpl.java

@@ -1687,21 +1687,24 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 				couponUser.setCouponId(exists.getPopularizeCouponId());
 				couponUser.setPopularizeId(exists.getPopularizeId());
 			}
-			//非渠道推广 推广优惠码只可使用一次
-			if ((exists.getPopularizeId() != null && exists.getIsGeneral()) || exists.getPopularizeId() == null) {
-				CouponUser received = couponUserMapper.selectOne(Wrappers.lambdaQuery(CouponUser.class).eq(CouponUser::getUserId, userId).eq(CouponUser::getCouponId, couponUser.getCouponId()).last("limit 1"));
-				if (received != null && received.getStatus() != CouponUser.Status.unused) {
-					throw BusinessRuntimeException.getInstance("您已使用该优惠码所对应的优惠券");
-				}
-				couponUser.setUserId(userId);
-				couponUser.setStatus(CouponUser.Status.used);
-				couponUser.setChannel(CouponUser.Channel.exCode);
-				couponFontService.updateCouponUserValidTime(couponUser.getCouponId(), couponUser);
-				try {
-					couponUserMapper.insert(couponUser);
-				} catch (DuplicateKeyException e) {
-					log.info("用户已领取该{}优惠券", couponUser.getCouponId());
-					throw BusinessRuntimeException.getInstance("您已领取该优惠码对应的优惠券,请使用优惠券");
+			//续费优惠码可重复使用
+			if (exists.getUseScope() != Coupon.UseScope.renew) {
+				//非渠道推广 推广优惠码只可使用一次
+				if ((exists.getPopularizeId() != null && exists.getIsGeneral()) || exists.getPopularizeId() == null) {
+					CouponUser received = couponUserMapper.selectOne(Wrappers.lambdaQuery(CouponUser.class).eq(CouponUser::getUserId, userId).eq(CouponUser::getCouponId, couponUser.getCouponId()).last("limit 1"));
+					if (received != null && received.getStatus() != CouponUser.Status.unused) {
+						throw BusinessRuntimeException.getInstance("您已使用该优惠码所对应的优惠券");
+					}
+					couponUser.setUserId(userId);
+					couponUser.setStatus(CouponUser.Status.used);
+					couponUser.setChannel(CouponUser.Channel.exCode);
+					couponFontService.updateCouponUserValidTime(couponUser.getCouponId(), couponUser);
+					try {
+						couponUserMapper.insert(couponUser);
+					} catch (DuplicateKeyException e) {
+						log.info("用户已领取该{}优惠券", couponUser.getCouponId());
+						throw BusinessRuntimeException.getInstance("您已领取该优惠码对应的优惠券,请使用优惠券");
+					}
 				}
 			}
 		} else {

+ 2 - 0
netflix-service/src/main/java/com/cyksj/service/relation/GroupRelationFrontService.java

@@ -53,4 +53,6 @@ public interface GroupRelationFrontService {
 	Integer getUserCodeNumBySkuId(Long userId, Long skuId, Boolean isHasVerifyCode);
 
 	List<RenewalView>  getHasPayGoods(long userId);
+
+	List<RenewalView> getExpiryRenewalNotify(Long userId);
 }

+ 55 - 0
netflix-service/src/main/java/com/cyksj/service/relation/impl/GroupRelationFrontServiceImpl.java

@@ -44,6 +44,8 @@ import org.springframework.transaction.annotation.Transactional;
 
 import javax.servlet.http.HttpServletRequest;
 import java.util.*;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.stream.Collectors;
 
 import static com.cyksj.enums.GatewayApiCode.GROUP_INDEX_ALREADY_BE_USER;
 import static com.cyksj.enums.GatewayApiCode.GROUP_INDEX_NOT_FIND;
@@ -618,6 +620,59 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
 		return list;
 	}
 
+	@Override
+	public List<RenewalView> getExpiryRenewalNotify(Long userId) {
+		DateTime now = DateTime.now();
+		DateTime thisZero = DateUtil.beginOfDay(now);
+		String thisDate = thisZero.toDateStr();
+		Object exists = redisService.get(RedisService.key.TICKET_EXPIRY_NOTIFY_DAY.getNameFormat(thisDate, userId));
+		if (exists != null) {
+			return null;
+		}
+		User u = userMapper.selectById(userId);
+		if (u == null) throw BusinessRuntimeException.getGatewayApiCode(GatewayApiCode.CMS_TOKEN_VALID);
+		if (u.getIsBlack()) {
+			redisService.setNx(RedisService.key.TICKET_EXPIRY_NOTIFY_DAY.getNameFormat(thisDate, userId), userId, RedisService.key.TICKET_EXPIRY_NOTIFY_DAY.getTimeout());
+			return null;
+		}
+		List<Long> userIds = userBindRelationService.getRelationUserIdList(userId, u);
+		MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
+		List<RenewalView> list = beanSearcher.searchAll(RenewalView.class, builder
+				.field(RenewalView::getUserId, 0).op(Operator.GreaterThan)
+				.field(RenewalView::getUserId, userIds).op(Operator.InList)
+				.field("condition", String.format("(gr.expiry_time is null or gr.expiry_time > '%s')", now))
+				.field(RenewalView::getStatus, List.of("validity", "overdue", "outside")).op(Operator.InList)
+				.orderBy(RenewalView::getExpiryTime).asc()
+				.onlySelect(RenewalView::getSkuNum, RenewalView::getExpiryTime, RenewalView::getRelationId, RenewalView::getAccount, RenewalView::getGoodsId, RenewalView::getTitle, RenewalView::getLogo, RenewalView::getImg, RenewalView::getGroupId, RenewalView::getSkuId, RenewalView::getSpecVal, RenewalView::getGoodsStatus, RenewalView::getSkuStatus)
+				.build());
+		if (list.size() > 5) {
+			redisService.setNx(RedisService.key.TICKET_EXPIRY_NOTIFY_DAY.getNameFormat(thisDate, userId), userId, RedisService.key.TICKET_EXPIRY_NOTIFY_DAY.getTimeout());
+			return null;
+		}
+		//提前7天
+		AtomicInteger day = new AtomicInteger(7);
+		List<RenewalView> expiryTickets = list.stream().filter(ticket -> {
+			//下架
+			if (ticket.getGoodsStatus() == null || ticket.getSkuStatus() == null || !ticket.getGoodsStatus() || !ticket.getSkuStatus()) {
+				return false;
+			}
+			Long skuNum = ticket.getSkuNum();
+			Date expiryTime = ticket.getExpiryTime();
+			//年付 提前一个月
+			if (skuNum >= 12) {
+				day.set(30);
+			}
+			if (DateUtil.beginOfDay(expiryTime).compareTo(DateUtil.offsetDay(thisZero, day.get())) <= 0) {
+				ticket.setExpiryTimeStr(DateUtil.format(ticket.getExpiryTime(), "yyyy-MM-dd"));
+				ticket.setExpiryTime(null);
+				return true;
+			}
+			return false;
+		}).collect(Collectors.toList());
+		redisService.setNx(RedisService.key.TICKET_EXPIRY_NOTIFY_DAY.getNameFormat(thisDate, userId), userId, RedisService.key.TICKET_EXPIRY_NOTIFY_DAY.getTimeout());
+		return expiryTickets;
+	}
+
 	public String getDifferentGoodsCode(Long goodsId, String body, Integer type) {
 		String code = null;
 		//奈飞

+ 10 - 0
netflix-web/src/main/java/com/cyksj/web/controller/group/GroupRelationController.java

@@ -753,4 +753,14 @@ public class GroupRelationController {
         cmsOrderDonService.unifiedRefund(refundReq);
         return GatewayResponse.SUCCESS.newBuilder().toResult();
     }
+
+    /**
+     * 每日车票到期弹窗
+     */
+    @GetMapping("/get/expiry/notify")
+    public Result<List<RenewalView>> getExpiryRenewalNotify() {
+        Long userId = StpUserUtil.getLoginIdAsLong();
+        List<RenewalView> expiryRenewals = groupRelationFrontService.getExpiryRenewalNotify(userId);
+        return GatewayResponse.SUCCESS.newBuilder().toResult(expiryRenewals);
+    }
 }