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

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

@@ -16,4 +16,6 @@ import java.util.List;
 public interface OrderDonRenewRecordMapper extends BaseMapper<OrderDonRenewRecord> {
 
 	OrderDon getOtherRenewSku(@Param("orderId") Long orderId, @Param("relationId") Long relationId, @Param("userIds") List<Long> userIds);
+
+	List<OrderDon> getOtherRenewSkus(@Param("orderId") Long orderId, @Param("relationId") Long relationId, @Param("userIdList") List<Long> userIdList);
 }

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

@@ -0,0 +1,13 @@
+package com.cyksj.mapper.vip;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.cyksj.model.entity.VipOrderDonDeductRelation;
+
+/**
+ * 项目名: yhlxj2
+ * 文件名: VipOrderDonDeductRelationMapper
+ * 创建者: JavaZou
+ * 创建时间:2025/5/16 15:54
+ */
+public interface VipOrderDonDeductRelationMapper extends BaseMapper<VipOrderDonDeductRelation> {
+}

+ 27 - 0
netflix-dao/src/main/java/com/cyksj/model/dto/VipDeductDto.java

@@ -0,0 +1,27 @@
+package com.cyksj.model.dto;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import java.math.BigDecimal;
+import java.util.List;
+
+/**
+ * 项目名: yhlxj2
+ * 文件名: VipDeductDto
+ * 创建者: JavaZou
+ * 创建时间:2025/5/16 15:40
+ */
+@Getter
+@Setter
+public class VipDeductDto {
+	/**
+	 * 抵扣车票ids
+	 */
+	private List<Long> deductRelationIds;
+
+	/**
+	 * 可抵扣金额
+	 */
+	private BigDecimal deductMoney;
+}

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

