Explorar el Código

fix 不在会员规格内的车票不增加时长

zoujiajian hace 9 meses
padre
commit
8a0adc6b5f

+ 2 - 0
netflix-dao/src/main/java/com/cyksj/mapper/GroupsRelationMapper.java

@@ -85,4 +85,6 @@ public interface GroupsRelationMapper extends BaseMapper<GroupsRelation> {
 	List<UserTicketView> selectUserTickets(@Param("userIds") List<Long> userIds, @Param("goodsId") Long goodsId, @Param("skuId") Long skuId);
 
 	Integer selectCountByGoodsId(@Param("userIds") List<Long> userIdList, @Param("goodsId") Long goodsId, @Param("now") DateTime now);
+
+	Integer updateUserVipSkusExpiryTime(@Param("userIds") List<Long> userIds, @Param("vipSkuIds") List<Long> vipSkuIds, @Param("expiryTime") Date expiryTime);
 }

+ 6 - 0
netflix-dao/src/main/java/com/cyksj/mapper/vip/VipGoodsSkuMapper.java

@@ -2,6 +2,9 @@ package com.cyksj.mapper.vip;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.cyksj.model.entity.VipGoodsSku;
+import org.apache.ibatis.annotations.Select;
+
+import java.util.List;
 
 /**
  * 项目名: yhlxj2
@@ -10,4 +13,7 @@ import com.cyksj.model.entity.VipGoodsSku;
  * 创建时间:2025/5/13 11:06
  */
 public interface VipGoodsSkuMapper extends BaseMapper<VipGoodsSku> {
+
+	@Select("select vgs.* from vip_goods_sku vgs inner join goods_don_sku sku on sku.id = vgs.sku_id where sku.status")
+	List<VipGoodsSku> selectUpSkus();
 }

+ 2 - 1
netflix-dao/src/main/java/com/cyksj/model/views/VipGoodsSkuFrontView.java

@@ -16,7 +16,8 @@ import java.math.BigDecimal;
 @Getter
 @Setter
 @SearchBean(tables = "vip_goods_sku vgs left join goods_don g on g.id = vgs.goods_id" +
-		" left join goods_don_sku sku on sku.id = vgs.sku_id")
+		" left join goods_don_sku sku on sku.id = vgs.sku_id",
+		where = "sku.status")
 public class VipGoodsSkuFrontView {
 
 	@DbField("vgs.goods_id")

+ 16 - 0
netflix-dao/src/main/resources/mapper/GroupRelationMapper.xml

@@ -45,6 +45,22 @@
         update groups_relation set expiry_time = DATE_ADD(expiry_time,interval 1 day) where id = #{relationId} and user_id = #{userId}
     </update>
 
+    <update id="updateUserVipSkusExpiryTime">
+        update groups_relation set expiry_time = #{expiryTime},
+        update_time = now()
+        where id in (select * from(
+        select gr.id from groups_relation gr inner join groups_trips gt on gt.id = gr.groups_id
+        where gt.sku_id in
+        <foreach collection="vipSkuIds" item="item" open="(" separator="," close=")">
+            #{item}
+        </foreach>
+        and gr.user_id in
+        <foreach collection="userIds" item="item" open="(" separator="," close=")">
+            #{item}
+        </foreach>
+        and is_vip)s)
+    </update>
+
     <select id="getAccountIdsByUserIdOrNickNameOrSubmitAccount" resultType="java.lang.Long">
         select gr.groups_id
         from groups_relation gr,

+ 5 - 8
netflix-service/src/main/java/com/cyksj/service/order/impl/VipOrderDonServiceImpl.java

@@ -497,7 +497,7 @@ public class VipOrderDonServiceImpl extends ServiceImpl<VipOrderDonMapper, VipOr
 			} catch (Exception e) {
 			}
 		}
