蛋蛋星球 后台端
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.
 
 
 
 
 

267 rivejä
7.6 KiB

  1. package member_center
  2. import (
  3. "applet/app/db"
  4. "applet/app/e"
  5. md "applet/app/md/institutional_management/member_center"
  6. svc "applet/app/svc/member_center"
  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. // UserManagementGetUserList
  12. // @Summary 制度中心-会员中心-用户信息管理(获取)
  13. // @Tags 会员中心
  14. // @Description 用户信息管理(获取)
  15. // @Accept json
  16. // @Produce json
  17. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  18. // @Param req body md.UserManagementGetUserListReq true "分页信息必填"
  19. // @Success 200 {object} md.UserManagementGetUserListResp "具体数据"
  20. // @Failure 400 {object} md.Response "具体错误"
  21. // @Router /api/memberCenter/userManagement/getUserList [post]
  22. func UserManagementGetUserList(c *gin.Context) {
  23. var req *md.UserManagementGetUserListReq
  24. if err := c.ShouldBindJSON(&req); err != nil {
  25. e.OutErr(c, e.ERR_INVALID_ARGS, err.Error())
  26. return
  27. }
  28. levelDb := implement.NewUserLevelDb(db.Db)
  29. levels, err1 := levelDb.UserLevelAllByAsc()
  30. if err1 != nil {
  31. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  32. return
  33. }
  34. levelsList := make([]map[string]interface{}, 0)
  35. levelsMap := make(map[int]string)
  36. for _, level := range levels {
  37. levelsList = append(levelsList, map[string]interface{}{
  38. "id": level.Id,
  39. "name": level.LevelName,
  40. })
  41. levelsMap[level.Id] = level.LevelName
  42. }
  43. tagDb := implement.NewUserTagDb(db.Db)
  44. tags, err2 := tagDb.UserTagAllByAsc()
  45. if err2 != nil {
  46. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  47. return
  48. }
  49. tagsList := make([]map[string]interface{}, 0)
  50. tagsMap := make(map[int]string)
  51. for _, tag := range tags {
  52. tagsList = append(tagsList, map[string]interface{}{
  53. "id": tag.Id,
  54. "name": tag.TagName,
  55. })
  56. tagsMap[tag.Id] = tag.TagName
  57. }
  58. users, total, err3 := svc.UserManagementGetUsers(db.Db, req)
  59. if err3 != nil {
  60. e.OutErr(c, e.ERR_DB_ORM, err3.Error())
  61. return
  62. }
  63. var levelCounts []md.LevelCount
  64. err4 := db.Db.Table("user").Select("level, Count(*) AS count").GroupBy("level").Find(&levelCounts)
  65. if err4 != nil {
  66. e.OutErr(c, e.ERR_DB_ORM, err4.Error())
  67. return
  68. }
  69. list := make([]md.UserManagementGetUserListNode, len(*users))
  70. for i, user := range *users {
  71. list[i] = md.UserManagementGetUserListNode{
  72. ID: user.Id,
  73. Tag: tagsMap[user.TagID],
  74. Avatar: user.Avatar,
  75. Nickname: user.Nickname,
  76. Phone: user.Phone,
  77. IsRealName: user.IsRealName,
  78. Level: levelsMap[user.Level],
  79. InviteCode: user.SystemInviteCode,
  80. ParentID: user.ParentUid,
  81. ParentInviteCode: user.ParentSystemInviteCode,
  82. ParentPhone: user.Phone,
  83. RegisterTime: user.CreateAt,
  84. Memo: user.Memo,
  85. }
  86. }
  87. resp := md.UserManagementGetUserListResp{
  88. LevelsList: levelsList,
  89. TagsList: tagsList,
  90. List: list,
  91. Paginate: md.Paginate{
  92. Limit: req.Limit,
  93. Page: req.Page,
  94. Total: total,
  95. },
  96. }
  97. e.OutSuc(c, resp, nil)
  98. }
  99. // UserManagementUpdateUserInfo
  100. // @Summary 制度中心-会员中心-用户信息管理(更新)
  101. // @Tags 会员中心
  102. // @Description 用户信息管理(更新)
  103. // @Accept json
  104. // @Produce json
  105. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  106. // @Param req body md.UserManagementUpdateUserInfoReq true "用户ID 必传"
  107. // @Success 200 {int} "修改数据行数"
  108. // @Failure 400 {object} md.Response "具体错误"
  109. // @Router /api/memberCenter/userManagement/updateUserInfo [post]
  110. func UserManagementUpdateUserInfo(c *gin.Context) {
  111. var req *md.UserManagementUpdateUserInfoReq
  112. if err := c.ShouldBindJSON(&req); err != nil {
  113. e.OutErr(c, e.ERR_INVALID_ARGS, err.Error())
  114. return
  115. }
  116. userDb := implement.NewUserDb(db.Db)
  117. var affected int64
  118. var err1 error
  119. forceColumns := make([]string, 0)
  120. user := model.User{
  121. Id: req.UID,
  122. }
  123. if req.Memo != "" {
  124. user.Memo = req.Memo
  125. forceColumns = append(forceColumns, "memo")
  126. }
  127. if req.Disable != false {
  128. user.State = 2
  129. forceColumns = append(forceColumns, "state")
  130. }
  131. if req.LastLoginIp != "" {
  132. user.LastLoginIp = req.LastLoginIp
  133. forceColumns = append(forceColumns, "last_login_ip")
  134. }
  135. if req.Avatar != "" {
  136. user.Avatar = req.Avatar
  137. forceColumns = append(forceColumns, "avatar")
  138. }
  139. if len(forceColumns) > 0 {
  140. affected, err1 = userDb.UserUpdate(req.UID, &user)
  141. if err1 != nil {
  142. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  143. return
  144. }
  145. }
  146. var err2 error
  147. if req.Tag != 0 {
  148. record := model.UserTagRecords{
  149. TagId: req.Tag,
  150. }
  151. recordsDb := implement.NewUserTagRecordsDb(db.Db)
  152. affected, err2 = recordsDb.UserTagRecordsUpdate(req.UID, &record, "tag_id")
  153. if err2 != nil {
  154. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  155. return
  156. }
  157. }
  158. e.OutSuc(c, affected, nil)
  159. }
  160. // UserManagementGetOneBasic
  161. // @Summary 制度中心-会员中心-会员明细概况(获取)
  162. // @Tags 会员中心
  163. // @Description 会员明细概况(更新)
  164. // @Accept json
  165. // @Produce json
  166. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  167. // @Param uid query int true "用户 ID"
  168. // @Success 200 {object} md.UserManagementGetOneBasicResp "会员明细概况具体数据"
  169. // @Failure 400 {object} md.Response "具体错误"
  170. // @Router /api/memberCenter/userManagement/getOneBasicInfo [get]
  171. //func UserManagementGetOneBasic(c *gin.Context) {
  172. // uid := c.Query("uid")
  173. // userDb := implement.NewUserDb(db.Db)
  174. // user, err := userDb.UserGetOneByParams(map[string]interface{}{
  175. // "key": "id",
  176. // "value": uid,
  177. // })
  178. // if err != nil {
  179. // e.OutErr(c, e.ERR_DB_ORM, err.Error())
  180. // return
  181. // }
  182. //
  183. // levelDb := implement.NewUserLevelDb(db.Db)
  184. // levels, err1 := levelDb.UserLevelAllByAsc()
  185. // if err1 != nil {
  186. // e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  187. // return
  188. // }
  189. // levelsList := make([]map[string]interface{}, 0)
  190. // levelsMap := make(map[int]string)
  191. // for _, level := range levels {
  192. // levelsList = append(levelsList, map[string]interface{}{
  193. // "id": level.Id,
  194. // "name": level.LevelName,
  195. // })
  196. // levelsMap[level.Id] = level.LevelName
  197. // }
  198. //
  199. // tagDb := implement.NewUserTagDb(db.Db)
  200. // tags, err2 := tagDb.UserTagAllByAsc()
  201. // if err2 != nil {
  202. // e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  203. // return
  204. // }
  205. // tagsList := make([]map[string]interface{}, 0)
  206. // tagsMap := make(map[int]string)
  207. // for _, tag := range tags {
  208. // tagsList = append(tagsList, map[string]interface{}{
  209. // "id": tag.Id,
  210. // "name": tag.TagName,
  211. // })
  212. // tagsMap[tag.Id] = tag.TagName
  213. // }
  214. //
  215. // coinDb := implement.NewVirtualCoinDb(db.Db)
  216. // coins, err3 := coinDb.VirtualCoinFindAll()
  217. // if err3 != nil {
  218. // e.OutErr(c, e.ERR_DB_ORM, err3.Error())
  219. // return
  220. // }
  221. // coinsList := make([]map[string]interface{}, 0)
  222. // coinsMap := make(map[int]string)
  223. // for _, coin := range coins {
  224. // coinsList = append(coinsList, map[string]interface{}{
  225. // "id": coin.Id,
  226. // "name": coin.Name,
  227. // })
  228. // coinsMap[coin.Id] = coin.Name
  229. // }
  230. //
  231. // parent, err := userDb.UserGetOneByParams(map[string]interface{}{
  232. // "key": "id",
  233. // "value": user.ParentUid,
  234. // })
  235. // if err != nil {
  236. // e.OutErr(c, e.ERR_DB_ORM, err.Error())
  237. // return
  238. // }
  239. //
  240. // recordsDb := implement.NewUserTagRecordsDb(db.Db)
  241. // userTagRecord, err := recordsDb.UserTagRecordsGetOneByParams(map[string]interface{}{
  242. // "key": "uid",
  243. // "value": uid,
  244. // })
  245. // if err != nil {
  246. // return
  247. // }
  248. //
  249. // amountDb := implement.NewUserVirtualAmountDb(db.Db)
  250. // amountDb.GetUserVirtualWalletBySession()
  251. //}