Эх сурвалжийг харах

fix 续费逻辑更改;修改账号导出错误

zoujiajian 3 жил өмнө
parent
commit
51179c287b

+ 13 - 0
netflix-dao/src/main/java/com/cyksj/mapper/UserRenewChangeTicketRecordMapper.java

@@ -0,0 +1,13 @@
+package com.cyksj.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.cyksj.model.entity.UserRenewChangeTicketRecord;
+
+/*
+ *项目名: netflix
+ *文件名: UserRenewChangeTicketRecordMapper
+ *创建者: JavaZou
+ *创建时间:2023/3/20 14:41
+ */
+public interface UserRenewChangeTicketRecordMapper extends BaseMapper<UserRenewChangeTicketRecord> {
+}

+ 10 - 0
netflix-dao/src/main/java/com/cyksj/model/entity/OrderDon.java

@@ -141,6 +141,16 @@ public class OrderDon extends BaseEntity implements Serializable {
      */
     private String subNode;
 
+    /**
+     * 续费后 是否需要更换车票
+     */
+    private Boolean isChangeTicket;
+
+    /**
+     * 之前的车票的规格id
+     */
+    private Long preSkuId;
+
     public enum Status {
         /**
          * 订单状态

+ 34 - 0
netflix-dao/src/main/java/com/cyksj/model/entity/UserRenewChangeTicketRecord.java

@@ -0,0 +1,34 @@
+package com.cyksj.model.entity;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import java.util.Date;
+
+/*
+ *项目名: netflix
+ *文件名: UserRenewChangeTicketRecord
+ *创建者: JavaZou
+ *创建时间:2023/3/20 14:39
+ */
+@Getter
+@Setter
+public class UserRenewChangeTicketRecord extends BaseEntity{
+	private Long userId;
+
+	private Long preRelationId;
+
+	private Long preSkuId;
+
+	private Date preStartTime;
+
+	private Date preExpiryTime;
+
+	private Long afterRelationId;
+
+	private Long afterSkuId;
+
+	private Date afterExpiryTime;
+
+	private Long renewOrderId;
+}

+ 7 - 1
netflix-dao/src/main/java/com/cyksj/model/excel/ExcelManageAccountData.java

@@ -8,6 +8,8 @@ import com.ejlchina.searcher.bean.SearchBean;
 import lombok.Getter;
 import lombok.Setter;
 
+import java.util.Date;
+
 /*
  *项目名: netflix
  *文件名: ExcelManageAccountData
@@ -45,9 +47,13 @@ public class ExcelManageAccountData {
 	@DbField("a.bank_card")
 	private String bankCard;
 
+	@DbField("a.expiry_time")
+	@ExcelIgnore
+	private Date expiryTime;
+
 	@ExcelProperty("到期时间")
 	@DbField("date_format(a.expiry_time,'%Y/%c/%e')")
-	private String expiryTime;
+	private String expiryTimeExcel;
 
 	@ExcelProperty("激活码")
 	@DbIgnore

+ 5 - 0
netflix-service/src/main/java/com/cyksj/service/exchange/ExchangeCodeService.java

@@ -38,4 +38,9 @@ public interface ExchangeCodeService extends IService<ExchangeCode> {
 	 * 获取车票
 	 */
 	GroupsRelation getGroupTripsTicket(GoodsDonSku sku, Long userId, OrderDon exCodeOrderDon, OrderDon.Type orderDonTye);
+
+	/**
+	 * 获取车票车位
+	 */
+	GroupsRelation getRelationNoOrder(GoodsDonSku sku, Long userId);
 }

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

@@ -227,46 +227,8 @@ public class ExchangeCodeServiceImpl extends ServiceImpl<ExchangeCodeMapper, Exc
 		if (user == null) {
 			throw BusinessRuntimeException.getInstance("用户不存在");
 		}
-		GroupsRelation relation = null;
-		//寻找差不多过期时间规格的车位
-		relation = groupRelationFrontService.getSimilarExpiredGroupRelation(sku.getId(), sku.getMonths());
-		if (relation == null) {
-			GroupsTrips groups = groupsMapper.selectOne(Wrappers.lambdaQuery(GroupsTrips.class).eq(GroupsTrips::getSkuId, sku.getId()).gt(GroupsTrips::getAvailableNum, 0).last("limit 1").orderByAsc(GroupsTrips::getAvailableNum));
-			if (groups == null) {
-				//新增车位 并关联
-				relation = createNewGroupTripsAndRelation(sku, groups, relation);
-			} else {
-				//寻找快满编车队进行占座
-				relation = groupsRelationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class)
-						.eq(GroupsRelation::getGroupsId, groups.getId())
-						.eq(GroupsRelation::getStatus, "none")
-						.eq(GroupsRelation::getUserId, 0)
-						.orderByAsc(GroupsRelation::getNum)
-						.last("limit 1")
-				);
-				//如果占位失败 新增车位并关联
-				if (relation == null) {
-					relation = createNewGroupTripsAndRelation(sku, groups, relation);
-				}
-			}
-		}
+		GroupsRelation relation = getRelationNoOrder(sku, userId);
 
