|
@@ -55,25 +55,27 @@ public class GptProxyRechargeServiceImpl implements GptProxyRechargeService {
|
|
|
|
|
|
|
|
private final OrderDonMapper orderDonMapper;
|
|
private final OrderDonMapper orderDonMapper;
|
|
|
|
|
|
|
|
- private final GptUserRechargeRecordService gptUserRechargeRecordService;
|
|
|
|
|
|
|
+ private final GptUserRechargeRecordService gptUserRechargeRecordService;
|
|
|
|
|
|
|
|
- private final RedisService redisService;
|
|
|
|
|
|
|
+ private final RedisService redisService;
|
|
|
|
|
|
|
|
- private final GptRechargeCardKeyChannelService gptRechargeCardKeyChannelService;
|
|
|
|
|
|
|
+ private final GptRechargeCardKeyChannelService gptRechargeCardKeyChannelService;
|
|
|
|
|
|
|
|
- private final AfDianRechargeService afDianRechargeService;
|
|
|
|
|
|
|
+ private final AfDianRechargeService afDianRechargeService;
|
|
|
|
|
|
|
|
- private final ChongAfDianRechargeService chongAfDianRechargeService;
|
|
|
|
|
|
|
+ private final ChongAfDianRechargeService chongAfDianRechargeService;
|
|
|
|
|
|
|
|
private final YearAfDianRechargeService yearAfDianRechargeService;
|
|
private final YearAfDianRechargeService yearAfDianRechargeService;
|
|
|
|
|
|
|
|
private final GoAfDianRechargeService goAfDianRechargeService;
|
|
private final GoAfDianRechargeService goAfDianRechargeService;
|
|
|
|
|
+ private final CdkAicnmRechargeService cdkAicnmRechargeService;
|
|
|
|
|
+
|
|
|
|
|
|
|
|
private final HiBoyRechargeService hiBoyRechargeService;
|
|
private final HiBoyRechargeService hiBoyRechargeService;
|
|
|
|
|
|
|
|
- private static final GlobalThreadPoolTaskExecutor TASK_EXECUTOR = GlobalThreadPoolTaskExecutor.getInstance();
|
|
|
|
|
|
|
+ private static final GlobalThreadPoolTaskExecutor TASK_EXECUTOR = GlobalThreadPoolTaskExecutor.getInstance();
|
|
|
|
|
|
|
|
- private HttpRequest createBaseRequest(String url) {
|
|
|
|
|
|
|
+ private HttpRequest createBaseRequest(String url) {
|
|
|
return HttpRequest.get(url)
|
|
return HttpRequest.get(url)
|
|
|
.header("accept", "application/json, text/plain, */*")
|
|
.header("accept", "application/json, text/plain, */*")
|
|
|
.header("accept-language", "zh-CN,zh;q=0.9,en;q=0.8")
|
|
.header("accept-language", "zh-CN,zh;q=0.9,en;q=0.8")
|
|
@@ -85,15 +87,15 @@ public class GptProxyRechargeServiceImpl implements GptProxyRechargeService {
|
|
|
public CardKeyValidationResult validateCardKey(String cardKey) {
|
|
public CardKeyValidationResult validateCardKey(String cardKey) {
|
|
|
log.info("开始验证卡密: {}", cardKey);
|
|
log.info("开始验证卡密: {}", cardKey);
|
|
|
try {
|
|
try {
|
|
|
- String BASE_URL = gptRechargeCardKeyChannelService.getCardKeyDomain(cardKey);
|
|
|
|
|
- HttpResponse response = createBaseRequest(BASE_URL + "/card-keys/" + cardKey)
|
|
|
|
|
- .execute();
|
|
|
|
|
|
|
+ String BASE_URL = gptRechargeCardKeyChannelService.getCardKeyDomain(cardKey);
|
|
|
|
|
+ HttpResponse response = createBaseRequest(BASE_URL + "/card-keys/" + cardKey)
|
|
|
|
|
+ .execute();
|
|
|
String body = response.body();
|
|
String body = response.body();
|
|
|
log.info("卡密验证响应: {}", body);
|
|
log.info("卡密验证响应: {}", body);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
JSONObject jsonResponse = JSONUtil.parseObj(body);
|
|
JSONObject jsonResponse = JSONUtil.parseObj(body);
|
|
|
CardKeyValidationResult result = new CardKeyValidationResult(
|
|
CardKeyValidationResult result = new CardKeyValidationResult(
|
|
|
- jsonResponse.getBool("available")
|
|
|
|
|
|
|
+ jsonResponse.getBool("available")
|
|
|
);
|
|
);
|
|
|
//{"available":false,"error":"卡密已被使用"}
|
|
//{"available":false,"error":"卡密已被使用"}
|
|
|
log.info("卡密验证结果: {}", result);
|
|
log.info("卡密验证结果: {}", result);
|
|
@@ -107,11 +109,11 @@ public class GptProxyRechargeServiceImpl implements GptProxyRechargeService {
|
|
|
public TokenParseResult parseToken(String accessToken) {
|
|
public TokenParseResult parseToken(String accessToken) {
|
|
|
log.info("开始验证凭证: {}", accessToken.substring(0, Math.min(20, accessToken.length())) + "...");
|
|
log.info("开始验证凭证: {}", accessToken.substring(0, Math.min(20, accessToken.length())) + "...");
|
|
|
try {
|
|
try {
|
|
|
- String BASE_URL = gptRechargeCardKeyChannelService.getCardKeyDomain(null);
|
|
|
|
|
- String url = BASE_URL + "/parse-token";
|
|
|
|
|
|
|
+ String BASE_URL = gptRechargeCardKeyChannelService.getCardKeyDomain(null);
|
|
|
|
|
+ String url = BASE_URL + "/parse-token";
|
|
|
JSONObject requestBody = new JSONObject();
|
|
JSONObject requestBody = new JSONObject();
|
|
|
requestBody.put("access_token", accessToken);
|
|
requestBody.put("access_token", accessToken);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
HttpResponse response = HttpRequest.post(url)
|
|
HttpResponse response = HttpRequest.post(url)
|
|
|
.header("accept", "application/json, text/plain, */*")
|
|
.header("accept", "application/json, text/plain, */*")
|
|
|
.header("accept-language", "zh-CN,zh;q=0.9,en;q=0.8")
|
|
.header("accept-language", "zh-CN,zh;q=0.9,en;q=0.8")
|
|
@@ -123,11 +125,11 @@ public class GptProxyRechargeServiceImpl implements GptProxyRechargeService {
|
|
|
.execute();
|
|
.execute();
|
|
|
String body = response.body();
|
|
String body = response.body();
|
|
|
log.info("凭证验证响应: {}", body);
|
|
log.info("凭证验证响应: {}", body);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
JSONObject jsonResponse = JSONUtil.parseObj(body);
|
|
JSONObject jsonResponse = JSONUtil.parseObj(body);
|
|
|
TokenParseResult result = new TokenParseResult(
|
|
TokenParseResult result = new TokenParseResult(
|
|
|
- jsonResponse.getStr("message"),
|
|
|
|
|
- jsonResponse.getBool("success")
|
|
|
|
|
|
|
+ jsonResponse.getStr("message"),
|
|
|
|
|
+ jsonResponse.getBool("success")
|
|
|
);
|
|
);
|
|
|
log.info("凭证验证结果: {}", result);
|
|
log.info("凭证验证结果: {}", result);
|
|
|
return result;
|
|
return result;
|
|
@@ -140,16 +142,16 @@ public class GptProxyRechargeServiceImpl implements GptProxyRechargeService {
|
|
|
public TaskSubmitResult submitTask(String cardKey, String accessToken, String idp) {
|
|
public TaskSubmitResult submitTask(String cardKey, String accessToken, String idp) {
|
|
|
log.info("开始提交任务 - 卡密: {}, idp: {}", cardKey, idp);
|
|
log.info("开始提交任务 - 卡密: {}, idp: {}", cardKey, idp);
|
|
|
try {
|
|
try {
|
|
|
- String BASE_URL = gptRechargeCardKeyChannelService.getCardKeyDomain(cardKey);
|
|
|
|
|
- String url = BASE_URL + "/tasks";
|
|
|
|
|
|
|
+ String BASE_URL = gptRechargeCardKeyChannelService.getCardKeyDomain(cardKey);
|
|
|
|
|
+ String url = BASE_URL + "/tasks";
|
|
|
JSONObject requestBody = new JSONObject();
|
|
JSONObject requestBody = new JSONObject();
|
|
|
requestBody.put("card_key", cardKey);
|
|
requestBody.put("card_key", cardKey);
|
|
|
requestBody.put("access_token", accessToken);
|
|
requestBody.put("access_token", accessToken);
|
|
|
requestBody.put("idp", idp);
|
|
requestBody.put("idp", idp);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
HttpResponse response = HttpRequest.post(url)
|
|
HttpResponse response = HttpRequest.post(url)
|
|
|
- .setConnectionTimeout(60000)
|
|
|
|
|
- .header("accept", "application/json, text/plain, */*")
|
|
|
|
|
|
|
+ .setConnectionTimeout(60000)
|
|
|
|
|
+ .header("accept", "application/json, text/plain, */*")
|
|
|
.header("accept-language", "zh-CN,zh;q=0.9,en;q=0.8")
|
|
.header("accept-language", "zh-CN,zh;q=0.9,en;q=0.8")
|
|
|
.header("content-type", "application/json")
|
|
.header("content-type", "application/json")
|
|
|
.header("origin", "https://www.ow520.com")
|
|
.header("origin", "https://www.ow520.com")
|
|
@@ -159,11 +161,11 @@ public class GptProxyRechargeServiceImpl implements GptProxyRechargeService {
|
|
|
.execute();
|
|
.execute();
|
|
|
String body = response.body();
|
|
String body = response.body();
|
|
|
log.info("任务提交响应: {}", body);
|
|
log.info("任务提交响应: {}", body);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
JSONObject jsonResponse = JSONUtil.parseObj(body);
|
|
JSONObject jsonResponse = JSONUtil.parseObj(body);
|
|
|
TaskSubmitResult result = new TaskSubmitResult(
|
|
TaskSubmitResult result = new TaskSubmitResult(
|
|
|
- jsonResponse.getStr("task_id"),
|
|
|
|
|
- jsonResponse.getBool("success")
|
|
|
|
|
|
|
+ jsonResponse.getStr("task_id"),
|
|
|
|
|
+ jsonResponse.getBool("success")
|
|
|
);
|
|
);
|
|
|
log.info("任务提交结果: {}", result);
|
|
log.info("任务提交结果: {}", result);
|
|
|
return result;
|
|
return result;
|
|
@@ -194,22 +196,22 @@ public class GptProxyRechargeServiceImpl implements GptProxyRechargeService {
|
|
|
}
|
|
}
|
|
|
log.info("开始查询任务结果: {}", taskId);
|
|
log.info("开始查询任务结果: {}", taskId);
|
|
|
try {
|
|
try {
|
|
|
- GroupsRelation relation = relationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class)
|
|
|
|
|
- .eq(GroupsRelation::getGptTaskId, taskId)
|
|
|
|
|
- .last("limit 1"));
|
|
|
|
|
- if (relation == null) {
|
|
|
|
|
- return null;
|
|
|
|
|
- }
|
|
|
|
|
- String cardKey = relation.getCardKey();
|
|
|
|
|
- GptRechargeCardKey gptRechargeCardKey = gptRechargeCardKeyMapper.selectOne(Wrappers.lambdaQuery(GptRechargeCardKey.class).eq(GptRechargeCardKey::getCardKey, cardKey).last("limit 1"));
|
|
|
|
|
- if (gptRechargeCardKey.getChannelId() == Constant.AF_DIAN_CHANNEL_ID) {
|
|
|
|
|
- return afDianRechargeService.getTaskResult(relation);
|
|
|
|
|
- }
|
|
|
|
|
- if (gptRechargeCardKey.getChannelId()==Constant.CHONG_AF_DIAN_CHANNEL_ID){
|
|
|
|
|
- return chongAfDianRechargeService.getTaskResult(relation);
|
|
|
|
|
- }
|
|
|
|
|
- String BASE_URL = gptRechargeCardKeyChannelService.getCardKeyDomain(cardKey);
|
|
|
|
|
- String url = BASE_URL + "/tasks/" + taskId;
|
|
|
|
|
|
|
+ GroupsRelation relation = relationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class)
|
|
|
|
|
+ .eq(GroupsRelation::getGptTaskId, taskId)
|
|
|
|
|
+ .last("limit 1"));
|
|
|
|
|
+ if (relation == null) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ String cardKey = relation.getCardKey();
|
|
|
|
|
+ GptRechargeCardKey gptRechargeCardKey = gptRechargeCardKeyMapper.selectOne(Wrappers.lambdaQuery(GptRechargeCardKey.class).eq(GptRechargeCardKey::getCardKey, cardKey).last("limit 1"));
|
|
|
|
|
+ if (gptRechargeCardKey.getChannelId() == Constant.AF_DIAN_CHANNEL_ID) {
|
|
|
|
|
+ return afDianRechargeService.getTaskResult(relation);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (gptRechargeCardKey.getChannelId() == Constant.CHONG_AF_DIAN_CHANNEL_ID) {
|
|
|
|
|
+ return chongAfDianRechargeService.getTaskResult(relation);
|
|
|
|
|
+ }
|
|
|
|
|
+ String BASE_URL = gptRechargeCardKeyChannelService.getCardKeyDomain(cardKey);
|
|
|
|
|
+ String url = BASE_URL + "/tasks/" + taskId;
|
|
|
HttpResponse response = createBaseRequest(url)
|
|
HttpResponse response = createBaseRequest(url)
|
|
|
.execute();
|
|
.execute();
|
|
|
String body = response.body();
|
|
String body = response.body();
|
|
@@ -217,58 +219,58 @@ public class GptProxyRechargeServiceImpl implements GptProxyRechargeService {
|
|
|
|
|
|
|
|
JSONObject jsonResponse = JSONUtil.parseObj(body);
|
|
JSONObject jsonResponse = JSONUtil.parseObj(body);
|
|
|
TaskResult result = new TaskResult(
|
|
TaskResult result = new TaskResult(
|
|
|
- jsonResponse.getStr("status"),
|
|
|
|
|
- jsonResponse.getStr("result"),
|
|
|
|
|
- jsonResponse.getStr("error")
|
|
|
|
|
|
|
+ jsonResponse.getStr("status"),
|
|
|
|
|
+ jsonResponse.getStr("result"),
|
|
|
|
|
+ jsonResponse.getStr("error")
|
|
|
);
|
|
);
|
|
|
log.info("任务查询结果: {}", result);
|
|
log.info("任务查询结果: {}", result);
|
|
|
- String status = result.getStatus();
|
|
|
|
|
- String resultResult = Optional.ofNullable(result.getError()).orElse(result.getResult());
|
|
|
|
|
- //更新代充状态
|
|
|
|
|
- resetGroupsRelationRechargeStatus(relation, status, resultResult);
|
|
|
|
|
- return result;
|
|
|
|
|
|
|
+ String status = result.getStatus();
|
|
|
|
|
+ String resultResult = Optional.ofNullable(result.getError()).orElse(result.getResult());
|
|
|
|
|
+ //更新代充状态
|
|
|
|
|
+ resetGroupsRelationRechargeStatus(relation, status, resultResult);
|
|
|
|
|
+ return result;
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
log.error("获取任务结果失败: {}", e.getMessage(), e);
|
|
log.error("获取任务结果失败: {}", e.getMessage(), e);
|
|
|
throw new RuntimeException("获取任务结果失败: " + e.getMessage(), e);
|
|
throw new RuntimeException("获取任务结果失败: " + e.getMessage(), e);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- @Override
|
|
|
|
|
- @Transactional(rollbackFor = Throwable.class)
|
|
|
|
|
- public String confirmRecharge(GroupsRelationRechargeReq req) {
|
|
|
|
|
- Long relationId = req.getRelationId();
|
|
|
|
|
- Long userId = req.getUserId();
|
|
|
|
|
- List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
|
|
|
|
|
- GroupsRelation relation = relationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class)
|
|
|
|
|
- .in(GroupsRelation::getUserId, userIdList)
|
|
|
|
|
- .eq(GroupsRelation::getId, relationId)
|
|
|
|
|
- .eq(GroupsRelation::getStatus, GroupsRelation.Status.validity));
|
|
|
|
|
- if (relation == null) {
|
|
|
|
|
- throw BusinessRuntimeException.getInstance("车票不存在");
|
|
|
|
|
- }
|
|
|
|
|
- String userAccount = relation.getAccount();
|
|
|
|
|
- GroupsTrips groupsTrips = groupsMapper.selectById(relation.getGroupsId());
|
|
|
|
|
- GoodsDonSku sku = skuMapper.selectById(groupsTrips.getSkuId());
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ @Transactional(rollbackFor = Throwable.class)
|
|
|
|
|
+ public String confirmRecharge(GroupsRelationRechargeReq req) {
|
|
|
|
|
+ Long relationId = req.getRelationId();
|
|
|
|
|
+ Long userId = req.getUserId();
|
|
|
|
|
+ List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
|
|
|
|
|
+ GroupsRelation relation = relationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class)
|
|
|
|
|
+ .in(GroupsRelation::getUserId, userIdList)
|
|
|
|
|
+ .eq(GroupsRelation::getId, relationId)
|
|
|
|
|
+ .eq(GroupsRelation::getStatus, GroupsRelation.Status.validity));
|
|
|
|
|
+ if (relation == null) {
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("车票不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ String userAccount = relation.getAccount();
|
|
|
|
|
+ GroupsTrips groupsTrips = groupsMapper.selectById(relation.getGroupsId());
|
|
|
|
|
+ GoodsDonSku sku = skuMapper.selectById(groupsTrips.getSkuId());
|
|
|
// //GPT 代充
|
|
// //GPT 代充
|
|
|
// if (sku.getGoodsId() != Constant.GPT_RECHARGE_GOODS_ID) {
|
|
// if (sku.getGoodsId() != Constant.GPT_RECHARGE_GOODS_ID) {
|
|
|
// throw BusinessRuntimeException.getInstance("车票类型错误");
|
|
// throw BusinessRuntimeException.getInstance("车票类型错误");
|
|
|
// }
|
|
// }
|
|
|
- Integer rechargeNum = relation.getRechargeNum();
|
|
|
|
|
- Integer rechargeRemainNum = relation.getRechargeRemainNum();
|
|
|
|
|
- if (rechargeRemainNum == null || rechargeRemainNum <= 0) {
|
|
|
|
|
- throw BusinessRuntimeException.getInstance("剩余可代充次数为0");
|
|
|
|
|
- }
|
|
|
|
|
- if (relation.getRechargeStatus() == GroupsRelation.RechargeStatus.recharging) {
|
|
|
|
|
- throw BusinessRuntimeException.getInstance("确认充值中");
|
|
|
|
|
- }
|
|
|
|
|
- if (relation.getRechargeStatus() == GroupsRelation.RechargeStatus.recharge_error) {
|
|
|
|
|
- throw BusinessRuntimeException.getInstance("充值失败,请联系客服开通");
|
|
|
|
|
- }
|
|
|
|
|
- String key = RedisService.key.GPT_RECHARGE_KEY.getName() + relationId;
|
|
|
|
|
- boolean b = redisService.setNx(key, relationId, RedisService.key.GPT_RECHARGE_KEY.getTimeout());
|
|
|
|
|
- if (!b) {
|
|
|
|
|
- throw BusinessRuntimeException.getInstance("确认充值中");
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ Integer rechargeNum = relation.getRechargeNum();
|
|
|
|
|
+ Integer rechargeRemainNum = relation.getRechargeRemainNum();
|
|
|
|
|
+ if (rechargeRemainNum == null || rechargeRemainNum <= 0) {
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("剩余可代充次数为0");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (relation.getRechargeStatus() == GroupsRelation.RechargeStatus.recharging) {
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("确认充值中");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (relation.getRechargeStatus() == GroupsRelation.RechargeStatus.recharge_error) {
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("充值失败,请联系客服开通");
|
|
|
|
|
+ }
|
|
|
|
|
+ String key = RedisService.key.GPT_RECHARGE_KEY.getName() + relationId;
|
|
|
|
|
+ boolean b = redisService.setNx(key, relationId, RedisService.key.GPT_RECHARGE_KEY.getTimeout());
|
|
|
|
|
+ if (!b) {
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("确认充值中");
|
|
|
|
|
+ }
|
|
|
Integer subRechargeNum = 1;
|
|
Integer subRechargeNum = 1;
|
|
|
Integer specificChannel = null;
|
|
Integer specificChannel = null;
|
|
|
//活动gpt代充类型
|
|
//活动gpt代充类型
|
|
@@ -280,217 +282,222 @@ public class GptProxyRechargeServiceImpl implements GptProxyRechargeService {
|
|
|
if (sku.getRechargeChannelId() != null) {
|
|
if (sku.getRechargeChannelId() != null) {
|
|
|
specificChannel = sku.getRechargeChannelId();
|
|
specificChannel = sku.getRechargeChannelId();
|
|
|
}
|
|
}
|
|
|
- try {
|
|
|
|
|
- int updateRemainNum = relationMapper.update(null, Wrappers.lambdaUpdate(GroupsRelation.class)
|
|
|
|
|
- .set(GroupsRelation::getRechargeRemainNum, rechargeRemainNum - subRechargeNum)
|
|
|
|
|
- .eq(GroupsRelation::getId, relationId)
|
|
|
|
|
- .eq(GroupsRelation::getUserId, relation.getUserId())
|
|
|
|
|
- .eq(GroupsRelation::getRechargeRemainNum, rechargeRemainNum));
|
|
|
|
|
- if (updateRemainNum == 0) {
|
|
|
|
|
- throw BusinessRuntimeException.getInstance("代充异常,请重试");
|
|
|
|
|
- }
|
|
|
|
|
- OrderDon orderDon = orderDonMapper.selectOne(Wrappers.lambdaQuery(OrderDon.class)
|
|
|
|
|
- .in(OrderDon::getUserId, userIdList)
|
|
|
|
|
- .eq(OrderDon::getRelationId, relationId)
|
|
|
|
|
- .notIn(OrderDon::getStatus, Constant.noOrderAllStatus)
|
|
|
|
|
- .orderByDesc(OrderDon::getId)
|
|
|
|
|
- .last("limit 1"));
|
|
|
|
|
- if (orderDon == null) {
|
|
|
|
|
- throw BusinessRuntimeException.getInstance("代充订单不存在或已退款");
|
|
|
|
|
- }
|
|
|
|
|
- //入库token json
|
|
|
|
|
- String saveTokenJson = req.getAccessToken();
|
|
|
|
|
- String accessToken;
|
|
|
|
|
- try {
|
|
|
|
|
- GptCardTokenDto gptCardTokenDto = Jsons.parseObject(saveTokenJson, GptCardTokenDto.class);
|
|
|
|
|
- accessToken = gptCardTokenDto.getAccessToken();
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- accessToken = saveTokenJson;
|
|
|
|
|
- }
|
|
|
|
|
- //验证用户token是否正确
|
|
|
|
|
- TokenParseResult tokenParseResult = parseToken(accessToken);
|
|
|
|
|
- if (!tokenParseResult.getSuccess()) {
|
|
|
|
|
- throw BusinessRuntimeException.getInstance("您输入的凭证有误,请重新输入");
|
|
|
|
|
- }
|
|
|
|
|
- String rechargeAccount = tokenParseResult.getMessage();
|
|
|
|
|
- //月付校验前后账号是否一致
|
|
|
|
|
- if (sku.getMonths() == 1 && !StrUtil.equals(rechargeAccount, userAccount)) {
|
|
|
|
|
- throw BusinessRuntimeException.getInstance("请填入绑定账号的token");
|
|
|
|
|
- }
|
|
|
|
|
- //记录代充账号 token
|
|
|
|
|
- relation.setGptToken(saveTokenJson);
|
|
|
|
|
- relation.setAccount(rechargeAccount);
|
|
|
|
|
- //获取GPT代充key
|
|
|
|
|
- //代充卡密类型
|
|
|
|
|
- Integer gptRechargeCardKeyType = 0;
|
|
|
|
|
- //若是季、年付 且首月代充
|
|
|
|
|
- if (sku.getMonths() > 1 && rechargeNum == rechargeRemainNum) {
|
|
|
|
|
- gptRechargeCardKeyType = 1;
|
|
|
|
|
- }
|
|
|
|
|
- GptRechargeCardKey gptRechargeCardKey = gptRechargeCardKeyMapper.selectOne(Wrappers.lambdaQuery(GptRechargeCardKey.class)
|
|
|
|
|
- .eq(GptRechargeCardKey::getType, gptRechargeCardKeyType)
|
|
|
|
|
- .eq(GptRechargeCardKey::getStatus, Boolean.FALSE)
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ int updateRemainNum = relationMapper.update(null, Wrappers.lambdaUpdate(GroupsRelation.class)
|
|
|
|
|
+ .set(GroupsRelation::getRechargeRemainNum, rechargeRemainNum - subRechargeNum)
|
|
|
|
|
+ .eq(GroupsRelation::getId, relationId)
|
|
|
|
|
+ .eq(GroupsRelation::getUserId, relation.getUserId())
|
|
|
|
|
+ .eq(GroupsRelation::getRechargeRemainNum, rechargeRemainNum));
|
|
|
|
|
+ if (updateRemainNum == 0) {
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("代充异常,请重试");
|
|
|
|
|
+ }
|
|
|
|
|
+ OrderDon orderDon = orderDonMapper.selectOne(Wrappers.lambdaQuery(OrderDon.class)
|
|
|
|
|
+ .in(OrderDon::getUserId, userIdList)
|
|
|
|
|
+ .eq(OrderDon::getRelationId, relationId)
|
|
|
|
|
+ .notIn(OrderDon::getStatus, Constant.noOrderAllStatus)
|
|
|
|
|
+ .orderByDesc(OrderDon::getId)
|
|
|
|
|
+ .last("limit 1"));
|
|
|
|
|
+ if (orderDon == null) {
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("代充订单不存在或已退款");
|
|
|
|
|
+ }
|
|
|
|
|
+ //入库token json
|
|
|
|
|
+ String saveTokenJson = req.getAccessToken();
|
|
|
|
|
+ String accessToken;
|
|
|
|
|
+ try {
|
|
|
|
|
+ GptCardTokenDto gptCardTokenDto = Jsons.parseObject(saveTokenJson, GptCardTokenDto.class);
|
|
|
|
|
+ accessToken = gptCardTokenDto.getAccessToken();
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ accessToken = saveTokenJson;
|
|
|
|
|
+ }
|
|
|
|
|
+ //验证用户token是否正确
|
|
|
|
|
+ TokenParseResult tokenParseResult = parseToken(accessToken);
|
|
|
|
|
+ if (!tokenParseResult.getSuccess()) {
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("您输入的凭证有误,请重新输入");
|
|
|
|
|
+ }
|
|
|
|
|
+ String rechargeAccount = tokenParseResult.getMessage();
|
|
|
|
|
+ //月付校验前后账号是否一致
|
|
|
|
|
+ if (sku.getMonths() == 1 && !StrUtil.equals(rechargeAccount, userAccount)) {
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("请填入绑定账号的token");
|
|
|
|
|
+ }
|
|
|
|
|
+ //记录代充账号 token
|
|
|
|
|
+ relation.setGptToken(saveTokenJson);
|
|
|
|
|
+ relation.setAccount(rechargeAccount);
|
|
|
|
|
+ //获取GPT代充key
|
|
|
|
|
+ //代充卡密类型
|
|
|
|
|
+ Integer gptRechargeCardKeyType = 0;
|
|
|
|
|
+ //若是季、年付 且首月代充
|
|
|
|
|
+ if (sku.getMonths() > 1 && rechargeNum == rechargeRemainNum) {
|
|
|
|
|
+ gptRechargeCardKeyType = 1;
|
|
|
|
|
+ }
|
|
|
|
|
+ GptRechargeCardKey gptRechargeCardKey = gptRechargeCardKeyMapper.selectOne(Wrappers.lambdaQuery(GptRechargeCardKey.class)
|
|
|
|
|
+ .eq(GptRechargeCardKey::getType, gptRechargeCardKeyType)
|
|
|
|
|
+ .eq(GptRechargeCardKey::getStatus, Boolean.FALSE)
|
|
|
.eq(specificChannel != null, GptRechargeCardKey::getChannelId, specificChannel)
|
|
.eq(specificChannel != null, GptRechargeCardKey::getChannelId, specificChannel)
|
|
|
.notIn(specificChannel == null, GptRechargeCardKey::getChannelId, List.of(Constant.YEAR_AF_DIAN_CHANNEL_ID, Constant.HIBOY_PRO_ONE_CHANNEL_ID, Constant.HIBOY_PRO_TWO_CHANNEL_ID))
|
|
.notIn(specificChannel == null, GptRechargeCardKey::getChannelId, List.of(Constant.YEAR_AF_DIAN_CHANNEL_ID, Constant.HIBOY_PRO_ONE_CHANNEL_ID, Constant.HIBOY_PRO_TWO_CHANNEL_ID))
|
|
|
.last("order by channel_id desc, rand() limit 1"));
|
|
.last("order by channel_id desc, rand() limit 1"));
|
|
|
- //季、年付卡密不存在 从月付代充卡密中获取
|
|
|
|
|
- if (gptRechargeCardKey == null && gptRechargeCardKeyType == 1) {
|
|
|
|
|
|
|
+ //季、年付卡密不存在 从月付代充卡密中获取
|
|
|
|
|
+ if (gptRechargeCardKey == null && gptRechargeCardKeyType == 1) {
|
|
|
gptRechargeCardKey = gptRechargeCardKeyMapper.selectOne(Wrappers.lambdaQuery(GptRechargeCardKey.class)
|
|
gptRechargeCardKey = gptRechargeCardKeyMapper.selectOne(Wrappers.lambdaQuery(GptRechargeCardKey.class)
|
|
|
.eq(GptRechargeCardKey::getType, 0)
|
|
.eq(GptRechargeCardKey::getType, 0)
|
|
|
.eq(GptRechargeCardKey::getStatus, Boolean.FALSE)
|
|
.eq(GptRechargeCardKey::getStatus, Boolean.FALSE)
|
|
|
.eq(specificChannel != null, GptRechargeCardKey::getChannelId, specificChannel)
|
|
.eq(specificChannel != null, GptRechargeCardKey::getChannelId, specificChannel)
|
|
|
.notIn(specificChannel == null, GptRechargeCardKey::getChannelId, List.of(Constant.YEAR_AF_DIAN_CHANNEL_ID, Constant.HIBOY_PRO_ONE_CHANNEL_ID, Constant.HIBOY_PRO_TWO_CHANNEL_ID))
|
|
.notIn(specificChannel == null, GptRechargeCardKey::getChannelId, List.of(Constant.YEAR_AF_DIAN_CHANNEL_ID, Constant.HIBOY_PRO_ONE_CHANNEL_ID, Constant.HIBOY_PRO_TWO_CHANNEL_ID))
|
|
|
.last("order by channel_id desc, rand() limit 1"));
|
|
.last("order by channel_id desc, rand() limit 1"));
|
|
|
- }
|
|
|
|
|
- if (gptRechargeCardKey == null) {
|
|
|
|
|
- setRechargeRelationStatusAutoError(relation);
|
|
|
|
|
- throw BusinessRuntimeException.getInstance("充值失败,请联系客服开通");
|
|
|
|
|
- }
|
|
|
|
|
- int update = gptRechargeCardKeyMapper.update(null, Wrappers.lambdaUpdate(GptRechargeCardKey.class)
|
|
|
|
|
- .set(GptRechargeCardKey::getStatus, Boolean.TRUE)
|
|
|
|
|
- .set(GptRechargeCardKey::getOrderId, orderDon.getId())
|
|
|
|
|
- .set(GptRechargeCardKey::getUpdateTime, DateTime.now())
|
|
|
|
|
- .set(GptRechargeCardKey::getOrderNo, orderDon.getOrderNo())
|
|
|
|
|
- .eq(GptRechargeCardKey::getId, gptRechargeCardKey.getId())
|
|
|
|
|
- .eq(GptRechargeCardKey::getStatus, Boolean.FALSE));
|
|
|
|
|
- if (update == 0) {
|
|
|
|
|
- setRechargeRelationStatusAutoError(relation);
|
|
|
|
|
- throw BusinessRuntimeException.getInstance("充值失败,请联系客服开通");
|
|
|
|
|
- }
|
|
|
|
|
- String gptCardKey = gptRechargeCardKey.getCardKey();
|
|
|
|
|
-
|
|
|
|
|
- Long channelId = gptRechargeCardKey.getChannelId();
|
|
|
|
|
- //AF dian
|
|
|
|
|
- if (channelId == Constant.AF_DIAN_CHANNEL_ID) {
|
|
|
|
|
- return afDianRechargeService.confirmRecharge(relation, gptCardKey, null);
|
|
|
|
|
- }
|
|
|
|
|
- //chong.afdian
|
|
|
|
|
- if (channelId == Constant.CHONG_AF_DIAN_CHANNEL_ID) {
|
|
|
|
|
- return chongAfDianRechargeService.confirmRecharge(relation, gptCardKey, null);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+ if (gptRechargeCardKey == null) {
|
|
|
|
|
+ setRechargeRelationStatusAutoError(relation);
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("充值失败,请联系客服开通");
|
|
|
|
|
+ }
|
|
|
|
|
+ int update = gptRechargeCardKeyMapper.update(null, Wrappers.lambdaUpdate(GptRechargeCardKey.class)
|
|
|
|
|
+ .set(GptRechargeCardKey::getStatus, Boolean.TRUE)
|
|
|
|
|
+ .set(GptRechargeCardKey::getOrderId, orderDon.getId())
|
|
|
|
|
+ .set(GptRechargeCardKey::getUpdateTime, DateTime.now())
|
|
|
|
|
+ .set(GptRechargeCardKey::getOrderNo, orderDon.getOrderNo())
|
|
|
|
|
+ .eq(GptRechargeCardKey::getId, gptRechargeCardKey.getId())
|
|
|
|
|
+ .eq(GptRechargeCardKey::getStatus, Boolean.FALSE));
|
|
|
|
|
+ if (update == 0) {
|
|
|
|
|
+ setRechargeRelationStatusAutoError(relation);
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("充值失败,请联系客服开通");
|
|
|
|
|
+ }
|
|
|
|
|
+ String gptCardKey = gptRechargeCardKey.getCardKey();
|
|
|
|
|
+
|
|
|
|
|
+ Long channelId = gptRechargeCardKey.getChannelId();
|
|
|
|
|
+ //AF dian
|
|
|
|
|
+ if (channelId == Constant.AF_DIAN_CHANNEL_ID) {
|
|
|
|
|
+ return afDianRechargeService.confirmRecharge(relation, gptCardKey, null);
|
|
|
|
|
+ }
|
|
|
|
|
+ //chong.afdian
|
|
|
|
|
+ if (channelId == Constant.CHONG_AF_DIAN_CHANNEL_ID) {
|
|
|
|
|
+ return chongAfDianRechargeService.confirmRecharge(relation, gptCardKey, null);
|
|
|
|
|
+ }
|
|
|
//year.afdian
|
|
//year.afdian
|
|
|
- if (channelId == Constant.YEAR_AF_DIAN_CHANNEL_ID) {
|
|
|
|
|
- return yearAfDianRechargeService.confirmRecharge(relation, gptCardKey, null);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (channelId == Constant.YEAR_AF_DIAN_CHANNEL_ID) {
|
|
|
|
|
+ return yearAfDianRechargeService.confirmRecharge(relation, gptCardKey, null);
|
|
|
|
|
+ }
|
|
|
//go.afdian
|
|
//go.afdian
|
|
|
if (channelId == Constant.GO_AF_DIAN_CHANNEL_ID) {
|
|
if (channelId == Constant.GO_AF_DIAN_CHANNEL_ID) {
|
|
|
return goAfDianRechargeService.confirmRecharge(relation, gptCardKey, null);
|
|
return goAfDianRechargeService.confirmRecharge(relation, gptCardKey, null);
|
|
|
}
|
|
}
|
|
|
|
|
+ //cdk.aicnm
|
|
|
|
|
+ if (channelId == Constant.CDK_AICNM_CHANNEL_ID) {
|
|
|
|
|
+ return cdkAicnmRechargeService.confirmRecharge(relation, gptCardKey, null);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
//hiboy
|
|
//hiboy
|
|
|
if (channelId == Constant.HIBOY_CHANNEL_ID || channelId == Constant.HIBOY_PRO_ONE_CHANNEL_ID || channelId == Constant.HIBOY_PRO_TWO_CHANNEL_ID) {
|
|
if (channelId == Constant.HIBOY_CHANNEL_ID || channelId == Constant.HIBOY_PRO_ONE_CHANNEL_ID || channelId == Constant.HIBOY_PRO_TWO_CHANNEL_ID) {
|
|
|
return hiBoyRechargeService.confirmRecharge(relation, gptCardKey, null);
|
|
return hiBoyRechargeService.confirmRecharge(relation, gptCardKey, null);
|
|
|
}
|
|
}
|
|
|
- //校验卡密是否可用
|
|
|
|
|
- CardKeyValidationResult cardKeyValidationResult = validateCardKey(gptCardKey);
|
|
|
|
|
- if (!cardKeyValidationResult.getAvailable()) {
|
|
|
|
|
- setRechargeRelationStatusAutoError(relation);
|
|
|
|
|
- throw BusinessRuntimeException.getInstance("充值失败,请联系客服开通");
|
|
|
|
|
- }
|
|
|
|
|
- //提交任务
|
|
|
|
|
- TaskSubmitResult result = submitTask(gptCardKey, accessToken, "auth0");
|
|
|
|
|
- if (!result.getSuccess()) {
|
|
|
|
|
- setRechargeRelationStatusAutoError(relation);
|
|
|
|
|
- throw BusinessRuntimeException.getInstance("充值失败,请联系客服开通");
|
|
|
|
|
- }
|
|
|
|
|
- String taskId = result.getTaskId();
|
|
|
|
|
- relationMapper.update(null, Wrappers.lambdaUpdate(GroupsRelation.class)
|
|
|
|
|
- //记录代充账号
|
|
|
|
|
- .set(GroupsRelation::getAccount, rechargeAccount)
|
|
|
|
|
- .set(GroupsRelation::getRechargeStatus, GroupsRelation.RechargeStatus.recharging)
|
|
|
|
|
- .set(GroupsRelation::getCardKey, gptCardKey)
|
|
|
|
|
- .set(GroupsRelation::getGptToken, saveTokenJson)
|
|
|
|
|
- .set(GroupsRelation::getGptTaskId, taskId)
|
|
|
|
|
- .eq(GroupsRelation::getId, relationId));
|
|
|
|
|
- return taskId;
|
|
|
|
|
- } finally {
|
|
|
|
|
- if (redisService.hasKey(key)) {
|
|
|
|
|
- redisService.del(key);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 设置代充自动充值异常
|
|
|
|
|
- */
|
|
|
|
|
- public void setRechargeRelationStatusAutoError(GroupsRelation relation) {
|
|
|
|
|
- TASK_EXECUTOR.execute(()->{
|
|
|
|
|
- relationMapper.update(null, Wrappers.lambdaUpdate(GroupsRelation.class)
|
|
|
|
|
- .set(GroupsRelation::getAccount, relation.getAccount())
|
|
|
|
|
- .set(GroupsRelation::getGptToken, relation.getGptToken())
|
|
|
|
|
- .set(GroupsRelation::getRechargeStatus, GroupsRelation.RechargeStatus.recharge_error)
|
|
|
|
|
- .eq(GroupsRelation::getId, relation.getId()));
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 更新代充状态
|
|
|
|
|
- */
|
|
|
|
|
- private void resetGroupsRelationRechargeStatus(GroupsRelation relation, String status, String result) {
|
|
|
|
|
- if ("completed".equals(status) || "failed".equals(status) || "unknown".equals(status)) {
|
|
|
|
|
- String taskId = relation.getGptTaskId();
|
|
|
|
|
- if (relation != null && relation.getRechargeStatus() == GroupsRelation.RechargeStatus.recharging) {
|
|
|
|
|
- Integer rechargeRemainNum = relation.getRechargeRemainNum();
|
|
|
|
|
- GroupsRelation.RechargeStatus rechargeStatus = "completed".equals(status) ? GroupsRelation.RechargeStatus.complete : GroupsRelation.RechargeStatus.recharge_error;
|
|
|
|
|
- String cardKey = relation.getCardKey();
|
|
|
|
|
- GptRechargeCardKey gptRechargeCardKey = gptRechargeCardKeyMapper.selectOne(Wrappers.lambdaQuery(GptRechargeCardKey.class)
|
|
|
|
|
- .eq(GptRechargeCardKey::getCardKey, cardKey)
|
|
|
|
|
- .last("limit 1"));
|
|
|
|
|
- if (rechargeStatus == GroupsRelation.RechargeStatus.recharge_error) {
|
|
|
|
|
- if (gptRechargeCardKey != null) {
|
|
|
|
|
- gptRechargeCardKeyMapper.update(null, Wrappers.lambdaUpdate(GptRechargeCardKey.class)
|
|
|
|
|
- .set(GptRechargeCardKey::getStatus, Boolean.FALSE)
|
|
|
|
|
- .set(GptRechargeCardKey::getOrderId, null)
|
|
|
|
|
- .set(GptRechargeCardKey::getOrderNo, null)
|
|
|
|
|
- .eq(GptRechargeCardKey::getId, gptRechargeCardKey.getId())
|
|
|
|
|
- .eq(GptRechargeCardKey::getStatus, Boolean.TRUE));
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- if (rechargeStatus == GroupsRelation.RechargeStatus.recharge_error) {
|
|
|
|
|
- if (!redisService.setNx(RedisService.key.GPT_RECHARGE_RECOVER_KEY.getName() + taskId, taskId, RedisService.key.GPT_RECHARGE_RECOVER_KEY.getTimeout())) {
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- Date startTime = relation.getStartTime();
|
|
|
|
|
- DateTime expiryTime = null;
|
|
|
|
|
- if (rechargeStatus == GroupsRelation.RechargeStatus.complete && startTime == null) {
|
|
|
|
|
- GroupsTrips groupsTrips = groupsMapper.selectById(relation.getGroupsId());
|
|
|
|
|
- if (groupsTrips != null) {
|
|
|
|
|
- startTime = DateTime.now();
|
|
|
|
|
- GoodsDonSku sku = skuMapper.selectById(groupsTrips.getSkuId());
|
|
|
|
|
- if (sku.getDays() != null && sku.getDays() > 0) {
|
|
|
|
|
- expiryTime = DateUtil.offsetDay(startTime, sku.getDays());
|
|
|
|
|
- } else {
|
|
|
|
|
- expiryTime = DateUtil.offsetMonth(startTime, sku.getMonths());
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- String rechargeErrorInfo = null;
|
|
|
|
|
- if (rechargeStatus == GroupsRelation.RechargeStatus.recharge_error) {
|
|
|
|
|
- rechargeErrorInfo = result;
|
|
|
|
|
- }
|
|
|
|
|
- relationMapper.update(null, Wrappers.lambdaUpdate(GroupsRelation.class)
|
|
|
|
|
- .set(rechargeStatus == GroupsRelation.RechargeStatus.recharge_error, GroupsRelation::getRechargeRemainNum, rechargeRemainNum + 1)
|
|
|
|
|
- .set(GroupsRelation::getRechargeStatus, rechargeStatus)
|
|
|
|
|
- .set(expiryTime != null, GroupsRelation::getStartTime, startTime)
|
|
|
|
|
- .set(expiryTime != null, GroupsRelation::getExpiryTime, expiryTime)
|
|
|
|
|
- .set(StrUtil.isNotEmpty(rechargeErrorInfo), GroupsRelation::getRechargeErrorInfo, rechargeErrorInfo)
|
|
|
|
|
- .eq(GroupsRelation::getId, relation.getId())
|
|
|
|
|
- .le(GroupsRelation::getRechargeRemainNum, relation.getRechargeNum())
|
|
|
|
|
- .eq(GroupsRelation::getRechargeStatus, GroupsRelation.RechargeStatus.recharging));
|
|
|
|
|
- //记录代充记录
|
|
|
|
|
- if (rechargeStatus == GroupsRelation.RechargeStatus.complete) {
|
|
|
|
|
|
|
+ //校验卡密是否可用
|
|
|
|
|
+ CardKeyValidationResult cardKeyValidationResult = validateCardKey(gptCardKey);
|
|
|
|
|
+ if (!cardKeyValidationResult.getAvailable()) {
|
|
|
|
|
+ setRechargeRelationStatusAutoError(relation);
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("充值失败,请联系客服开通");
|
|
|
|
|
+ }
|
|
|
|
|
+ //提交任务
|
|
|
|
|
+ TaskSubmitResult result = submitTask(gptCardKey, accessToken, "auth0");
|
|
|
|
|
+ if (!result.getSuccess()) {
|
|
|
|
|
+ setRechargeRelationStatusAutoError(relation);
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("充值失败,请联系客服开通");
|
|
|
|
|
+ }
|
|
|
|
|
+ String taskId = result.getTaskId();
|
|
|
|
|
+ relationMapper.update(null, Wrappers.lambdaUpdate(GroupsRelation.class)
|
|
|
|
|
+ //记录代充账号
|
|
|
|
|
+ .set(GroupsRelation::getAccount, rechargeAccount)
|
|
|
|
|
+ .set(GroupsRelation::getRechargeStatus, GroupsRelation.RechargeStatus.recharging)
|
|
|
|
|
+ .set(GroupsRelation::getCardKey, gptCardKey)
|
|
|
|
|
+ .set(GroupsRelation::getGptToken, saveTokenJson)
|
|
|
|
|
+ .set(GroupsRelation::getGptTaskId, taskId)
|
|
|
|
|
+ .eq(GroupsRelation::getId, relationId));
|
|
|
|
|
+ return taskId;
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ if (redisService.hasKey(key)) {
|
|
|
|
|
+ redisService.del(key);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 设置代充自动充值异常
|
|
|
|
|
+ */
|
|
|
|
|
+ public void setRechargeRelationStatusAutoError(GroupsRelation relation) {
|
|
|
|
|
+ TASK_EXECUTOR.execute(() -> {
|
|
|
|
|
+ relationMapper.update(null, Wrappers.lambdaUpdate(GroupsRelation.class)
|
|
|
|
|
+ .set(GroupsRelation::getAccount, relation.getAccount())
|
|
|
|
|
+ .set(GroupsRelation::getGptToken, relation.getGptToken())
|
|
|
|
|
+ .set(GroupsRelation::getRechargeStatus, GroupsRelation.RechargeStatus.recharge_error)
|
|
|
|
|
+ .eq(GroupsRelation::getId, relation.getId()));
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 更新代充状态
|
|
|
|
|
+ */
|
|
|
|
|
+ private void resetGroupsRelationRechargeStatus(GroupsRelation relation, String status, String result) {
|
|
|
|
|
+ if ("completed".equals(status) || "failed".equals(status) || "unknown".equals(status)) {
|
|
|
|
|
+ String taskId = relation.getGptTaskId();
|
|
|
|
|
+ if (relation != null && relation.getRechargeStatus() == GroupsRelation.RechargeStatus.recharging) {
|
|
|
|
|
+ Integer rechargeRemainNum = relation.getRechargeRemainNum();
|
|
|
|
|
+ GroupsRelation.RechargeStatus rechargeStatus = "completed".equals(status) ? GroupsRelation.RechargeStatus.complete : GroupsRelation.RechargeStatus.recharge_error;
|
|
|
|
|
+ String cardKey = relation.getCardKey();
|
|
|
|
|
+ GptRechargeCardKey gptRechargeCardKey = gptRechargeCardKeyMapper.selectOne(Wrappers.lambdaQuery(GptRechargeCardKey.class)
|
|
|
|
|
+ .eq(GptRechargeCardKey::getCardKey, cardKey)
|
|
|
|
|
+ .last("limit 1"));
|
|
|
|
|
+ if (rechargeStatus == GroupsRelation.RechargeStatus.recharge_error) {
|
|
|
|
|
+ if (gptRechargeCardKey != null) {
|
|
|
|
|
+ gptRechargeCardKeyMapper.update(null, Wrappers.lambdaUpdate(GptRechargeCardKey.class)
|
|
|
|
|
+ .set(GptRechargeCardKey::getStatus, Boolean.FALSE)
|
|
|
|
|
+ .set(GptRechargeCardKey::getOrderId, null)
|
|
|
|
|
+ .set(GptRechargeCardKey::getOrderNo, null)
|
|
|
|
|
+ .eq(GptRechargeCardKey::getId, gptRechargeCardKey.getId())
|
|
|
|
|
+ .eq(GptRechargeCardKey::getStatus, Boolean.TRUE));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (rechargeStatus == GroupsRelation.RechargeStatus.recharge_error) {
|
|
|
|
|
+ if (!redisService.setNx(RedisService.key.GPT_RECHARGE_RECOVER_KEY.getName() + taskId, taskId, RedisService.key.GPT_RECHARGE_RECOVER_KEY.getTimeout())) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ Date startTime = relation.getStartTime();
|
|
|
|
|
+ DateTime expiryTime = null;
|
|
|
|
|
+ if (rechargeStatus == GroupsRelation.RechargeStatus.complete && startTime == null) {
|
|
|
|
|
+ GroupsTrips groupsTrips = groupsMapper.selectById(relation.getGroupsId());
|
|
|
|
|
+ if (groupsTrips != null) {
|
|
|
|
|
+ startTime = DateTime.now();
|
|
|
|
|
+ GoodsDonSku sku = skuMapper.selectById(groupsTrips.getSkuId());
|
|
|
|
|
+ if (sku.getDays() != null && sku.getDays() > 0) {
|
|
|
|
|
+ expiryTime = DateUtil.offsetDay(startTime, sku.getDays());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ expiryTime = DateUtil.offsetMonth(startTime, sku.getMonths());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ String rechargeErrorInfo = null;
|
|
|
|
|
+ if (rechargeStatus == GroupsRelation.RechargeStatus.recharge_error) {
|
|
|
|
|
+ rechargeErrorInfo = result;
|
|
|
|
|
+ }
|
|
|
|
|
+ relationMapper.update(null, Wrappers.lambdaUpdate(GroupsRelation.class)
|
|
|
|
|
+ .set(rechargeStatus == GroupsRelation.RechargeStatus.recharge_error, GroupsRelation::getRechargeRemainNum, rechargeRemainNum + 1)
|
|
|
|
|
+ .set(GroupsRelation::getRechargeStatus, rechargeStatus)
|
|
|
|
|
+ .set(expiryTime != null, GroupsRelation::getStartTime, startTime)
|
|
|
|
|
+ .set(expiryTime != null, GroupsRelation::getExpiryTime, expiryTime)
|
|
|
|
|
+ .set(StrUtil.isNotEmpty(rechargeErrorInfo), GroupsRelation::getRechargeErrorInfo, rechargeErrorInfo)
|
|
|
|
|
+ .eq(GroupsRelation::getId, relation.getId())
|
|
|
|
|
+ .le(GroupsRelation::getRechargeRemainNum, relation.getRechargeNum())
|
|
|
|
|
+ .eq(GroupsRelation::getRechargeStatus, GroupsRelation.RechargeStatus.recharging));
|
|
|
|
|
+ //记录代充记录
|
|
|
|
|
+ if (rechargeStatus == GroupsRelation.RechargeStatus.complete) {
|
|
|
gptUserRechargeRecordService.recordGptUserRechargeNum(relation.getCardKey(), relation.getUserId(), relation.getId(), relation.getAccount(), -1, null, "自动代充");
|
|
gptUserRechargeRecordService.recordGptUserRechargeNum(relation.getCardKey(), relation.getUserId(), relation.getId(), relation.getAccount(), -1, null, "自动代充");
|
|
|
- //修改对应订单状态
|
|
|
|
|
- if (gptRechargeCardKey != null) {
|
|
|
|
|
- Long orderId = gptRechargeCardKey.getOrderId();
|
|
|
|
|
- OrderDon orderDon = orderDonMapper.selectById(orderId);
|
|
|
|
|
- if (orderDon != null && orderDon.getStatus() == OrderDon.Status.hasPayment) {
|
|
|
|
|
- orderDon.setStatus(OrderDon.Status.complete);
|
|
|
|
|
- orderDonMapper.updateById(orderDon);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ //修改对应订单状态
|
|
|
|
|
+ if (gptRechargeCardKey != null) {
|
|
|
|
|
+ Long orderId = gptRechargeCardKey.getOrderId();
|
|
|
|
|
+ OrderDon orderDon = orderDonMapper.selectById(orderId);
|
|
|
|
|
+ if (orderDon != null && orderDon.getStatus() == OrderDon.Status.hasPayment) {
|
|
|
|
|
+ orderDon.setStatus(OrderDon.Status.complete);
|
|
|
|
|
+ orderDonMapper.updateById(orderDon);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|