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

296 lines
9.0 KiB

  1. package notice
  2. import (
  3. "applet/app/db"
  4. "applet/app/e"
  5. "applet/app/md"
  6. svc2 "applet/app/svc"
  7. svc "applet/app/svc/member_center"
  8. "applet/app/svc/notice"
  9. "applet/app/utils"
  10. "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
  11. "github.com/gin-gonic/gin"
  12. )
  13. // List
  14. // @Summary 消息中心-基本配置-通知模板
  15. // @Tags 消息中心
  16. // @Description 基本配置-通知模板
  17. // @Accept json
  18. // @Produce json
  19. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  20. // @Param req body md.NoticeListReq true "(分页信息必填)"
  21. // @Success 200 {object} md.NoticeListResp "具体数据"
  22. // @Failure 400 {object} md.Response "具体错误"
  23. // @Router /api/notice/base/list [post]
  24. func List(c *gin.Context) {
  25. notice.List(c)
  26. }
  27. // Save
  28. // @Summary 消息中心-基本配置-通知模板添加编辑
  29. // @Tags 消息中心
  30. // @Description 基本配置-通知模板添加编辑
  31. // @Accept json
  32. // @Produce json
  33. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  34. // @Param req body md.NoticeSaveReq true "(分页信息必填)"
  35. // @Success 200 {string} "具体数据"
  36. // @Failure 400 {object} md.Response "具体错误"
  37. // @Router /api/notice/base/save [post]
  38. func Save(c *gin.Context) {
  39. notice.Save(c)
  40. }
  41. // Del
  42. // @Summary 消息中心-基本配置-通知模板删除
  43. // @Tags 消息中心
  44. // @Description 基本配置-通知模板删除
  45. // @Accept json
  46. // @Produce json
  47. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  48. // @Param req body md.NoticeDelReq true "(分页信息必填)"
  49. // @Success 200 {string} "具体数据"
  50. // @Failure 400 {object} md.Response "具体错误"
  51. // @Router /api/notice/base/del [post]
  52. func Del(c *gin.Context) {
  53. notice.Del(c)
  54. }
  55. // PushList
  56. // @Summary 消息中心-基本配置-推送记录列表
  57. // @Tags 消息中心
  58. // @Description 基本配置-推送记录列表
  59. // @Accept json
  60. // @Produce json
  61. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  62. // @Param req body md.NoticeListReq true "(分页信息必填)"
  63. // @Success 200 {object} md.NoticePushListResp "具体数据"
  64. // @Failure 400 {object} md.Response "具体错误"
  65. // @Router /api/notice/jPush/push/list [post]
  66. func PushList(c *gin.Context) {
  67. notice.PushList(c)
  68. }
  69. // PushSave
  70. // @Summary 消息中心-基本配置-推送记录添加-发送(不做编辑了)
  71. // @Tags 消息中心
  72. // @Description 基本配置-推送记录添加-发送 (不做编辑了)
  73. // @Accept json
  74. // @Produce json
  75. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  76. // @Param req body md.NoticePushSaveReq true "(分页信息必填)"
  77. // @Success 200 {string} "具体数据"
  78. // @Failure 400 {object} md.Response "具体错误"
  79. // @Router /api/notice/jPush/push/save [post]
  80. func PushSave(c *gin.Context) {
  81. notice.PushSave(c)
  82. }
  83. // JPushGetUserList
  84. // @Summary 消息中心-基本配置-获取用户信息
  85. // @Tags 消息中心
  86. // @Description 获取用户信息
  87. // @Accept json
  88. // @Produce json
  89. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  90. // @Param req body md.JPushGetUserListReq true "(分页信息必填)"
  91. // @Success 200 {Object} md.JPushGetUserListResp "具体数据"
  92. // @Failure 400 {object} md.Response "具体错误"
  93. // @Router /api/notice/jPush/getUserList [post]
  94. func JPushGetUserList(c *gin.Context) {
  95. var req *md.JPushGetUserListReq
  96. if err := c.ShouldBindJSON(&req); err != nil {
  97. e.OutErr(c, e.ERR_INVALID_ARGS, err.Error())
  98. return
  99. }
  100. levelDb := implement.NewUserLevelDb(db.Db)
  101. levels, err1 := levelDb.UserLevelAllByAsc()
  102. if err1 != nil {
  103. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  104. return
  105. }
  106. levelsList := make([]map[string]interface{}, 0)
  107. levelsMap := make(map[int]string)
  108. for _, level := range levels {
  109. levelsList = append(levelsList, map[string]interface{}{
  110. "id": level.Id,
  111. "name": level.LevelName,
  112. })
  113. levelsMap[level.Id] = level.LevelName
  114. }
  115. tagDb := implement.NewUserTagDb(db.Db)
  116. tags, err2 := tagDb.UserTagAllByAsc()
  117. if err2 != nil {
  118. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  119. return
  120. }
  121. tagsList := make([]map[string]interface{}, 0)
  122. tagsMap := make(map[int]string)
  123. for _, tag := range tags {
  124. tagsList = append(tagsList, map[string]interface{}{
  125. "id": tag.Id,
  126. "name": tag.TagName,
  127. })
  128. tagsMap[tag.Id] = tag.TagName
  129. }
  130. stateList := []map[string]interface{}{
  131. {
  132. "name": "正常",
  133. "value": "1",
  134. },
  135. {
  136. "name": "冻结",
  137. "value": "2",
  138. },
  139. }
  140. userMemberRequest := req.ToUserMemberRequest()
  141. users, total, err3 := svc.UserManagementGetUsers(userMemberRequest)
  142. if err3 != nil {
  143. e.OutErr(c, e.ERR_DB_ORM, err3.Error())
  144. return
  145. }
  146. userIDs := make([]int64, len(users))
  147. for i, user := range users {
  148. userIDs[i] = user.Id
  149. }
  150. recordsDb := implement.NewUserTagRecordsDb(db.Db)
  151. records, err := recordsDb.UserTagRecordsFindByParams(map[string]interface{}{
  152. "key": "uid",
  153. "value": userIDs,
  154. })
  155. if err != nil {
  156. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  157. return
  158. }
  159. var levelCounts []md.LevelCount
  160. err4 := db.Db.Table("user").Select("level, Count(*) AS count").GroupBy("level").Find(&levelCounts)
  161. if err4 != nil {
  162. e.OutErr(c, e.ERR_DB_ORM, err4.Error())
  163. return
  164. }
  165. userMap := make(map[int64]int, len(users))
  166. list := make([]md.GetUserListNode, len(users))
  167. for i, user := range users {
  168. list[i] = md.GetUserListNode{
  169. ID: user.Id,
  170. Sex: user.Sex,
  171. Avatar: svc2.GetOssUrl(user.Avatar),
  172. Nickname: user.Nickname,
  173. Phone: user.Phone,
  174. IsRealName: user.IsRealName,
  175. InviteCode: user.SystemInviteCode,
  176. ParentID: user.ParentUid,
  177. ParentInviteCode: user.ParentSystemInviteCode,
  178. ParentPhone: user.Phone,
  179. RegisterTime: user.CreateAt,
  180. Memo: user.Memo,
  181. Wechat: user.UnionId,
  182. RegisterType: user.RegisterType,
  183. State: user.State,
  184. LastLoginAt: user.UpdateAt,
  185. }
  186. var tempTagList []md.TagNode
  187. list[i].Tag = tempTagList
  188. userMap[user.Id] = i
  189. level, ok := levelsMap[user.Level]
  190. if ok {
  191. list[i].LevelName = level
  192. }
  193. }
  194. for _, record := range *records {
  195. tempTagNode := md.TagNode{
  196. TagID: record.TagId,
  197. TagName: tagsMap[record.TagId],
  198. }
  199. list[userMap[record.Uid]].Tag = append(list[userMap[record.Uid]].Tag, tempTagNode)
  200. }
  201. resp := md.JPushGetUserListResp{
  202. LevelsList: levelsList,
  203. TagsList: tagsList,
  204. StateList: stateList,
  205. List: list,
  206. Paginate: md.Paginate{
  207. Limit: req.Limit,
  208. Page: req.Page,
  209. Total: total,
  210. },
  211. }
  212. e.OutSuc(c, resp, nil)
  213. }
  214. // JPushGetTagList
  215. // @Summary 消息中心-基本配置-标签管理(获取)
  216. // @Tags 消息中心
  217. // @Description 标签管理(获取)
  218. // @Accept json
  219. // @Produce json
  220. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  221. // @Param limit query int true "每页大小"
  222. // @Param page query int true "页数"
  223. // @Success 200 {object} md.JPushGetTagListResp "具体数据"
  224. // @Failure 400 {object} md.Response "具体错误"
  225. // @Router /api/notice/jPush/getTagList [get]
  226. func JPushGetTagList(c *gin.Context) {
  227. page := c.DefaultQuery("page", "1")
  228. limit := c.DefaultQuery("limit", "10")
  229. list, total, err := svc.TagManagementGetList(page, limit)
  230. if err != nil {
  231. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  232. return
  233. }
  234. resp := md.JPushGetTagListResp{
  235. List: list,
  236. Paginate: md.Paginate{
  237. Limit: utils.StrToInt(limit),
  238. Page: utils.StrToInt(page),
  239. Total: total,
  240. },
  241. }
  242. e.OutSuc(c, resp, nil)
  243. }
  244. // JPushGetLevelList
  245. // @Summary 消息中心-基本配置-等级管理(获取)
  246. // @Tags 消息中心
  247. // @Description 等级管理(获取)
  248. // @Accept json
  249. // @Produce json
  250. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  251. // @Param limit query int true "每页大小"
  252. // @Param page query int true "页数"
  253. // @Success 200 {object} md.JPushGetLevelListResp "具体数据"
  254. // @Failure 400 {object} md.Response "具体错误"
  255. // @Router /api/notice/jPush/getLevelList [get]
  256. func JPushGetLevelList(c *gin.Context) {
  257. page := c.DefaultQuery("page", "1")
  258. limit := c.DefaultQuery("limit", "10")
  259. list, total, err := svc.LevelManagementGetLevelList(page, limit)
  260. if err != nil {
  261. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  262. return
  263. }
  264. resp := md.JPushGetLevelListResp{
  265. List: list,
  266. Paginate: md.Paginate{
  267. Limit: utils.StrToInt(limit),
  268. Page: utils.StrToInt(page),
  269. Total: total,
  270. },
  271. }
  272. e.OutSuc(c, resp, nil)
  273. }