- 删 CheckTenantBalance/DeductBalance/GetTenantSurplus(admin-go 租户余额退出 model-gateway) - 新增 pricing_client.go:门禁 config/get + calcModelCost 调 shop-user-trade /calc 算费 - sync/stream/async 三处 Cost 改为按用量调 /calc(媒体类型映射 text/audio/video/image) - 删 price.go 本地 PriceConfig 换算体系与 entity/dto 的 price_config 字段 Co-Authored-By: Claude <noreply@anthropic.com>
64 lines
2.1 KiB
Go
64 lines
2.1 KiB
Go
package service
|
||
|
||
import (
|
||
"context"
|
||
"model-gateway/model/dto"
|
||
|
||
commonHttp "gitea.redpowerfuture.com/red-future/common/http"
|
||
"gitea.redpowerfuture.com/red-future/common/oss"
|
||
"gitea.redpowerfuture.com/red-future/common/utils"
|
||
"github.com/gogf/gf/v2/frame/g"
|
||
"github.com/gogf/gf/v2/util/gconv"
|
||
)
|
||
|
||
// IsSuperAdmin 调用admin-go服务检查是否是管理员
|
||
func IsSuperAdmin(ctx context.Context) (res bool, err error) {
|
||
headers := setCtxHeader(ctx)
|
||
var r = make(map[string]bool)
|
||
if err = commonHttp.Get(ctx, "admin-go/api/v1/system/user/checkIsSuperAdmin", headers, &r); err != nil {
|
||
return false, err
|
||
}
|
||
return r["isSuperAdmin"], err
|
||
}
|
||
|
||
// Upload 上传文件到 OSS。统一走 common/oss(multipart field=file、X-User-Info 三态注入与旧 setCtxHeader 等价)。
|
||
func Upload(ctx context.Context, req *dto.UploadFileBytesReq) (*dto.UploadFileBytesRes, error) {
|
||
res, err := oss.UploadFileBytes(ctx, req.FileName, req.FileBytes)
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
return &dto.UploadFileBytesRes{
|
||
FileURL: res.FileURL,
|
||
FileSize: res.FileSize,
|
||
FileName: res.FileName,
|
||
FileFormat: res.FileFormat,
|
||
FileAddressPrefix: res.FileAddressPrefix,
|
||
}, nil
|
||
}
|
||
|
||
// setCtxHeader 构造调用方请求头透传(X-User-Info 三态注入):
|
||
// 1. 透传 HTTP 请求头(含 Authorization/X-User-Info)
|
||
// 2. ctx 无请求头时,用任务体注入的 user(异步任务 Creator/TenantId)生成 X-User-Info
|
||
// 3. 仍为空时,解析调用方 token 得到用户生成 X-User-Info(直连场景归属校验)
|
||
func setCtxHeader(ctx context.Context) map[string]string {
|
||
headers := make(map[string]string)
|
||
if r := g.RequestFromCtx(ctx); r != nil {
|
||
for k, v := range r.Request.Header {
|
||
if len(v) > 0 {
|
||
headers[k] = v[0]
|
||
}
|
||
}
|
||
}
|
||
if headers["X-User-Info"] == "" {
|
||
if user := ctx.Value("user"); !g.IsNil(user) {
|
||
headers["X-User-Info"] = gconv.String(user)
|
||
}
|
||
}
|
||
if headers["X-User-Info"] == "" {
|
||
if user, err := utils.GetUserInfo(ctx); err == nil && user != nil {
|
||
headers["X-User-Info"] = gconv.String(user)
|
||
}
|
||
}
|
||
return headers
|
||
}
|