-		List<VipGoodsSku> skus = vipGoodsSkuMapper.selectList(null);
+		List<VipGoodsSku> skus = vipGoodsSkuMapper.selectUpSkus();
 		List<Long> deductSkuIds = null;
 		if (CollUtil.isNotEmpty(deductRelationIds)) {
 			List<GroupsRelationView> groupsRelationViews = beanSearcher.searchAll(GroupsRelationView.class, MapUtils.builder()
@@ -684,7 +684,7 @@ public class VipOrderDonServiceImpl extends ServiceImpl<VipOrderDonMapper, VipOr
 	 * 设置会员车票同一过期时间
 	 */
 	private void setTicketToVipExpiryTime(List<Long> userIds, Long vipUserId, Date expiryTime) {
-		List<Long> vipSkuIds = vipGoodsSkuMapper.selectList(null).stream().map(VipGoodsSku::getSkuId).collect(Collectors.toList());
+		List<Long> vipSkuIds = vipGoodsSkuMapper.selectUpSkus().stream().map(VipGoodsSku::getSkuId).collect(Collectors.toList());
 		List<Long> selfSkuIds = beanSearcher.searchAll(GroupsRelationView.class, MapUtils.builder()
 				.field(GroupsRelationView::getUserId, userIds).op(Operator.InList)
 				.field(GroupsRelationView::getSkuId, vipSkuIds).op(Operator.InList)
@@ -699,12 +699,9 @@ public class VipOrderDonServiceImpl extends ServiceImpl<VipOrderDonMapper, VipOr
 				}
 			});
 		}
-		relationMapper.update(null, Wrappers.lambdaUpdate(GroupsRelation.class)
-				.set(GroupsRelation::getExpiryTime, expiryTime)
-				.set(GroupsRelation::getUpdateTime, DateTime.now())
-				.in(GroupsRelation::getUserId, userIds)
-				.eq(GroupsRelation::getStatus, GroupsRelation.Status.validity)
-				.eq(GroupsRelation::getIsVip, Boolean.TRUE));
+		//更新会员车票
+		Integer update = relationMapper.updateUserVipSkusExpiryTime(userIds, vipSkuIds, expiryTime);
+		log.info("uid;{}镜像会员续费,更新会员{}张车票时长成功", vipUserId, update);
 	}
 
 	private BigDecimal getVipMoney(Integer num) {

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

@@ -301,7 +301,7 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
 				} catch (Exception e) {
 				}
 			}
