🎨 新增vip模块

This commit is contained in:
loser 2025-05-09 11:49:44 +08:00
parent 7903175c91
commit bf220076dd
12 changed files with 226 additions and 0 deletions

View File

@ -7,6 +7,7 @@ import (
"git.echol.cn/loser/lckt/api/v1/example"
"git.echol.cn/loser/lckt/api/v1/system"
"git.echol.cn/loser/lckt/api/v1/user"
"git.echol.cn/loser/lckt/api/v1/vip"
)
var ApiGroupApp = new(ApiGroup)
@ -18,4 +19,5 @@ type ApiGroup struct {
BotApiGroup bot.ApiGroup
ArticleApiGroup article.ApiGroup
UserApiGroup user.APPUserApi
VipApiGroup vip.ApiGroup
}

7
api/v1/vip/enter.go Normal file
View File

@ -0,0 +1,7 @@
package vip
import "git.echol.cn/loser/lckt/service"
type ApiGroup struct{ VipApi }
var vipService = service.ServiceGroupApp.VipServiceGroup.VipService

88
api/v1/vip/vip.go Normal file
View File

@ -0,0 +1,88 @@
package vip
import (
"git.echol.cn/loser/lckt/model/common/request"
"git.echol.cn/loser/lckt/model/common/response"
"git.echol.cn/loser/lckt/model/vip"
"github.com/gin-gonic/gin"
)
type VipApi struct{}
// GetVipList 获取会员列表
func (v *VipApi) GetVipList(ctx *gin.Context) {
var p request.PageInfo
if err := ctx.ShouldBind(&p); err != nil {
response.FailWithMessage("参数有误", ctx)
return
}
vipList, total, err := vipService.GetVipList(p)
if err != nil {
response.FailWithMessage("获取VIP列表失败", ctx)
return
}
response.OkWithDetailed(
response.PageResult{
List: vipList,
Total: total,
Page: p.Page,
PageSize: p.PageSize,
},
"获取VIP列表成功",
ctx,
)
}
// Create 创建会员
func (v *VipApi) Create(ctx *gin.Context) {
var p vip.Vip
if err := ctx.ShouldBind(&p); err != nil {
response.FailWithMessage("参数有误", ctx)
return
}
if err := vipService.CreateVip(p); err != nil {
response.FailWithMessage("创建会员失败", ctx)
return
}
response.OkWithMessage("创建会员成功", ctx)
}
// Update 更新会员
func (v *VipApi) Update(ctx *gin.Context) {
var p vip.Vip
if err := ctx.ShouldBind(&p); err != nil {
response.FailWithMessage("参数有误", ctx)
return
}
if err := vipService.UpdateVip(p); err != nil {
response.FailWithMessage("更新会员失败", ctx)
return
}
response.OkWithMessage("更新会员成功", ctx)
}
// Delete 删除会员
func (v *VipApi) Delete(ctx *gin.Context) {
var p vip.Vip
if err := ctx.ShouldBind(&p); err != nil {
response.FailWithMessage("参数有误", ctx)
return
}
if err := vipService.DeleteVip(p); err != nil {
response.FailWithMessage("删除会员失败", ctx)
return
}
response.OkWithMessage("删除会员成功", ctx)
}
// GetVipById 获取会员详情
func (v *VipApi) GetVipById(ctx *gin.Context) {
id := ctx.Param("id")
vip, err := vipService.GetVipById(id)
if err != nil {
response.FailWithMessage("获取会员详情失败", ctx)
return
}
response.OkWithDetailed(vip, "获取会员详情成功", ctx)
}

View File

