Browse Source

add tag management

master
shenjiachi 1 month ago
parent
commit
7fa519e754
6 changed files with 275 additions and 3 deletions
  1. +103
    -0
      app/hdl/member_center/hdl_level__management.go
  2. +109
    -0
      app/hdl/member_center/hdl_tag__management.go
  3. +24
    -0
      app/md/institutional_management/member_center/md_level_management.go
  4. +25
    -0
      app/md/institutional_management/member_center/md_tag_management.go
  5. +11
    -0
      app/router/router.go
  6. +3
    -3
      go.mod

+ 103
- 0
app/hdl/member_center/hdl_level__management.go View File

@@ -0,0 +1,103 @@
package member_center

import (
"applet/app/db"
"applet/app/e"
md "applet/app/md/institutional_management/member_center"
"applet/app/utils"
"code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
"code.fnuoos.com/EggPlanet/egg_models.git/src/model"
"github.com/gin-gonic/gin"
)

// GetLevelList
// @Summary 制度中心-会员中心-等级管理(获取)
// @Tags 会员中心
// @Description 标签管理(获取)
// @Accept json
// @Produce json
// @param Authorization header string true "验证参数Bearer和token空格拼接"
// @Param limit query int true "每页大小"
// @Param page query int true "页数"
// @Success 200 {object} md.GetLevelListResp "具体数据"
// @Failure 400 {object} md.Response "具体错误"
// @Router /api/memberCenter/levelManagement/getLevelList [get]
func GetLevelList(c *gin.Context) {
page := c.DefaultQuery("page", "1")
limit := c.DefaultQuery("limit", "10")

levelDb := implement.NewUserLevelDb(db.Db)
levels, total, err := levelDb.UserLevelAllByAscByPage(utils.StrToInt(page), utils.StrToInt(limit))
if err != nil {
e.OutErr(c, e.ERR_DB_ORM, err.Error())
return
}

sql := "SElECT count(distinct id) as total, level FROM `user` GROUP BY level"
results, err := db.QueryNativeString(db.Db, sql)
if err != nil {
e.OutErr(c, e.ERR_DB_ORM, err.Error())
return
}
var countMap = map[int]string{}
for _, res := range results {
countMap[utils.StrToInt(res["level"])] = res["total"]
}

list := make([]md.LevelListNode, 0)
for i, level := range levels {
list[i].LevelWeight = level.LevelWeight
list[i].LevelID = level.Id
list[i].LevelName = level.LevelName
list[i].Count = countMap[level.Id]
list[i].CreateAt = level.CreateAt
list[i].IsUse = level.IsUse
list[i].Memo = level.Memo
}

resp := md.GetLevelListResp{
List: list,
Paginate: md.Paginate{
Limit: utils.StrToInt(limit),
Page: utils.StrToInt(page),
Total: total,
},
}

e.OutSuc(c, resp, nil)
}

// UpdateLevel
// @Summary 制度中心-会员中心-等级管理(更新)
// @Tags 会员中心
// @Description 等级管理(更新)
// @Accept json
// @Produce json
// @param Authorization header string true "验证参数Bearer和token空格拼接"
// @Param req body md.UpdateLevelReq true "需要修改的等级信息"
// @Success 200 {int} "成功修改数据条数"
// @Failure 400 {object} md.Response "具体错误"
// @Router /api/memberCenter/levelManagement/updateLevel [post]
func UpdateLevel(c *gin.Context) {
var req *md.UpdateLevelReq
if err := c.ShouldBindJSON(&req); err != nil {
e.OutErr(c, e.ERR_INVALID_ARGS, err.Error())
return
}

level := &model.UserLevel{
Id: utils.StrToInt(req.LevelID),
LevelName: req.LevelName,
LevelWeight: req.LevelWeight,
IsUse: req.IsUse,
Memo: req.Memo,
}
forceColumns := []string{"level_weight", "is_use"}
levelDb := implement.NewUserLevelDb(db.Db)
affected, err := levelDb.UserLevelUpdate(req.LevelID, level, forceColumns...)
if err != nil {
e.OutErr(c, e.ERR_DB_ORM, err.Error())
return
}
e.OutSuc(c, affected, nil)
}

+ 109
- 0
app/hdl/member_center/hdl_tag__management.go View File

@@ -0,0 +1,109 @@
package member_center

import (
"applet/app/db"
"applet/app/e"
md "applet/app/md/institutional_management/member_center"
"applet/app/utils"
"code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
"code.fnuoos.com/EggPlanet/egg_models.git/src/model"
"github.com/gin-gonic/gin"
)

// GetTagList
// @Summary 制度中心-会员中心-标签管理(获取)
// @Tags 会员中心
// @Description 标签管理(获取)
// @Accept json
// @Produce json
// @param Authorization header string true "验证参数Bearer和token空格拼接"
// @Param limit query int true "每页大小"
// @Param page query int true "页数"
// @Success 200 {object} md.GetTagListResp "具体数据"
// @Failure 400 {object} md.Response "具体错误"
// @Router /api/memberCenter/tagManagement/getTagList [get]
func GetTagList(c *gin.Context) {
page := c.DefaultQuery("page", "1")
limit := c.DefaultQuery("limit", "10")

sql := "SElECT count(distinct uid) as total, tag_id FROM `user_tag_records` GROUP BY tag_id"
results, err := db.QueryNativeString(db.Db, sql)
if err != nil {
e.OutErr(c, e.ERR_DB_ORM, err.Error())
return
}
var countMap = map[int64]string{}
for _, res := range results {
countMap[utils.StrToInt64(res["tag_id"])] = res["total"]
}

tagDb := implement.NewUserTagDb(db.Db)
tags, total, err := tagDb.UserTagAllByAscByPage(utils.StrToInt(page), utils.StrToInt(limit))
if err != nil {
e.OutErr(c, e.ERR_DB_ORM, err.Error())
return
}

list := make([]md.TagListNode, len(*tags))
for i, tag := range *tags {
list[i].Name = tag.TagName
list[i].Count = countMap[int64(tag.Id)]
list[i].CreateAt = tag.CreateAt
list[i].Memo = tag.Memo
}

resp := md.GetTagListResp{
List: list,
Paginate: md.Paginate{
Limit: utils.StrToInt(limit),
Page: utils.StrToInt(page),
Total: total,
},
}
e.OutSuc(c, resp, nil)
}

