Просмотр исходного кода

fix 更换车票上车限制;下单车队顺序id限制

zoujiajian 2 лет назад
Родитель
Сommit
024aa928de

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

@@ -28,7 +28,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);
+	Long selectSimilarExpiredRelation(@Param("skuId") Long skuId, @Param("minExpiryTime") DateTime minExpiryTime, @Param("maxNum") Integer maxNum);
 
 	List<GroupsRelationView> selectRelationByGoodsId(@Param("goodsId") Long goodsId, @Param("userId") Long userId, @Param("yhsId") Long yhsId);
 
@@ -52,7 +52,7 @@ public interface GroupsRelationMapper extends BaseMapper<GroupsRelation> {
 
 	Page<UserRecommendGoodsFrontView> getRecommendGoodsViews(@Param("page") Page<UserRecommendGoodsFrontView> page, @Param("list") List<Long> filter_goods_id, @Param("isPayNf") Boolean isPayNf);
 
-	Long getOutSideGroupsTripsRelationByGoodsId(@Param("skuId") Long skuId, @Param("beginOfDay") DateTime beginOfDay, @Param("extraNum") Integer extraNum, @Param("userId") Long userId, @Param("skuNum") Integer skuNum);
+	Long getOutSideGroupsTripsRelationByGoodsId(@Param("skuId") Long skuId, @Param("beginOfDay") DateTime beginOfDay, @Param("extraNum") Integer extraNum, @Param("userId") Long userId, @Param("skuNum") Integer skuNum, @Param("maxNum") Integer maxNum);
 
 	Integer selectAvailableRelation(@Param("skuId") Long skuId, @Param("skuNum") Integer skuNum);
 

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

@@ -17,7 +17,7 @@ import java.util.Date;
 @Getter
 @Setter
 @SearchBean(tables = "account a inner join groups_trips gt on gt.account_id = a.id",
-		where = ":account_id:")
+		where = ":condition:")
 public class EmptyGroupsRelationView {
 	@DbField("a.id")
 	private Long accountId;

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

@@ -52,7 +52,7 @@
               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) &lt; gt.available_parking_num)
+                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'
@@ -236,7 +236,7 @@
         where gr.groups_id = gt.id
           and gr.user_id
             = #{userId}) = 0
-        and (gt.available_parking_num = 0 or (select count(*) from groups_relation gr where gr.groups_id = gt.id and gr.user_id != 0) &lt; gt.available_parking_num)
+          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)
         order by RAND() limit 1
     </select>
 

+ 4 - 0
netflix-service/src/main/java/com/cyksj/service/mange/impl/CmsOrderDonServiceImpl.java

@@ -561,6 +561,10 @@ public class CmsOrderDonServiceImpl extends ServiceImpl<OrderDonMapper,OrderDon>
         });
         log.info("userId:{}更换车票,原座位号relationId:{}======>新座位号newRelationId:{}", newRelation.getUserId(), relationId, newRelation.getId());
         relationMapper.updateById(newRelation);
