zoujiajian 6 miesięcy temu
rodzic
commit
a2e1245dff

+ 5 - 0
netflix-common/src/main/java/com/cyksj/common/constant/Constant.java

@@ -790,4 +790,9 @@ public interface Constant {
 	 * 商品订阅邮件模板
 	 */
 	String GOODS_SUBSCRIBE_ALERT_EMAIL_MSG = "您好,您关注的%s已上线,登录网站https://nf.video/buy/%s 看看吧";
+
+	/**
+	 * CC转化按量规格ID
+	 */
+	Long CC_TRANS_SKU_ID = 794L;
 }

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

@@ -70,7 +70,8 @@ public class UserTicketClearedRecord extends BaseEntity{
 		codex_deduct("codex抵扣"),
 		cc_deduct("claude code抵扣"),
 		recover_replace("奈飞恢复直接替换"),
-		yt_refund("油管掉会员退款")
+		yt_refund("油管掉会员退款"),
+		cc_trans_other("cc转化按量余额")
 		;
 		String desc;
 

+ 7 - 0
netflix-service/src/main/java/com/cyksj/service/claude/ClaudeCodeService.java

@@ -19,6 +19,7 @@ import com.cyksj.model.views.ClaudeCodeUserInfoView;
 import com.cyksj.model.views.ClaudeCodeUserResetRecordView;
 import com.ejlchina.searcher.SearchResult;
 
+import java.math.BigDecimal;
 import java.util.Date;
 import java.util.List;
 
@@ -135,4 +136,10 @@ public interface ClaudeCodeService {
 	ClaudeCodeDeductDto getDeductSkuMoney(Long userId, Long relationId, Long upgradeSkuId);
 
 	void adjClaudeCodeUserPoints(Long userId, Integer points, String type, String description) throws Exception;
+
+	BigDecimal getCcRemainDeductMoney(long userId);
+
+	void ccRefund(long userId) throws Exception;
+
+	void trans(long userId);
 }

+ 99 - 5
netflix-service/src/main/java/com/cyksj/service/claude/impl/ClaudeCodeServiceImpl.java

@@ -22,10 +22,7 @@ import com.cyksj.mapper.manage.distribute.DistributeWaitingSendPointsMapper;
 import com.cyksj.model.dto.ClaudeCodeDeductDto;
 import com.cyksj.model.entity.*;
 import com.cyksj.model.manage.views.GroupsRelationView;
-import com.cyksj.model.request.ClaudeCodeApiKeysReq;
-import com.cyksj.model.request.ClaudeCodeCreditCardUseReq;
-import com.cyksj.model.request.ClaudeCodeDelReq;
-import com.cyksj.model.request.CreditResetReq;
+import com.cyksj.model.request.*;
 import com.cyksj.model.request.codex.CodexUserPackageReq;
 import com.cyksj.model.response.ClaudeCodeRewardDetailsResp;
 import com.cyksj.model.response.CreditResetResp;
@@ -36,6 +33,9 @@ import com.cyksj.redis.RedisService;
 import com.cyksj.service.api.ClaudeCodexApiService;
 import com.cyksj.service.claude.ClaudeCodeService;
 import com.cyksj.service.codex.CodexService;
+import com.cyksj.service.order.OrderRefundService;
+import com.cyksj.service.relation.GroupRelationClearService;
+import com.cyksj.service.relation.GroupRelationFrontService;
 import com.cyksj.service.user.UserBindRelationService;
 import com.ejlchina.searcher.BeanSearcher;
 import com.ejlchina.searcher.SearchResult;
@@ -108,6 +108,14 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
 
 	private final ClaudeCodeDeductOrderRelateMapper claudeCodeDeductOrderRelateMapper;
 
+	private final GroupRelationFrontService groupRelationFrontService;
+
+	private final GroupRelationClearService clearService;
+
+	private final GoodsDonSkuMapper goodsDonSkuMapper;
+
+	private final OrderRefundService orderRefundService;
+
 	@Override
 	public void generateOrUpdateClaudeCodeUserInfo(Long orderId, Long relationId, Long userId, GoodsDonSku sku, Integer orderType) {
 		List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
@@ -1171,7 +1179,7 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
 		}
 		log.info("车票id:{}最终到期时间为:{}车票可返回 抵扣金额:{}", relationId, DateUtil.format(relationExpiryTime, "yyyy-MM-dd HH:mm:ss"), deductMoney);
 		//超出可抵扣的金额 直接返回
-		if (deductMoney.compareTo(upgradeSku.getPrice()) >= 0) {
+		if (upgradeSku != null && deductMoney.compareTo(upgradeSku.getPrice()) >= 0) {
 			BigDecimal overMoney = deductMoney.subtract(upgradeSku.getPrice());
 			//超过抵扣金额可换延长会员多少天
 			//每天单价
@@ -1198,6 +1206,70 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
 		}
 	}
 
+	@Override
+	public BigDecimal getCcRemainDeductMoney(long userId) {
+		List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
+		GroupsRelationView relationView = beanSearcher.searchFirst(GroupsRelationView.class, MapUtils.builder()
+				.field(GroupsRelationView::getGoodsId, Constant.CLAUDE_CODE_GOODS_ID)
+				.field(GroupsRelationView::getUserId, userIdList).op(Operator.InList)
+				.field(GroupsRelationView::getExpiryTime, DateTime.now()).op(Operator.GreaterThan)
+				.build());
+		if (relationView == null) {
+			return BigDecimal.ZERO;
+		}
+		Long relationId = relationView.getId();
+		ClaudeCodeUser claudeCodeUser = claudeCodeUserMapper.selectOne(Wrappers.lambdaQuery(ClaudeCodeUser.class).eq(ClaudeCodeUser::getRelationId, relationId).last("limit 1"));
+		OrderDon oriOrderDon = orderDonMapper.selectOne(Wrappers.lambdaQuery(OrderDon.class).eq(OrderDon::getRelationId, relationId).in(OrderDon::getUserId, userIdList).notIn(OrderDon::getStatus, Constant.noOrderAllStatus).eq(OrderDon::getOrderType, 1).orderByDesc(OrderDon::getId).last("limit 1"));
+		ClaudeCodeDeductDto claudeCodeDeductDto = getDeductMoney(relationId, oriOrderDon.getSkuId(), claudeCodeUser.getRenewSkuId(), claudeCodeUser.getRenewOrderId(), claudeCodeUser.getRenewExpiryTime(), relationView.getStartTime(), relationView.getExpiryTime(), DateTime.now(), userIdList, null);
+		return claudeCodeDeductDto.getDeductMoney();
+	}
+
+	@Override
+	public void ccRefund(long userId) throws Exception {
+		BigDecimal ccRemainDeductMoney = getCcRemainDeductMoney(userId);
+		if (ccRemainDeductMoney.compareTo(BigDecimal.ZERO) == 0) {
+			throw BusinessRuntimeException.getInstance("车票剩余价值为0,无法退款");
+		}
+		List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
+		ClaudeCodeUser claudeCodeUser = claudeCodeUserMapper.selectOne(Wrappers.lambdaQuery(ClaudeCodeUser.class).in(ClaudeCodeUser::getUserId, userIdList).last("limit 1"));
+		GroupsRelation groupsRelation = relationMapper.selectById(claudeCodeUser.getRelationId());
+
+		Long relationId = groupsRelation.getId();
+		OrderDon oriOrderDon = orderDonMapper.selectOne(Wrappers.lambdaQuery(OrderDon.class).eq(OrderDon::getRelationId, relationId).in(OrderDon::getUserId, userIdList).notIn(OrderDon::getStatus, Constant.noOrderAllStatus).eq(OrderDon::getOrderType, 1).orderByDesc(OrderDon::getId).last("limit 1"));
+		GoodsDonSku sku = goodsDonSkuMapper.selectById(oriOrderDon.getSkuId());
+		GoodsDon goodsDon = goodsDonMapper.selectById(oriOrderDon.getGoodsId());
+		if (ccRemainDeductMoney.compareTo(oriOrderDon.getMoney()) > 0) {
+			throw BusinessRuntimeException.getInstance("请联系客服退款");
+		} else {
+			//直接退原订单
+			ccRefund(goodsDon, sku, oriOrderDon, ccRemainDeductMoney, BigDecimal.ZERO);
+		}
+		clearService.clearTicket(groupsRelation, UserTicketClearedRecord.Source.refund);
+	}
+
+	@Override
+	@Transactional(rollbackFor = Throwable.class)
+	public void trans(long userId) {
+		BigDecimal ccRemainDeductMoney = getCcRemainDeductMoney(userId);
+		if (ccRemainDeductMoney.compareTo(BigDecimal.ZERO) == 0) {
+			throw BusinessRuntimeException.getInstance("车票剩余价值为0,不可转换");
+		}
+
+		List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
+
+		ClaudeCodeUser claudeCodeUser = claudeCodeUserMapper.selectOne(Wrappers.lambdaQuery(ClaudeCodeUser.class).in(ClaudeCodeUser::getUserId, userIdList).last("limit 1"));
+		GroupsRelation groupsRelation = relationMapper.selectById(claudeCodeUser.getRelationId());
+
+		//获取默认规格车票
+		Long skuId = Constant.CC_TRANS_SKU_ID;
+		Long relationId = groupRelationFrontService.getTicket(userId,skuId , false);
+		clearService.clearTicket(groupsRelation, UserTicketClearedRecord.Source.cc_trans_other);
+
+		BigDecimal transDeduct = ccRemainDeductMoney.multiply(BigDecimal.valueOf(1.2));
+		GoodsDonSku sku = goodsDonSkuMapper.selectById(skuId);
+		generateOrUpdateClaudeCodeUser(userId, relationId, sku.getClaudeDailyLimit(), transDeduct.intValue(), DateUtil.offsetMonth(DateTime.now(), sku.getMonths()), false, null, null, null, sku.getSpecVal(), userIdList);
+	}
+
 	/**
 	 * 获取订单单价
 	 */
@@ -1299,4 +1371,26 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
 		}
 		return deductMoney;
 	}
