fix
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"errors"
|
||||
"tyapi-server/internal/application/api/commands"
|
||||
"tyapi-server/internal/application/api/dto"
|
||||
"tyapi-server/internal/application/api/utils"
|
||||
"tyapi-server/internal/config"
|
||||
entities "tyapi-server/internal/domains/api/entities"
|
||||
"tyapi-server/internal/domains/api/repositories"
|
||||
@@ -80,6 +81,14 @@ func (s *ApiApplicationServiceImpl) CallApi(ctx context.Context, cmd *commands.A
|
||||
businessError = ErrInvalidAccessId
|
||||
return ErrInvalidAccessId
|
||||
}
|
||||
// 3. 查产品
|
||||
product, err := s.productManagementService.GetProductByCode(txCtx, cmd.ApiName)
|
||||
if err != nil {
|
||||
s.logger.Error("查产品失败", zap.Error(err))
|
||||
businessError = ErrProductNotFound
|
||||
return ErrProductNotFound
|
||||
}
|
||||
apiCall.ProductId = &product.ID
|
||||
// 加入UserId
|
||||
apiCall.UserId = &apiUser.UserId
|
||||
if apiUser.IsFrozen() {
|
||||
@@ -109,14 +118,6 @@ func (s *ApiApplicationServiceImpl) CallApi(ctx context.Context, cmd *commands.A
|
||||
businessError = ErrArrears
|
||||
return ErrArrears
|
||||
}
|
||||
|
||||
// 3. 查产品
|
||||
product, err := s.productManagementService.GetProductByCode(txCtx, cmd.ApiName)
|
||||
if err != nil {
|
||||
s.logger.Error("查产品失败", zap.Error(err))
|
||||
businessError = ErrProductNotFound
|
||||
return ErrProductNotFound
|
||||
}
|
||||
// 4. 查订阅
|
||||
subscription, err := s.productSubscriptionService.GetUserSubscribedProduct(txCtx, apiUser.UserId, product.ID)
|
||||
if err != nil {
|
||||
@@ -129,7 +130,6 @@ func (s *ApiApplicationServiceImpl) CallApi(ctx context.Context, cmd *commands.A
|
||||
businessError = ErrNotSubscribed
|
||||
return ErrNotSubscribed
|
||||
}
|
||||
apiCall.ProductId = &product.ID
|
||||
if !product.IsValid() {
|
||||
s.logger.Error("产品已停用", zap.String("productId", product.ID))
|
||||
businessError = ErrProductDisabled
|
||||
@@ -172,7 +172,7 @@ func (s *ApiApplicationServiceImpl) CallApi(ctx context.Context, cmd *commands.A
|
||||
businessError = ErrSystem
|
||||
return ErrSystem
|
||||
}
|
||||
apiCall.ResponseData = &encryptedResponse
|
||||
// apiCall.ResponseData = &encryptedResponse
|
||||
|
||||
// 8. 更新订阅使用次数
|
||||
subscription.IncrementAPIUsage(1)
|
||||
@@ -193,7 +193,7 @@ func (s *ApiApplicationServiceImpl) CallApi(ctx context.Context, cmd *commands.A
|
||||
apiCall.Cost = &subscription.Price
|
||||
|
||||
// 10. 标记成功
|
||||
apiCall.MarkSuccess(encryptedResponse, subscription.Price)
|
||||
apiCall.MarkSuccess(subscription.Price)
|
||||
return nil
|
||||
})
|
||||
|
||||
@@ -392,6 +392,8 @@ func (s *ApiApplicationServiceImpl) GetUserApiCalls(ctx context.Context, userID
|
||||
}
|
||||
if call.ErrorMsg != nil {
|
||||
item.ErrorMsg = call.ErrorMsg
|
||||
// 添加翻译后的错误信息
|
||||
item.TranslatedErrorMsg = utils.TranslateErrorMsg(call.ErrorType, call.ErrorMsg)
|
||||
}
|
||||
|
||||
items = append(items, item)
|
||||
|
||||
Reference in New Issue
Block a user