+
+        //更换车票 调整GPT相关规格新车队 上车数
+        GoodsDonSku sku = goodsDonSkuMapper.selectById(groups.getSkuId());
+        groupRelationFrontService.adjustGroupsParkingTime(newRelation.getId(), sku);
     }
 
     public String zfbRefund(OrderRefundReq refundReq, OrderDon orderDon) throws Exception {

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

@@ -20,7 +20,7 @@ public interface GroupRelationFrontService {
 
 	Boolean isJoinCorpWx(Long userId, Boolean isJoin, Boolean noCoupon);
 
-	GroupsRelation getSimilarExpiredGroupRelation(Long skuId, Integer days, Integer months, List<Long> errorsRelationIds);
+	GroupsRelation getSimilarExpiredGroupRelation(GoodsDonSku sku, List<Long> errorsRelationIds);
 
 	Page<UserRecommendGoodsFrontView> getRecommendGoodsViews(Boolean isPayNf, List<Long> filter_goods_id, Integer start, Integer limit);
 

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

@@ -231,15 +231,24 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
 	}
 
 	@Override
-	public GroupsRelation getSimilarExpiredGroupRelation(Long skuId, Integer days, Integer months, List<Long> errorsRelationIds) {
+	public GroupsRelation getSimilarExpiredGroupRelation(GoodsDonSku sku, List<Long> errorsRelationIds) {
+		Long skuId = sku.getId();
+		Integer days = sku.getDays();
+		Integer months = sku.getMonths();
+		Integer maxNum = sku.getNum();
 		DateTime expiryTime = null;
 		if (days != null && days > 0) {
 			expiryTime = DateUtil.offsetDay(DateTime.now(), days);
 		} else {
 			expiryTime = DateUtil.offsetMonth(DateTime.now(), months);
 		}
+		Integer extraNum = 5;
+		if (sku.getId() == 178l) {
+			extraNum = 2;
+		}
+		maxNum += extraNum;
 		DateTime minExpiryTime = DateUtil.offsetDay(expiryTime, -5);
-		Long groupsId = groupsRelationMapper.selectSimilarExpiredRelation(skuId, minExpiryTime);
+		Long groupsId = groupsRelationMapper.selectSimilarExpiredRelation(skuId, minExpiryTime, maxNum);
 		if (groupsId == null) {
 			log.info("暂无相似过期时间车队");
 			return null;
@@ -315,14 +324,16 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
 			GroupsTrips groups = null;
 			//ChatGpt Plus、Midjourney非独立规格 上车先获取硬塞座位 硬塞5个座位
 			//主账号过期时间25天以外
+			Integer maxNum = sku.getNum();
 			if (sku.getNum() > 1 && Constant.AI_goodsIds.contains(sku.getGoodsId())) {
 				Integer extraNum = 5;
 				if (sku.getId() == 178l) {
 					extraNum = 2;
 				}
+				maxNum += extraNum;
 				DateTime time = DateUtil.offsetDay(DateUtil.beginOfDay(DateTime.now()), 25);
 				//不塞存在该用户的车队
-				Long groupsId = groupsRelationMapper.getOutSideGroupsTripsRelationByGoodsId(sku.getId(), time, extraNum, userId, sku.getNum());
+				Long groupsId = groupsRelationMapper.getOutSideGroupsTripsRelationByGoodsId(sku.getId(), time, extraNum, userId, sku.getNum(), maxNum);
 				if (groupsId != null) {
 					relation = groupsRelationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class)
 							.eq(GroupsRelation::getGroupsId, groupsId)
@@ -348,13 +359,13 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
 			}
 			if (groups == null) {
 				//寻找差不多过期时间规格的车位
-				relation = getSimilarExpiredGroupRelation(sku.getId(), sku.getDays(), sku.getMonths(), null);
+				relation = getSimilarExpiredGroupRelation(sku,null);
 				if (relation == null) {
 					//TODO 如果没指定座位,等待逻辑确认
 					groups = groupsMapper.selectOne(Wrappers.lambdaQuery(GroupsTrips.class)
 							.eq(GroupsTrips::getSkuId, sku.getId())
 							.gt(GroupsTrips::getAvailableNum, 0).last("limit 1")
-							.apply("(available_parking_num = 0 or available_parking_num > (select count(*) from groups_relation gr where gr.groups_id = groups_trips.id and user_id != 0))")
+							.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));
 					if (groups == null) {
@@ -363,7 +374,7 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
 								.eq(GroupsTrips::getSkuId, sku.getId())
 								.gt(GroupsTrips::getAvailableNum, 0).last("limit 1")
 								.eq(GroupsTrips::getStatus, GroupsTrips.Status.waiting)
-								.apply("(available_parking_num = 0 or available_parking_num > (select count(*) from groups_relation gr where gr.groups_id = groups_trips.id and user_id != 0))")
+								.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));
 					}
 					//新增空车队

+ 16 - 2
netflix-web/src/main/java/com/cyksj/web/controller/manage/CmsOrderController.java

@@ -626,6 +626,7 @@ public class CmsOrderController {
 				.field(EmptyGroupsRelationView::getStatus, GroupsTrips.Status.down.name()).op(Operator.NotEqual)
 				.field(EmptyGroupsRelationView::getSkuId, skuId).orderBy(EmptyGroupsRelationView::getAvailableNum)
 				.desc();
+		GoodsDonSku sku = skuMapper.selectById(skuId);
 		Date expiryTime = null;
 		if (relationId != null) {
 			GroupsRelation relation = relationMapper.selectById(relationId);
@@ -634,14 +635,27 @@ public class CmsOrderController {
 		if (groupsId != null) {
 			builder.field(EmptyGroupsRelationView::getGroupsId, groupsId).op(Operator.NotEqual);
 		}
+		String condition = StrUtil.EMPTY;
 		if (isNormal != null && isNormal) {
-			builder.put("account_id", String.format("gt.account_id not in (select account_id from work_order where sku_id = %s and account_id is not null)", skuId));
+			condition += String.format("gt.account_id not in (select account_id from work_order where sku_id = %s and account_id is not null)", skuId);
+		}
+		if (StrUtil.isNotEmpty(condition)) {
+			Integer maxNum = sku.getNum();
+			Integer extraNum = 5;
+			//GPT 4人月付
+			if (sku.getId() == 178l) {
+				extraNum = 2;
+			}
+			maxNum += extraNum;
+			condition += String.format(" and (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);
+		}
+		if (StrUtil.isNotEmpty(condition)) {
+			builder.put("condition", condition);
 		}
 		if (expiryTime != null) {
 			builder.field(AccountView::getExpiryTime, expiryTime).op(Operator.GreaterEqual);
 			builder.orderBy(AccountView::getExpiryTime).asc();
 		}
-		GoodsDonSku sku = skuMapper.selectById(skuId);
 		if (sku.getNum() == 1 || !Constant.AI_goodsIds.contains(sku.getGoodsId())) {
 			builder.field(EmptyGroupsRelationView::getAvailableNum, 0).op(Operator.GreaterThan);
 		}