@@ -59,7 +59,8 @@ public class UserTicketClearedRecord extends BaseEntity{
 		dp("优惠加购订单退款"),
 		manual("手动清除"),
 		refund("退款"),
-		vip_refund("退款")
+		vip_refund("退款"),
+		vip_deduct("会员抵扣")
 		;
 		String desc;
 

+ 23 - 0
netflix-dao/src/main/java/com/cyksj/model/entity/VipOrderDonDeductRelation.java

@@ -0,0 +1,23 @@
+package com.cyksj.model.entity;
+
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * 项目名: yhlxj2
+ * 文件名: VipOrderDonDeductRelation
+ * 创建者: JavaZou
+ * 创建时间:2025/5/16 15:53
+ */
+@Getter
+@Setter
+public class VipOrderDonDeductRelation extends BaseEntity{
+
+	private Long orderId;
+
+	private Long userId;
+
+	private String relationIds;
+
+	private Boolean status;
+}

+ 13 - 0
netflix-dao/src/main/resources/mapper/OrderDonRenewRecordMapper.xml

@@ -16,4 +16,17 @@
         order by sku.months desc,sku.gpt_limit_num desc
         limit 1
     </select>
+
+    <select id="getOtherRenewSkus" resultType="com.cyksj.model.entity.OrderDon">
+        select o.* from (select order_id from order_don_renew_record where order_id != #{orderId}
+        and is_valid = 0
+        and user_id in
+        <foreach collection="userIds" item="item" open="(" separator="," close=")">
+            #{item}
+        </foreach>) orr inner join order_don o on o.id = orr.order_id
+        and o.status not in ('close','noPayment','refund')
+        and o.order_type = 2 and o.relation_id = #{relationId}
+        inner join goods_don_sku sku on sku.id = o.sku_id
+        order by sku.months desc,sku.gpt_limit_num desc
+    </select>
 </mapper>

+ 53 - 10
netflix-service/src/main/java/com/cyksj/service/order/impl/VipOrderDonServiceImpl.java

@@ -19,23 +19,28 @@ import com.cyksj.mapper.UserMapper;
 import com.cyksj.mapper.channel.ShopConfigMapper;
 import com.cyksj.mapper.sys.SysConfigMapper;
 import com.cyksj.mapper.vip.VipGoodsSkuMapper;
+import com.cyksj.mapper.vip.VipOrderDonDeductRelationMapper;
 import com.cyksj.mapper.vip.VipOrderDonMapper;
 import com.cyksj.mapper.vip.VipUserMapper;
 import com.cyksj.model.dto.AliPayParams;
+import com.cyksj.model.dto.VipDeductDto;
 import com.cyksj.model.entity.*;
 import com.cyksj.model.request.AlipayOrderDonReq;
 import com.cyksj.model.request.OrderAttach;
 import com.cyksj.model.request.VipOrderDonPayReq;
 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;
+import com.cyksj.service.vip.VipFrontService;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.dao.DuplicateKeyException;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.math.BigDecimal;
 import java.util.Date;
@@ -75,7 +80,16 @@ public class VipOrderDonServiceImpl extends ServiceImpl<VipOrderDonMapper, VipOr
 
 	private final GroupsRelationMapper relationMapper;
 
+	private final VipFrontService vipFrontService;
+
+	private final VipOrderDonDeductRelationMapper vipOrderDonDeductRelationMapper;
+
+	private final GroupsRelationMapper groupsRelationMapper;
+
+	private final GroupRelationClearService groupRelationClearService;
+
 	@Override
+	@Transactional(rollbackFor = Throwable.class)
 	public VipOrderDon submit(VipOrderDonPayReq payRequest) {
 		Long userId = payRequest.getUserId();
 		User user = userMapper.selectById(userId);
@@ -87,7 +101,12 @@ public class VipOrderDonServiceImpl extends ServiceImpl<VipOrderDonMapper, VipOr
 		orderDon.setOrderNo(donNo);
 		orderDon.setOpenId(user.getOpenId());
 		//获取会员价格
-		payRequest.setDonMoney(getVipMoneyIfDeduct(user, payRequest.getIsDeduct()));
+		VipDeductDto vipMoneyIfDeduct = getVipMoneyIfDeduct(user, payRequest.getIsDeduct());
+		BigDecimal vipMoney = getVipMoney();
+		payRequest.setDonMoney(vipMoney);
+		if (vipMoneyIfDeduct != null) {
+			payRequest.setDonMoney(vipMoney.subtract(vipMoneyIfDeduct.getDeductMoney()));
+		}
 		orderDon.setMoney(payRequest.getDonMoney());
 		//渠道链接id
 		if (payRequest.getPopularizeId() != null) {
@@ -109,6 +128,11 @@ public class VipOrderDonServiceImpl extends ServiceImpl<VipOrderDonMapper, VipOr
 			orderDon = getById(orderId);
 			unifiedHandlerOrderNotify(orderDon);
 		}
+		//存在抵扣 记录抵扣成功后 需清除车票的ids
+		if (vipMoneyIfDeduct != null) {
+			List<Long> deductRelationIds = vipMoneyIfDeduct.getDeductRelationIds();
+			recordVipDeductRelationIds(orderDon.getId(), orderDon.getUserId(), deductRelationIds);
+		}
 		return orderDon;
 	}
 
@@ -248,6 +272,22 @@ public class VipOrderDonServiceImpl extends ServiceImpl<VipOrderDonMapper, VipOr
 			//续费订单
 			setTicketToVipExpiryTime(userId, vipUser.getExpiryTime());
 		}
