|
@@ -14,6 +14,7 @@ import com.cyksj.common.task.GlobalThreadPoolTaskExecutor;
|
|
|
import com.cyksj.mapper.*;
|
|
import com.cyksj.mapper.*;
|
|
|
import com.cyksj.mapper.manage.cms.CmsUserMapper;
|
|
import com.cyksj.mapper.manage.cms.CmsUserMapper;
|
|
|
import com.cyksj.model.entity.*;
|
|
import com.cyksj.model.entity.*;
|
|
|
|
|
+import com.cyksj.model.request.GptIndependentExportRechargeReq;
|
|
|
import com.cyksj.model.request.GroupsRelationRechargeReq;
|
|
import com.cyksj.model.request.GroupsRelationRechargeReq;
|
|
|
import com.cyksj.redis.RedisService;
|
|
import com.cyksj.redis.RedisService;
|
|
|
import com.cyksj.server.recharge.dto.CardKeyValidationResult;
|
|
import com.cyksj.server.recharge.dto.CardKeyValidationResult;
|
|
@@ -22,12 +23,15 @@ import com.cyksj.server.recharge.dto.TaskSubmitResult;
|
|
|
import com.cyksj.server.recharge.dto.TokenParseResult;
|
|
import com.cyksj.server.recharge.dto.TokenParseResult;
|
|
|
import com.cyksj.service.chatgpt.GptUserRechargeRecordService;
|
|
import com.cyksj.service.chatgpt.GptUserRechargeRecordService;
|
|
|
import com.cyksj.service.mange.gpt.GptRechargeService;
|
|
import com.cyksj.service.mange.gpt.GptRechargeService;
|
|
|
|
|
+import com.cyksj.service.user.UserBindRelationService;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 项目名: yhlxj11111111
|
|
* 项目名: yhlxj11111111
|
|
@@ -57,6 +61,10 @@ public class GptRechargeServiceImpl implements GptRechargeService {
|
|
|
|
|
|
|
|
private final RedisService redisService;
|
|
private final RedisService redisService;
|
|
|
|
|
|
|
|
|
|
+ private final UserBindRelationService userBindRelationService;
|
|
|
|
|
+
|
|
|
|
|
+ private final AccountMapper accountMapper;
|
|
|
|
|
+
|
|
|
private static final GlobalThreadPoolTaskExecutor TASK_EXECUTOR = GlobalThreadPoolTaskExecutor.getInstance();
|
|
private static final GlobalThreadPoolTaskExecutor TASK_EXECUTOR = GlobalThreadPoolTaskExecutor.getInstance();
|
|
|
|
|
|
|
|
|
|
|
|
@@ -114,10 +122,10 @@ public class GptRechargeServiceImpl implements GptRechargeService {
|
|
|
}
|
|
}
|
|
|
GroupsTrips groupsTrips = groupsMapper.selectById(relation.getGroupsId());
|
|
GroupsTrips groupsTrips = groupsMapper.selectById(relation.getGroupsId());
|
|
|
GoodsDonSku sku = skuMapper.selectById(groupsTrips.getSkuId());
|
|
GoodsDonSku sku = skuMapper.selectById(groupsTrips.getSkuId());
|
|
|
- //GPT 代充
|
|
|
|
|
- if (sku.getGoodsId() != Constant.GPT_RECHARGE_GOODS_ID) {
|
|
|
|
|
- throw BusinessRuntimeException.getInstance("车票类型错误");
|
|
|
|
|
- }
|
|
|
|
|
|
|
+// //GPT 代充
|
|
|
|
|
+// if (sku.getGoodsId() != Constant.GPT_RECHARGE_GOODS_ID) {
|
|
|
|
|
+// throw BusinessRuntimeException.getInstance("车票类型错误");
|
|
|
|
|
+// }
|
|
|
Integer rechargeRemainNum = relation.getRechargeRemainNum();
|
|
Integer rechargeRemainNum = relation.getRechargeRemainNum();
|
|
|
if (rechargeRemainNum == null || rechargeRemainNum <= 0) {
|
|
if (rechargeRemainNum == null || rechargeRemainNum <= 0) {
|
|
|
throw BusinessRuntimeException.getInstance("剩余可代充次数为0");
|
|
throw BusinessRuntimeException.getInstance("剩余可代充次数为0");
|
|
@@ -232,6 +240,80 @@ public class GptRechargeServiceImpl implements GptRechargeService {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void gptIndependentExportRecharge(GptIndependentExportRechargeReq rechargeReq) {
|
|
|
|
|
+ String orderNo = rechargeReq.getOrderNo();
|
|
|
|
|
+ OrderDon orderDon = orderDonMapper.selectOne(Wrappers.lambdaQuery(OrderDon.class).eq(OrderDon::getOrderNo, orderNo).notIn(OrderDon::getStatus, Constant.noOrderAllStatus));
|
|
|
|
|
+ if (orderDon == null) {
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("订单不存在或已退款");
|
|
|
|
|
+ }
|
|
|
|
|
+ //只支持GPT独立会员类型
|
|
|
|
|
+ List<Long> gptIdpSkuIds = skuMapper.selectList(Wrappers.lambdaQuery(GoodsDonSku.class).eq(GoodsDonSku::getGoodsId, Constant.GPT_PLUS_GID).eq(GoodsDonSku::getNum, 1)).stream().map(GoodsDonSku::getId).collect(Collectors.toList());
|
|
|
|
|
+ if (!gptIdpSkuIds.contains(orderDon.getSkuId())) {
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("只支持GPT独立会员类型");
|
|
|
|
|
+ }
|
|
|
|
|
+ Long relationId = orderDon.getRelationId();
|
|
|
|
|
+ Long userId = orderDon.getUserId();
|
|
|
|
|
+ List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
|
|
|
|
|
+ GroupsRelation relation = relationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class).eq(GroupsRelation::getId, relationId).in(GroupsRelation::getUserId, userIdList).gt(GroupsRelation::getExpiryTime, DateTime.now()).last("limit 1"));
|
|
|
|
|
+ if (relation == null) {
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("独立会员车票不存在或已过期");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (relation.getRechargeStatus() != null) {
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("该笔订单号已导入");
|
|
|
|
|
+ }
|
|
|
|
|
+ Integer num = rechargeReq.getNum();
|
|
|
|
|
+ relation.setRechargeStatus(GroupsRelation.RechargeStatus.complete);
|
|
|
|
|
+ GoodsDonSku sku = skuMapper.selectById(orderDon.getSkuId());
|
|
|
|
|
+ Integer months = sku.getMonths();
|
|
|
|
|
+ //总代充次数
|
|
|
|
|
+ relation.setRechargeNum(months > num ? months : num);
|
|
|
|
|
+ relation.setRechargeRemainNum(num);
|
|
|
|
|
+ GroupsTrips groupsTrips = groupsMapper.selectById(relation.getGroupsId());
|
|
|
|
|
+ if (groupsTrips.getAccountId() == null) {
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("该订单车队未配置账号");
|
|
|
|
|
+ }
|
|
|
|
|
+ Account account = accountMapper.selectById(groupsTrips.getAccountId());
|
|
|
|
|
+ //代充账号设置
|
|
|
|
|
+ relation.setAccount(account.getAccount());
|
|
|
|
|
+ relation.setPassword(account.getPassword());
|
|
|
|
|
+ relation.setSubmitTime(relation.getStartTime());
|
|
|
|
|
+ relation.setSendTime(relation.getSubmitTime());
|
|
|
|
|
+ //记录首次导入的代充次数
|
|
|
|
|
+ CmsUser cmsUser = cmsUserMapper.selectById(rechargeReq.getAdminId());
|
|
|
|
|
+ gptUserRechargeRecordService.recordGptUserRechargeNum(relation.getUserId(), relation.getId(), relation.getAccount(), num, cmsUser != null ? cmsUser.getNickname() : null, "导入GPT订单");
|
|
|
|
|
+ relationMapper.updateById(relation);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public GroupsRelation getOrderRelation(String orderNo) {
|
|
|
|
|
+ OrderDon orderDon = orderDonMapper.selectOne(Wrappers.lambdaQuery(OrderDon.class).eq(OrderDon::getOrderNo, orderNo).notIn(OrderDon::getStatus, Constant.noOrderAllStatus));
|
|
|
|
|
+ if (orderDon == null) {
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("订单不存在或已退款");
|
|
|
|
|
+ }
|
|
|
|
|
+ //只支持GPT独立会员类型
|
|
|
|
|
+ List<Long> gptIdpSkuIds = skuMapper.selectList(Wrappers.lambdaQuery(GoodsDonSku.class).eq(GoodsDonSku::getGoodsId, Constant.GPT_PLUS_GID).eq(GoodsDonSku::getNum, 1)).stream().map(GoodsDonSku::getId).collect(Collectors.toList());
|
|
|
|
|
+ if (!gptIdpSkuIds.contains(orderDon.getSkuId())) {
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("只支持GPT独立会员类型");
|
|
|
|
|
+ }
|
|
|
|
|
+ Long relationId = orderDon.getRelationId();
|
|
|
|
|
+ Long userId = orderDon.getUserId();
|
|
|
|
|
+ List<Long> userIdList = null;
|
|
|
|
|
+ try {
|
|
|
|
|
+ userIdList = userBindRelationService.getRelationUserIdList(userId, null);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("订单用户不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ GroupsRelation relation = relationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class).eq(GroupsRelation::getId, relationId).in(GroupsRelation::getUserId, userIdList).gt(GroupsRelation::getExpiryTime, DateTime.now()).last("limit 1"));
|
|
|
|
|
+ if (relation == null) {
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("独立会员车票不存在或已过期");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (relation.getRechargeStatus() != null) {
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("该笔订单号已导入");
|
|
|
|
|
+ }
|
|
|
|
|
+ return relation;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public CardKeyValidationResult validateCardKey(String cardKey) {
|
|
public CardKeyValidationResult validateCardKey(String cardKey) {
|
|
|
log.info("开始验证卡密: {}", cardKey);
|
|
log.info("开始验证卡密: {}", cardKey);
|
|
|
try {
|
|
try {
|
|
@@ -358,7 +440,7 @@ public class GptRechargeServiceImpl implements GptRechargeService {
|
|
|
.eq(GroupsRelation::getRechargeStatus, GroupsRelation.RechargeStatus.recharging));
|
|
.eq(GroupsRelation::getRechargeStatus, GroupsRelation.RechargeStatus.recharging));
|
|
|
//记录代充记录
|
|
//记录代充记录
|
|
|
if (rechargeStatus == GroupsRelation.RechargeStatus.complete) {
|
|
if (rechargeStatus == GroupsRelation.RechargeStatus.complete) {
|
|
|
- gptUserRechargeRecordService.recordGptUserRechargeNum(relation.getUserId(), relation.getId(), relation.getAccount(), 1, relation.getOperator());
|
|
|
|
|
|
|
+ gptUserRechargeRecordService.recordGptUserRechargeNum(relation.getUserId(), relation.getId(), relation.getAccount(), -1, relation.getOperator(), "后台自动代充");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|