+
+	public void ccRefund(GoodsDon goodsDon, GoodsDonSku sku, OrderDon orderDon, BigDecimal refundMoney, BigDecimal refundBalance) throws Exception {
+		//调用第三方接口退款
+		OrderRefundReq refundReq = new OrderRefundReq();
+		refundReq.setRefundMoney(refundMoney);
+		refundReq.setRefundType("money");
+		String outNo = orderRefundService.centerRefund(refundReq, orderDon);
+		orderDon.setRefundMoney(refundMoney);
+		orderDon.setStatus(OrderDon.Status.refund);
+		orderDon.setRefundDesc("cc售后退款");
+		orderDonMapper.updateById(orderDon);
+
+		String refundType;
+		if (refundMoney.compareTo(BigDecimal.ZERO) > 0 && refundBalance.compareTo(BigDecimal.ZERO) > 0) {
+			refundType = "bxj";
+		} else if (refundMoney.compareTo(BigDecimal.ZERO) == 0 && refundBalance.compareTo(BigDecimal.ZERO) > 0) {
+			refundType = "balance";
+		} else {
+			refundType = orderDon.getType().name();
+		}
+		orderRefundService.refundRecord(orderDon, refundMoney, null, "系统", goodsDon, sku, outNo, refundType, null);
+	}
 }