+		//是否存在抵扣 抵扣成功 清除车票
+		VipOrderDonDeductRelation vipOrderDonDeductRelation = vipOrderDonDeductRelationMapper.selectOne(Wrappers.lambdaQuery(VipOrderDonDeductRelation.class)
+				.eq(VipOrderDonDeductRelation::getOrderId, orderDon.getId())
+				.last("limit 1"));
+		if (vipOrderDonDeductRelation != null) {
+			try {
+				List<Long> relationIds = Jsons.parseList(vipOrderDonDeductRelation.getRelationIds(), Long.class);
+				List<GroupsRelation> groupsRelations = groupsRelationMapper.selectList(Wrappers.lambdaQuery(GroupsRelation.class)
+						.eq(GroupsRelation::getUserId, orderDon.getUserId())
+						.eq(GroupsRelation::getStatus, GroupsRelation.Status.validity)
+						.in(GroupsRelation::getId, relationIds));
+				groupsRelations.forEach(relation -> groupRelationClearService.clearTicket(relation, UserTicketClearedRecord.Source.vip_deduct));
+			} catch (Exception e) {
+
+			}
+		}
 	}
 
 	private void sendVipTicketToUser(Long userId) {
@@ -263,17 +303,12 @@ public class VipOrderDonServiceImpl extends ServiceImpl<VipOrderDonMapper, VipOr
 		deductBalancePayOrderMoney(orderDon, balance, user);
 	}
 
-	private BigDecimal getVipMoneyIfDeduct(User user, Boolean isDeduct) {
-		List<VipGoodsSku> skus = vipGoodsSkuMapper.selectList(null);
-		List<Long> userIdList = userBindRelationService.getRelationUserIdList(user.getId(), user);
-		BigDecimal vipFee = getVipMoney();
-		//是否使用抵扣
+	private VipDeductDto getVipMoneyIfDeduct(User user, Boolean isDeduct) {
+		//若用户抵扣
 		if (isDeduct) {
-			for (VipGoodsSku vipGoodsSku : skus) {
-				Long skuId = vipGoodsSku.getSkuId();
-			}
+			return vipFrontService.checkAndGetOrderDeductMoney(user.getId());
 		}
-		return vipFee;
+		return null;
 	}
 
 	public void deductBalancePayOrderMoney(VipOrderDon orderDon, BigDecimal balance, User user) {
@@ -319,4 +354,12 @@ public class VipOrderDonServiceImpl extends ServiceImpl<VipOrderDonMapper, VipOr
 		BigDecimal vipFee = BigDecimal.valueOf(Long.valueOf(sysConfig.getSysValue()));
 		return vipFee;
 	}
+
+	private void recordVipDeductRelationIds(Long orderId, Long userId, List<Long> deductRelationIds) {
+		VipOrderDonDeductRelation vipOrderDonDeductRelation = new VipOrderDonDeductRelation();
+		vipOrderDonDeductRelation.setOrderId(orderId);
+		vipOrderDonDeductRelation.setUserId(userId);
+		vipOrderDonDeductRelation.setRelationIds(deductRelationIds.toString());
+		vipOrderDonDeductRelationMapper.insert(vipOrderDonDeductRelation);
+	}
 }

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

@@ -1,5 +1,6 @@
 package com.cyksj.service.vip;
 
+import com.cyksj.model.dto.VipDeductDto;
 import com.cyksj.model.response.VipUserPageResp;
 
 /**
@@ -10,4 +11,6 @@ import com.cyksj.model.response.VipUserPageResp;
  */
 public interface VipFrontService {
 	void fillVipInfo(long userId, VipUserPageResp vipUserPageResp);
+
+	VipDeductDto checkAndGetOrderDeductMoney(Long userId);
 }

+ 123 - 61
netflix-service/src/main/java/com/cyksj/service/vip/impl/VipFrontServiceImpl.java

@@ -12,10 +12,8 @@ import com.cyksj.mapper.GoodsDonSkuMapper;
 import com.cyksj.mapper.OrderDonRenewRecordMapper;
 import com.cyksj.mapper.sys.SysConfigMapper;
 import com.cyksj.mapper.vip.VipGoodsSkuMapper;
