|
|
@@ -244,6 +244,12 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
|
|
|
|
|
|
private static final Date GPT_ACTIVITY_PAY_TIME_BEGIN = DateUtil.parse("2026-05-01 00:00:00");
|
|
|
|
|
|
+ private static final String GPT_ACTIVITY_REDEEM_NAME = "GPT代充/独立赠送";
|
|
|
+
|
|
|
+ private static final String STUDENT_CERT_API_QUOTA_REDEEM_NAME = "大学生认证API站额度券";
|
|
|
+
|
|
|
+ private static final Integer DEFAULT_API_QUOTA = 2500000;
|
|
|
+
|
|
|
@Override
|
|
|
public SearchResult<RenewalView> getMyTicket(long userId, Boolean isLoginPopularize, String customId, String account, String orderNo, Integer cmt) {
|
|
|
User u = userMapper.selectById(userId);
|
|
|
@@ -2809,7 +2815,7 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
|
|
|
record.setSourceGoodsId(sourceGoodsId);
|
|
|
record.setSkuId(Constant.GPT_ACTIVITY_GIFT_SKU_ID);
|
|
|
record.setSourceType(RedisKey.GPT_API_QUOTA_KEY);
|
|
|
- record.setRedeemName("GPT代充/独立赠送");
|
|
|
+ record.setRedeemName(GPT_ACTIVITY_REDEEM_NAME);
|
|
|
record.setStatus("processing");
|
|
|
record.setRelationExpiryTime(sourceRelation.getExpiryTime());
|
|
|
ticketRedemptionCodeRecordMapper.insert(record);
|
|
|
@@ -2828,7 +2834,7 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
|
|
|
throw BusinessRuntimeException.getInstance("系统繁忙,请重新领取");
|
|
|
}
|
|
|
}
|
|
|
- GptActivityRedeemResult redeemResult = requestGptActivityRedeemCode(Constant.AI_API_SVC_DOMAIN, giftRelation, giftSku);
|
|
|
+ GptActivityRedeemResult redeemResult = requestGptActivityRedeemCode(Constant.AI_API_SVC_DOMAIN, GPT_ACTIVITY_REDEEM_NAME, DEFAULT_API_QUOTA);
|
|
|
record.setRelationId(giftRelation.getId());
|
|
|
record.setGoodsId(giftSku.getGoodsId());
|
|
|
record.setSourceGoodsId(sourceGoodsId);
|
|
|
@@ -2862,6 +2868,89 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public ReceiveGptActivityTicketResp receiveStudentCertGptApiQuotaTicket(long userId, Integer quota) throws Exception {
|
|
|
+ List<Long> userIds = userBindRelationService.getRelationUserIdList(userId, null);
|
|
|
+ if (CollUtil.isEmpty(userIds)) {
|
|
|
+ userIds = List.of(userId);
|
|
|
+ }
|
|
|
+ quota = resolveApiQuota(quota);
|
|
|
+ String lockKey = String.format("%s:%s", RedisKey.STUDENT_CERT_GPT_API_QUOTA_KEY, Collections.min(userIds));
|
|
|
+ if (!redisService.setNx(lockKey, userId, 60L)) {
|
|
|
+ throw BusinessRuntimeException.getInstance("领取中,请稍后再试");
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ TicketRedemptionCodeRecord existRecord = ticketRedemptionCodeRecordMapper.selectOne(Wrappers.lambdaQuery(TicketRedemptionCodeRecord.class)
|
|
|
+ .in(TicketRedemptionCodeRecord::getUserId, userIds)
|
|
|
+ .eq(TicketRedemptionCodeRecord::getSkuId, Constant.GPT_ACTIVITY_GIFT_SKU_ID)
|
|
|
+ .eq(TicketRedemptionCodeRecord::getSourceType, RedisKey.STUDENT_CERT_GPT_API_QUOTA_KEY)
|
|
|
+ .eq(TicketRedemptionCodeRecord::getStatus, "success")
|
|
|
+ .orderByDesc(TicketRedemptionCodeRecord::getId)
|
|
|
+ .last("limit 1"));
|
|
|
+ if (existRecord != null) {
|
|
|
+ ReceiveGptActivityTicketResp resp = new ReceiveGptActivityTicketResp();
|
|
|
+ resp.setRelationId(existRecord.getRelationId());
|
|
|
+ resp.setRedeemCode(existRecord.getRedeemCode());
|
|
|
+ return resp;
|
|
|
+ }
|
|
|
+
|
|
|
+ TicketRedemptionCodeRecord record = new TicketRedemptionCodeRecord();
|
|
|
+ record.setUserId(userId);
|
|
|
+ record.setSkuId(Constant.GPT_ACTIVITY_GIFT_SKU_ID);
|
|
|
+ record.setSourceType(RedisKey.STUDENT_CERT_GPT_API_QUOTA_KEY);
|
|
|
+ record.setRedeemName(STUDENT_CERT_API_QUOTA_REDEEM_NAME);
|
|
|
+ record.setStatus("processing");
|
|
|
+ ticketRedemptionCodeRecordMapper.insert(record);
|
|
|
+
|
|
|
+ GoodsDonSku giftSku = goodsDonSkuMapper.selectById(Constant.GPT_ACTIVITY_GIFT_SKU_ID);
|
|
|
+ GroupsRelation giftRelation = null;
|
|
|
+ try {
|
|
|
+ if (giftSku == null) {
|
|
|
+ throw BusinessRuntimeException.getInstance("系统繁忙,请重新领取");
|
|
|
+ }
|
|
|
+ Long giftRelationId = getTicket(userId, giftSku.getId(), Boolean.FALSE);
|
|
|
+ if (giftRelationId == null) {
|
|
|
+ throw BusinessRuntimeException.getInstance("系统繁忙,请重新领取");
|
|
|
+ }
|
|
|
+ giftRelation = groupsRelationMapper.selectById(giftRelationId);
|
|
|
+ if (giftRelation == null) {
|
|
|
+ throw BusinessRuntimeException.getInstance("系统繁忙,请重新领取");
|
|
|
+ }
|
|
|
+
|
|
|
+ GptActivityRedeemResult redeemResult = requestGptActivityRedeemCode(Constant.AI_API_SVC_DOMAIN, STUDENT_CERT_API_QUOTA_REDEEM_NAME, quota);
|
|
|
+ record.setRelationId(giftRelation.getId());
|
|
|
+ record.setGoodsId(giftSku.getGoodsId());
|
|
|
+ record.setRedeemCode(redeemResult.getRedeemCode());
|
|
|
+ record.setQuota(redeemResult.getQuota());
|
|
|
+ record.setRedeemCount(0);
|
|
|
+ record.setExpiredTime(redeemResult.getExpiredTime());
|
|
|
+ record.setStatus("success");
|
|
|
+ record.setRelationExpiryTime(giftRelation.getExpiryTime());
|
|
|
+ record.setApiResponse(redeemResult.getApiResponse());
|
|
|
+ ticketRedemptionCodeRecordMapper.updateById(record);
|
|
|
+
|
|
|
+ ReceiveGptActivityTicketResp resp = new ReceiveGptActivityTicketResp();
|
|
|
+ resp.setRelationId(giftRelation.getId());
|
|
|
+ resp.setRedeemCode(redeemResult.getRedeemCode());
|
|
|
+ return resp;
|
|
|
+ } catch (Exception e) {
|
|
|
+ if (giftSku != null) {
|
|
|
+ record.setGoodsId(giftSku.getGoodsId());
|
|
|
+ }
|
|
|
+ record.setStatus("error");
|
|
|
+ record.setErrorMsg(StringUtil.getErrorText(e));
|
|
|
+ if (giftRelation != null) {
|
|
|
+ record.setRelationId(giftRelation.getId());
|
|
|
+ record.setRelationExpiryTime(giftRelation.getExpiryTime());
|
|
|
+ }
|
|
|
+ ticketRedemptionCodeRecordMapper.updateById(record);
|
|
|
+ throw e;
|
|
|
+ }
|
|
|
+ } finally {
|
|
|
+ redisService.del(lockKey);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private boolean isGptApiQuotaSourceTicket(OrderDon orderDon, Long goodsId, Integer skuNum) {
|
|
|
if (orderDon == null) {
|
|
|
return false;
|
|
|
@@ -2885,11 +2974,13 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
- private GptActivityRedeemResult requestGptActivityRedeemCode(String apiDomain, GroupsRelation giftRelation, GoodsDonSku giftSku) throws Exception {
|
|
|
- //默认5刀额度
|
|
|
- Integer quota = 2500000;
|
|
|
+ private Integer resolveApiQuota(Integer quota) {
|
|
|
+ return quota == null || quota <= 0 ? DEFAULT_API_QUOTA : quota;
|
|
|
+ }
|
|
|
+
|
|
|
+ private GptActivityRedeemResult requestGptActivityRedeemCode(String apiDomain, String redeemName, Integer quota) throws Exception {
|
|
|
Map<String, Object> params = new HashMap<>();
|
|
|
- params.put("name", "GPT代充/独立赠送");
|
|
|
+ params.put("name", redeemName);
|
|
|
params.put("count", 1);
|
|
|
params.put("quota", quota);
|
|
|
String apiUrl = StrUtil.removeSuffix(apiDomain, "/") + "/api/redemption/";
|