蛋蛋星球 后台端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

hdl_level__management.go 3.2 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. package member_center
  2. import (
  3. "applet/app/db"
  4. "applet/app/e"
  5. md "applet/app/md/institutional_management/member_center"
  6. "applet/app/utils"
  7. "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
  8. "code.fnuoos.com/EggPlanet/egg_models.git/src/model"
  9. "github.com/gin-gonic/gin"
  10. )
  11. // GetLevelList
  12. // @Summary 制度中心-会员中心-等级管理(获取)
  13. // @Tags 会员中心
  14. // @Description 标签管理(获取)
  15. // @Accept json
  16. // @Produce json
  17. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  18. // @Param limit query int true "每页大小"
  19. // @Param page query int true "页数"
  20. // @Success 200 {object} md.GetLevelListResp "具体数据"
  21. // @Failure 400 {object} md.Response "具体错误"
  22. // @Router /api/memberCenter/levelManagement/getLevelList [get]
  23. func GetLevelList(c *gin.Context) {
  24. page := c.DefaultQuery("page", "1")
  25. limit := c.DefaultQuery("limit", "10")
  26. levelDb := implement.NewUserLevelDb(db.Db)
  27. levels, total, err := levelDb.UserLevelAllByAscByPage(utils.StrToInt(page), utils.StrToInt(limit))
  28. if err != nil {
  29. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  30. return
  31. }
  32. sql := "SElECT count(distinct id) as total, level FROM `user` GROUP BY level"
  33. results, err := db.QueryNativeString(db.Db, sql)
  34. if err != nil {
  35. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  36. return
  37. }
  38. var countMap = map[int]string{}
  39. for _, res := range results {
  40. countMap[utils.StrToInt(res["level"])] = res["total"]
  41. }
  42. list := make([]md.LevelListNode, 0)
  43. for i, level := range levels {
  44. list[i].LevelWeight = level.LevelWeight
  45. list[i].LevelID = level.Id
  46. list[i].LevelName = level.LevelName
  47. list[i].Count = countMap[level.Id]
  48. list[i].CreateAt = level.CreateAt
  49. list[i].IsUse = level.IsUse
  50. list[i].Memo = level.Memo
  51. }
  52. resp := md.GetLevelListResp{
  53. List: list,
  54. Paginate: md.Paginate{
  55. Limit: utils.StrToInt(limit),
  56. Page: utils.StrToInt(page),
  57. Total: total,
  58. },
  59. }
  60. e.OutSuc(c, resp, nil)
  61. }
  62. // UpdateLevel
  63. // @Summary 制度中心-会员中心-等级管理(更新)
  64. // @Tags 会员中心
  65. // @Description 等级管理(更新)
  66. // @Accept json
  67. // @Produce json
  68. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  69. // @Param req body md.UpdateLevelReq true "需要修改的等级信息"
  70. // @Success 200 {int} "成功修改数据条数"
  71. // @Failure 400 {object} md.Response "具体错误"
  72. // @Router /api/memberCenter/levelManagement/updateLevel [post]
  73. func UpdateLevel(c *gin.Context) {
  74. var req *md.UpdateLevelReq
  75. if err := c.ShouldBindJSON(&req); err != nil {
  76. e.OutErr(c, e.ERR_INVALID_ARGS, err.Error())
  77. return
  78. }
  79. level := &model.UserLevel{
  80. Id: utils.StrToInt(req.LevelID),
  81. LevelName: req.LevelName,
  82. LevelWeight: req.LevelWeight,
  83. IsUse: req.IsUse,
  84. Memo: req.Memo,
  85. }
  86. forceColumns := []string{"level_weight", "is_use"}
  87. levelDb := implement.NewUserLevelDb(db.Db)
  88. affected, err := levelDb.UserLevelUpdate(req.LevelID, level, forceColumns...)
  89. if err != nil {
  90. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  91. return
  92. }
  93. e.OutSuc(c, affected, nil)
  94. }