diff --git a/controllers/api_getcard.go b/controllers/api_getcard.go index b174cc8..8fce360 100644 --- a/controllers/api_getcard.go +++ b/controllers/api_getcard.go @@ -33,9 +33,9 @@ var validModules = map[string]bool{ } func (c *ApiGetCardController) cardErr(httpStatus, code int, msg string) { - c.Ctx.Output.SetStatus(httpStatus) + c.Ctx.Output.SetStatus(200) c.Ctx.Output.Header("Content-Type", "text/plain; charset=utf-8") - _ = c.Ctx.Output.Body([]byte(msg)) + _ = c.Ctx.Output.Body([]byte("error:" + msg)) } func (c *ApiGetCardController) cardOK(text string) { diff --git a/controllers/platform_account_pool.go b/controllers/platform_account_pool.go index 8aae92c..7d45f14 100644 --- a/controllers/platform_account_pool.go +++ b/controllers/platform_account_pool.go @@ -462,6 +462,104 @@ func extractPoolRow(c *beego.Controller, module string) { _ = c.ServeJSON() } +func replenishPoolRow(c *beego.Controller, module string) { + if _, err := requirePlatformAuth(c); err != nil { + poolJSONErr(c, 401, 401, err.Error()) + return + } + raw, err := io.ReadAll(c.Ctx.Request.Body) + if err != nil { + poolJSONErr(c, 400, 400, "参数错误") + return + } + var payload struct { + Type string `json:"type"` + Platform string `json:"platform"` + Remark string `json:"remark"` + } + if err := json.Unmarshal(raw, &payload); err != nil { + poolJSONErr(c, 400, 400, "参数错误") + return + } + if !isValidPoolType(payload.Type) { + poolJSONErr(c, 400, 400, "账号类型不正确") + return + } + validPlatforms := map[string]bool{"local": true, "xianyu": true, "pinduoduo": true, "jingdong": true, "douyin": true} + if !validPlatforms[payload.Platform] { + poolJSONErr(c, 400, 400, "提取平台错误") + return + } + + now := time.Now() + platform := payload.Platform + remark := strings.TrimSpace(payload.Remark) + + switch module { + case "cursor": + var row models.PlatformAccountPoolCursor + if err := models.Orm.QueryTable(new(models.PlatformAccountPoolCursor)). + Filter("is_extracted", 0).Filter("data_type", payload.Type). + OrderBy("id").One(&row); err != nil { + poolJSONErr(c, 404, 404, "暂无可用账号") + return + } + if _, err = models.Orm.QueryTable(new(models.PlatformAccountPoolCursor)).Filter("id", row.ID).Update(map[string]interface{}{ + "is_extracted": 1, "extracted_time": now, "extracted_platform": platform, "remark": remark, + }); err != nil { + poolJSONErr(c, 500, 500, "补号失败: "+err.Error()) + return + } + row.IsExtracted = 1 + row.ExtractedTime = &now + row.ExtractedPlatform = &platform + row.Remark = remark + c.Data["json"] = map[string]interface{}{"code": 200, "msg": "补号成功", "data": row} + case "windsurf": + var row models.PlatformAccountPoolWindsurf + if err := models.Orm.QueryTable(new(models.PlatformAccountPoolWindsurf)). + Filter("is_extracted", 0).Filter("data_type", payload.Type). + OrderBy("id").One(&row); err != nil { + poolJSONErr(c, 404, 404, "暂无可用账号") + return + } + if _, err = models.Orm.QueryTable(new(models.PlatformAccountPoolWindsurf)).Filter("id", row.ID).Update(map[string]interface{}{ + "is_extracted": 1, "extracted_time": now, "extracted_platform": platform, "remark": remark, + }); err != nil { + poolJSONErr(c, 500, 500, "补号失败: "+err.Error()) + return + } + row.IsExtracted = 1 + row.ExtractedTime = &now + row.ExtractedPlatform = &platform + row.Remark = remark + c.Data["json"] = map[string]interface{}{"code": 200, "msg": "补号成功", "data": row} + case "krio": + var row models.PlatformAccountPoolKiro + if err := models.Orm.QueryTable(new(models.PlatformAccountPoolKiro)). + Filter("is_extracted", 0).Filter("data_type", payload.Type). + OrderBy("id").One(&row); err != nil { + poolJSONErr(c, 404, 404, "暂无可用账号") + return + } + if _, err = models.Orm.QueryTable(new(models.PlatformAccountPoolKiro)).Filter("id", row.ID).Update(map[string]interface{}{ + "is_extracted": 1, "extracted_time": now, "extracted_platform": platform, "remark": remark, + }); err != nil { + poolJSONErr(c, 500, 500, "补号失败: "+err.Error()) + return + } + row.IsExtracted = 1 + row.ExtractedTime = &now + row.ExtractedPlatform = &platform + row.Remark = remark + c.Data["json"] = map[string]interface{}{"code": 200, "msg": "补号成功", "data": row} + default: + poolJSONErr(c, 400, 400, "无效模块") + return + } + _ = c.ServeJSON() +} + func updatePoolRemark(c *beego.Controller, module string) { if _, err := requirePlatformAuth(c); err != nil { poolJSONErr(c, 401, 401, err.Error()) @@ -517,6 +615,7 @@ func (c *PlatformAccountPoolCursorController) Add() { addPoolRow(&c.Control func (c *PlatformAccountPoolCursorController) BatchAdd() { batchAddPoolRows(&c.Controller, "cursor") } func (c *PlatformAccountPoolCursorController) Detail() { getPoolDetail(&c.Controller, "cursor") } func (c *PlatformAccountPoolCursorController) Extract() { extractPoolRow(&c.Controller, "cursor") } +func (c *PlatformAccountPoolCursorController) Replenish() { replenishPoolRow(&c.Controller, "cursor") } func (c *PlatformAccountPoolCursorController) UpdateRemark() { updatePoolRemark(&c.Controller, "cursor") } @@ -526,6 +625,7 @@ func (c *PlatformAccountPoolWindsurfController) Add() { addPoolRow(&c.Contr func (c *PlatformAccountPoolWindsurfController) BatchAdd() { batchAddPoolRows(&c.Controller, "windsurf") } func (c *PlatformAccountPoolWindsurfController) Detail() { getPoolDetail(&c.Controller, "windsurf") } func (c *PlatformAccountPoolWindsurfController) Extract() { extractPoolRow(&c.Controller, "windsurf") } +func (c *PlatformAccountPoolWindsurfController) Replenish() { replenishPoolRow(&c.Controller, "windsurf") } func (c *PlatformAccountPoolWindsurfController) UpdateRemark() { updatePoolRemark(&c.Controller, "windsurf") } @@ -535,6 +635,7 @@ func (c *PlatformAccountPoolKrioController) Add() { addPoolRow(&c.Controlle func (c *PlatformAccountPoolKrioController) BatchAdd() { batchAddPoolRows(&c.Controller, "krio") } func (c *PlatformAccountPoolKrioController) Detail() { getPoolDetail(&c.Controller, "krio") } func (c *PlatformAccountPoolKrioController) Extract() { extractPoolRow(&c.Controller, "krio") } +func (c *PlatformAccountPoolKrioController) Replenish() { replenishPoolRow(&c.Controller, "krio") } func (c *PlatformAccountPoolKrioController) UpdateRemark() { updatePoolRemark(&c.Controller, "krio") } diff --git a/routers/platform/platform.go b/routers/platform/platform.go index 7a9cd7f..36ca890 100644 --- a/routers/platform/platform.go +++ b/routers/platform/platform.go @@ -165,6 +165,7 @@ func Register() { beego.Router("/platform/accountPool/cursor/detail/:id", &controllers.PlatformAccountPoolCursorController{}, "get:Detail") beego.Router("/platform/accountPool/cursor/extract", &controllers.PlatformAccountPoolCursorController{}, "post:Extract") beego.Router("/platform/accountPool/cursor/updateRemark", &controllers.PlatformAccountPoolCursorController{}, "post:UpdateRemark") + beego.Router("/platform/accountPool/cursor/replenish", &controllers.PlatformAccountPoolCursorController{}, "post:Replenish") beego.Router("/platform/accountPool/windsurf/list", &controllers.PlatformAccountPoolWindsurfController{}, "get:List") beego.Router("/platform/accountPool/windsurf/add", &controllers.PlatformAccountPoolWindsurfController{}, "post:Add") @@ -172,6 +173,7 @@ func Register() { beego.Router("/platform/accountPool/windsurf/detail/:id", &controllers.PlatformAccountPoolWindsurfController{}, "get:Detail") beego.Router("/platform/accountPool/windsurf/extract", &controllers.PlatformAccountPoolWindsurfController{}, "post:Extract") beego.Router("/platform/accountPool/windsurf/updateRemark", &controllers.PlatformAccountPoolWindsurfController{}, "post:UpdateRemark") + beego.Router("/platform/accountPool/windsurf/replenish", &controllers.PlatformAccountPoolWindsurfController{}, "post:Replenish") beego.Router("/platform/accountPool/krio/list", &controllers.PlatformAccountPoolKrioController{}, "get:List") beego.Router("/platform/accountPool/krio/add", &controllers.PlatformAccountPoolKrioController{}, "post:Add") @@ -179,4 +181,5 @@ func Register() { beego.Router("/platform/accountPool/krio/detail/:id", &controllers.PlatformAccountPoolKrioController{}, "get:Detail") beego.Router("/platform/accountPool/krio/extract", &controllers.PlatformAccountPoolKrioController{}, "post:Extract") beego.Router("/platform/accountPool/krio/updateRemark", &controllers.PlatformAccountPoolKrioController{}, "post:UpdateRemark") + beego.Router("/platform/accountPool/krio/replenish", &controllers.PlatformAccountPoolKrioController{}, "post:Replenish") }