+ 31 - 0
netflix-web/src/main/java/com/cyksj/web/controller/claude/ClaudeCodeController.java

@@ -42,6 +42,7 @@ import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletRequest;
+import java.math.BigDecimal;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -599,4 +600,34 @@ public class ClaudeCodeController {
 		ClaudeCodeDeductDto claudeCodeDeductDto = claudeCodeService.getDeductSkuMoney(userId, relationId, upgradeSkuId);
 		return GatewayResponse.SUCCESS.newBuilder().toResult(claudeCodeDeductDto);
 	}
+
+	/**
+	 * cc车票剩余价值
+	 */
+	@GetMapping("/get/remain/deductMoney")
+	public Result<BigDecimal> getCcRemainDeductMoney() {
+		long userId = StpUserUtil.getLoginIdAsLong();
+		BigDecimal ccRemainDeductMoney = claudeCodeService.getCcRemainDeductMoney(userId);
+		return GatewayResponse.SUCCESS.newBuilder().toResult(ccRemainDeductMoney);
+	}
+
+	/**
+	 * cc售后退款
+	 */
+	@PutMapping("/cc/refund")
+	public Result<String> ccRefund() throws Exception {
+		long userId = StpUserUtil.getLoginIdAsLong();
+		claudeCodeService.ccRefund(userId);
+		return GatewayResponse.SUCCESS.newBuilder().toResult();
+	}
+
+	/**
+	 * cc 售后量能转化
+	 */
+	@PostMapping("/trans")
+	public Result<String> trans() {
+		long userId = StpUserUtil.getLoginIdAsLong();
+		claudeCodeService.trans(userId);
+		return GatewayResponse.SUCCESS.newBuilder().toResult();
+	}
 }