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

854 lines
25 KiB

  1. package member_center
  2. import (
  3. "applet/app/db"
  4. "applet/app/e"
  5. md2 "applet/app/md"
  6. "applet/app/md/member_center"
  7. svc2 "applet/app/svc"
  8. svc "applet/app/svc/member_center"
  9. "applet/app/utils"
  10. "applet/app/utils/cache"
  11. "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
  12. "code.fnuoos.com/EggPlanet/egg_models.git/src/model"
  13. "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit"
  14. "errors"
  15. "fmt"
  16. "github.com/gin-gonic/gin"
  17. "strings"
  18. "time"
  19. )
  20. // UserManagementGetUserList
  21. // @Summary 制度中心-会员中心-用户管理-用户信息管理(获取)
  22. // @Tags 会员中心
  23. // @Description 用户信息管理(获取)
  24. // @Accept json
  25. // @Produce json
  26. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  27. // @Param req body md.UserManagementGetUserListReq true "分页信息必填"
  28. // @Success 200 {object} md.UserManagementGetUserListResp "具体数据"
  29. // @Failure 400 {object} md.Response "具体错误"
  30. // @Router /api/memberCenter/userManagement/getUserList [post]
  31. func UserManagementGetUserList(c *gin.Context) {
  32. var req *md.UserManagementGetUserListReq
  33. if err := c.ShouldBindJSON(&req); err != nil {
  34. e.OutErr(c, e.ERR_INVALID_ARGS, err.Error())
  35. return
  36. }
  37. levelDb := implement.NewUserLevelDb(db.Db)
  38. levels, err1 := levelDb.UserLevelAllByAsc()
  39. if err1 != nil {
  40. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  41. return
  42. }
  43. levelsList := make([]map[string]interface{}, 0)
  44. levelsMap := make(map[int]string)
  45. for _, level := range levels {
  46. levelsList = append(levelsList, map[string]interface{}{
  47. "id": level.Id,
  48. "name": level.LevelName,
  49. })
  50. levelsMap[level.Id] = level.LevelName
  51. }
  52. tagDb := implement.NewUserTagDb(db.Db)
  53. tags, err2 := tagDb.UserTagAllByAsc()
  54. if err2 != nil {
  55. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  56. return
  57. }
  58. tagsList := make([]map[string]interface{}, 0)
  59. tagsMap := make(map[int]string)
  60. for _, tag := range tags {
  61. tagsList = append(tagsList, map[string]interface{}{
  62. "id": tag.Id,
  63. "name": tag.TagName,
  64. })
  65. tagsMap[tag.Id] = tag.TagName
  66. }
  67. stateList := []map[string]interface{}{
  68. {
  69. "name": "正常",
  70. "value": "1",
  71. },
  72. {
  73. "name": "冻结",
  74. "value": "2",
  75. },
  76. }
  77. users, total, err3 := svc.UserManagementGetUsers(req)
  78. if err3 != nil {
  79. e.OutErr(c, e.ERR_DB_ORM, err3.Error())
  80. return
  81. }
  82. userIDs := make([]int64, len(users))
  83. for i, user := range users {
  84. userIDs[i] = user.Id
  85. }
  86. recordsDb := implement.NewUserTagRecordsDb(db.Db)
  87. records, err := recordsDb.UserTagRecordsFindByParams(map[string]interface{}{
  88. "key": "uid",
  89. "value": userIDs,
  90. })
  91. if err != nil {
  92. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  93. return
  94. }
  95. var levelCounts []md.LevelCount
  96. err4 := db.Db.Table("user").Select("level, Count(*) AS count").GroupBy("level").Find(&levelCounts)
  97. if err4 != nil {
  98. e.OutErr(c, e.ERR_DB_ORM, err4.Error())
  99. return
  100. }
  101. userMap := make(map[int64]int, len(users))
  102. list := make([]md.UserManagementGetUserListNode, len(users))
  103. for i, user := range users {
  104. list[i] = md.UserManagementGetUserListNode{
  105. ID: user.Id,
  106. Sex: user.Sex,
  107. Avatar: svc2.GetOssUrl(user.Avatar),
  108. Nickname: user.Nickname,
  109. Phone: user.Phone,
  110. IsRealName: user.IsRealName,
  111. InviteCode: user.SystemInviteCode,
  112. ParentID: user.ParentUid,
  113. ParentInviteCode: user.ParentSystemInviteCode,
  114. ParentPhone: user.ParentPhone,
  115. RegisterTime: user.CreateAt,
  116. Memo: user.Memo,
  117. Wechat: user.UnionId,
  118. RegisterType: user.RegisterType,
  119. State: user.State,
  120. LastLoginAt: user.UpdateAt,
  121. }
  122. var tempTagList []md.TagNode
  123. list[i].Tag = tempTagList
  124. userMap[user.Id] = i
  125. level, ok := levelsMap[user.Level]
  126. if ok {
  127. list[i].LevelName = level
  128. }
  129. }
  130. for _, record := range *records {
  131. tempTagNode := md.TagNode{
  132. TagID: record.TagId,
  133. TagName: tagsMap[record.TagId],
  134. }
  135. list[userMap[record.Uid]].Tag = append(list[userMap[record.Uid]].Tag, tempTagNode)
  136. }
  137. resp := md.UserManagementGetUserListResp{
  138. LevelsList: levelsList,
  139. TagsList: tagsList,
  140. StateList: stateList,
  141. List: list,
  142. Paginate: md.Paginate{
  143. Limit: req.Limit,
  144. Page: req.Page,
  145. Total: total,
  146. },
  147. }
  148. e.OutSuc(c, resp, nil)
  149. }
  150. // UserManagementUpdateUserInfo
  151. // @Summary 制度中心-会员中心-用户管理-用户信息管理(更新)
  152. // @Tags 会员中心
  153. // @Description 用户信息管理(更新)
  154. // @Accept json
  155. // @Produce json
  156. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  157. // @Param req body md.UserManagementUpdateUserInfoReq true "用户ID 必传"
  158. // @Success 200 {int} "修改数据行数"
  159. // @Failure 400 {object} md.Response "具体错误"
  160. // @Router /api/memberCenter/userManagement/updateUserInfo [post]
  161. func UserManagementUpdateUserInfo(c *gin.Context) {
  162. var req *md.UserManagementUpdateUserInfoReq
  163. if err := c.ShouldBindJSON(&req); err != nil {
  164. e.OutErr(c, e.ERR_INVALID_ARGS, err.Error())
  165. return
  166. }
  167. affected, err := svc.UserManagementUpdateUserInfo(db.Db, req)
  168. if err != nil {
  169. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  170. return
  171. }
  172. e.OutSuc(c, affected, nil)
  173. }
  174. // UserManagementGetUserRecycleList
  175. // @Summary 会员中心-用户管理-回收站列表
  176. // @Tags 会员中心
  177. // @Description 回收站列表
  178. // @Accept json
  179. // @Produce json
  180. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  181. // @Param req body md.UserManagementGetUserListReq true "分页信息必填"
  182. // @Success 200 {object} md.UserManagementGetUserListResp "具体数据"
  183. // @Failure 400 {object} md.Response "具体错误"
  184. // @Router /api/memberCenter/userManagement/userRecycleList [post]
  185. func UserManagementGetUserRecycleList(c *gin.Context) {
  186. var req *md.UserManagementGetUserListReq
  187. if err := c.ShouldBindJSON(&req); err != nil {
  188. e.OutErr(c, e.ERR_INVALID_ARGS, err.Error())
  189. return
  190. }
  191. req.IsRecycle = "1"
  192. levelDb := implement.NewUserLevelDb(db.Db)
  193. levels, err1 := levelDb.UserLevelAllByAsc()
  194. if err1 != nil {
  195. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  196. return
  197. }
  198. levelsList := make([]map[string]interface{}, 0)
  199. levelsMap := make(map[int]string)
  200. for _, level := range levels {
  201. levelsList = append(levelsList, map[string]interface{}{
  202. "id": level.Id,
  203. "name": level.LevelName,
  204. })
  205. levelsMap[level.Id] = level.LevelName
  206. }
  207. tagDb := implement.NewUserTagDb(db.Db)
  208. tags, err2 := tagDb.UserTagAllByAsc()
  209. if err2 != nil {
  210. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  211. return
  212. }
  213. tagsList := make([]map[string]interface{}, 0)
  214. tagsMap := make(map[int]string)
  215. for _, tag := range tags {
  216. tagsList = append(tagsList, map[string]interface{}{
  217. "id": tag.Id,
  218. "name": tag.TagName,
  219. })
  220. tagsMap[tag.Id] = tag.TagName
  221. }
  222. stateList := []map[string]interface{}{
  223. {
  224. "name": "正常",
  225. "value": "1",
  226. },
  227. {
  228. "name": "冻结",
  229. "value": "2",
  230. },
  231. }
  232. users, total, err3 := svc.UserManagementGetUsers(req)
  233. if err3 != nil {
  234. e.OutErr(c, e.ERR_DB_ORM, err3.Error())
  235. return
  236. }
  237. userIDs := make([]int64, len(users))
  238. for i, user := range users {
  239. userIDs[i] = user.Id
  240. }
  241. recordsDb := implement.NewUserTagRecordsDb(db.Db)
  242. records, err := recordsDb.UserTagRecordsFindByParams(map[string]interface{}{
  243. "key": "uid",
  244. "value": userIDs,
  245. })
  246. if err != nil {
  247. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  248. return
  249. }
  250. var levelCounts []md.LevelCount
  251. err4 := db.Db.Table("user").Select("level, Count(*) AS count").GroupBy("level").Find(&levelCounts)
  252. if err4 != nil {
  253. e.OutErr(c, e.ERR_DB_ORM, err4.Error())
  254. return
  255. }
  256. userMap := make(map[int64]int, len(users))
  257. list := make([]md.UserManagementGetUserListNode, len(users))
  258. for i, user := range users {
  259. list[i] = md.UserManagementGetUserListNode{
  260. ID: user.Id,
  261. Sex: user.Sex,
  262. Avatar: svc2.GetOssUrl(user.Avatar),
  263. Nickname: user.Nickname,
  264. Phone: user.Phone,
  265. IsRealName: user.IsRealName,
  266. InviteCode: user.SystemInviteCode,
  267. ParentID: user.ParentUid,
  268. ParentInviteCode: user.ParentSystemInviteCode,
  269. ParentPhone: user.ParentPhone,
  270. RegisterTime: user.CreateAt,
  271. Memo: user.Memo,
  272. Wechat: user.UnionId,
  273. RegisterType: user.RegisterType,
  274. State: user.State,
  275. LastLoginAt: user.UpdateAt,
  276. }
  277. var tempTagList []md.TagNode
  278. list[i].Tag = tempTagList
  279. userMap[user.Id] = i
  280. level, ok := levelsMap[user.Level]
  281. if ok {
  282. list[i].LevelName = level
  283. }
  284. }
  285. for _, record := range *records {
  286. tempTagNode := md.TagNode{
  287. TagID: record.TagId,
  288. TagName: tagsMap[record.TagId],
  289. }
  290. list[userMap[record.Uid]].Tag = append(list[userMap[record.Uid]].Tag, tempTagNode)
  291. }
  292. resp := md.UserManagementGetUserListResp{
  293. LevelsList: levelsList,
  294. TagsList: tagsList,
  295. StateList: stateList,
  296. List: list,
  297. Paginate: md.Paginate{
  298. Limit: req.Limit,
  299. Page: req.Page,
  300. Total: total,
  301. },
  302. }
  303. e.OutSuc(c, resp, nil)
  304. }
  305. // UserManagementUserRecycle
  306. // @Summary 会员中心-用户管理-删除到回收站
  307. // @Tags 会员中心
  308. // @Description 删除到回收站
  309. // @Accept json
  310. // @Produce json
  311. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  312. // @Param req body md.UserManagementUserInfoReq true "用户ID 必传"
  313. // @Success 200 {int} "修改数据行数"
  314. // @Failure 400 {object} md.Response "具体错误"
  315. // @Router /api/memberCenter/userManagement/userRecycle [post]
  316. func UserManagementUserRecycle(c *gin.Context) {
  317. var req *md.UserManagementUserInfoReq
  318. if err := c.ShouldBindJSON(&req); err != nil {
  319. e.OutErr(c, e.ERR_INVALID_ARGS, err.Error())
  320. return
  321. }
  322. ex := strings.Split(req.UID, ",")
  323. NewUserDb := implement.NewUserDb(db.Db)
  324. for _, v := range ex {
  325. user, _ := NewUserDb.GetUser(utils.StrToInt64(v))
  326. if user == nil {
  327. e.OutErr(c, 400, e.NewErr(400, "用户不存在"))
  328. return
  329. }
  330. user.State = 4
  331. user.RecycleParentUid = utils.StrToInt(req.ParentUid)
  332. db.Db.Where("id=?", user.Id).Cols("state,recycle_parent_uid").Update(user)
  333. // 清掉token
  334. cacheKey := fmt.Sprintf("egg_app_jwt_token:%d", user.Id)
  335. cache.SetEx(cacheKey, "", 1)
  336. admin := svc2.GetUser(c)
  337. svc2.AddAdminLog(c, admin.AdmId, "用户回收", "用户id:"+utils.Int64ToStr(user.Id)+",用户手机号:"+user.Phone+" 删除到回收站", "")
  338. }
  339. e.OutSuc(c, "success", nil)
  340. }
  341. // UserManagementUserRecycleCancel
  342. // @Summary 会员中心-用户管理-恢复到会员列表
  343. // @Tags 会员中心
  344. // @Description 恢复到会员列表
  345. // @Accept json
  346. // @Produce json
  347. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  348. // @Param req body md.UserManagementUserInfoCancelReq true "用户ID 必传"
  349. // @Success 200 {int} "修改数据行数"
  350. // @Failure 400 {object} md.Response "具体错误"
  351. // @Router /api/memberCenter/userManagement/userRecycleCancel [post]
  352. func UserManagementUserRecycleCancel(c *gin.Context) {
  353. var req *md.UserManagementUserInfoReq
  354. if err := c.ShouldBindJSON(&req); err != nil {
  355. e.OutErr(c, e.ERR_INVALID_ARGS, err.Error())
  356. return
  357. }
  358. NewUserDb := implement.NewUserDb(db.Db)
  359. ex := strings.Split(req.UID, ",")
  360. for _, v := range ex {
  361. user, _ := NewUserDb.GetUser(utils.StrToInt64(v))
  362. if user == nil {
  363. e.OutErr(c, 400, e.NewErr(400, "用户不存在"))
  364. return
  365. }
  366. user.State = 1
  367. user.RecycleParentUid = 0
  368. db.Db.Where("id=?", user.Id).Cols("state,recycle_parent_uid").Update(user)
  369. admin := svc2.GetUser(c)
  370. svc2.AddAdminLog(c, admin.AdmId, "用户恢复", "用户id:"+utils.Int64ToStr(user.Id)+",用户手机号:"+user.Phone+" 恢复到会员列表", "")
  371. }
  372. e.OutSuc(c, "success", nil)
  373. }
  374. // UserManagementUserDelete
  375. // @Summary 会员中心-用户管理-永久删除
  376. // @Tags 会员中心
  377. // @Description 删除到回收站
  378. // @Accept json
  379. // @Produce json
  380. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  381. // @Param req body md.UserManagementUserInfoReq true "用户ID 必传"
  382. // @Success 200 {int} "修改数据行数"
  383. // @Failure 400 {object} md.Response "具体错误"
  384. // @Router /api/memberCenter/userManagement/userDelete [post]
  385. func UserManagementUserDelete(c *gin.Context) {
  386. var req *md.UserManagementUserInfoReq
  387. if err := c.ShouldBindJSON(&req); err != nil {
  388. e.OutErr(c, e.ERR_INVALID_ARGS, err.Error())
  389. return
  390. }
  391. NewUserDb := implement.NewUserDb(db.Db)
  392. ex := strings.Split(req.UID, ",")
  393. ch, err := rabbit.Cfg.Pool.GetChannel()
  394. if err == nil {
  395. defer ch.Release()
  396. }
  397. for _, v := range ex {
  398. user, _ := NewUserDb.GetUser(utils.StrToInt64(v))
  399. if user == nil {
  400. e.OutErr(c, 400, e.NewErr(400, "用户不存在"))
  401. return
  402. }
  403. if user.State != 4 {
  404. e.OutErr(c, 400, e.NewErr(400, "不能删除"))
  405. return
  406. }
  407. user.State = 3
  408. db.Db.Where("id=?", user.Id).Cols("state").Update(user)
  409. tmp := model.UserDeleteInfo{
  410. Uid: int(user.Id),
  411. Phone: user.Phone,
  412. CreateAt: time.Now(),
  413. }
  414. db.Db.Insert(&tmp)
  415. err = ch.PublishV2(md2.EggUserExchange, md2.CommUserId{
  416. Uid: utils.Int64ToStr(user.Id),
  417. ParentUid: utils.IntToStr(user.RecycleParentUid),
  418. }, md2.EggUserDelete)
  419. if err != nil {
  420. ch.PublishV2(md2.EggUserExchange, md2.CommUserId{
  421. Uid: utils.Int64ToStr(user.Id),
  422. ParentUid: utils.IntToStr(user.RecycleParentUid),
  423. }, md2.EggUserDelete)
  424. }
  425. // 清掉token
  426. cacheKey := fmt.Sprintf("egg_app_jwt_token:%d", user.Id)
  427. _, err = cache.SetEx(cacheKey, "", 1)
  428. admin := svc2.GetUser(c)
  429. svc2.AddAdminLog(c, admin.AdmId, "用户永久删除", "用户id:"+utils.Int64ToStr(user.Id)+",用户手机号:"+user.Phone+" 永久删除", "")
  430. }
  431. e.OutSuc(c, "success", nil)
  432. return
  433. }
  434. // UserManagementGetOneBasic
  435. // @Summary 制度中心-会员中心-用户管理-会员明细概况(获取)
  436. // @Tags 会员中心
  437. // @Description 会员明细概况(获取)
  438. // @Accept json
  439. // @Produce json
  440. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  441. // @Param uid query string true "用户 ID"
  442. // @Success 200 {object} md.UserManagementGetOneBasicResp "会员明细概况具体数据"
  443. // @Failure 400 {object} md.Response "具体错误"
  444. // @Router /api/memberCenter/userManagement/userData [get]
  445. func UserManagementGetOneBasic(c *gin.Context) {
  446. uid := c.Query("uid")
  447. userDb := implement.NewUserDb(db.Db)
  448. user, err := userDb.UserGetOneByParams(map[string]interface{}{
  449. "key": "id",
  450. "value": uid,
  451. })
  452. if err != nil {
  453. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  454. return
  455. }
  456. // 1. 查询等级列表
  457. levelDb := implement.NewUserLevelDb(db.Db)
  458. levels, err1 := levelDb.UserLevelAllByAsc()
  459. if err1 != nil {
  460. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  461. return
  462. }
  463. levelsList := make([]map[string]interface{}, 0)
  464. levelsMap := make(map[int]string)
  465. for _, level := range levels {
  466. levelsList = append(levelsList, map[string]interface{}{
  467. "id": level.Id,
  468. "name": level.LevelName,
  469. })
  470. levelsMap[level.Id] = level.LevelName
  471. }
  472. //2. 查询标签列表
  473. tagDb := implement.NewUserTagDb(db.Db)
  474. tags, err2 := tagDb.UserTagAllByAsc()
  475. if err2 != nil {
  476. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  477. return
  478. }
  479. tagsList := make([]map[string]interface{}, 0)
  480. tagsMap := make(map[int]string)
  481. for _, tag := range tags {
  482. tagsList = append(tagsList, map[string]interface{}{
  483. "id": tag.Id,
  484. "name": tag.TagName,
  485. })
  486. tagsMap[tag.Id] = tag.TagName
  487. }
  488. //3. 查询父用户信息
  489. parent, err := userDb.UserGetOneByParams(map[string]interface{}{
  490. "key": "id",
  491. "value": user.ParentUid,
  492. })
  493. if err != nil {
  494. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  495. return
  496. }
  497. //4. 查询用户标签
  498. recordsDb := implement.NewUserTagRecordsDb(db.Db)
  499. userTagRecords, err := recordsDb.UserTagRecordsFindByParams(map[string]interface{}{
  500. "key": "uid",
  501. "value": uid,
  502. })
  503. if err != nil {
  504. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  505. return
  506. }
  507. resp := md.UserManagementGetOneBasicResp{
  508. TagsList: tagsList,
  509. LevelsList: levelsList,
  510. BasicInfo: md.BasicInfoNode{
  511. Avatar: svc2.GetOssUrl(user.Avatar),
  512. Sex: user.Sex,
  513. Nickname: user.Nickname,
  514. LevelId: user.Level,
  515. Phone: user.Phone,
  516. UnionId: user.UnionId,
  517. Password: user.Password,
  518. State: user.State,
  519. Memo: user.Memo,
  520. },
  521. OtherInfo: md.OtherNode{
  522. LastLoginIp: user.LastLoginIp,
  523. LastLoginAt: user.UpdateAt,
  524. CreateAt: user.CreateAt,
  525. },
  526. }
  527. tagList := make([]md.TagNode, len(*userTagRecords))
  528. if *userTagRecords != nil {
  529. for i, records := range *userTagRecords {
  530. tagList[i].TagID = records.TagId
  531. tagList[i].TagName = tagsMap[records.TagId]
  532. }
  533. }
  534. resp.BasicInfo.Tag = tagList
  535. if parent != nil {
  536. resp.BasicInfo.ParentUid = parent.Id
  537. resp.BasicInfo.ParentName = parent.Nickname
  538. resp.BasicInfo.ParentPhone = parent.Phone
  539. }
  540. level, ok := levelsMap[user.Level]
  541. if ok {
  542. resp.BasicInfo.LevelName = level
  543. }
  544. e.OutSuc(c, resp, nil)
  545. }
  546. // UserManagementGetFans
  547. // @Summary 制度中心-会员中心-用户管理-会员明细粉丝情况(获取)
  548. // @Tags 会员中心
  549. // @Description 会员明细粉丝情况(获取)
  550. // @Accept json
  551. // @Produce json
  552. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  553. // @Param uid query string true "用户 ID"
  554. // @Param type query string true "粉丝类型(1.全部 2.直推 3.二代 4.二代以后)"
  555. // @Param limit query string true "每页大小"
  556. // @Param page query string true "页数"
  557. // @Success 200 {object} md.UserManagementGetFansResp "具体数据"
  558. // @Failure 400 {object} md.Response "具体错误"
  559. // @Router /api/memberCenter/userManagement/getFans [get]
  560. func UserManagementGetFans(c *gin.Context) {
  561. uid := c.Query("uid")
  562. fansType := c.Query("type")
  563. limit := c.Query("limit")
  564. page := c.Query("page")
  565. //1. 查询符合情况用户 ID
  566. relateDb := implement.NewUserRelateDb(db.Db)
  567. var level int
  568. switch fansType {
  569. case "0":
  570. level = 0
  571. case "1":
  572. level = 1
  573. case "2":
  574. level = 2
  575. default:
  576. level = 3
  577. }
  578. relates, total, err := relateDb.PageFindUserRelateByParentUidAndLevel(utils.StrToInt64(uid), utils.StrToInt(page), utils.StrToInt(limit), level)
  579. if err != nil {
  580. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  581. return
  582. }
  583. userIDs := make([]int64, len(*relates))
  584. for i, relate := range *relates {
  585. userIDs[i] = relate.Uid
  586. }
  587. //2. 查询所属代数
  588. platoonUserRelationDb := implement.NewPublicPlatoonUserRelationDb(db.Db)
  589. levelTotals, err := platoonUserRelationDb.PublicPlatoonUserRelationFindByParamsByPage(map[string]interface{}{
  590. "key": "uid",
  591. "value": userIDs,
  592. }, utils.StrToInt(page), utils.StrToInt(limit))
  593. if err != nil {
  594. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  595. return
  596. }
  597. levelTotalMap := make(map[int64]int)
  598. for _, levelTotal := range *levelTotals {
  599. levelTotalMap[levelTotal.Uid] = levelTotal.LevelTotal
  600. }
  601. //3. 查询可提现余额
  602. walletDb := implement.NewUserWalletDb(db.Db)
  603. wallets, err := walletDb.FindUserWalletByParams(map[string]interface{}{
  604. "key": uid,
  605. "value": userIDs,
  606. })
  607. if err != nil {
  608. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  609. return
  610. }
  611. walletMap := make(map[int64]string)
  612. for _, wallet := range *wallets {
  613. walletMap[wallet.Uid] = wallet.Amount
  614. }
  615. //4. 查询累计收益
  616. var incomeMap = map[int64]string{}
  617. if len(*relates) > 0 {
  618. userIDStrs := make([]string, len(*relates))
  619. for i, id := range userIDs {
  620. userIDStrs[i] = utils.Int64ToStr(id)
  621. }
  622. sql := "SELECT SUM(amount) as total, uid FROM `user_wallet_flow` WHERE uid in (%s) AND direction = 1 Group BY uid"
  623. results, err := db.QueryNativeString(db.Db, fmt.Sprintf(sql, strings.Join(userIDStrs, ",")))
  624. if err != nil {
  625. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  626. return
  627. }
  628. for _, res := range results {
  629. incomeMap[utils.StrToInt64(res["uid"])] = res["total"]
  630. }
  631. }
  632. //5. 查询用户信息
  633. userDb := implement.NewUserDb(db.Db)
  634. users, err := userDb.UserFindByParams(map[string]interface{}{
  635. "key": "uid",
  636. "value": userIDs,
  637. })
  638. if err != nil {
  639. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  640. return
  641. }
  642. list := make([]md.FansNode, len(users))
  643. for i, user := range users {
  644. list[i] = md.FansNode{
  645. ID: user.Id,
  646. Nickname: user.Nickname,
  647. Phone: user.Phone,
  648. RegisterAt: user.CreateAt,
  649. }
  650. val, ok := incomeMap[user.Id]
  651. if ok {
  652. list[i].TotalIncome = val
  653. }
  654. levelTotal, ok := levelTotalMap[user.Id]
  655. if ok {
  656. list[i].LevelTotal = levelTotal
  657. }
  658. amount, ok := walletMap[user.Id]
  659. if ok {
  660. list[i].Amount = amount
  661. }
  662. }
  663. resp := md.UserManagementGetFansResp{
  664. List: list,
  665. Paginate: md.Paginate{
  666. Limit: utils.StrToInt(limit),
  667. Page: utils.StrToInt(page),
  668. Total: total,
  669. },
  670. }
  671. e.OutSuc(c, resp, nil)
  672. }
  673. // UserManagementGetBalanceDetail
  674. // @Summary 制度中心-会员中心-用户管理-会员明细(余额获取)
  675. // @Tags 会员中心
  676. // @Description 会员明细(余额获取)
  677. // @Accept json
  678. // @Produce json
  679. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  680. // @Param uid query string true "用户 ID"
  681. // @Param limit query string true "每页大小"
  682. // @Param page query string true "页数"
  683. // @Success 200 {object} md.UserManagementGetBalanceDetailResp "具体数据"
  684. // @Failure 400 {object} md.Response "具体错误"
  685. // @Router /api/memberCenter/userManagement/balanceDetail [get]
  686. func UserManagementGetBalanceDetail(c *gin.Context) {
  687. uid := c.Query("uid")
  688. page := c.DefaultQuery("page", "1")
  689. limit := c.DefaultQuery("limit", "10")
  690. walletFlowDb := implement.NewUserWalletFlowDb(db.Db)
  691. walletFlows, total, err := walletFlowDb.UserWalletFlowFindByParams(map[string]interface{}{
  692. "key": "uid",
  693. "value": uid,
  694. }, utils.StrToInt(page), utils.StrToInt(limit))
  695. if err != nil {
  696. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  697. return
  698. }
  699. kindMap := map[int]string{
  700. 1: "管理员操作增加余额",
  701. 2: "管理员操作扣除余额",
  702. 3: "蛋蛋能量兑换余额",
  703. 4: "余额兑换蛋蛋能量",
  704. }
  705. list := make([]md.BalanceDetailNode, len(*walletFlows))
  706. for i, flow := range *walletFlows {
  707. list[i] = md.BalanceDetailNode{
  708. ID: flow.Id,
  709. Amount: flow.Amount,
  710. AfterAmount: flow.AfterAmount,
  711. Kind: kindMap[flow.Kind],
  712. CreateAt: flow.CreateAt,
  713. }
  714. }
  715. resp := md.UserManagementGetBalanceDetailResp{
  716. List: list,
  717. Paginate: md.Paginate{
  718. Limit: utils.StrToInt(limit),
  719. Page: utils.StrToInt(page),
  720. Total: total,
  721. },
  722. }
  723. e.OutSuc(c, resp, nil)
  724. }
  725. // UserManagementGetVirtualCoinDetail
  726. // @Summary 制度中心-会员中心-用户管理-会员明细(积分明细获取)
  727. // @Tags 会员中心
  728. // @Description 会员明细(积分明细获取)
  729. // @Accept json
  730. // @Produce json
  731. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  732. // @Param uid query string true "用户 ID"
  733. // @Param coinId query string true "货币 ID"
  734. // @Param limit query string true "每页大小"
  735. // @Param page query string true "页数"
  736. // @Success 200 {object} md.UserManagementGetVirtualCoinDetailResp "具体数据"
  737. // @Failure 400 {object} md.Response "具体错误"
  738. // @Router /api/memberCenter/userManagement/getVirtualCoinDetail [get]
  739. func UserManagementGetVirtualCoinDetail(c *gin.Context) {
  740. page := c.DefaultQuery("page", "1")
  741. limit := c.DefaultQuery("limit", "10")
  742. uid := c.Query("uid")
  743. coinID := c.Query("coinId")
  744. coinDb := implement.NewVirtualCoinDb(db.Db)
  745. coins, err := coinDb.VirtualCoinFindAll()
  746. if err != nil {
  747. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  748. return
  749. }
  750. if coins == nil {
  751. e.OutErr(c, e.ERR_NO_DATA, errors.New("未初始化货币"))
  752. return
  753. }
  754. coinsList := make([]map[string]interface{}, len(coins))
  755. coinsMap := map[int]string{}
  756. for i, coin := range coins {
  757. coinsList[i] = map[string]interface{}{
  758. "coinID": coin.Id,
  759. "name": coin.Name,
  760. }
  761. coinsMap[coin.Id] = coin.Name
  762. }
  763. // 传入不存在的货币类型时 默认为第一种货币类型
  764. var reqCoinID int
  765. _, ok := coinsMap[utils.StrToInt(coinID)]
  766. if !ok {
  767. reqCoinID = coinsList[0]["coinID"].(int)
  768. } else {
  769. reqCoinID = utils.StrToInt(coinID)
  770. }
  771. flowDb := implement.NewUserVirtualCoinFlowDb(db.Db)
  772. flows, total, err := flowDb.UserVirtualCoinFlowFindByCoinAndUser(utils.StrToInt(page), utils.StrToInt(limit), reqCoinID, utils.StrToInt64(uid), "", "", 0, false, 0)
  773. if err != nil {
  774. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  775. return
  776. }
  777. list := make([]md.VirtualCoinDetailNode, len(flows))
  778. for i, flow := range flows {
  779. list[i] = md.VirtualCoinDetailNode{
  780. Uid: flow.Uid,
  781. Amount: flow.Amount,
  782. AfterAmount: flow.AfterAmount,
  783. Direction: flow.Direction,
  784. CreateAt: flow.CreateAt,
  785. }
  786. }
  787. resp := md.UserManagementGetVirtualCoinDetailResp{
  788. CoinList: coinsList,
  789. List: list,
  790. Paginate: md.Paginate{
  791. Limit: utils.StrToInt(limit),
  792. Page: utils.StrToInt(page),
  793. Total: total,
  794. },
  795. }
  796. e.OutSuc(c, resp, nil)
  797. }