// UpdateTag
// @Summary 制度中心-会员中心-标签管理(更新)
// @Tags 会员中心
// @Description 标签管理(更新)
// @Accept json
// @Produce json
// @param Authorization header string true "验证参数Bearer和token空格拼接"
// @Param req body md.UpdateTagReq true "需要修改的标签信息"
// @Success 200 {int} "成功修改数据条数"
// @Failure 400 {object} md.Response "具体错误"
// @Router /api/memberCenter/tagManagement/updateTag [post]
func UpdateTag(c *gin.Context) {
var req *md.UpdateTagReq
if err := c.ShouldBindJSON(&req); err != nil {
e.OutErr(c, e.ERR_INVALID_ARGS, err.Error())
return
}
tagID := utils.StrToInt(req.TagID)

tag := &model.UserTag{
Id: tagID,
TagName: req.Name,
Memo: req.Memo,
}

forceColumns := []string{"tag_name", "memo"}

tagDb := implement.NewUserTagDb(db.Db)
affected, err := tagDb.UserTagUpdate(tagID, tag, forceColumns...)
if err != nil {
e.OutErr(c, e.ERR_DB_ORM, err.Error())
return
}
e.OutSuc(c, affected, nil)
}

func DeleteTag(c *gin.Context) {
var req *md.UpdateTagReq
if err := c.ShouldBindJSON(&req); err != nil {
e.OutErr(c, e.ERR_INVALID_ARGS, err.Error())
return
}
// todo 删除标签
}

+ 24
- 0
app/md/institutional_management/member_center/md_level_management.go View File

@@ -0,0 +1,24 @@
package md

type LevelListNode struct {
LevelID int `json:"level_id"` // 等级 ID
LevelName string `json:"level_name"` // 等级名称
LevelWeight int `json:"level_weight"` // 等级权重
Count string `json:"count"` // 等级人数
IsUse int `json:"is_use"` // 是否开启(0.否, 1.是)
Memo string `json:"memo"` // 备注
CreateAt string `json:"create_at"` // 创建时间
}

type GetLevelListResp struct {
List []LevelListNode `json:"list"`
Paginate Paginate `json:"paginate"`
}

type UpdateLevelReq struct {
LevelID string `json:"level_id"`
IsUse int `json:"is_use"` // 是否开启(0.否, 1.是)
LevelName string `json:"level_name"` // 等级名称
Memo string `json:"memo"` // 备注
LevelWeight int `json:"level_weight"` // 等级权重
}

+ 25
- 0
app/md/institutional_management/member_center/md_tag_management.go View File

@@ -0,0 +1,25 @@
package md

import "time"

type TagListNode struct {
TagID string `json:"tag_id"` // 标签 ID
Name string `json:"name"` // 名称
Count string `json:"count"` // 标签人数
CreateAt time.Time `json:"create_at"` // 创建时间
Memo string `json:"memo"` // 备注
}

type GetTagListResp struct {
List []TagListNode `json:"list"`
Paginate Paginate `json:"paginate"`
}

type UpdateTagReq struct {
TagID string `json:"tag_id,required"` // 标签 ID
Name string `json:"name,required"` // 标签名称
Memo string `json:"memo,required"` // 备注
}

type DeleteTagReq struct {
}

+ 11
- 0
app/router/router.go View File

@@ -153,6 +153,17 @@ func rMemberCenter(r *gin.RouterGroup) { // 会员中心
rUserManagement.GET("/balanceDetail", member_center.UserManagementGetBalanceDetail)
rUserManagement.GET("/getVirtualCoinDetail", member_center.UserManagementGetVirtualCoinDetail)
}
rTagManagement := r.Group("/tagManagement")
{
rTagManagement.GET("/getTagList", member_center.GetTagList)
rTagManagement.POST("/updateTag", member_center.UpdateTag)
rTagManagement.DELETE("/deleteTag", member_center.DeleteTag)
}
rLevelManagement := r.Group("/levelManagement")
{
rLevelManagement.GET("/getLevelList", member_center.GetLevelList)
rLevelManagement.POST("/updateLevel", member_center.UpdateLevel)
}
}

func rComm(r *gin.RouterGroup) {


+ 3
- 3
go.mod View File

@@ -2,9 +2,9 @@ module applet

go 1.19

replace code.fnuoos.com/EggPlanet/egg_models.git => E:/company/Egg/egg_models
replace code.fnuoos.com/EggPlanet/egg_models.git => E:/company/Egg/egg_models

replace code.fnuoos.com/EggPlanet/egg_system_rules.git => E:/company/Egg/egg_system_rules
replace code.fnuoos.com/EggPlanet/egg_system_rules.git => E:/company/Egg/egg_system_rules

require (
github.com/boombuler/barcode v1.0.1
@@ -82,7 +82,7 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/onsi/ginkgo v1.16.5 // indirect
github.com/onsi/gomega v1.19.0 // indirect
github.com/onsi/gomega v1.27.8 // indirect
github.com/pelletier/go-toml/v2 v2.2.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/saintfish/chardet v0.0.0-20230101081208-5e3ef4b5456d // indirect


Loading…
Cancel
Save