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

Merge branch 'vip_order_season'

zoujiajian 1 год назад
Родитель
Сommit
6dcbf0c1fb

+ 2 - 1
netflix-dao/src/main/java/com/cyksj/model/entity/UserTicketClearedRecord.java

@@ -65,7 +65,8 @@ public class UserTicketClearedRecord extends BaseEntity{
 		manual("手动清除"),
 		refund("退款"),
 		vip_refund("退款"),
-		ticket_replace("替换车票")
+		ticket_replace("替换车票"),
+		vip_deduct("会员抵扣"),
 		;
 		String desc;
 

+ 5 - 0
netflix-dao/src/main/java/com/cyksj/model/entity/VipOrderDon.java

@@ -50,6 +50,11 @@ public class VipOrderDon extends BaseEntity{
 	 */
 	private String openId;
 
+	/**
+	 * 续费月数
+	 */
+	private Integer num;
+
 	/** 金额 */
 	private BigDecimal money;
 

+ 6 - 0
netflix-dao/src/main/java/com/cyksj/model/manage/views/GroupsRelationView.java

@@ -94,6 +94,12 @@ public class GroupsRelationView {
     @JsonIgnore
     private Integer gtNum;
 
+    /**
+     * 车票获取类型 默认1购买,2.体验
+     */
+    @DbField("gr.aq_type")
+    private Integer aqType;
+
     @DbField("u.nickname")
     private String nickName;
 

+ 5 - 0
netflix-dao/src/main/java/com/cyksj/model/request/VipOrderDonPayReq.java

@@ -24,6 +24,11 @@ public class VipOrderDonPayReq {
 	@NotNull(message = "请输入金额")
 	private BigDecimal donMoney;
 
+	/**
+	 * 续费月数 默认1
+	 */
+	private Integer num = 1;
+
 	/**
 	 * 渠道链接id
 	 */

+ 3 - 0
netflix-dao/src/main/java/com/cyksj/model/views/CmsVipOrderDonView.java

@@ -58,6 +58,9 @@ public class CmsVipOrderDonView {
 	@DbField("u.email")
 	private String email;
 
+	@DbField("o.num")
+	private Integer num;
+
 	@DbField("o.money")
 	private BigDecimal money;
 

+ 13 - 0
netflix-service/src/main/java/com/cyksj/service/mange/impl/MirrorUserCleatServiceImpl.java

@@ -1,6 +1,7 @@
 package com.cyksj.service.mange.impl;
 
 import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.cyksj.common.constant.Constant;
@@ -161,6 +162,12 @@ public class MirrorUserCleatServiceImpl implements MirrorUserCleatService {
 				log.info("claude pro 续费升级订单退款,relation_id:{}存在次级续费升级订单", orderDon.getUserId());
 				Date payTime = Optional.ofNullable(otherRenewOrderDon.getPayTime()).orElse(otherRenewOrderDon.getCreatedTime());
 				renewExpiryTime = DateUtil.offsetMonth(payTime, otherRenewSku.getMonths());
+				//同规格不处理
+				if (!ObjectUtil.equal(otherRenewOrderDon.getSkuId(), orderDon.getSkuId())) {
+					//相差多少天
+					Long betDay = DateUtil.betweenDay(otherRenewOrderDon.getCreatedTime(), orderDon.getCreatedTime(), false);
+					renewExpiryTime = DateUtil.offsetDay(renewExpiryTime, -betDay.intValue());
+				}
 				claudeUser.setRenewOrderId(otherRenewOrderDon.getId());
 				claudeUser.setRenewSkuId(otherRenewOrderDon.getSkuId());
 			}
@@ -225,6 +232,12 @@ public class MirrorUserCleatServiceImpl implements MirrorUserCleatService {
 				}
 				Date payTime = Optional.ofNullable(otherRenewOrderDon.getPayTime()).orElse(otherRenewOrderDon.getCreatedTime());
 				renewExpiryTime = DateUtil.offsetMonth(payTime, otherRenewSku.getMonths());
+				//同规格不处理
+				if (!ObjectUtil.equal(otherRenewOrderDon.getSkuId(), orderDon.getSkuId())) {
+					//相差多少天
+					Long betDay = DateUtil.betweenDay(otherRenewOrderDon.getCreatedTime(), orderDon.getCreatedTime(), false);
+					renewExpiryTime = DateUtil.offsetDay(renewExpiryTime, -betDay.intValue());
+				}
 				chatgptUser.setRenewOrderId(otherRenewOrderDon.getId());
 				chatgptUser.setRenewSkuId(otherRenewOrderDon.getSkuId());
 			}

+ 4 - 2
netflix-service/src/main/java/com/cyksj/service/mange/vip/impl/CmsVipOrderServiceImpl.java

@@ -102,8 +102,9 @@ public class CmsVipOrderServiceImpl implements CmsVipOrderService {
 				.in(VipUser::getUserId, userIdList)
 				.last("limit 1"));
 		if (vipUser != null) {
+			int offsetMonths = orderDon.getNum();
 			Date expiryTime = vipUser.getExpiryTime();
-			DateTime subExpiryTime = DateUtil.offsetMonth(expiryTime, -1);
+			DateTime subExpiryTime = DateUtil.offsetMonth(expiryTime, -offsetMonths);
 			vipUser.setExpiryTime(subExpiryTime);
 			//若会员过期清除镜像user
 			clearVipMirrorUser(vipUser.getUserId(), subExpiryTime);
@@ -206,9 +207,10 @@ public class CmsVipOrderServiceImpl implements CmsVipOrderService {
 			throw BusinessRuntimeException.getInstance("订单状态异常");
 		}
 		Long userId = orderDon.getUserId();
+		List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
 		//会员是否已过期
 		VipUser vipUser = vipUserMapper.selectOne(Wrappers.lambdaQuery(VipUser.class)
-				.eq(VipUser::getUserId, userId)
+				.in(VipUser::getUserId, userIdList)
 				.gt(VipUser::getExpiryTime, DateTime.now())
 				.last("limit 1"));
 		if (vipUser == null) {

+ 138 - 106
netflix-service/src/main/java/com/cyksj/service/order/impl/VipOrderDonServiceImpl.java

@@ -42,6 +42,7 @@ import com.cyksj.service.chatgpt.ChatGptAccountService;
 import com.cyksj.service.claude.ClaudeService;
 import com.cyksj.service.order.VipOrderDonService;
 import com.cyksj.service.pay.AliPayCommonService;
+import com.cyksj.service.relation.GroupRelationClearService;
 import com.cyksj.service.relation.GroupRelationFrontService;
 import com.cyksj.service.user.UserBenefitsService;
 import com.cyksj.service.user.UserBindRelationService;
@@ -57,10 +58,7 @@ import org.springframework.stereotype.Service;
 
 import java.math.BigDecimal;
 import java.math.RoundingMode;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -131,6 +129,8 @@ public class VipOrderDonServiceImpl extends ServiceImpl<VipOrderDonMapper, VipOr
 
 	private final UserPlatDistributeRateMapper userPlatDistributeRateMapper;
 
+	private final GroupRelationClearService relationClearService;
+
 	private final BusinessDistributeDefaultRateConfigMapper businessDistributeDefaultRateConfigMapper;
 
 	@Override
@@ -145,8 +145,8 @@ public class VipOrderDonServiceImpl extends ServiceImpl<VipOrderDonMapper, VipOr
 		orderDon.setOrderNo(donNo);
 		orderDon.setOpenId(user.getOpenId());
 		//获取会员价格
-		VipDeductDto vipMoneyIfDeduct = getVipMoneyIfDeduct(user, payRequest.getIsDeduct());
-		BigDecimal vipMoney = getVipMoney();
+		VipDeductDto vipMoneyIfDeduct = getVipMoneyIfDeduct(user, payRequest.getIsDeduct(), payRequest.getNum());
+		BigDecimal vipMoney = getVipMoney(payRequest.getNum());
 		payRequest.setDonMoney(vipMoney);
 		if (vipMoneyIfDeduct != null) {
 			payRequest.setDonMoney(vipMoney.subtract(vipMoneyIfDeduct.getDeductMoney()));
@@ -165,6 +165,8 @@ public class VipOrderDonServiceImpl extends ServiceImpl<VipOrderDonMapper, VipOr
 		//设置订单支付商品信息
 		orderDon.setPayTitle(Constant.VIP_TITLE);
 		orderDon.setGoodsId(Constant.VIP_RELATE_GOODS_ID);
+		//购买月数
+		orderDon.setNum(payRequest.getNum());
 		this.saveOrUpdate(orderDon);
 
 		Long orderId = orderDon.getId();
@@ -257,7 +259,7 @@ public class VipOrderDonServiceImpl extends ServiceImpl<VipOrderDonMapper, VipOr
 		orderDon.setOrderNo(donNo);
 		orderDon.setOpenId(user.getOpenId());
 		//获取续费会员价格
-		payRequest.setDonMoney(getVipMoney());
+		payRequest.setDonMoney(getVipMoney(payRequest.getNum()));
 		//续费订单
 		orderDon.setOrderType(2);
 		orderDon.setMoney(payRequest.getDonMoney());
@@ -274,6 +276,7 @@ public class VipOrderDonServiceImpl extends ServiceImpl<VipOrderDonMapper, VipOr
 		//设置订单支付商品信息
 		orderDon.setPayTitle(Constant.VIP_TITLE);
 		orderDon.setGoodsId(Constant.VIP_RELATE_GOODS_ID);
+		orderDon.setNum(payRequest.getNum());
 
 		this.saveOrUpdate(orderDon);
 
@@ -364,10 +367,11 @@ public class VipOrderDonServiceImpl extends ServiceImpl<VipOrderDonMapper, VipOr
 				.in(VipUser::getUserId, userIdList)
 				.last("limit 1"))).orElse(new VipUser());
 		vipUser.setUserId(userId);
+		int offsetMonths = orderDon.getNum();
 		//发放会员车票 普通订单
 		if (orderDon.getOrderType() == 1) {
 			vipUser.setStartTime(DateTime.now());
-			vipUser.setExpiryTime(DateUtil.offsetMonth(vipUser.getStartTime(), 1));
+			vipUser.setExpiryTime(DateUtil.offsetMonth(vipUser.getStartTime(), offsetMonths));
 			if (vipUser.getId() == null) {
 				try {
 					vipUserMapper.insert(vipUser);
@@ -378,7 +382,7 @@ public class VipOrderDonServiceImpl extends ServiceImpl<VipOrderDonMapper, VipOr
 			sendVipTicketToUser(vipUser.getUserId(), vipUser.getStartTime(), vipUser.getExpiryTime(), userIdList, orderDon.getId());
 		} else {
 			//续费订单
-			vipUser.setExpiryTime(DateUtil.offsetMonth(vipUser.getExpiryTime(), 1));
+			vipUser.setExpiryTime(DateUtil.offsetMonth(vipUser.getExpiryTime(), offsetMonths));
 			vipUserMapper.updateById(vipUser);
 			//续费订单
 			setTicketToVipExpiryTime(userIdList, vipUser.getUserId(), vipUser.getExpiryTime());
@@ -410,17 +414,41 @@ public class VipOrderDonServiceImpl extends ServiceImpl<VipOrderDonMapper, VipOr
 			List<GroupsRelationView> groupsRelationViews = beanSearcher.searchAll(GroupsRelationView.class, MapUtils.builder()
 					.field(GroupsRelationView::getUserId, userIds).op(Operator.InList)
 					.field(GroupsRelationView::getId, deductRelationIds).op(Operator.InList).build());
-			deductSkuIds = groupsRelationViews.stream().map(GroupsRelationView::getSkuId).collect(Collectors.toList());
-			//将车票弄成会员类型
-			relationMapper.update(null, Wrappers.lambdaUpdate(GroupsRelation.class)
-					.set(GroupsRelation::getUserId, userId)
-					.set(GroupsRelation::getIsVip, Boolean.TRUE)
-					.set(GroupsRelation::getStartTime, vipStartTime)
-					.set(GroupsRelation::getExpiryTime, vipExpiryTime)
-					.in(GroupsRelation::getUserId, userIds)
-					.in(GroupsRelation::getId, deductRelationIds));
-			//重置镜像user
-			resetMirrorUser(groupsRelationViews, vipExpiryTime);
+			deductSkuIds = new ArrayList<>();
+			//不是同规格车票直接清除
+			List<Long> vipSkuIds = skus.stream().map(VipGoodsSku::getSkuId).collect(Collectors.toList());
+			Map<Long, List<VipGoodsSku>> vipGoodsSkuMap = skus.stream().collect(Collectors.groupingBy(VipGoodsSku::getGoodsId));
+			for (GroupsRelationView groupsRelationView : groupsRelationViews) {
+				Long goodsId = groupsRelationView.getGoodsId();
+				Long skuId = groupsRelationView.getSkuId();
+				Long relationId = groupsRelationView.getId();
+				Long newRelationId = relationId;
+				Long vipSkuId = skuId;
+				if (vipSkuIds.contains(skuId)) {
+					//同规格抵扣会员
+					//将车票弄成会员类型
+					relationMapper.update(null, Wrappers.lambdaUpdate(GroupsRelation.class)
+							.set(GroupsRelation::getUserId, userId)
+							.set(GroupsRelation::getIsVip, Boolean.TRUE)
+							.set(GroupsRelation::getStartTime, vipStartTime)
+							.set(GroupsRelation::getExpiryTime, vipExpiryTime)
+							.in(GroupsRelation::getUserId, userIds)
+							.eq(GroupsRelation::getId, relationId));
+				} else {
+					//获取对应类型 会员规格id
+					List<VipGoodsSku> thisGoodsVipSkuIds = vipGoodsSkuMap.get(goodsId);
+					vipSkuId = thisGoodsVipSkuIds.get(0).getSkuId();
+					newRelationId = groupRelationFrontService.getTicket(userId, vipSkuId, Boolean.TRUE);
+					GroupsRelation relation = relationMapper.selectById(relationId);
+					relation.setNewRelationId(newRelationId);
+					//清除不是同规格旧车票
+					relationClearService.clearTicket(relation, UserTicketClearedRecord.Source.vip_deduct);
+				}
+				//抵扣规格
+				deductSkuIds.add(vipSkuId);
+				//重置镜像user
+				resetMirrorUser(goodsId, vipSkuId, relationId, newRelationId, vipExpiryTime);
+			}
 		}
 		for (VipGoodsSku sku : skus) {
 			//未有抵扣 直接发送会员车票
@@ -436,10 +464,10 @@ public class VipOrderDonServiceImpl extends ServiceImpl<VipOrderDonMapper, VipOr
 		deductBalancePayOrderMoney(orderDon, balance, user);
 	}
 
-	private VipDeductDto getVipMoneyIfDeduct(User user, Boolean isDeduct) {
+	private VipDeductDto getVipMoneyIfDeduct(User user, Boolean isDeduct, Integer months) {
 		//若用户抵扣
 		if (isDeduct) {
-			return vipFrontService.checkAndGetOrderDeductMoney(user.getId());
+			return vipFrontService.checkAndGetOrderDeductMoney(user.getId(), months);
 		}
 		return null;
 	}
@@ -492,15 +520,19 @@ public class VipOrderDonServiceImpl extends ServiceImpl<VipOrderDonMapper, VipOr
 				.eq(GroupsRelation::getIsVip, Boolean.TRUE));
 	}
 
-	private BigDecimal getVipMoney() {
+	private BigDecimal getVipMoney(Integer num) {
 		SysConfig sysConfig = sysConfigMapper.selectOne(Wrappers.lambdaQuery(SysConfig.class)
 				.eq(SysConfig::getSysKey, Constant.VIP_FEE_KEY)
 				.last("limit 1"));
 		if (sysConfig == null || StrUtil.isEmpty(sysConfig.getSysValue())) {
 			throw BusinessRuntimeException.getInstance("系统异常");
 		}
+		//校验月数
+		if (num != 1 && num != 3 && num != 12) {
+			throw BusinessRuntimeException.getInstance("购买的会员月数错误");
+		}
 		BigDecimal vipFee = BigDecimal.valueOf(Long.valueOf(sysConfig.getSysValue()));
-		return vipFee;
+		return vipFee.multiply(BigDecimal.valueOf(num));
 	}
 
 	private void recordVipDeductRelationIds(Long orderId, Long userId, List<Long> deductRelationIds) {
@@ -514,94 +546,94 @@ public class VipOrderDonServiceImpl extends ServiceImpl<VipOrderDonMapper, VipOr
 	/**
 	 * 重置镜像user
 	 */
-	private void resetMirrorUser(List<GroupsRelationView> groupsRelationViews, Date vipExpiryTime) {
-		for (GroupsRelationView groupsRelationView : groupsRelationViews) {
-			Long skuId = groupsRelationView.getSkuId();
-			Long goodsId = groupsRelationView.getGoodsId();
-			Long relationId = groupsRelationView.getId();
-			GoodsDonSku sku = skuMapper.selectById(skuId);
-			if (goodsId == Constant.MJ_GID) {
-				MidjourneyUser user = midjourneyUserMapper.selectOne(Wrappers.lambdaQuery(MidjourneyUser.class)
-						.eq(MidjourneyUser::getRelationId, relationId)
-						.last("limit 1"));
-				if (user != null) {
-					user.setMjFastNum(sku.getMjFastNum());
-					user.setMjRelaxNum(sku.getMjRelaxNum());
-					user.setIsVip(Boolean.TRUE);
-					user.setExpireTime(vipExpiryTime);
-					midjourneyUserMapper.updateById(user);
-					redisService.del(RedisService.key.MIDJOURNEY_USER.getName() + user.getUserToken());
-				}
+	private void resetMirrorUser(Long goodsId, Long skuId, Long oldRelationId, Long newRelationId, Date vipExpiryTime) {
+		GoodsDonSku sku = skuMapper.selectById(skuId);
+		if (goodsId == Constant.MJ_GID) {
+			MidjourneyUser user = midjourneyUserMapper.selectOne(Wrappers.lambdaQuery(MidjourneyUser.class)
+					.eq(MidjourneyUser::getRelationId, oldRelationId)
+					.last("limit 1"));
+			if (user != null) {
+				user.setMjFastNum(sku.getMjFastNum());
+				user.setMjRelaxNum(sku.getMjRelaxNum());
+				user.setIsVip(Boolean.TRUE);
+				user.setExpireTime(vipExpiryTime);
+				user.setRelationId(newRelationId);
+				midjourneyUserMapper.updateById(user);
+				redisService.del(RedisService.key.MIDJOURNEY_USER.getName() + user.getUserToken());
 			}
-			if (goodsId == Constant.GPT_PLUS_GID) {
-				ChatgptUser chatgptUser = chatgptUserMapper.selectOne(Wrappers.lambdaQuery(ChatgptUser.class)
-						.eq(ChatgptUser::getRelationId, relationId)
-						.last("limit 1"));
-				if (chatgptUser != null) {
-					chatgptUser.setLimitNum(sku.getGptLimitNum());
-					chatgptUser.setLimitTime(sku.getGptLimitTime());
-					chatgptUser.setDsLimitNum(sku.getDsLimitNum());
-					chatgptUser.setDsLimitTime(sku.getDsLimitTime());
-					chatgptUser.setOtherLimitNum(sku.getOtherLimitNum());
-					chatgptUser.setOtherLimitTime(sku.getOtherLimitTime());
-					chatgptUser.setPackageId(0l);
-					chatgptUser.setClearPackageTime(null);
-					chatgptUser.setRenewOrderId(0l);
-					chatgptUser.setRenewSkuId(null);
-					chatgptUser.setRenewExpiryTime(null);
-					chatgptUser.setIsVip(Boolean.TRUE);
-					chatgptUser.setExpireTime(vipExpiryTime);
-					chatgptUserMapper.updateById(chatgptUser);
-					try {
-						//清除次数
-						chatGptAccountService.clearGptNum(relationId);
-					} catch (Exception e) {
-					}
+		}
+		if (goodsId == Constant.GPT_PLUS_GID) {
+			ChatgptUser chatgptUser = chatgptUserMapper.selectOne(Wrappers.lambdaQuery(ChatgptUser.class)
+					.eq(ChatgptUser::getRelationId, oldRelationId)
+					.last("limit 1"));
+			if (chatgptUser != null) {
+				chatgptUser.setLimitNum(sku.getGptLimitNum());
+				chatgptUser.setLimitTime(sku.getGptLimitTime());
+				chatgptUser.setDsLimitNum(sku.getDsLimitNum());
+				chatgptUser.setDsLimitTime(sku.getDsLimitTime());
+				chatgptUser.setOtherLimitNum(sku.getOtherLimitNum());
+				chatgptUser.setOtherLimitTime(sku.getOtherLimitTime());
+				chatgptUser.setPackageId(0l);
+				chatgptUser.setClearPackageTime(null);
+				chatgptUser.setRenewOrderId(0l);
+				chatgptUser.setRenewSkuId(null);
+				chatgptUser.setRenewExpiryTime(null);
+				chatgptUser.setIsVip(Boolean.TRUE);
+				chatgptUser.setExpireTime(vipExpiryTime);
+				chatgptUser.setRelationId(newRelationId);
+				chatgptUserMapper.updateById(chatgptUser);
+				try {
+					//清除次数
+					chatGptAccountService.clearGptNum(oldRelationId);
+				} catch (Exception e) {
 				}
 			}
-			if (goodsId == Constant.CALUDE_GOODS_ID) {
-				ClaudeUser claudeUser = claudeUserMapper.selectOne(Wrappers.lambdaQuery(ClaudeUser.class)
-						.eq(ClaudeUser::getRelationId, relationId)
-						.last("limit 1"));
-				if (claudeUser != null) {
-					claudeUser.setLimitNum(sku.getGptLimitNum());
-					claudeUser.setLimitTime(sku.getGptLimitTime());
-					claudeUser.setRenewOrderId(null);
-					claudeUser.setRenewExpiryTime(null);
-					claudeUser.setRenewSkuId(null);
-					claudeUser.setIsVip(Boolean.TRUE);
-					claudeUser.setExpireTime(vipExpiryTime);
-					claudeUserMapper.updateById(claudeUser);
-					try {
-						//清除次数
-						claudeService.clearNum(claudeUser.getUserToken());
-					} catch (Exception e) {
-					}
+		}
+		if (goodsId == Constant.CALUDE_GOODS_ID) {
+			ClaudeUser claudeUser = claudeUserMapper.selectOne(Wrappers.lambdaQuery(ClaudeUser.class)
+					.eq(ClaudeUser::getRelationId, oldRelationId)
+					.last("limit 1"));
+			if (claudeUser != null) {
+				claudeUser.setLimitNum(sku.getGptLimitNum());
+				claudeUser.setLimitTime(sku.getGptLimitTime());
+				claudeUser.setRenewOrderId(null);
+				claudeUser.setRenewExpiryTime(null);
+				claudeUser.setRenewSkuId(null);
+				claudeUser.setIsVip(Boolean.TRUE);
+				claudeUser.setExpireTime(vipExpiryTime);
+				claudeUser.setRelationId(newRelationId);
+				claudeUserMapper.updateById(claudeUser);
+				try {
+					//清除次数
+					claudeService.clearNum(claudeUser.getUserToken());
+				} catch (Exception e) {
 				}
 			}
-			if (goodsId == Constant.GROK_GOODS_ID) {
-				GrokUser grokUser = grokUserMapper.selectOne(Wrappers.lambdaQuery(GrokUser.class)
-						.eq(GrokUser::getRelationId, relationId)
-						.last("limit 1"));
-				if (grokUser != null) {
-					grokUser.setLimitNum(sku.getGptLimitNum());
-					grokUser.setLimitTime(sku.getGptLimitTime());
-					grokUser.setIsVip(Boolean.TRUE);
-					grokUser.setExpireTime(vipExpiryTime);
-					grokUserMapper.updateById(grokUser);
-				}
+		}
+		if (goodsId == Constant.GROK_GOODS_ID) {
+			GrokUser grokUser = grokUserMapper.selectOne(Wrappers.lambdaQuery(GrokUser.class)
+					.eq(GrokUser::getRelationId, oldRelationId)
+					.last("limit 1"));
+			if (grokUser != null) {
+				grokUser.setLimitNum(sku.getGptLimitNum());
+				grokUser.setLimitTime(sku.getGptLimitTime());
+				grokUser.setIsVip(Boolean.TRUE);
+				grokUser.setExpireTime(vipExpiryTime);
+				grokUser.setRelationId(newRelationId);
+				grokUserMapper.updateById(grokUser);
 			}
-			if (goodsId == Constant.LUMA_GOODS_ID) {
-				LumaUser lumaUser = lumaUserMapper.selectOne(Wrappers.lambdaQuery(LumaUser.class)
-						.eq(LumaUser::getRelationId, relationId)
-						.last("limit 1"));
-				if (lumaUser != null) {
-					lumaUser.setNum(sku.getLumaNum());
-					lumaUser.setIsVip(Boolean.TRUE);
-					lumaUser.setExpireTime(vipExpiryTime);
-					lumaUserMapper.updateById(lumaUser);
-					redisService.del(RedisService.key.LUMA_NUM_LIMIT.getName() + lumaUser.getId());
-				}
+		}
+		if (goodsId == Constant.LUMA_GOODS_ID) {
+			LumaUser lumaUser = lumaUserMapper.selectOne(Wrappers.lambdaQuery(LumaUser.class)
+					.eq(LumaUser::getRelationId, oldRelationId)
+					.last("limit 1"));
+			if (lumaUser != null) {
+				lumaUser.setNum(sku.getLumaNum());
+				lumaUser.setIsVip(Boolean.TRUE);
+				lumaUser.setExpireTime(vipExpiryTime);
+				lumaUser.setRelationId(newRelationId);
+				lumaUserMapper.updateById(lumaUser);
+				redisService.del(RedisService.key.LUMA_NUM_LIMIT.getName() + lumaUser.getId());
 			}
 		}
 	}

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

@@ -126,7 +126,9 @@ public class GroupRelationClearServiceImpl implements GroupRelationClearService
 //						log.info("ChatGPT 独立会员账号车票过期,删除原先车队id:{}并生成一个10人月付规格的车队id:{}", groupsRelation.getId(), gt.getId());
 //					}
 //				}
-				mirrorUserCleatService.delMirrorUser(groupsRelation.getGoodsId(), groupsRelation.getId(), userTicketClearedRecord.getId());
+				if (source != UserTicketClearedRecord.Source.vip_deduct) {
+					mirrorUserCleatService.delMirrorUser(groupsRelation.getGoodsId(), groupsRelation.getId(), userTicketClearedRecord.getId());
+				}
 			}
 		}
 	}

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

@@ -270,6 +270,8 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
 				}
 			}
 			List<Long> vipSkuIds = vipGoodsSkuMapper.selectList(null).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)
 					.in(VipUser::getUserId, userIds)
 					.gt(VipUser::getExpiryTime, now));
@@ -420,7 +422,7 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
 						ticket.setReceivedGptGift(count.intValue() > 0);
 					}
 				}
-				markVipDeductTicket(userIds, ticket, vipSkuIds, vipUserCount > 0);
+				markVipDeductTicket(userIds, ticket, vipGoodsIds, vipUserCount > 0);
 			});
 		}
 		userLoginRecordService.saveUserLoginDayRecord(userId);
@@ -1973,14 +1975,18 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
 	/**
 	 * 标记是否可抵扣会员车票
 	 */
-	private void markVipDeductTicket(List<Long> userIds, RenewalView ticket, List<Long> vipSkuIds, Boolean isVip) {
-		if (CollUtil.isNotEmpty(vipSkuIds) && !isVip) {
-			Long skuId = ticket.getSkuId();
-			if (vipSkuIds.contains(skuId)) {
+	private void markVipDeductTicket(List<Long> userIds, RenewalView ticket, Set<Long> vipGoodsIds, Boolean isVip) {
+		if (CollUtil.isNotEmpty(vipGoodsIds) && !isVip) {
+			Long goodsId = ticket.getGoodsId();
+			//只购买
+			if (ticket.getAqType() != 1) {
+				return;
+			}
+			if (vipGoodsIds.contains(goodsId)) {
 				//是否时长最长
 				Number number = beanSearcher.searchCount(RenewalView.class, MapUtils.builder()
 						.field(RenewalView::getRelationId, ticket.getRelationId()).op(Operator.NotEqual)
-						.field(RenewalView::getSkuId, skuId)
+						.field(RenewalView::getGoodsId, goodsId)
 						.field(RenewalView::getUserId, userIds).op(Operator.InList)
 						.field(RenewalView::getExpiryTime, ticket.getExpiryTime()).op(Operator.GreaterThan)
 						.build());

+ 1 - 1
netflix-service/src/main/java/com/cyksj/service/vip/VipFrontService.java

@@ -12,5 +12,5 @@ import com.cyksj.model.response.VipUserPageResp;
 public interface VipFrontService {
 	void fillVipInfo(Long userId, VipUserPageResp vipUserPageResp);
 
-	VipDeductDto checkAndGetOrderDeductMoney(Long userId);
+	VipDeductDto checkAndGetOrderDeductMoney(Long userId, Integer months);
 }

+ 153 - 45
netflix-service/src/main/java/com/cyksj/service/vip/impl/VipFrontServiceImpl.java

@@ -2,6 +2,7 @@ package com.cyksj.service.vip.impl;
 
 import cn.hutool.core.date.DateTime;
 import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.cyksj.common.constant.Constant;
@@ -55,6 +56,8 @@ public class VipFrontServiceImpl implements VipFrontService {
 
 	private final OrderDonMapper orderDonMapper;
 
+	private final GoodsDonSkuMapper goodsDonSkuMapper;
+
 	@Override
 	public void fillVipInfo(Long userId, VipUserPageResp vipUserPageResp) {
 		SysConfig sysConfig = sysConfigMapper.selectOne(Wrappers.lambdaQuery(SysConfig.class).eq(SysConfig::getSysKey, Constant.VIP_FEE_KEY).last("limit 1"));
@@ -70,11 +73,14 @@ public class VipFrontServiceImpl implements VipFrontService {
 		List<Long> vipSkuIds = vipGoodsSkuMapper.selectList(null).stream().map(VipGoodsSku::getSkuId).collect(Collectors.toList());
 		//可有抵扣车票
 		DateTime now = DateTime.now();
-		Number count = beanSearcher.searchCount(GroupsRelationView.class, MapUtils.builder().field(GroupsRelationView::getUserId, userIdList).op(Operator.InList).field(GroupsRelationView::getSkuId, vipSkuIds).op(Operator.InList).field(GroupsRelationView::getExpiryTime, now).op(Operator.GreaterThan).build());
+		//会员规格
+		Set<Long> goodsIds = goodsDonSkuMapper.selectList(Wrappers.lambdaQuery(GoodsDonSku.class)
+				.in(GoodsDonSku::getId, vipSkuIds)).stream().map(GoodsDonSku::getGoodsId).collect(Collectors.toSet());
+		Number count = beanSearcher.searchCount(GroupsRelationView.class, MapUtils.builder().field(GroupsRelationView::getUserId, userIdList).op(Operator.InList).field(GroupsRelationView::getGoodsId, goodsIds).op(Operator.InList).field(GroupsRelationView::getExpiryTime, now).op(Operator.GreaterThan).build());
 		//可抵扣车票
 		if (count.intValue() > 0) {
 			//处理vip抵扣金额
-			VipDeductDto vipDeductDto = commonHandleVipDeductMoney(userIdList, vipSkuIds);
+			VipDeductDto vipDeductDto = commonHandleVipDeductMoney(userIdList, goodsIds, 12);
 			deductMoney = vipDeductDto.getDeductMoney();
 			vipUserPageResp.setRelationUserViews(vipDeductDto.getRelationUserViews());
 		}
@@ -85,63 +91,67 @@ public class VipFrontServiceImpl implements VipFrontService {
 	 * 检查用户并获取订单抵扣金额
 	 */
 	@Override
-	public VipDeductDto checkAndGetOrderDeductMoney(Long userId) {
+	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());
+		//会员规格
+		Set<Long> goodsIds = goodsDonSkuMapper.selectList(Wrappers.lambdaQuery(GoodsDonSku.class)
+				.in(GoodsDonSku::getId, vipSkuIds)).stream().map(GoodsDonSku::getGoodsId).collect(Collectors.toSet());
 		Number count = beanSearcher.searchCount(GroupsRelationView.class, MapUtils.builder()
 				.field(GroupsRelationView::getUserId, userIdList).op(Operator.InList)
-				.field(GroupsRelationView::getSkuId, vipSkuIds).op(Operator.InList)
+				.field(GroupsRelationView::getGoodsId, goodsIds).op(Operator.InList)
 				.field(GroupsRelationView::getExpiryTime, DateTime.now()).op(Operator.GreaterThan)
 				.field(GroupsRelationView::getIsVip, false)
 				.build());
 		if (count.intValue() == 0) {
 			throw BusinessRuntimeException.getInstance("暂无可抵扣AI车票");
 		}
-		VipDeductDto vipDeductDto = commonHandleVipDeductMoney(userIdList, vipSkuIds);
+		VipDeductDto vipDeductDto = commonHandleVipDeductMoney(userIdList, goodsIds, months);
 		return vipDeductDto;
 	}
 
 
-	private BigDecimal getVipMoney() {
+	private BigDecimal getVipMoney(Integer months) {
 		SysConfig sysConfig = sysConfigMapper.selectOne(Wrappers.lambdaQuery(SysConfig.class).eq(SysConfig::getSysKey, Constant.VIP_FEE_KEY).last("limit 1"));
 		if (sysConfig == null || StrUtil.isEmpty(sysConfig.getSysValue())) {
 			throw BusinessRuntimeException.getInstance("系统异常");
 		}
 		BigDecimal vipFee = BigDecimal.valueOf(Long.valueOf(sysConfig.getSysValue()));
-		return vipFee;
+		return vipFee.multiply(BigDecimal.valueOf(months));
 	}
 
 	/**
 	 * 统一处理vip抵扣金额
 	 */
-	public VipDeductDto commonHandleVipDeductMoney(List<Long> userIdList, List<Long> vipSkuIds) {
+	public VipDeductDto commonHandleVipDeductMoney(List<Long> userIdList, Set<Long> goodsIds, Integer months) {
 		VipDeductDto vipDeductDto = new VipDeductDto();
 		DateTime now = DateTime.now();
 		List<Long> deductRelationIds = new ArrayList<>();
 		BigDecimal deductMoney = BigDecimal.ZERO;
-		BigDecimal vipMoney = getVipMoney();
+		BigDecimal vipMoney = getVipMoney(months);
 		List<GroupsRelationView> relations = beanSearcher.searchAll(GroupsRelationView.class, MapUtils.builder()
-				.field(GroupsRelationView::getSkuId, vipSkuIds).op(Operator.InList)
+				.field(GroupsRelationView::getGoodsId, goodsIds).op(Operator.InList)
 				.field(GroupsRelationView::getUserId, userIdList).op(Operator.InList)
 				.field(GroupsRelationView::getIsVip, false)
 				.field(GroupsRelationView::getExpiryTime, DateTime.now()).op(Operator.GreaterThan)
+				.field(GroupsRelationView::getAqType, 1)
 				.orderBy(GroupsRelationView::getExpiryTime).desc()
 				.build());
-		Set<Long> deductSkuIds = null;
+		Set<Long> deductGoodsIds = null;
 		List<GroupsRelationView> deductRelations = null;
 		for (GroupsRelationView relation : relations) {
-			if (deductSkuIds == null) {
-				deductSkuIds = new HashSet<>();
+			if (deductGoodsIds == null) {
+				deductGoodsIds = new HashSet<>();
 			}
 			if (deductRelations == null) {
 				deductRelations = new ArrayList<>();
 			}
-			Long vipSkuId = relation.getSkuId();
-			if (deductSkuIds.contains(vipSkuId)) {
+			Long goodsId = relation.getGoodsId();
+			if (deductGoodsIds.contains(goodsId)) {
 				continue;
 			}
-			deductSkuIds.add(vipSkuId);
-			Long goodsId = relation.getGoodsId();
+			Long skuId = relation.getSkuId();
+			deductGoodsIds.add(goodsId);
 			Long relationId = relation.getId();
 			Date relationExpiryTime = relation.getExpiryTime();
 			//GPT
@@ -159,7 +169,7 @@ public class VipFrontServiceImpl implements VipFrontService {
 				}
 			} else {
 				//该车票抵扣金额
-				deductMoney = deductMoney.add(getDeductMoneyFromTicket(vipSkuId, now, relation.getId(), relation.getStartTime(), relationExpiryTime));
+				deductMoney = deductMoney.add(getDeductMoneyFromTicket(relationId, userIdList, skuId, now, relation.getStartTime(), relationExpiryTime));
 			}
 			deductRelationIds.add(relationId);
 			//可抵扣车票
@@ -183,39 +193,92 @@ public class VipFrontServiceImpl implements VipFrontService {
 		BigDecimal deductMoney = BigDecimal.ZERO;
 		//一个月当30天算单价 往上取整
 		//续费规格
-		if (renewSkuId != null) {
+		if (renewSkuId != null && renewExpiryTime.compareTo(now) > 0) {
 			OrderDon renewOrderDon = orderDonMapper.selectById(renewOrderId);
-			GoodsDonSku sku = skuMapper.selectById(renewSkuId);
+			BigDecimal orderMoney = renewOrderDon.getMoney().add(Optional.ofNullable(renewOrderDon.getBalance()).orElse(BigDecimal.ZERO));
+			GoodsDonSku presentSku = skuMapper.selectById(renewSkuId);
+			if (orderMoney.compareTo(BigDecimal.ZERO) == 0) {
+				orderMoney = presentSku.getPrice();
+			}
 			Long betweenDay = DateUtil.betweenDay(now, renewExpiryTime, false) + 1;
 			//当天购买的按规格原价抵扣
+			BigDecimal renewDeductMoney;
 			if (now.toDateStr().equals(DateUtil.format(renewOrderDon.getCreatedTime(), "yyyy-MM-dd"))) {
-				deductMoney = deductMoney.add(sku.getPrice());
+				renewDeductMoney = orderMoney;
+				deductMoney = deductMoney.add(renewDeductMoney);
+				if (presentSku.getDays() != null) {
+					relationExpiryTime = DateUtil.offsetDay(relationExpiryTime, -presentSku.getDays());
+				} else {
+					relationExpiryTime = DateUtil.offsetMonth(relationExpiryTime, -presentSku.getMonths());
+				}
 			} else {
-				BigDecimal single = sku.getPrice().divide(BigDecimal.valueOf(sku.getMonths()).multiply(BigDecimal.valueOf(30)), 0, RoundingMode.UP);
+				//此次续费规格单价
+				BigDecimal single = getPayOrderSingle(orderMoney, presentSku);
 				//该车票抵扣金额
-				BigDecimal renewDeductMoney = single.multiply(BigDecimal.valueOf(betweenDay));
+				renewDeductMoney = single.multiply(BigDecimal.valueOf(betweenDay));
 				log.info("车票id:{}目前续费升级规格可抵扣的金额为:{}", relationId, renewDeductMoney);
 				deductMoney = deductMoney.add(renewDeductMoney);
+				relationExpiryTime = DateUtil.offsetDay(relationExpiryTime, -betweenDay.intValue());
 			}
-			relationExpiryTime = DateUtil.offsetDay(relationExpiryTime, -betweenDay.intValue());
 			//上一个续费升级规格
 			List<OrderDon> orderDOns = orderDonRenewRecordMapper.getOtherRenewSkus(renewOrderId, relationId, userIdList);
-			for (OrderDon orderDOn : orderDOns) {
-				Long skuId = orderDOn.getSkuId();
-				sku = skuMapper.selectById(skuId);
-				BigDecimal upDeductMoney = sku.getPrice();
-				log.info("车票id:{}目前次一级规格:{}可抵扣的金额为:{}", relationId, sku.getSpecVal(), upDeductMoney);
-				deductMoney = deductMoney.add(upDeductMoney);
-				if (sku.getDays() != null) {
-					relationExpiryTime = DateUtil.offsetDay(relationExpiryTime, -sku.getDays());
+			OrderDon presentRenewOrderDon = renewOrderDon;
+			for (OrderDon thisRenewOrderDon : orderDOns) {
+				Long skuId = thisRenewOrderDon.getSkuId();
+				GoodsDonSku thisRenewSku = skuMapper.selectById(skuId);
+				BigDecimal thisOrderMoney = thisRenewOrderDon.getMoney().add(Optional.ofNullable(thisRenewOrderDon.getBalance()).orElse(BigDecimal.ZERO));
+				if (thisOrderMoney.compareTo(BigDecimal.ZERO) == 0) {
+					thisOrderMoney = thisRenewSku.getPrice();
+				}
+				//当天购买的按规格原价抵扣
+				BigDecimal thisRenewDeductMoney = BigDecimal.ZERO;
+				if (now.toDateStr().equals(DateUtil.format(thisRenewOrderDon.getCreatedTime(), "yyyy-MM-dd"))) {
+					thisRenewDeductMoney = thisOrderMoney;
+					deductMoney = deductMoney.add(thisRenewDeductMoney);
+					if (thisRenewSku.getDays() != null) {
+						relationExpiryTime = DateUtil.offsetDay(relationExpiryTime, -thisRenewSku.getDays());
+					} else {
+						relationExpiryTime = DateUtil.offsetMonth(relationExpiryTime, -thisRenewSku.getMonths());
+					}
 				} else {
-					relationExpiryTime = DateUtil.offsetMonth(relationExpiryTime, -sku.getMonths());
+					//此次续费订单过期时间
+					Date thisOrderExpiryTime;
+					if (thisRenewSku.getDays() != null) {
+						thisOrderExpiryTime = DateUtil.offsetDay(thisRenewOrderDon.getCreatedTime(), thisRenewSku.getDays());
+					} else {
+						thisOrderExpiryTime = DateUtil.offsetMonth(thisRenewOrderDon.getCreatedTime(), thisRenewSku.getMonths());
+					}
+					//续费同规格不处理
+					if (!ObjectUtil.equal(thisRenewOrderDon.getSkuId(), presentRenewOrderDon.getSkuId())) {
+						//先扣除已使用的天数
+						//相差多少天
+						Long thisRenewBetDay = DateUtil.betweenDay(thisRenewOrderDon.getCreatedTime(), presentRenewOrderDon.getCreatedTime(), false);
+						//扣除已使用的
+						thisOrderExpiryTime = DateUtil.offsetDay(thisOrderExpiryTime, -thisRenewBetDay.intValue());
+					}
+					//此订单过期时间
+					if (thisOrderExpiryTime.compareTo(now) > 0) {
+						//距离过期还剩多少天
+						Long thisDeductBetweenDay = DateUtil.betweenDay(now, thisOrderExpiryTime, false) + 1;
+						if (thisDeductBetweenDay != 0) {
+							//此次续费规格单价
+							BigDecimal single = getPayOrderSingle(thisOrderMoney, thisRenewSku);
+							//该车票抵扣金额
+							thisRenewDeductMoney = single.multiply(BigDecimal.valueOf(thisDeductBetweenDay));
+							deductMoney = deductMoney.add(thisRenewDeductMoney);
+						}
+						//目前级别续费订单
+						presentRenewOrderDon = thisRenewOrderDon;
+						relationExpiryTime = DateUtil.offsetDay(relationExpiryTime, -thisDeductBetweenDay.intValue());
+					}
 				}
+				log.info("车票id:{}目前次一级规格:{}可抵扣的金额为:{}", relationId, thisRenewSku.getSpecVal(), thisRenewDeductMoney);
+
 			}
 		}
-		if (relationExpiryTime.after(DateTime.now())) {
+		if (relationExpiryTime.after(now)) {
 			//该车票抵扣金额
-			BigDecimal deductMoneyFromTicket = getDeductMoneyFromTicket(relationSkuId, now, relationId, relationStartTime, relationExpiryTime);
+			BigDecimal deductMoneyFromTicket = getDeductMoneyFromTicket(relationId, userIdList, relationSkuId, now, relationStartTime, relationExpiryTime);
 			deductMoney = deductMoney.add(deductMoneyFromTicket);
 		}
 		log.info("车票id:{}最终到期时间为:{}车票可返回 抵扣金额:{}", relationId, DateUtil.format(relationExpiryTime, "yyyy-MM-dd HH:mm:ss"), deductMoney);
@@ -225,19 +288,64 @@ public class VipFrontServiceImpl implements VipFrontService {
 	/**
 	 * 获取车票可抵扣金额
 	 */
-	public BigDecimal getDeductMoneyFromTicket(Long skuId, DateTime now, Long relationId, Date relationStartTime, Date relationExpiryTime) {
-		GoodsDonSku sku = skuMapper.selectById(skuId);
-		BigDecimal single = sku.getPrice().divide(BigDecimal.valueOf(sku.getMonths()).multiply(BigDecimal.valueOf(30)), 0, RoundingMode.UP);
-		Long betweenDay = DateUtil.betweenDay(now, relationExpiryTime, false) + 1;
-		//当天购买的按规格原价抵扣
-		if (now.toDateStr().equals(DateUtil.format(relationStartTime, "yyyy-MM-dd"))) {
-			//并且没有续费 且未扣时长
-			if (DateUtil.betweenDay(DateUtil.offsetMonth(relationStartTime, 1), relationExpiryTime, true) == 0) {
-				return sku.getPrice();
+	public BigDecimal getDeductMoneyFromTicket(Long relationId, List<Long> userIdList, Long skuId, DateTime now, Date relationStartTime, Date relationExpiryTime) {
+		List<OrderDon> orderDonList = orderDonMapper.selectList(Wrappers.lambdaQuery(OrderDon.class)
+				.eq(OrderDon::getRelationId, relationId)
+				.in(OrderDon::getUserId, userIdList)
+				.eq(OrderDon::getSkuId, skuId)
+				.notIn(OrderDon::getStatus, Constant.noOrderAllStatus)
+				.orderByDesc(OrderDon::getId));
+		//原车票订单总实付金额
+		BigDecimal totalOrderMoney = BigDecimal.ZERO;
+		//原车票订单总天数
+		Integer totalDays = 0;
+		for (OrderDon orderDon : orderDonList) {
+			GoodsDonSku sku = skuMapper.selectById(skuId);
+			BigDecimal thisOrderMoney = orderDon.getMoney().add(Optional.ofNullable(orderDon.getBalance()).orElse(BigDecimal.ZERO));
+			if (thisOrderMoney.compareTo(BigDecimal.ZERO) == 0) {
+				thisOrderMoney = sku.getPrice();
+			}
+			totalOrderMoney = totalOrderMoney.add(thisOrderMoney);
+			//总时间
+			if (sku.getDays() != null) {
+				totalDays += sku.getDays();
+			} else {
+				totalDays += sku.getMonths() * 30;
+			}
+			//原订单数
+			if (orderDonList.size() == 1) {
+				//此次订单过期时间
+				Date thisOrderExpiryTime;
+				if (sku.getDays() != null) {
+					thisOrderExpiryTime = DateUtil.offsetDay(orderDon.getCreatedTime(), sku.getDays());
+				} else {
+					thisOrderExpiryTime = DateUtil.offsetMonth(orderDon.getCreatedTime(), sku.getMonths());
+				}
+				//当天购买的按规格原价抵扣
+				if (now.toDateStr().equals(DateUtil.format(relationStartTime, "yyyy-MM-dd")) && (DateUtil.betweenDay(thisOrderExpiryTime, relationExpiryTime, true) == 0)) {
+					return thisOrderMoney;
+				}
 			}
 		}
+		Long thisDeductBetweenDay = DateUtil.betweenDay(now, relationExpiryTime, false) + 1;
+		BigDecimal single = totalOrderMoney.divide(BigDecimal.valueOf(totalDays), 0, RoundingMode.HALF_UP);
 		//该车票抵扣金额
-		BigDecimal deductMoney = single.multiply(BigDecimal.valueOf(betweenDay));
+		BigDecimal deductMoney = single.multiply(BigDecimal.valueOf(thisDeductBetweenDay));
 		return deductMoney;
 	}
+
+	/**
+	 * 获取订单单价
+	 */
+	public BigDecimal getPayOrderSingle(BigDecimal orderMoney, GoodsDonSku sku) {
+		//此次续费规格单价
+		BigDecimal single;
+		//区分天/月
+		if (sku.getDays() != null) {
+			single = orderMoney.divide(BigDecimal.valueOf(sku.getDays()), 0, RoundingMode.HALF_UP);
+		} else {
+			single = orderMoney.divide(BigDecimal.valueOf(sku.getMonths()).multiply(BigDecimal.valueOf(30)), 0, RoundingMode.HALF_UP);
+		}
+		return single;
+	}
 }