🎨 新增域名管理功能

This commit is contained in:
2025-09-11 21:03:57 +08:00
parent 2293ee2463
commit 57289a24e7
10 changed files with 209 additions and 0 deletions

105
api/v1/app/domain.go Normal file
View File

@@ -0,0 +1,105 @@
package app
import (
"git.echol.cn/loser/lckt/global"
"git.echol.cn/loser/lckt/model/app"
"git.echol.cn/loser/lckt/model/app/request"
r "git.echol.cn/loser/lckt/model/common/response"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
type DomainApi struct{}
// Create 创建域名
func (d *DomainApi) Create(ctx *gin.Context) {
var p app.Domain
if err := ctx.ShouldBind(&p); err != nil {
global.GVA_LOG.Error("新建域名参数有误", zap.Error(err))
r.FailWithMessage("参数有误", ctx)
return
}
err := domainService.Create(p)
if err != nil {
r.FailWithMessage("创建域名失败", ctx)
return
}
r.OkWithMessage("创建域名成功", ctx)
}
// GetList 获取域名列表
func (d *DomainApi) GetList(ctx *gin.Context) {
var p request.GetDomainList
if err := ctx.ShouldBind(&p); err != nil {
global.GVA_LOG.Error("获取域名列表参数有误", zap.Error(err))
r.FailWithMessage("参数有误", ctx)
return
}
list, total, err := domainService.GetList(p)
if err != nil {
r.FailWithMessage("获取域名列表失败", ctx)
return
}
r.OkWithDetailed(r.PageResult{
List: list,
Total: total,
Page: p.Page,
PageSize: p.PageSize,
}, "获取域名列表成功", ctx)
}
// Update 更新域名
func (d *DomainApi) Update(ctx *gin.Context) {
var p app.Domain
if err := ctx.ShouldBind(&p); err != nil {
global.GVA_LOG.Error("更新域名参数有误", zap.Error(err))
r.FailWithMessage("参数有误", ctx)
return
}
err := domainService.Update(p)
if err != nil {
r.FailWithMessage("更新域名失败", ctx)
return
}
r.OkWithMessage("更新域名成功", ctx)
}
// Delete 删除域名
func (d *DomainApi) Delete(ctx *gin.Context) {
var p app.Domain
if err := ctx.ShouldBind(&p); err != nil {
global.GVA_LOG.Error("删除域名参数有误", zap.Error(err))
r.FailWithMessage("参数有误", ctx)
return
}
err := domainService.Delete(p.ID)
if err != nil {
r.FailWithMessage("删除域名失败", ctx)
return
}
r.OkWithMessage("删除域名成功", ctx)
}
// GetByID 根据ID获取域名
func (d *DomainApi) GetByID(ctx *gin.Context) {
id := ctx.Param("id")
if id == "" {
global.GVA_LOG.Error("获取域名详情参数错误: ID不能为空")
r.FailWithMessage("获取域名详情参数错误: ID不能为空", ctx)
return
}
domain, err := domainService.GetByID(id)
if err != nil {
r.FailWithMessage("获取域名失败", ctx)
return
}
r.OkWithDetailed(domain, "获取域名成功", ctx)
}

View File

@@ -9,6 +9,7 @@ type ApiGroup struct {
TeacherVip
RedeemCodeApi
WithApi
DomainApi
}
var userService = service.ServiceGroupApp.UserServiceGroup.UserService
@@ -18,3 +19,4 @@ var orderService = service.ServiceGroupApp.AppServiceGroup.OrderService
var teacherVipService = service.ServiceGroupApp.AppServiceGroup.TeacherVipService
var redeemCodeService = service.ServiceGroupApp.AppServiceGroup.RedeemCodeService
var withService = service.ServiceGroupApp.AppServiceGroup.WithService
var domainService = service.ServiceGroupApp.AppServiceGroup.DomainService

View File

@@ -88,6 +88,7 @@ func RegisterTables() {
app.CDK{},
app.BalanceLog{},
app.With{},
app.Domain{},
)
if err != nil {
global.GVA_LOG.Error("register table failed", zap.Error(err))

View File

@@ -119,6 +119,7 @@ func Routers() *gin.Engine {
appRouter.InitOrderRouter(AppAuthGroup, PrivateGroup, PublicGroup) // 订单相关路由
appRouter.InitRedeemCodeRouter(AppAuthGroup, PrivateGroup) // 兑换码相关路由
appRouter.InitWithRouter(AppAuthGroup, PrivateGroup)
appRouter.InitDomainRouter(PrivateGroup)
}
//插件路由安装

16
model/app/domain.go Normal file
View File

@@ -0,0 +1,16 @@
package app
import "git.echol.cn/loser/lckt/global"
type Domain struct {
global.GVA_MODEL
Name string `json:"name" gorm:"column:name;comment:域名名称"` // 域名名称
DomainUrl string `json:"domain_url" gorm:"column:domain;comment:域名"` // 域名
Description string `json:"description" gorm:"column:description;comment:域名描述"` // 域名描述
Status int `json:"status" gorm:"column:status;comment:状态 1 启用 2 禁用"` // 状态 1 启用 2 禁用
Type int `json:"type" gorm:"column:type;comment:类型 1 炮灰域名 2 入口域名"` // 类型 1 炮灰域名 2 入口域名
}
func (Domain) TableName() string {
return "app_domain"
}

View File

@@ -0,0 +1,11 @@
package request
import common "git.echol.cn/loser/lckt/model/common/request"
type GetDomainList struct {
common.PageInfo
Name string `json:"name" form:"name"` // 域名名称
Domain string `json:"domain" form:"domain"` // 域名
Status int `json:"status" form:"status"` // 状态 1 启用 2 禁用
Type int `json:"type" form:"type"` // 类型 1 炮灰域名 2 业务域名 3 入口域名
}

17
router/app/domain.go Normal file
View File

@@ -0,0 +1,17 @@
package app
import "github.com/gin-gonic/gin"
type DomainRouter struct{}
func (d *DomainRouter) InitDomainRouter(SysteamRouter *gin.RouterGroup) {
domainRouter := SysteamRouter.Group("domain")
{
domainRouter.POST("", domainApi.Create) // 创建域名
domainRouter.GET("list", domainApi.GetList) // 获取域名列表
domainRouter.GET("/:id", domainApi.GetByID) // 获取域名列表
domainRouter.PUT("", domainApi.Update) // 更新域名
domainRouter.DELETE("", domainApi.Delete) // 删除域名
}
}

View File

@@ -8,6 +8,7 @@ type RouterGroup struct {
OrderRouter
RedeemCodeRouter
WithRouter
DomainRouter
}
var userApi = api.ApiGroupApp.AppApiGroup.AppUserApi
@@ -16,3 +17,4 @@ var orderApi = api.ApiGroupApp.AppApiGroup.OrderApi
var teacherVipApi = api.ApiGroupApp.AppApiGroup.TeacherVip
var redeemCodeApi = api.ApiGroupApp.AppApiGroup.RedeemCodeApi
var withApi = api.ApiGroupApp.AppApiGroup.WithApi
var domainApi = api.ApiGroupApp.AppApiGroup.DomainApi

53
service/app/domain.go Normal file
View File

@@ -0,0 +1,53 @@
package app
import (
"git.echol.cn/loser/lckt/global"
"git.echol.cn/loser/lckt/model/app"
"git.echol.cn/loser/lckt/model/app/request"
)
type DomainService struct{}
func (s DomainService) Create(p app.Domain) error {
return global.GVA_DB.Create(&p).Error
}
func (s DomainService) GetList(p request.GetDomainList) (list []app.Domain, total int64, err error) {
limit := p.PageSize
offset := p.PageSize * (p.Page - 1)
db := global.GVA_DB.Model(&app.Domain{})
if p.Name != "" {
db = db.Where("name LIKE ?", "%"+p.Name+"%")
}
if p.Status != 0 {
db = db.Where("status = ?", p.Status)
}
if p.Domain != "" {
db = db.Where("domain_url LIKE ?", "%"+p.Domain+"%")
}
if p.Type != 0 {
db = db.Where("type = ?", p.Type)
}
err = db.Count(&total).Error
if err != nil {
return
}
err = db.Limit(limit).Offset(offset).Order("created_at DESC").Find(&list).Error
return
}
func (s DomainService) Update(p app.Domain) error {
return global.GVA_DB.Save(&p).Error
}
func (s DomainService) Delete(id uint) error {
return global.GVA_DB.Delete(&app.Domain{}, id).Error
}
func (s DomainService) GetByID(id string) (domain app.Domain, err error) {
err = global.GVA_DB.Where("id = ?", id).First(&domain).Error
return
}

View File

@@ -7,4 +7,5 @@ type ServiceGroup struct {
TeacherVipService
RedeemCodeService
WithService
DomainService
}