-import com.cyksj.model.entity.ChatgptUser;
-import com.cyksj.model.entity.GoodsDonSku;
-import com.cyksj.model.entity.SysConfig;
-import com.cyksj.model.entity.VipGoodsSku;
+import com.cyksj.model.dto.VipDeductDto;
+import com.cyksj.model.entity.*;
 import com.cyksj.model.manage.views.GroupsRelationView;
 import com.cyksj.model.response.VipUserPageResp;
 import com.cyksj.service.user.UserBindRelationService;
@@ -24,10 +22,12 @@ import com.ejlchina.searcher.BeanSearcher;
 import com.ejlchina.searcher.param.Operator;
 import com.ejlchina.searcher.util.MapUtils;
 import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 
 import java.math.BigDecimal;
 import java.math.RoundingMode;
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 import java.util.stream.Collectors;
@@ -40,6 +40,7 @@ import java.util.stream.Collectors;
  */
 @Service
 @RequiredArgsConstructor
+@Slf4j
 public class VipFrontServiceImpl implements VipFrontService {
 	private final SysConfigMapper sysConfigMapper;
 
@@ -59,9 +60,7 @@ public class VipFrontServiceImpl implements VipFrontService {
 
 	@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"));
+		SysConfig sysConfig = sysConfigMapper.selectOne(Wrappers.lambdaQuery(SysConfig.class).eq(SysConfig::getSysKey, Constant.VIP_FEE_KEY).last("limit 1"));
 		if (sysConfig != null && StrUtil.isNotBlank(sysConfig.getSysValue())) {
 			vipUserPageResp.setVipFee(BigDecimal.valueOf(Integer.parseInt(sysConfig.getSysValue())));
 		}
@@ -71,72 +70,135 @@ 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());
+		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());
 		//可抵扣车票
 		if (count.intValue() > 0) {
-			for (Long vipSkuId : vipSkuIds) {
-				GroupsRelationView relation = beanSearcher.searchFirst(GroupsRelationView.class, MapUtils.builder()
-						.field(GroupsRelationView::getSkuId, vipSkuId)
-						.field(GroupsRelationView::getUserId, userIdList).op(Operator.InList)
-						.orderBy(GroupsRelationView::getExpiryTime).desc()
-						.build());
-				if (relation != null) {
-					Long goodsId = relation.getGoodsId();
-					Long relationId = relation.getId();
-					//GPT
-					if (goodsId == Constant.GPT_PLUS_GID) {
-						Date relationExpiryTime = relation.getExpiryTime();
-						ChatgptUser chatgptUser = chatgptUserMapper.selectOne(Wrappers.lambdaQuery(ChatgptUser.class)
-								.eq(ChatgptUser::getRelationId, relationId)
-								.last("limit 1"));
-						if (chatgptUser != null) {
-							//续费规格
-							Long renewSkuId = chatgptUser.getRenewSkuId();
-							if (renewSkuId != null) {
-								Date renewExpiryTime = chatgptUser.getRenewExpiryTime();
-								GoodsDonSku sku = skuMapper.selectById(renewSkuId);
-								BigDecimal single = sku.getPrice().divide(BigDecimal.valueOf(sku.getMonths()).multiply(BigDecimal.valueOf(30)), 0, RoundingMode.UP);
-								Long betweenDay = DateUtil.betweenDay(now, renewExpiryTime, false);
-								//该车票抵扣金额
-								deductMoney.add(single.multiply(BigDecimal.valueOf(betweenDay)));
-								relationExpiryTime = DateUtil.offsetDay(relationExpiryTime, betweenDay.intValue());
-							}else {
-								GoodsDonSku sku = skuMapper.selectById(vipSkuId);
-								BigDecimal single = sku.getPrice().divide(BigDecimal.valueOf(sku.getMonths()).multiply(BigDecimal.valueOf(30)), 0, RoundingMode.UP);
-								Long betweenDay = DateUtil.betweenDay(now, relationExpiryTime, false);
-								//该车票抵扣金额
-								deductMoney.add(single.multiply(BigDecimal.valueOf(betweenDay)));
-							}
-						}
-					} else if (goodsId == Constant.CLAUDE_PRO_GID) {
-
-					} else {
-						Long skuId = relation.getSkuId();
-						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, relation.getExpiryTime(), false);
-						//该车票抵扣金额
-						deductMoney.add(single.multiply(BigDecimal.valueOf(betweenDay)));
-					}
-				}
-			}
+			//处理vip抵扣金额
+			VipDeductDto vipDeductDto = commonHandleVipDeductMoney(userIdList, vipSkuIds);
+			deductMoney = vipDeductDto.getDeductMoney();
 		}
 		vipUserPageResp.setDeductMoney(deductMoney);
 	}
 