-		try {
-			//锁定座位
-			setRelation(relation.getId(), userId);
-		} catch (Exception e) {
-			//失败重新给他分配车位
-			getGroupTripsTicket(sku, userId, exCodeOrderDon, orderDonTye);
-			redisService.del(RedisKey.GROUPS_RELATION_NUM_KEY + relation.getId());
-		}
-		relation.setUserId(userId);
-		relation.setStatus(GroupsRelation.Status.validity);
-		//如果续费增加时间,如果首次则设置当前时间为初始时间
-		Date expiryTime = Optional.ofNullable(relation.getExpiryTime()).orElse(new Date());
-		Date newDate = DateUtil.offset(expiryTime, DateField.MONTH, sku.getMonths() * 1);
-		relation.setExpiryTime(newDate);
-		relation.setStartTime(relation.getStartTime() == null ? new Date() : null);
-		groupsRelationMapper.updateById(relation);
 		Long relationId = relation.getId();
 		OrderDon orderDon;
 		if (exCodeOrderDon != null) {
@@ -323,6 +285,56 @@ public class ExchangeCodeServiceImpl extends ServiceImpl<ExchangeCodeMapper, Exc
 		return relation;
 	}
 
+	@Override
+	public GroupsRelation getRelationNoOrder(GoodsDonSku sku, Long userId) {
+		GroupsRelation relation = null;
+		relation = getFinalRelation(sku, userId, relation);
+		return relation;
+	}
+
+	public GroupsRelation getFinalRelation(GoodsDonSku sku, Long userId, GroupsRelation relation) {
+		//寻找差不多过期时间规格的车位
+		relation = groupRelationFrontService.getSimilarExpiredGroupRelation(sku.getId(), sku.getMonths());
+		if (relation == null) {
+			GroupsTrips groups = groupsMapper.selectOne(Wrappers.lambdaQuery(GroupsTrips.class).eq(GroupsTrips::getSkuId, sku.getId()).gt(GroupsTrips::getAvailableNum, 0).last("limit 1").orderByAsc(GroupsTrips::getAvailableNum));
+			if (groups == null) {
+				//新增车位 并关联
+				relation = createNewGroupTripsAndRelation(sku, groups, relation);
+			} else {
+				//寻找快满编车队进行占座
+				relation = groupsRelationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class)
+						.eq(GroupsRelation::getGroupsId, groups.getId())
+						.eq(GroupsRelation::getStatus, "none")
+						.eq(GroupsRelation::getUserId, 0)
+						.orderByAsc(GroupsRelation::getNum)
+						.last("limit 1")
+				);
+				//如果占位失败 新增车位并关联
+				if (relation == null) {
+					relation = createNewGroupTripsAndRelation(sku, groups, relation);
+				}
+			}
+		}
+
+		try {
+			//锁定座位
+			setRelation(relation.getId(), userId);
+			relation.setUserId(userId);
+			relation.setStatus(GroupsRelation.Status.validity);
+			//如果续费增加时间,如果首次则设置当前时间为初始时间
+			Date expiryTime = Optional.ofNullable(relation.getExpiryTime()).orElse(new Date());
+			Date newDate = DateUtil.offset(expiryTime, DateField.MONTH, sku.getMonths() * 1);
+			relation.setExpiryTime(newDate);
+			relation.setStartTime(relation.getStartTime() == null ? new Date() : null);
+			groupsRelationMapper.updateById(relation);
+		} catch (Exception e) {
+			//失败重新给他分配车位
+			getFinalRelation(sku, userId, relation);
+			redisService.del(RedisKey.GROUPS_RELATION_NUM_KEY + relation.getId());
+		}
+		return relation;
+	}
+
 	private void setRelation(Long relationId, Long userId) {
 		if (redisService.get(RedisKey.GROUPS_RELATION_NUM_KEY + relationId) != null) {
 			throw new BusinessRuntimeException("客官手慢啦,该座位已经有人啦!");

+ 91 - 7
netflix-service/src/main/java/com/cyksj/service/order/impl/OrderDonServiceImpl.java

@@ -53,6 +53,7 @@ import com.cyksj.model.request.*;
 import com.cyksj.model.response.AliPayRefundRep;
 import com.cyksj.model.views.CouponNewUserView;
 import com.cyksj.model.views.CouponUserView;
+import com.cyksj.model.views.GoodsDonSkuView;
 import com.cyksj.redis.RedisService;
 import com.cyksj.service.coupon.CouponFontService;
 import com.cyksj.service.distribute.equipment.EquipmentDistributeService;
@@ -62,6 +63,7 @@ import com.cyksj.service.market.MarketFrontService;
 import com.cyksj.service.market.task.TaskService;
 import com.cyksj.service.order.OrderDonService;
 import com.cyksj.service.order.UserRealOrderBenefitsService;
+import com.cyksj.service.relation.GroupRelationClearService;
 import com.cyksj.service.relation.GroupRelationFrontService;
 import com.cyksj.service.template.TemplateCommonService;
 import com.cyksj.service.wechat.WeChatService;
@@ -184,6 +186,10 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 
 	private final TransferAccountsRecordMapper transferAccountsRecordMapper;
 
+	private final GroupRelationClearService groupRelationClearService;
+
+	private final UserRenewChangeTicketRecordMapper userRenewChangeTicketRecordMapper;
+
 	private final List<String> noChekGoodsTemp = List.of("Apple One", "Youtube", "Spotify");
 
 	@Transactional(rollbackFor = Throwable.class)
@@ -488,8 +494,14 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 		if (order.getIsNoLogin()) {
 			order.setStatus(OrderDon.Status.hasPayment);
 		}
+
 		if (!order.getIsNoLogin()) {
-			updateCarParkAndSendMsg(goodsDon, sku, order);
+			if (order.getOrderType() == 2 && order.getIsChangeTicket()) {
+				//将奈飞月付车票更换成其他规格的车票
+				changeTicketAndRecord(order.getPreSkuId(), order.getRelationId(), order.getId(), order.getNum(), sku);
+			} else {
+				updateCarParkAndSendMsg(goodsDon, sku, order);
+			}
 			if (order.getMoney().compareTo(BigDecimal.ZERO) > 0 && order.getIsDistribute()) {
 				TASK_POOL.execute(() -> distributeWaitingSendPointsRecord(order));
 			}
@@ -590,29 +602,33 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 	public OrderDon renewal(OrderPayRequest payRequest) throws Exception {
 		Long userId = payRequest.getUserId();
 		User user = userMapper.selectById(userId);
+		Long renewSkuId = payRequest.getSkuId();
 		CouponUser couponUser = null;
 		if (StrUtil.isNotBlank(payRequest.getCouponExCode()) || payRequest.getCouponId() != null) {
-			checkCouponStatus(payRequest.getSkuId(), payRequest.getCouponExCode(), payRequest.getCouponId(), payRequest.getUserId(), true);
+			checkCouponStatus(renewSkuId, payRequest.getCouponExCode(), payRequest.getCouponId(), payRequest.getUserId(), true);
 			//记录优惠券使用状态
 			couponUser = couponStatusRecord(payRequest.getCouponExCode(), payRequest.getCouponId(), payRequest.getUserId());
 		}
 		Long relationId = payRequest.getRelationId();
-		if (relationId == null || relationId <= 0 || payRequest.getSkuId() == null || payRequest.getNum() == null) {
+		if (relationId == null || relationId <= 0 || renewSkuId == null || payRequest.getNum() == null) {
 			throw new BusinessRuntimeException("缺少必填参数");
 		}
 
-		GoodsDonSku sku = goodsDonSkuMapper.selectById(payRequest.getSkuId());
+		GoodsDonSku sku = goodsDonSkuMapper.selectById(renewSkuId);
 
         GroupsRelation relation = groupsRelationMapper.selectById(relationId);
         if (relation == null) {
             throw new BusinessRuntimeException("");
         }
 
+		//todo 多账号同一用户绑定 续费
 		if (!relation.getUserId().equals(user.getId())) {
 			throw new BusinessRuntimeException("");
 		}
         GroupsTrips groupsTrips = groupsMapper.selectById(relation.getGroupsId());
-
+		if (groupsTrips == null) {
+			throw BusinessRuntimeException.getInstance("该车队不存在,请联系客服");
+		}
 		GoodsDon goodsDon = goodsDonMapper.selectById(sku.getGoodsId());
 
 		if (goodsDon == null || !goodsDon.getStatus()) {
@@ -622,12 +638,32 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 		if (goodsDon.getType() == 2) {
 			throw new BusinessRuntimeException("实物不支持续费");
 		}
+		//用户车票规格
+		Long tripsSkuId = groupsTrips.getSkuId();
+		GoodsDonSkuView goodsDonSkuView = beanSearcher.searchFirst(GoodsDonSkuView.class, MapUtils.builder().field(GoodsDonSkuView::getGoodsId, goodsDon.getId())
+				.field(GoodsDonSkuView::getSkuId, tripsSkuId).build());
+		if (goodsDonSkuView == null) {
+			throw BusinessRuntimeException.getInstance("该续费规格不属于该车队");
+		}
 
 		if (GroupsTrips.Status.waiting.equals(groupsTrips.getStatus())) {
 			if (!noChekGoodsTemp.contains(goodsDon.getTitle())) {
 				throw new BusinessRuntimeException("亲,该车次还未发车,需等待客服发车才能续费哦.");
 			}
 		}
+		//netflix 续费逻辑 月付可续费所有规格 其他规格只能续费对应规格
+		//netflix月付 续费其他规格 更换车队车位
+		Boolean isChangeTicket = false;
+		if (goodsDon.getType() == 1 && goodsDon.getId() == 1) {
+			if (groupsTrips.getSkuId() != 4 && tripsSkuId != renewSkuId) {
+				if (groupsTrips.getSkuId() == 5) {
+					throw BusinessRuntimeException.getInstance("季付车票只能续费季付");
+				} else if (groupsTrips.getSkuId() == 6) {
+					throw BusinessRuntimeException.getInstance("年付车票只能续费年付");
+				} else throw BusinessRuntimeException.getInstance("请选择对应规格的车票续费");
+			}
+			isChangeTicket = true;
+		}
 
 		String payOpenId = user.getOpenId();
 
@@ -637,12 +673,17 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 		orderDon.setOrderNo(donNo);
 		orderDon.setOpenId(payOpenId);
 		orderDon.setMoney(sku.getPrice().multiply(BigDecimal.valueOf(payRequest.getNum())));
-		orderDon.setSkuId(payRequest.getSkuId());
+		orderDon.setSkuId(renewSkuId);
 		orderDon.setRelationId(relation.getId());
 		//续费订单
 		orderDon.setOrderType(2);
 		orderDon.setStatus(OrderDon.Status.noPayment);
 		orderDon.setUserId(user.getId());
+		//续费后 是否需要更换车票
+		if (isChangeTicket) {
+			orderDon.setIsChangeTicket(isChangeTicket);
+			orderDon.setPreSkuId(tripsSkuId);
+		}
 		orderDon.setGoodsId(goodsDon.getId());
 		//虚拟商品订单,是否是分销订单
 		if (goodsDon.getType() == 1) {
@@ -974,7 +1015,9 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 						.orderByDesc(OrderDon::getId)
 						.last("limit 1"));
 				if (otherOrder != null) {
-					DateTime endTime = DateUtil.offsetMonth(otherOrder.getCreatedTime(), months * num);
+					Long otherSkuId = otherOrder.getSkuId();
+					GoodsDonSku otherGoodsSku = goodsDonSkuMapper.selectById(otherSkuId);
+					DateTime endTime = DateUtil.offsetMonth(otherOrder.getCreatedTime(), otherGoodsSku.getMonths() * num);
 					if (now.isBefore(endTime)) {
 						isFlag = false;
 					}
@@ -1751,4 +1794,45 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 		Optional.ofNullable(transDate).ifPresent(transferTime -> record.setTransferTime(DateTime.of(transferTime, "yyyy-MM-dd HH:mm:ss")));
 		transferAccountsRecordMapper.insert(record);
 	}
+
+	/**
+	 *
+	 * @param preSkuId 续费之前的规格id
+	 * @param preRelationId 续费之前的座位id
+	 * @param orderId 订单id
+	 * @param afterSku 续费之后的规格
+	 */
+	private void changeTicketAndRecord(Long preSkuId, Long preRelationId, Long orderId, Integer num, GoodsDonSku afterSku) {
+		Long afterSkuId = afterSku.getId();
+		//清理之前的车票
+		GroupsRelation relation = groupsRelationMapper.selectById(preRelationId);
+		if (relation != null) {
+			Long userId = relation.getUserId();
+			groupRelationClearService.clearRenewGroupRelation(relation);
+			//记录更换车票记录
+			Date preStartTime = relation.getStartTime();
+			Date preExpiryTime = relation.getStartTime();
+			UserRenewChangeTicketRecord record = new UserRenewChangeTicketRecord();
+			record.setUserId(userId);
+			record.setPreRelationId(relation.getId());
+			record.setPreSkuId(preSkuId);
+			record.setPreStartTime(preStartTime);
+			record.setPreExpiryTime(preExpiryTime);
+			record.setRenewOrderId(orderId);
+
+			//获取续费规格的车票
+			GroupsRelation afterRelation = exchangeCodeService.getRelationNoOrder(afterSku, userId);
+
+			record.setAfterSkuId(afterSkuId);
+			record.setAfterRelationId(afterRelation.getId());
+			DateTime afterExpiryTime = DateUtil.offsetMonth(preExpiryTime, num * afterSku.getMonths());
+			record.setAfterExpiryTime(afterExpiryTime);
+
+			afterRelation.setStartTime(preStartTime);
+			afterRelation.setExpiryTime(afterExpiryTime);
+			groupsRelationMapper.updateById(afterRelation);
+
+			userRenewChangeTicketRecordMapper.insert(record);
+		}
+	}
 }

+ 5 - 0
netflix-service/src/main/java/com/cyksj/service/relation/GroupRelationClearService.java

@@ -15,4 +15,9 @@ public interface GroupRelationClearService {
 	 * 清除车票
 	 */
 	void clearTicket(GroupsRelation relation, UserTicketClearedRecord.Source source);
+
+	/**
+	 * 续费换车票,清理之前的车票
+	 */
+	void clearRenewGroupRelation(GroupsRelation relation);
 }

+ 20 - 0
netflix-service/src/main/java/com/cyksj/service/relation/impl/GroupRelationClearServiceImpl.java

@@ -73,4 +73,24 @@ public class GroupRelationClearServiceImpl implements GroupRelationClearService
 			}
 		}
 	}
+
+	@Override
+	public void clearRenewGroupRelation(GroupsRelation relation) {
+		Date expireTime = relation.getExpiryTime();
+		relation.setStartTime(null);
+		relation.setExpiryTime(null);
+		relation.setUserId(0l);
+		relation.setStatus(GroupsRelation.Status.none);
+		relation.setIsHandle(false);
+		relation.setRenewStatus(false);
+		relation.setAccount(null);
+		Integer success = groupsRelationMapper.updateExpiryTime(relation, expireTime);
+		if (success == 1) {
+			log.info("续费后更换车票,座位号:{}", relation.getId());
+			int count = groupsMapper.incrAvailableNum(relation.getGroupsId());
+			if (count == 0) {
+				log.error("续费更换车位异常 groupId:{}", relation.getGroupsId());
+			}
+		}
+	}
 }

+ 2 - 2
netflix-web/src/main/java/com/cyksj/web/controller/manage/account/CmsAccountController.java

@@ -115,7 +115,7 @@ public class CmsAccountController {
     public void exportAccount(Long userId, String nickName, String submitAccount, String expiryStartTime, String expiryEndTime, HttpServletResponse response) {
         MapBuilder mapBuilder = MapUtils.flatBuilder(request.getParameterMap());
         if (StrUtil.isNotEmpty(expiryStartTime) || StrUtil.isNotEmpty(expiryEndTime)) {
-            mapBuilder.field(AccountView::getExpiryTime, expiryStartTime, expiryEndTime)
+            mapBuilder.field(ExcelManageAccountData::getExpiryTime, expiryStartTime, expiryEndTime)
                     .op(Operator.Between);
         }
 
@@ -125,7 +125,7 @@ public class CmsAccountController {
                 throw BusinessRuntimeException.getInstance("暂无数据!");
             }
 
-            mapBuilder.field(AccountView::getId, accountIds).op(Operator.InList);
+            mapBuilder.field(ExcelManageAccountData::getId, accountIds).op(Operator.InList);
         }
         List<ExcelManageAccountData> list = beanSearcher.searchAll(ExcelManageAccountData.class, mapBuilder.build());