-			List<Long> vipSkuIds = vipGoodsSkuMapper.selectList(null).stream().map(VipGoodsSku::getSkuId).collect(Collectors.toList());
+			List<Long> vipSkuIds = vipGoodsSkuMapper.selectUpSkus().stream().map(VipGoodsSku::getSkuId).collect(Collectors.toList());
 			Set<Long> vipGoodsIds = goodsDonSkuMapper.selectList(Wrappers.lambdaQuery(GoodsDonSku.class)
 					.in(GoodsDonSku::getId, vipSkuIds)).stream().map(GoodsDonSku::getGoodsId).collect(Collectors.toSet());
 			Integer vipUserCount = vipUserMapper.selectCount(Wrappers.lambdaQuery(VipUser.class)

+ 12 - 10
netflix-service/src/main/java/com/cyksj/service/vip/impl/CmsVipUserServiceImpl.java

@@ -16,9 +16,11 @@ import com.cyksj.service.relation.GroupRelationFrontService;
 import com.cyksj.service.user.UserBindRelationService;
 import com.cyksj.service.vip.CmsVipUserService;
 import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 
 import java.util.List;
+import java.util.stream.Collectors;
 
 /**
  * 项目名: yhlxj2
@@ -28,6 +30,7 @@ import java.util.List;
  */
 @Service
 @RequiredArgsConstructor
+@Slf4j
 public class CmsVipUserServiceImpl implements CmsVipUserService {
 	private final VipUserMapper vipUserMapper;
 
@@ -69,16 +72,16 @@ public class CmsVipUserServiceImpl implements CmsVipUserService {
 			vipUserMapper.updateById(vipUser);
 		}
 		//发送车票
-		List<VipGoodsSku> skus = vipGoodsSkuMapper.selectList(null);
+		List<VipGoodsSku> skus = vipGoodsSkuMapper.selectUpSkus();
 		for (VipGoodsSku sku : skus) {
 			//未有抵扣 直接发送会员车票
 			groupRelationFrontService.getTicket(userId, sku.getSkuId(), Boolean.TRUE);
 		}
 		//同步时间
-		groupsRelationMapper.update(null, Wrappers.lambdaUpdate(GroupsRelation.class)
-				.set(GroupsRelation::getExpiryTime, vipUser.getExpiryTime())
-				.in(GroupsRelation::getUserId, userIdList)
-				.eq(GroupsRelation::getIsVip, Boolean.TRUE));
+		List<Long> vipSkuIds = skus.stream().map(VipGoodsSku::getSkuId).collect(Collectors.toList());
+		Integer update = groupsRelationMapper.updateUserVipSkusExpiryTime(userIdList, vipSkuIds, vipUser.getExpiryTime());
+		log.info("后台开通uid;{}镜像会员,更新会员{}张车票时长成功", vipUser.getUserId(), update);
+
 		//操作记录
 		VipUserOperateLog vipUserOperateLog = new VipUserOperateLog();
 		vipUserOperateLog.setUserId(userId);
@@ -102,11 +105,10 @@ public class CmsVipUserServiceImpl implements CmsVipUserService {
 		vipUser.setExpiryTime(DateUtil.offsetDay(vipUser.getExpiryTime(), days));
 		vipUserMapper.updateById(vipUser);
 
-		//同步时间
-		groupsRelationMapper.update(null, Wrappers.lambdaUpdate(GroupsRelation.class)
-				.set(GroupsRelation::getExpiryTime, vipUser.getExpiryTime())
-				.in(GroupsRelation::getUserId, userIdList)
-				.eq(GroupsRelation::getIsVip, Boolean.TRUE));
+		//更新会员车票
+		List<Long> vipSkuIds = vipGoodsSkuMapper.selectUpSkus().stream().map(VipGoodsSku::getSkuId).collect(Collectors.toList());
+		Integer update = groupsRelationMapper.updateUserVipSkusExpiryTime(userIdList, vipSkuIds, vipUser.getExpiryTime());
+		log.info("后台uid;{}镜像会员延长或扣除,更新会员{}张车票时长成功", vipUser.getUserId(), update);
 
 		//操作记录
 		VipUserOperateLog vipUserOperateLog = new VipUserOperateLog();

+ 3 - 2
netflix-service/src/main/java/com/cyksj/service/vip/impl/VipFrontServiceImpl.java

@@ -16,6 +16,7 @@ import com.cyksj.model.entity.*;
 import com.cyksj.model.manage.views.GroupsRelationView;
 import com.cyksj.model.response.VipUserPageResp;
 import com.cyksj.model.views.RenewalView;
+import com.cyksj.model.views.VipGoodsSkuFrontView;
 import com.cyksj.service.chatgpt.ChatGptAccountService;
 import com.cyksj.service.claude.ClaudeService;
 import com.cyksj.service.user.UserBindRelationService;
@@ -86,7 +87,7 @@ public class VipFrontServiceImpl implements VipFrontService {
 		//可抵扣价格
 		BigDecimal deductMoney = BigDecimal.ZERO;
 		List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
-		List<Long> vipSkuIds = vipGoodsSkuMapper.selectList(null).stream().map(VipGoodsSku::getSkuId).collect(Collectors.toList());
+		List<Long> vipSkuIds = beanSearcher.searchAll(VipGoodsSkuFrontView.class, MapUtils.builder().build()).stream().map(VipGoodsSkuFrontView::getSkuId).collect(Collectors.toList());
 		//可有抵扣车票
 		DateTime now = DateTime.now();
 		//会员规格
@@ -115,7 +116,7 @@ public class VipFrontServiceImpl implements VipFrontService {
 	@Override
 	public VipDeductDto checkAndGetOrderDeductMoney(Long userId, Integer months) {
 		List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
-		List<Long> vipSkuIds = vipGoodsSkuMapper.selectList(null).stream().map(VipGoodsSku::getSkuId).collect(Collectors.toList());
+		List<Long> vipSkuIds = vipGoodsSkuMapper.selectUpSkus().stream().map(VipGoodsSku::getSkuId).collect(Collectors.toList());
 		//会员规格
 		Set<Long> goodsIds = goodsDonSkuMapper.selectList(Wrappers.lambdaQuery(GoodsDonSku.class)
 				.in(GoodsDonSku::getId, vipSkuIds)).stream().map(GoodsDonSku::getGoodsId).collect(Collectors.toSet());