@ -6,6 +6,7 @@ import (
"git.echol.cn/loser/lckt/model/bot"
"git.echol.cn/loser/lckt/model/category"
"git.echol.cn/loser/lckt/model/user"
"git.echol.cn/loser/lckt/model/vip"
)
func bizModel() error {
@ -15,6 +16,7 @@ func bizModel() error {
bot.Bot{},
article.Article{},
user.User{},
vip.Vip{},
)
if err != nil {
return err

View File

@ -30,4 +30,8 @@ func initBizRouter(routers ...*gin.RouterGroup) {
userRouter.InitUserRouter(privateGroup, publicGroup)
userRouter.InitAppUserRouter(publicGroup)
}
{
vipRouter := router.RouterGroupApp.Vip
vipRouter.InitVipRouter(privateGroup, publicGroup)
}
}

16
model/vip/vip.go Normal file
View File

@ -0,0 +1,16 @@
package vip
import "git.echol.cn/loser/lckt/global"
type Vip struct {
global.GVA_MODEL
Name string `json:"name" form:"name" gorm:"comment:会员名称"` // 会员名称
Level int `json:"level" form:"level" gorm:"comment:会员等级 1 Vip 2 Svip"` // 会员等级
Price float64 `json:"price" form:"price" gorm:"comment:会员价格"` // 会员价格
Expiration int64 `json:"expiration" form:"expiration" gorm:"comment:会员有效期"` // 会员过期时间
}
// TableName 设置表名
func (Vip) TableName() string {
return "lckt_vip"
}

View File

@ -7,6 +7,7 @@ import (
"git.echol.cn/loser/lckt/router/example"
"git.echol.cn/loser/lckt/router/system"
"git.echol.cn/loser/lckt/router/user"
"git.echol.cn/loser/lckt/router/vip"
)
var RouterGroupApp = new(RouterGroup)
@ -18,4 +19,5 @@ type RouterGroup struct {
Bot bot.RouterGroup
Article article.RouterGroup
User user.UserRouter
Vip vip.VipRouter
}

7
router/vip/enter.go Normal file
View File

@ -0,0 +1,7 @@
package vip
import api "git.echol.cn/loser/lckt/api/v1"
type RouterGroup struct{ VipRouter }
var vipApi = api.ApiGroupApp.VipApiGroup

23
router/vip/vip.go Normal file
View File

@ -0,0 +1,23 @@
package vip
import (
"git.echol.cn/loser/lckt/middleware"
"github.com/gin-gonic/gin"
)
type VipRouter struct{}
// InitVipRouter 初始化会员路由
func (s *VipRouter) InitVipRouter(Router *gin.RouterGroup, PublicRouter *gin.RouterGroup) {
vipRouter := Router.Group("vip").Use(middleware.OperationRecord())
vipNoAuthRouter := PublicRouter.Group("vip").Use(middleware.OperationRecord())
{
vipRouter.POST("", vipApi.Create) // 获取用户列表
vipRouter.DELETE("", vipApi.Delete) // 更新用户余额
vipRouter.PUT("", vipApi.Update) // 注册
}
{
vipNoAuthRouter.GET(":id", vipApi.GetVipById) // 根据获取vip信息
vipNoAuthRouter.GET("list", vipApi.GetVipList) // 获取会员列表
}
}

View File

@ -7,6 +7,7 @@ import (
"git.echol.cn/loser/lckt/service/example"
"git.echol.cn/loser/lckt/service/system"
"git.echol.cn/loser/lckt/service/user"
"git.echol.cn/loser/lckt/service/vip"
)
var ServiceGroupApp = new(ServiceGroup)
@ -18,4 +19,5 @@ type ServiceGroup struct {
BotServiceGroup bot.ServiceGroup
ArticleGroup article.ServiceGroup
UserServiceGroup user.ServiceGroup
VipServiceGroup vip.ServiceGroup
}

3
service/vip/enter.go Normal file
View File

@ -0,0 +1,3 @@
package vip
type ServiceGroup struct{ VipService }

70
service/vip/vip.go Normal file
View File

@ -0,0 +1,70 @@
package vip
import (
"git.echol.cn/loser/lckt/global"
"git.echol.cn/loser/lckt/model/common/request"
"git.echol.cn/loser/lckt/model/vip"
"go.uber.org/zap"
)
type VipService struct{}
// GetVipList 获取会员列表
func (v *VipService) GetVipList(p request.PageInfo) (vipList []vip.Vip, total int64, err error) {
limit := p.PageSize
offset := p.PageSize * (p.Page - 1)
// 创建db
db := global.GVA_DB.Model(&vip.Vip{})
err = db.Count(&total).Error
if err != nil {
global.GVA_LOG.Error("获取会员列表失败", zap.Error(err))
return
}
if limit != 0 {
db = db.Limit(limit).Offset(offset)
}
err = db.Find(&vipList).Error
if err != nil {
global.GVA_LOG.Error("获取会员列表失败", zap.Error(err))
return
}
return
}
// CreateVip 创建会员
func (v *VipService) CreateVip(vip vip.Vip) (err error) {
err = global.GVA_DB.Create(&vip).Error
if err != nil {
return
}
return
}
// UpdateVip 更新会员
func (v *VipService) UpdateVip(vip vip.Vip) (err error) {
err = global.GVA_DB.Save(&vip).Error
if err != nil {
return
}
return
}
// DeleteVip 删除会员
func (v *VipService) DeleteVip(vip vip.Vip) (err error) {
err = global.GVA_DB.Delete(&vip).Error
if err != nil {
return
}
return
}
// GetVipById 获取会员详情
func (v *VipService) GetVipById(id string) (vip vip.Vip, err error) {
err = global.GVA_DB.Where("id = ?", id).First(&vip).Error
if err != nil {
return
}
return
}