阶段更新

This commit is contained in:
2026-07-14 10:09:24 +08:00
parent 3da6718729
commit cc9f6c4d71
13 changed files with 1262 additions and 446 deletions
+396
View File
@@ -0,0 +1,396 @@
package controllers
import (
"strconv"
"strings"
"server/models"
"github.com/beego/beego/v2/client/orm"
beego "github.com/beego/beego/v2/server/web"
)
// IndexPortalController 前台门户及租户官网公共接口(无需登录)
type IndexPortalController struct {
beego.Controller
}
// getTidByHost 根据访问域名识别租户 ID,默认返回 1
func (c *IndexPortalController) getTidByHost() uint64 {
host := c.Ctx.Request.Host
parts := strings.Split(host, ":")
domain := parts[0]
if domain == "localhost" || domain == "127.0.0.1" {
return 1 // 开发环境默认租户
}
var td models.SystemTenantDomain
err := models.Orm.QueryTable(new(models.SystemTenantDomain)).
Filter("full_domain", domain).
Filter("status", 1).
Filter("delete_time__isnull", true).
One(&td)
if err == nil && td.Tid != nil {
return *td.Tid
}
return 1 // 默认租户
}
// GetHeadMenu GET /index/headmenu
func (c *IndexPortalController) GetHeadMenu() {
// 前台的静态导航菜单结构
menuData := []map[string]interface{}{
{
"id": 1,
"title": "首页",
"path": "/",
"type": 2,
},
{
"id": 2,
"title": "解决方案",
"path": "/solutions",
"type": 2,
"children": []map[string]interface{}{
{
"id": 21,
"title": "行业解决方案",
"path": "/solutions/solution",
"type": 2,
},
{
"id": 22,
"title": "成功案例",
"path": "/solutions/successCases",
"type": 2,
},
},
},
{
"id": 3,
"title": "新闻中心",
"path": "/newsCenter",
"type": 2,
"children": []map[string]interface{}{
{
"id": 31,
"title": "站点新闻",
"path": "/newsCenter/news",
"type": 2,
},
{
"id": 32,
"title": "站点公告",
"path": "/newsCenter/announcement",
"type": 2,
},
{
"id": 33,
"title": "技术中心",
"path": "/newsCenter/technologyCenter",
"type": 2,
},
},
},
}
c.Data["json"] = map[string]interface{}{
"code": 200,
"msg": "success",
"data": menuData,
}
_ = c.ServeJSON()
}
// GetFooterData GET /index/footerdata
func (c *IndexPortalController) GetFooterData() {
tid := c.getTidByHost()
// 准备默认的 Footer 配置数据
footerMap := map[string]string{
"sitename": "云泽官方网站",
"companyname": "云泽智能科技有限公司",
"copyright": "Copyright © 2026 Yunzer. All Rights Reserved.",
"icp": "苏ICP备2026000000号-1",
"description": "专业为企业建设数字化管理与官网门户的一站式 SaaS 服务平台",
"logo": "",
"logow": "",
"ico": "",
}
// 尝试从租户站点设置表中查询最新的配置
var rows []models.TenantSiteSetting
_, err := models.Orm.QueryTable(new(models.TenantSiteSetting)).
Filter("tid", tid).
Filter("delete_time__isnull", true).
Limit(1).
All(&rows)
if err == nil && len(rows) > 0 {
r := rows[0]
if r.Sitename != "" {
footerMap["sitename"] = r.Sitename
}
if r.Companyname != "" {
footerMap["companyname"] = r.Companyname
}
if r.Copyright != "" {
footerMap["copyright"] = r.Copyright
}
if r.Icp != "" {
footerMap["icp"] = r.Icp
}
if r.Description != "" {
footerMap["description"] = r.Description
}
footerMap["logo"] = r.Logo
footerMap["logow"] = r.Logow
footerMap["ico"] = r.Ico
}
// 将 Map 转换为前端需要的 [{label: "...", value: "..."}] 数组格式
var dataList []map[string]string
for k, v := range footerMap {
dataList = append(dataList, map[string]string{
"label": k,
"value": v,
})
}
c.Data["json"] = map[string]interface{}{
"code": 200,
"msg": "success",
"data": dataList,
}
_ = c.ServeJSON()
}
// GetNewsCenterTop4 GET /index/newscentertop4
func (c *IndexPortalController) GetNewsCenterTop4() {
tid := c.getTidByHost()
_ = models.EnsureCmsArticleTables()
var articles []models.CmsArticle
_, err := models.Orm.QueryTable(new(models.CmsArticle)).
Filter("tid", tid).
Filter("status", 1).
Filter("delete_time__isnull", true).
OrderBy("-top", "-recommend", "-id").
Limit(4).
All(&articles)
if err != nil {
c.Data["json"] = map[string]interface{}{"code": 200, "data": []interface{}{}}
_ = c.ServeJSON()
return
}
c.Data["json"] = map[string]interface{}{
"code": 200,
"msg": "success",
"data": articles,
}
_ = c.ServeJSON()
}
// queryCmsArticles 统一的分页查询文章辅助方法
func (c *IndexPortalController) queryCmsArticles(categoryName string, categoryID int64) {
tid := c.getTidByHost()
_ = models.EnsureCmsArticleTables()
page, _ := c.GetInt("page", 1)
limit, _ := c.GetInt("limit", 10)
if page < 1 {
page = 1
}
if limit < 1 {
limit = 10
}
qs := models.Orm.QueryTable(new(models.CmsArticle)).
Filter("tid", tid).
Filter("status", 1).
Filter("delete_time__isnull", true)
// 如果有传具体的分类 ID
if categoryID > 0 {
qs = qs.Filter("cate_id", categoryID)
}
total, _ := qs.Count()
var articles []models.CmsArticle
_, err := qs.OrderBy("-top", "-id").
Limit(limit, (page-1)*limit).
All(&articles)
if err != nil {
c.Data["json"] = map[string]interface{}{
"code": 200,
"data": map[string]interface{}{
"list": []interface{}{},
"total": 0,
},
}
_ = c.ServeJSON()
return
}
c.Data["json"] = map[string]interface{}{
"code": 200,
"msg": "success",
"data": map[string]interface{}{
"list": articles,
"total": total,
},
}
_ = c.ServeJSON()
}
// GetCompanyNews GET /index/companynews
func (c *IndexPortalController) GetCompanyNews() {
// 可根据实际需要分配固定的分类 ID
c.queryCmsArticles("companynews", 0)
}
// GetKingdeeNews GET /index/kingdeenews
func (c *IndexPortalController) GetKingdeeNews() {
c.queryCmsArticles("kingdeenews", 0)
}
// GetTechnologyCenter GET /index/technologyCenter
func (c *IndexPortalController) GetTechnologyCenter() {
categoryID, _ := c.GetInt64("category_id", 0)
c.queryCmsArticles("technologyCenter", categoryID)
}
// GetTechnologyCategories GET /index/technologyCategories
func (c *IndexPortalController) GetTechnologyCategories() {
tid := c.getTidByHost()
_ = models.EnsureCmsArticleTables()
var categories []models.CmsArticleCategory
_, err := models.Orm.QueryTable(new(models.CmsArticleCategory)).
Filter("tid", tid).
Filter("status", 1).
Filter("delete_time__isnull", true).
OrderBy("sort", "id").
All(&categories)
if err != nil {
c.Data["json"] = map[string]interface{}{"code": 200, "data": []interface{}{}}
_ = c.ServeJSON()
return
}
c.Data["json"] = map[string]interface{}{
"code": 200,
"msg": "success",
"data": categories,
}
_ = c.ServeJSON()
}
// GetCompanyNewsDetail GET /index/companynews/detail/:id
func (c *IndexPortalController) GetCompanyNewsDetail() {
c.getArticleDetail()
}
// GetKingdeeNewsDetail GET /index/kingdeenews/detail/:id
func (c *IndexPortalController) GetKingdeeNewsDetail() {
c.getArticleDetail()
}
// getArticleDetail 查询文章详情的内部辅助方法
func (c *IndexPortalController) getArticleDetail() {
idStr := c.Ctx.Input.Param(":id")
id, _ := strconv.ParseUint(idStr, 10, 64)
tid := c.getTidByHost()
_ = models.EnsureCmsArticleTables()
var article models.CmsArticle
err := models.Orm.QueryTable(new(models.CmsArticle)).
Filter("id", id).
Filter("tid", tid).
Filter("delete_time__isnull", true).
One(&article)
if err != nil {
c.Data["json"] = map[string]interface{}{"code": 404, "msg": "文章不存在"}
_ = c.ServeJSON()
return
}
c.Data["json"] = map[string]interface{}{
"code": 200,
"msg": "success",
"data": article,
}
_ = c.ServeJSON()
}
// AddLike POST /index/articleLikes/:id
func (c *IndexPortalController) AddLike() {
idStr := c.Ctx.Input.Param(":id")
id, _ := strconv.ParseUint(idStr, 10, 64)
tid := c.getTidByHost()
_ = models.EnsureCmsArticleTables()
_, _ = models.Orm.QueryTable(new(models.CmsArticle)).
Filter("id", id).
Filter("tid", tid).
Update(orm.Params{
"likes": orm.ColValue(orm.ColAdd, 1),
})
c.Data["json"] = map[string]interface{}{"code": 200, "msg": "点赞成功"}
_ = c.ServeJSON()
}
// ReduceLike POST /index/articleUnlikes/:id
func (c *IndexPortalController) ReduceLike() {
idStr := c.Ctx.Input.Param(":id")
id, _ := strconv.ParseUint(idStr, 10, 64)
tid := c.getTidByHost()
_ = models.EnsureCmsArticleTables()
_, _ = models.Orm.QueryTable(new(models.CmsArticle)).
Filter("id", id).
Filter("tid", tid).
Filter("likes__gt", 0).
Update(orm.Params{
"likes": orm.ColValue(orm.ColMinus, 1),
})
c.Data["json"] = map[string]interface{}{"code": 200, "msg": "已取消点赞"}
_ = c.ServeJSON()
}
// AddViews POST /index/views/:id
func (c *IndexPortalController) AddViews() {
idStr := c.Ctx.Input.Param(":id")
id, _ := strconv.ParseUint(idStr, 10, 64)
tid := c.getTidByHost()
_ = models.EnsureCmsArticleTables()
_, _ = models.Orm.QueryTable(new(models.CmsArticle)).
Filter("id", id).
Filter("tid", tid).
Update(orm.Params{
"views": orm.ColValue(orm.ColAdd, 1),
})
c.Data["json"] = map[string]interface{}{"code": 200, "msg": "阅读量+1"}
_ = c.ServeJSON()
}
// GetOnePageByPath GET /index/onepage/:path
func (c *IndexPortalController) GetOnePageByPath() {
// 简单返回空数据,防止前端单页接口报错
c.Data["json"] = map[string]interface{}{
"code": 200,
"msg": "success",
"data": nil,
}
_ = c.ServeJSON()
}
+144 -9
View File
@@ -401,41 +401,168 @@ func batchAddPoolRows(c *beego.Controller, module string) {
return
}
}
var accounts []string
var tokens []string
seenAccs := make(map[string]bool)
seenTks := make(map[string]bool)
for _, row := range payload.Rows {
acc := strings.TrimSpace(row.Account)
tk := strings.TrimSpace(row.Token)
if acc != "" && !seenAccs[acc] {
seenAccs[acc] = true
accounts = append(accounts, acc)
}
if tk != "" && !seenTks[tk] {
seenTks[tk] = true
tokens = append(tokens, tk)
}
}
existingAccs := make(map[string]bool)
existingTks := make(map[string]bool)
if len(accounts) > 0 || len(tokens) > 0 {
condObj := orm.NewCondition()
subCond := orm.NewCondition()
if len(accounts) > 0 {
subCond = subCond.Or("account__in", accounts)
}
if len(tokens) > 0 {
subCond = subCond.Or("token__in", tokens)
}
switch module {
case "cursor":
var dbRows []models.PlatformAccountPoolCursor
cond := models.Orm.QueryTable(new(models.PlatformAccountPoolCursor)).Filter("delete_time__isnull", true)
cond = cond.SetCond(condObj.AndCond(subCond))
if _, err := cond.All(&dbRows, "account", "token"); err == nil {
for _, r := range dbRows {
if r.Account != "" {
existingAccs[r.Account] = true
}
if r.Token != "" {
existingTks[r.Token] = true
}
}
}
case "windsurf":
var dbRows []models.PlatformAccountPoolWindsurf
cond := models.Orm.QueryTable(new(models.PlatformAccountPoolWindsurf)).Filter("delete_time__isnull", true)
cond = cond.SetCond(condObj.AndCond(subCond))
if _, err := cond.All(&dbRows, "account", "token"); err == nil {
for _, r := range dbRows {
if r.Account != "" {
existingAccs[r.Account] = true
}
if r.Token != "" {
existingTks[r.Token] = true
}
}
}
case "krio":
var dbRows []models.PlatformAccountPoolKiro
cond := models.Orm.QueryTable(new(models.PlatformAccountPoolKiro)).Filter("delete_time__isnull", true)
cond = cond.SetCond(condObj.AndCond(subCond))
if _, err := cond.All(&dbRows, "account", "token"); err == nil {
for _, r := range dbRows {
if r.Account != "" {
existingAccs[r.Account] = true
}
if r.Token != "" {
existingTks[r.Token] = true
}
}
}
case "codex":
var dbRows []models.PlatformAccountPoolCodex
cond := models.Orm.QueryTable(new(models.PlatformAccountPoolCodex)).Filter("delete_time__isnull", true)
cond = cond.SetCond(condObj.AndCond(subCond))
if _, err := cond.All(&dbRows, "account", "token"); err == nil {
for _, r := range dbRows {
if r.Account != "" {
existingAccs[r.Account] = true
}
if r.Token != "" {
existingTks[r.Token] = true
}
}
}
}
}
insertedAccs := make(map[string]bool)
insertedTks := make(map[string]bool)
var successCount int
var duplicateCount int
for _, row := range payload.Rows {
acc := strings.TrimSpace(row.Account)
tk := strings.TrimSpace(row.Token)
isDuplicate := false
if row.DataType == "account" {
if existingAccs[acc] || insertedAccs[acc] {
isDuplicate = true
}
} else if row.DataType == "tk" {
if existingTks[tk] || insertedTks[tk] {
isDuplicate = true
}
} else if row.DataType == "account_tk" {
if (acc != "" && (existingAccs[acc] || insertedAccs[acc])) || (tk != "" && (existingTks[tk] || insertedTks[tk])) {
isDuplicate = true
}
}
if isDuplicate {
duplicateCount++
continue
}
if acc != "" {
insertedAccs[acc] = true
}
if tk != "" {
insertedTks[tk] = true
}
switch module {
case "cursor":
_, err = models.Orm.Insert(&models.PlatformAccountPoolCursor{
DataType: strings.TrimSpace(row.DataType),
Account: strings.TrimSpace(row.Account),
Account: acc,
Password: strings.TrimSpace(row.Password),
Token: strings.TrimSpace(row.Token),
Token: tk,
Remark: strings.TrimSpace(row.Remark),
IsExtracted: 0,
})
case "windsurf":
_, err = models.Orm.Insert(&models.PlatformAccountPoolWindsurf{
DataType: strings.TrimSpace(row.DataType),
Account: strings.TrimSpace(row.Account),
Account: acc,
Password: strings.TrimSpace(row.Password),
Token: strings.TrimSpace(row.Token),
Token: tk,
Remark: strings.TrimSpace(row.Remark),
IsExtracted: 0,
})
case "krio":
_, err = models.Orm.Insert(&models.PlatformAccountPoolKiro{
DataType: strings.TrimSpace(row.DataType),
Account: strings.TrimSpace(row.Account),
Account: acc,
Password: strings.TrimSpace(row.Password),
Token: strings.TrimSpace(row.Token),
Token: tk,
Remark: strings.TrimSpace(row.Remark),
IsExtracted: 0,
})
case "codex":
_, err = models.Orm.Insert(&models.PlatformAccountPoolCodex{
DataType: strings.TrimSpace(row.DataType),
Account: strings.TrimSpace(row.Account),
Account: acc,
Password: strings.TrimSpace(row.Password),
Token: strings.TrimSpace(row.Token),
Token: tk,
Remark: strings.TrimSpace(row.Remark),
IsExtracted: 0,
})
@@ -447,8 +574,16 @@ func batchAddPoolRows(c *beego.Controller, module string) {
poolJSONErr(c, 500, 500, "批量添加失败: "+err.Error())
return
}
successCount++
}
c.Data["json"] = map[string]interface{}{
"code": 200,
"msg": "批量添加成功",
"data": map[string]interface{}{
"success_count": successCount,
"duplicate_count": duplicateCount,
},
}
c.Data["json"] = map[string]interface{}{"code": 200, "msg": "批量添加成功"}
_ = c.ServeJSON()
}
+24 -7
View File
@@ -1,7 +1,24 @@
package index
// Register 注册前端站点(index)路由。
// 建议统一使用 /index/* 或根路径,根据后续设计补充。
func Register() {
}
package index
import (
"server/controllers"
beego "github.com/beego/beego/v2/server/web"
)
// Register 注册前端站点(index)路由。
func Register() {
beego.Router("/index/headmenu", &controllers.IndexPortalController{}, "get:GetHeadMenu")
beego.Router("/index/footerdata", &controllers.IndexPortalController{}, "get:GetFooterData")
beego.Router("/index/newscentertop4", &controllers.IndexPortalController{}, "get:GetNewsCenterTop4")
beego.Router("/index/companynews", &controllers.IndexPortalController{}, "get:GetCompanyNews")
beego.Router("/index/kingdeenews", &controllers.IndexPortalController{}, "get:GetKingdeeNews")
beego.Router("/index/technologyCenter", &controllers.IndexPortalController{}, "get:GetTechnologyCenter")
beego.Router("/index/technologyCategories", &controllers.IndexPortalController{}, "get:GetTechnologyCategories")
beego.Router("/index/companynews/detail/:id", &controllers.IndexPortalController{}, "get:GetCompanyNewsDetail")
beego.Router("/index/kingdeenews/detail/:id", &controllers.IndexPortalController{}, "get:GetKingdeeNewsDetail")
beego.Router("/index/articleLikes/:id", &controllers.IndexPortalController{}, "post:AddLike")
beego.Router("/index/articleUnlikes/:id", &controllers.IndexPortalController{}, "post:ReduceLike")
beego.Router("/index/views/:id", &controllers.IndexPortalController{}, "post:AddViews")
beego.Router("/index/onepage/:path", &controllers.IndexPortalController{}, "get:GetOnePageByPath")
}