diff --git a/controllers/platform_home.go b/controllers/platform_home.go index 96dc012..2d3943b 100644 --- a/controllers/platform_home.go +++ b/controllers/platform_home.go @@ -188,3 +188,68 @@ func int64SliceToInt(in []int64) []int { } return out } + +func countPoolInventory(mi interface{}, soldOnly bool) (int64, error) { + qs := models.Orm.QueryTable(mi).Filter("delete_time__isnull", true) + if soldOnly { + qs = qs.Filter("is_extracted__in", 1, 2) + } + n, err := qs.Count() + return n, err +} + +// AccountPoolInventoryTotals GET /platform/home/accountPoolInventoryTotals +// 各号池:账号总数(未删)、已售卖(is_extracted 为 1 或 2) +func (c *PlatformHomeController) AccountPoolInventoryTotals() { + if _, err := requirePlatformAuth(&c.Controller); err != nil { + poolJSONErr(&c.Controller, 401, 401, err.Error()) + return + } + + type invModule struct { + Key string `json:"key"` + Label string `json:"label"` + Total int64 `json:"total"` + Sold int64 `json:"sold"` + } + + modules := []invModule{ + {Key: "cursor", Label: "Cursor"}, + {Key: "krio", Label: "Kiro"}, + {Key: "windsurf", Label: "Windsurf"}, + } + modelsList := []interface{}{ + new(models.PlatformAccountPoolCursor), + new(models.PlatformAccountPoolKiro), + new(models.PlatformAccountPoolWindsurf), + } + + var grandTotal, grandSold int64 + for i := range modules { + tot, err := countPoolInventory(modelsList[i], false) + if err != nil { + poolJSONErr(&c.Controller, 500, 500, "统计失败: "+err.Error()) + return + } + sd, err := countPoolInventory(modelsList[i], true) + if err != nil { + poolJSONErr(&c.Controller, 500, 500, "统计失败: "+err.Error()) + return + } + modules[i].Total = tot + modules[i].Sold = sd + grandTotal += tot + grandSold += sd + } + + c.Data["json"] = map[string]interface{}{ + "code": 200, + "msg": "success", + "data": map[string]interface{}{ + "modules": modules, + "grandTotal": grandTotal, + "grandSold": grandSold, + }, + } + _ = c.ServeJSON() +} diff --git a/routers/platform/platform.go b/routers/platform/platform.go index 3783a3e..bfd4481 100644 --- a/routers/platform/platform.go +++ b/routers/platform/platform.go @@ -160,6 +160,7 @@ func Register() { // 首页统计 beego.Router("/platform/home/accountPoolDailyExtract", &controllers.PlatformHomeController{}, "get:AccountPoolDailyExtract") + beego.Router("/platform/home/accountPoolInventoryTotals", &controllers.PlatformHomeController{}, "get:AccountPoolInventoryTotals") // 账号池管理(cursor/windsurf/krio) beego.Router("/platform/accountPool/cursor/list", &controllers.PlatformAccountPoolCursorController{}, "get:List") diff --git a/server.exe b/server.exe index b2cc4f5..8d3d1d4 100644 Binary files a/server.exe and b/server.exe differ