|
@@ -48,6 +48,7 @@ import com.cyksj.model.response.NetflixErrorAccountStatus;
|
|
|
import com.cyksj.model.response.NetflixRecoverResp;
|
|
import com.cyksj.model.response.NetflixRecoverResp;
|
|
|
import com.cyksj.model.response.NetflixRefundInfoResp;
|
|
import com.cyksj.model.response.NetflixRefundInfoResp;
|
|
|
import com.cyksj.model.response.ReceiveGptActivityTicketResp;
|
|
import com.cyksj.model.response.ReceiveGptActivityTicketResp;
|
|
|
|
|
+import com.cyksj.model.response.GptApiQuotaTagResp;
|
|
|
import com.cyksj.model.views.*;
|
|
import com.cyksj.model.views.*;
|
|
|
import com.cyksj.redis.RedisService;
|
|
import com.cyksj.redis.RedisService;
|
|
|
import com.cyksj.service.chatgpt.ChatGptAccountService;
|
|
import com.cyksj.service.chatgpt.ChatGptAccountService;
|
|
@@ -604,7 +605,7 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
|
|
|
// PLUS 仅 skuNum == 1 的独立规格可领;与实际领取接口共用资格校验。
|
|
// PLUS 仅 skuNum == 1 的独立规格可领;与实际领取接口共用资格校验。
|
|
|
ticket.setCanReceiveGptApiQuota(isGptApiQuotaSourceTicket(sourceOrder, ticket.getGoodsId(), ticket.getSkuNum())
|
|
ticket.setCanReceiveGptApiQuota(isGptApiQuotaSourceTicket(sourceOrder, ticket.getGoodsId(), ticket.getSkuNum())
|
|
|
&& !hasReceivedGptApiQuota(userIds, ticket.getGoodsId(), yearQuota)
|
|
&& !hasReceivedGptApiQuota(userIds, ticket.getGoodsId(), yearQuota)
|
|
|
- && !hasPendingGptApiQuota(userIds, ticket.getGoodsId())
|
|
|
|
|
|
|
+ && !hasPendingGptApiQuota(userIds, ticket.getGoodsId(), yearQuota)
|
|
|
&& (!yearQuota || hasNewGptApiQuotaPurchase(userIds, ticket.getGoodsId(), sourceOrder)));
|
|
&& (!yearQuota || hasNewGptApiQuotaPurchase(userIds, ticket.getGoodsId(), sourceOrder)));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -620,19 +621,44 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
|
|
|
if (yearQuota) {
|
|
if (yearQuota) {
|
|
|
// 独立年付、代充年付按商品各限领一次50元;原5元不占用50元资格。
|
|
// 独立年付、代充年付按商品各限领一次50元;原5元不占用50元资格。
|
|
|
query.ge(TicketRedemptionCodeRecord::getQuota, YEAR_RECHARGE_API_QUOTA);
|
|
query.ge(TicketRedemptionCodeRecord::getQuota, YEAR_RECHARGE_API_QUOTA);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 5元与50元分开限领;兼容未记录quota的历史5元记录。
|
|
|
|
|
+ query.and(wrapper -> wrapper.lt(TicketRedemptionCodeRecord::getQuota, YEAR_RECHARGE_API_QUOTA)
|
|
|
|
|
+ .or().isNull(TicketRedemptionCodeRecord::getQuota));
|
|
|
}
|
|
}
|
|
|
- // 普通规格仍按当前商品的任意已发额度限制一次。
|
|
|
|
|
return ticketRedemptionCodeRecordMapper.selectCount(query) > 0;
|
|
return ticketRedemptionCodeRecordMapper.selectCount(query) > 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private boolean hasPendingGptApiQuota(List<Long> userIds, Long sourceGoodsId) {
|
|
|
|
|
- // 同一商品发放中或结果不确定时禁止重发,不占用另一商品的领取资格。
|
|
|
|
|
- return ticketRedemptionCodeRecordMapper.selectCount(Wrappers.lambdaQuery(TicketRedemptionCodeRecord.class)
|
|
|
|
|
|
|
+ private boolean hasPendingGptApiQuota(List<Long> userIds, Long sourceGoodsId, boolean yearQuota) {
|
|
|
|
|
+ // 只阻止同一商品、同一额度档的重复发放;旧processing金额未知时保守拦截。
|
|
|
|
|
+ LambdaQueryWrapper<TicketRedemptionCodeRecord> query = Wrappers.lambdaQuery(TicketRedemptionCodeRecord.class)
|
|
|
.in(TicketRedemptionCodeRecord::getUserId, userIds)
|
|
.in(TicketRedemptionCodeRecord::getUserId, userIds)
|
|
|
.eq(TicketRedemptionCodeRecord::getSkuId, Constant.GPT_ACTIVITY_GIFT_SKU_ID)
|
|
.eq(TicketRedemptionCodeRecord::getSkuId, Constant.GPT_ACTIVITY_GIFT_SKU_ID)
|
|
|
.eq(TicketRedemptionCodeRecord::getSourceType, RedisKey.GPT_API_QUOTA_KEY)
|
|
.eq(TicketRedemptionCodeRecord::getSourceType, RedisKey.GPT_API_QUOTA_KEY)
|
|
|
.eq(TicketRedemptionCodeRecord::getSourceGoodsId, sourceGoodsId)
|
|
.eq(TicketRedemptionCodeRecord::getSourceGoodsId, sourceGoodsId)
|
|
|
- .eq(TicketRedemptionCodeRecord::getStatus, "processing")) > 0;
|
|
|
|
|
|
|
+ .eq(TicketRedemptionCodeRecord::getStatus, "processing");
|
|
|
|
|
+ if (yearQuota) {
|
|
|
|
|
+ query.and(wrapper -> wrapper.ge(TicketRedemptionCodeRecord::getQuota, YEAR_RECHARGE_API_QUOTA)
|
|
|
|
|
+ .or().isNull(TicketRedemptionCodeRecord::getQuota));
|
|
|
|
|
+ } else {
|
|
|
|
|
+ query.and(wrapper -> wrapper.lt(TicketRedemptionCodeRecord::getQuota, YEAR_RECHARGE_API_QUOTA)
|
|
|
|
|
+ .or().isNull(TicketRedemptionCodeRecord::getQuota));
|
|
|
|
|
+ }
|
|
|
|
|
+ return ticketRedemptionCodeRecordMapper.selectCount(query) > 0;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public GptApiQuotaTagResp getGptApiQuotaTagStatus(long userId, Long goodsId) {
|
|
|
|
|
+ List<Long> userIds = userBindRelationService.getRelationUserIdList(userId, null);
|
|
|
|
|
+ if (CollUtil.isEmpty(userIds)) {
|
|
|
|
|
+ userIds = List.of(userId);
|
|
|
|
|
+ }
|
|
|
|
|
+ GptApiQuotaTagResp resp = new GptApiQuotaTagResp();
|
|
|
|
|
+ resp.setGoodsId(goodsId);
|
|
|
|
|
+ // 仅查询传入商品的记录,5 元和 50 元分开返回,另一商品不影响结果。
|
|
|
|
|
+ resp.setReceived5ApiQuota(hasReceivedGptApiQuota(userIds, goodsId, false));
|
|
|
|
|
+ resp.setReceived50ApiQuota(hasReceivedGptApiQuota(userIds, goodsId, true));
|
|
|
|
|
+ return resp;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private boolean hasNewGptApiQuotaPurchase(List<Long> userIds, Long sourceGoodsId, OrderDon sourceOrder) {
|
|
private boolean hasNewGptApiQuotaPurchase(List<Long> userIds, Long sourceGoodsId, OrderDon sourceOrder) {
|
|
@@ -674,7 +700,7 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
|
|
|
if (hasReceivedGptApiQuota(userIds, record.getSourceGoodsId(), yearQuota)) {
|
|
if (hasReceivedGptApiQuota(userIds, record.getSourceGoodsId(), yearQuota)) {
|
|
|
throw BusinessRuntimeException.getInstance(yearQuota ? "您已领取50元API额度" : "您已领取");
|
|
throw BusinessRuntimeException.getInstance(yearQuota ? "您已领取50元API额度" : "您已领取");
|
|
|
}
|
|
}
|
|
|
- if (hasPendingGptApiQuota(userIds, record.getSourceGoodsId())) {
|
|
|
|
|
|
|
+ if (hasPendingGptApiQuota(userIds, record.getSourceGoodsId(), yearQuota)) {
|
|
|
throw BusinessRuntimeException.getInstance("额度正在发放或结果待确认,请勿重复领取;长时间未到账请联系客服");
|
|
throw BusinessRuntimeException.getInstance("额度正在发放或结果待确认,请勿重复领取;长时间未到账请联系客服");
|
|
|
}
|
|
}
|
|
|
if (yearQuota && !hasNewGptApiQuotaPurchase(userIds, record.getSourceGoodsId(), sourceOrder)) {
|
|
if (yearQuota && !hasNewGptApiQuotaPurchase(userIds, record.getSourceGoodsId(), sourceOrder)) {
|