Переглянути джерело

MJ车票统一ip不允许上同一车次

zoujiajian 2 роки тому
батько
коміт
97e119d599

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

@@ -39,4 +39,6 @@ public interface GroupsMapper extends BaseMapper<GroupsTrips> {
 	Long selectMidJourneySameSpecItemGroups(@Param("groupsId") Long groupsId, @Param("skuId") Long skuId, @Param("expiryTime") Date expiryTime);
 
 	Integer countExpiredNum(Long accountId);
+
+	GroupsTrips selectTicketGroups(@Param("skuId") Long skuId, @Param("status") GroupsTrips.Status status, @Param("maxNum") Integer maxNum, @Param("ip") String ip);
 }

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

@@ -31,7 +31,7 @@ public interface GroupsRelationMapper extends BaseMapper<GroupsRelation> {
 	@Update("update groups_relation set customer_service = null where id = #{id}")
 	void updateCustomerService(Long id);
 
-	Long selectSimilarExpiredRelation(@Param("skuId") Long skuId, @Param("minExpiryTime") DateTime minExpiryTime, @Param("maxNum") Integer maxNum);
+	Long selectSimilarExpiredRelation(@Param("skuId") Long skuId, @Param("minExpiryTime") DateTime minExpiryTime, @Param("maxNum") Integer maxNum, @Param("ip") String ip);
 
 	List<GroupsRelationView> selectRelationByGoodsId(@Param("goodsId") Long goodsId, @Param("userId") Long userId, @Param("yhsId") Long yhsId);
 

+ 17 - 11
netflix-dao/src/main/resources/mapper/GroupRelationMapper.xml

@@ -12,7 +12,6 @@
         user_id = #{entity.userId},
         account = null,
         customer_service = null,
-        verify_code = null,
         password = null,
         recharge_status = null,
         send_time = null,
@@ -49,17 +48,24 @@
     <select id="selectSimilarExpiredRelation" resultType="java.lang.Long">
         select s.id
         from (select gt.id, min(gr.expiry_time) minExpiryTime
-              from `groups_trips` gt
-                       left join `groups_relation` gr on gr.groups_id = gt.id
-              where gt.sku_id = #{skuId}
-                and (gt.available_parking_num = 0 or (select count(*) from groups_relation gr where gr.groups_id = gt.id and gr.user_id != 0 and gr.num &lt;= #{maxNum}) &lt; gt.available_parking_num)
-                and gt.available_num > 0
-                and gt.status = 'validity'
-                and gr.status = 'validity'
-                and gr.user_id != 0
-              and gr.expiry_time is not null
-              group by gr.groups_id) s
+        from `groups_trips` gt
+        left join `groups_relation` gr on gr.groups_id = gt.id
+        where gt.sku_id = #{skuId}
+        and (gt.available_parking_num = 0 or (select count(*)
+        from groups_relation gr
+        where gr.groups_id = gt.id and gr.user_id != 0 and gr.num &lt;=
+        #{maxNum}) &lt; gt.available_parking_num) and gt.available_num > 0
+        and gt.status = 'validity'
+        and gr.status = 'validity'
+        and gr.user_id != 0
+        and gr.expiry_time is not null
+        group by gr.groups_id) s
         where s.minExpiryTime >= #{minExpiryTime}
+        <if test="ip != null">
+            and not exists (select 1 from (select id, user_id from groups_relation gnr where gnr.groups_id = s.id and gnr.user_id != 0) gr inner join
+            order_don o on o.user_id = gr.user_id and o.relation_id = gr.id
+            inner join order_don_location_relate ocr on ocr.order_id = o.id where ocr.ip = #{ip} limit 1)
+        </if>
         order by minExpiryTime desc limit 1
     </select>
 

+ 20 - 0
netflix-dao/src/main/resources/mapper/GroupsMapper.xml

@@ -78,4 +78,24 @@
           and deleted is true
           and source = 'self'
     </select>
+
+    <select id="selectTicketGroups" resultType="com.cyksj.model.entity.GroupsTrips">
+        select *
+        from groups_trips gt
+        where gt.sku_id = #{skuId}
+        and gt.status = #{status}
+        and gt.available_num > 0
+        <if test="ip != null">
+            and not exists (select 1 from (select id, user_id from groups_relation gnr where gnr.groups_id = gt.id
+            and gnr.user_id != 0) gr inner join
+            order_don o on o.user_id = gr.user_id and o.relation_id = gr.id
+            inner join order_don_location_relate ocr on ocr.order_id = o.id where ocr.ip = #{ip} limit 1)
+        </if>
+        and (available_parking_num = 0 or available_parking_num > (select count(*)
+        from groups_relation gr
+        where gr.groups_id = gt.id
+        and gr.user_id != 0 and gr.num &lt;= #{maxNum}))
+        order by available_num asc
+        limit 1
+    </select>
 </mapper>

+ 1 - 1
netflix-service/src/main/java/com/cyksj/service/exchange/impl/ExchangeCodeServiceImpl.java

@@ -367,7 +367,7 @@ public class ExchangeCodeServiceImpl extends ServiceImpl<ExchangeCodeMapper, Exc
 
 	public GroupsRelation getFinalRelation(GoodsDonSku sku, Long userId, Integer retryNum, Long yhsId, List<Long> errorsRelationIds) {
 		//获取车票车位
-		GroupsRelation relation = groupRelationFrontService.getRelation(null, userId, sku);
+		GroupsRelation relation = groupRelationFrontService.getRelation(null, userId, sku, null);
 
 		try {
 			//锁定座位

+ 6 - 1
netflix-service/src/main/java/com/cyksj/service/order/impl/OrderDonServiceImpl.java

@@ -2028,8 +2028,13 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 	public GroupsRelation getRelation(OrderPayRequest payRequest, GoodsDonSku sku, Long yhsId) {
 		Long payRelationId = payRequest.getRelationId();
 		Long userId = payRequest.getUserId();
+		String ip = null;
+		//MJ车票统一ip不允许上同一车次
+		if (sku.getGoodsId() == 26) {
+			ip = payRequest.getIp();
+		}
 		//获取车票车位
-		GroupsRelation relation = groupRelationFrontService.getRelation(payRelationId, userId, sku);
+		GroupsRelation relation = groupRelationFrontService.getRelation(payRelationId, userId, sku, ip);
 
 		//锁定座位
 		setRelation(relation);

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

@@ -21,7 +21,7 @@ public interface GroupRelationFrontService {
 
 	Boolean isJoinCorpWx(Long userId, Boolean isJoin, Boolean noCoupon);
 
-	GroupsRelation getSimilarExpiredGroupRelation(GoodsDonSku sku, List<Long> errorsRelationIds);
+	GroupsRelation getSimilarExpiredGroupRelation(GoodsDonSku sku, List<Long> errorsRelationIds, String ip);
 
 	Page<UserRecommendGoodsFrontView> getRecommendGoodsViews(Boolean isPayNf, List<Long> filter_goods_id, Integer start, Integer limit);
 
@@ -33,7 +33,7 @@ public interface GroupRelationFrontService {
 	/**
 	 * 获取车票座位
 	 */
-	GroupsRelation getRelation(Long payRelationId, Long userId, GoodsDonSku sku);
+	GroupsRelation getRelation(Long payRelationId, Long userId, GoodsDonSku sku, String ip);
 
 	/**
 	 * 获取车票账号登录 验证码

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

@@ -268,7 +268,7 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
 	}
 
 	@Override
-	public GroupsRelation getSimilarExpiredGroupRelation(GoodsDonSku sku, List<Long> errorsRelationIds) {
+	public GroupsRelation getSimilarExpiredGroupRelation(GoodsDonSku sku, List<Long> errorsRelationIds, String ip) {
 		Long skuId = sku.getId();
 		Integer days = sku.getDays();
 		Integer months = sku.getMonths();
@@ -285,7 +285,7 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
 		}
 		maxNum += extraNum;
 		DateTime minExpiryTime = DateUtil.offsetDay(expiryTime, -5);
-		Long groupsId = groupsRelationMapper.selectSimilarExpiredRelation(skuId, minExpiryTime, maxNum);
+		Long groupsId = groupsRelationMapper.selectSimilarExpiredRelation(skuId, minExpiryTime, maxNum, ip);
 		if (groupsId == null) {
 			log.info("暂无相似过期时间车队");
 			return null;
@@ -346,7 +346,7 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
 	}
 
 	@Override
-	public GroupsRelation getRelation(Long payRelationId, Long userId, GoodsDonSku sku) {
+	public GroupsRelation getRelation(Long payRelationId, Long userId, GoodsDonSku sku, String ip) {
 		GroupsRelation relation = null;
 		Integer maxNum = sku.getNum();
 		if (payRelationId != null && payRelationId > 0) {
@@ -397,23 +397,14 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
 			}
 			if (groups == null) {
 				//寻找差不多过期时间规格的车位
-				relation = getSimilarExpiredGroupRelation(sku,null);
+				relation = getSimilarExpiredGroupRelation(sku, null, ip);
 				if (relation == null) {
 					//TODO 如果没指定座位,等待逻辑确认
-					groups = groupsMapper.selectOne(Wrappers.lambdaQuery(GroupsTrips.class)
-							.eq(GroupsTrips::getSkuId, sku.getId())
-							.gt(GroupsTrips::getAvailableNum, 0).last("limit 1")
-							.apply(String.format("(available_parking_num = 0 or available_parking_num > (select count(*) from groups_relation gr where gr.groups_id = groups_trips.id and gr.user_id != 0 and gr.num <= %s))", maxNum))
-							.eq(GroupsTrips::getStatus, GroupsTrips.Status.validity)
-							.orderByAsc(GroupsTrips::getAvailableNum));
+					groups = groupsMapper.selectTicketGroups(sku.getId(), GroupsTrips.Status.validity, maxNum, ip);
+
 					if (groups == null) {
 						//待发车
-						groups = groupsMapper.selectOne(Wrappers.lambdaQuery(GroupsTrips.class)
-								.eq(GroupsTrips::getSkuId, sku.getId())
-								.gt(GroupsTrips::getAvailableNum, 0).last("limit 1")
-								.eq(GroupsTrips::getStatus, GroupsTrips.Status.waiting)
-								.apply(String.format("(available_parking_num = 0 or available_parking_num > (select count(*) from groups_relation gr where gr.groups_id = groups_trips.id and gr.user_id != 0 and gr.num <= %s))", maxNum))
-								.orderByAsc(GroupsTrips::getAvailableNum));
+						groups = groupsMapper.selectTicketGroups(sku.getId(), GroupsTrips.Status.waiting, maxNum, ip);
 					}
 					//新增空车队
 					if (groups == null) {