You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.0 KiB
49 lines
1.0 KiB
// Code scaffolded by goctl. Safe to edit.
|
|
// goctl 1.9.2
|
|
|
|
package ai
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"github.com/youruser/base/internal/svc"
|
|
"github.com/youruser/base/internal/types"
|
|
"github.com/youruser/base/model"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type AiQuotaMeLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
// 获取我的配额
|
|
func NewAiQuotaMeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AiQuotaMeLogic {
|
|
return &AiQuotaMeLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *AiQuotaMeLogic) AiQuotaMe() (resp *types.AIQuotaInfo, err error) {
|
|
userId, _ := l.ctx.Value("userId").(int64)
|
|
if userId == 0 {
|
|
return nil, errors.New("unauthorized")
|
|
}
|
|
|
|
quota, err := model.AIUserQuotaEnsure(l.ctx, l.svcCtx.DB, userId)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &types.AIQuotaInfo{
|
|
Balance: quota.Balance,
|
|
TotalRecharged: quota.TotalRecharged,
|
|
TotalConsumed: quota.TotalConsumed,
|
|
FrozenAmount: quota.FrozenAmount,
|
|
}, nil
|
|
}
|
|
|