+	/**
+	 * 检查用户并获取订单抵扣金额
+	 */
+	@Override
+	public VipDeductDto checkAndGetOrderDeductMoney(Long userId) {
+		List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
+		List<Long> vipSkuIds = vipGoodsSkuMapper.selectList(null).stream().map(VipGoodsSku::getSkuId).collect(Collectors.toList());
+		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, DateTime.now()).op(Operator.GreaterThan).build());
+		if (count.intValue() == 0) {
+			throw BusinessRuntimeException.getInstance("暂无可抵扣AI车票");
+		}
+		VipDeductDto vipDeductDto = commonHandleVipDeductMoney(userIdList, vipSkuIds);
+		return vipDeductDto;
+	}
+
 
 	private BigDecimal getVipMoney() {
-		SysConfig sysConfig = sysConfigMapper.selectOne(Wrappers.lambdaQuery(SysConfig.class)
-				.eq(SysConfig::getSysKey, Constant.VIP_FEE_KEY)
-				.last("limit 1"));
+		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;
 	}
+
+	/**
+	 * 统一处理vip抵扣金额
+	 */
+	public VipDeductDto commonHandleVipDeductMoney(List<Long> userIdList, List<Long> vipSkuIds) {
+		VipDeductDto vipDeductDto = new VipDeductDto();
+		DateTime now = DateTime.now();
+		List<Long> deductRelationIds = new ArrayList<>();
+		BigDecimal deductMoney = BigDecimal.ZERO;
+		BigDecimal vipMoney = getVipMoney();
+		for (Long vipSkuId : vipSkuIds) {
+			GroupsRelationView relation = beanSearcher.searchFirst(GroupsRelationView.class, MapUtils.builder().field(GroupsRelationView::getSkuId, vipSkuId).field(GroupsRelationView::getUserId, userIdList).op(Operator.InList).orderBy(GroupsRelationView::getExpiryTime).desc().build());
+			if (relation != null) {
+				Long goodsId = relation.getGoodsId();
+				Long relationId = relation.getId();
+				Date relationExpiryTime = relation.getExpiryTime();
+				//GPT
+				if (goodsId == Constant.GPT_PLUS_GID) {
+					ChatgptUser chatgptUser = chatgptUserMapper.selectOne(Wrappers.lambdaQuery(ChatgptUser.class).eq(ChatgptUser::getRelationId, relationId).last("limit 1"));
+					if (chatgptUser != null) {
+						//获取抵扣金额
+						deductMoney.add(getFinalDeductMoney(relationId, relation.getSkuId(), chatgptUser.getRenewSkuId(), chatgptUser.getRenewOrderId(), chatgptUser.getRenewExpiryTime(), relationExpiryTime, now, userIdList));
+					}
+				} else if (goodsId == Constant.CLAUDE_PRO_GID) {
+					ClaudeUser claudeUser = claudeUserMapper.selectOne(Wrappers.lambdaQuery(ClaudeUser.class).eq(ClaudeUser::getRelationId, relationId).last("limit 1"));
+					if (claudeUser != null) {
+						//获取抵扣金额
+						deductMoney.add(getFinalDeductMoney(relationId, relation.getSkuId(), claudeUser.getRenewSkuId(), claudeUser.getRenewOrderId(), claudeUser.getRenewExpiryTime(), relationExpiryTime, now, userIdList));
+					}
+				} else {
+					//该车票抵扣金额
+					deductMoney.add(getDeductMoneyFromTicket(vipSkuId, now, relationExpiryTime));
+				}
+				deductRelationIds.add(relationId);
+				//超出可抵扣的金额 直接返回
+				if (deductMoney.compareTo(vipMoney) >= 0) {
+					deductMoney = vipMoney;
+					break;
+				}
+			}
+		}
+		vipDeductDto.setDeductMoney(deductMoney);
+		vipDeductDto.setDeductRelationIds(deductRelationIds);
+		return vipDeductDto;
+	}
+
+	/**
+	 * 获取最终抵扣金额
+	 */
+	public BigDecimal getFinalDeductMoney(Long relationId, Long relationSkuId, Long renewSkuId, Long renewOrderId, Date renewExpiryTime, Date relationExpiryTime, DateTime now, List<Long> userIdList) {
+		BigDecimal deductMoney = BigDecimal.ZERO;
+		//一个月当30天算单价 往上取整
+		//续费规格
+		if (renewSkuId != null) {
+			GoodsDonSku sku = skuMapper.selectById(renewSkuId);
+			BigDecimal single = sku.getPrice().divide(BigDecimal.valueOf(sku.getMonths()).multiply(BigDecimal.valueOf(30)), 0, RoundingMode.UP);
+			Long betweenDay = DateUtil.betweenDay(now, renewExpiryTime, false);
+			//该车票抵扣金额
+			BigDecimal renewDeductMoney = single.multiply(BigDecimal.valueOf(betweenDay));
+			log.info("车票id:{}目前续费升级规格可抵扣的金额为:{}", relationId, renewDeductMoney);
+			deductMoney.add(renewDeductMoney);
+			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 = orderDOn.getMoney().add(orderDOn.getBalance());
+				log.info("车票id:{}目前次一级规格:{}可抵扣的金额为:{}", relationId, sku.getSpecVal(), upDeductMoney);
+				deductMoney.add(upDeductMoney);
+				if (sku.getDays() != null) {
+					relationExpiryTime = DateUtil.offsetDay(relationExpiryTime, -sku.getDays());
+				} else {
+					relationExpiryTime = DateUtil.offsetMonth(relationExpiryTime, -sku.getMonths());
+				}
+			}
+		}
+		if (relationExpiryTime.after(DateTime.now())) {
+			//该车票抵扣金额
+			BigDecimal deductMoneyFromTicket = getDeductMoneyFromTicket(relationSkuId, now, relationExpiryTime);
+			log.info("车票id:{}最终到期时间为:{}车票可返回 抵扣金额:{}", relationId, relationExpiryTime, deductMoney);
+			deductMoney.add(deductMoneyFromTicket);
+		}
+		return deductMoney;
+	}
+
+	/**
+	 * 获取车票可抵扣金额
+	 */
+	public BigDecimal getDeductMoneyFromTicket(Long skuId, DateTime now, 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);
+		//该车票抵扣金额
+		BigDecimal deductMoney = single.multiply(BigDecimal.valueOf(betweenDay));
+		return deductMoney;
+	}
 }

+ 1 - 1
netflix-web/src/main/java/com/cyksj/web/controller/payment/OrderController.java

@@ -157,7 +157,7 @@ public class OrderController {
         String address = StringUtil.getNewInternalAddressByIp(ip);
         //address.contains("柬埔寨") ||
         if (address != null && address.contains("缅甸")) {
-            throw BusinessRuntimeException.getInstance("用户系统异常");
+            throw BusinessRuntimeException.getInstance("用户异常");
         }
         payRequest.setIp(ip);