Files
yunzerwebsiteallinone/go/controllers/backend_tenant_quota.go
T
2026-09-16 00:22:17 +08:00

66 lines
1.9 KiB
Go

package controllers
import (
"server/services"
beego "github.com/beego/beego/v2/server/web"
)
// BackendTenantQuotaController 租户端「用户数配额」信息(只读)
// 供租户端用户管理页展示「已用/上限」;增购由平台端操作。
type BackendTenantQuotaController struct {
beego.Controller
}
// GetQuotaInfo GET /backend/tenant/quotaInfo
// 返回当前登录租户的用户数使用情况与生效套餐。
func (c *BackendTenantQuotaController) GetQuotaInfo() {
tid := backendJWTTenantID(c.Ctx.Request.Header.Get("Authorization"))
if tid == 0 {
// 兜底:从 tid 参数取(部分历史调用未带 token 场景)
if v, err := c.GetUint64("tid"); err == nil {
tid = v
}
}
if tid == 0 {
c.Data["json"] = map[string]interface{}{"code": 401, "msg": "未登录或非法请求"}
_ = c.ServeJSON()
return
}
info, err := services.GetTenantQuotaInfo(tid)
if err != nil {
c.Data["json"] = map[string]interface{}{"code": 404, "msg": "租户不存在"}
_ = c.ServeJSON()
return
}
modules, _ := services.GetTenantPackageModules(tid)
moduleCodes := make([]string, 0, len(modules))
moduleNames := make([]string, 0, len(modules))
for _, m := range modules {
moduleCodes = append(moduleCodes, m.ModuleCode)
moduleNames = append(moduleNames, m.ModuleName)
}
c.Data["json"] = map[string]interface{}{
"code": 200,
"msg": "success",
"data": map[string]interface{}{
"tid": info.Tid,
"package_id": info.EffectivePackageID,
"package_name": info.PackageName,
"quota": info.Quota,
"used": info.Used,
"remaining": info.Remaining,
"extra_user_price": info.ExtraUserPrice,
"duration_days": info.DurationDays,
"package_expire_time": info.PackageExpireTime,
"days_remaining": info.DaysRemaining,
"module_codes": moduleCodes,
"module_names": moduleNames,
},
}
_ = c.ServeJSON()
}