蛋蛋星球 后台端
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_user_management.go 16 KiB

1 month ago
3 weeks ago
1 week ago
1 month ago
1 month ago
4 weeks ago
1 month ago
1 month ago
4 weeks ago
1 month ago
3 weeks ago
1 week ago
1 month ago
1 week ago
3 weeks ago
1 month ago
1 week ago
1 month ago
3 weeks ago
1 week ago
1 month ago
1 week ago
1 month ago
3 weeks ago
1 month ago
3 weeks ago
4 weeks ago
1 month ago
3 weeks ago
1 month ago
3 weeks ago
1 month ago
4 weeks ago
1 month ago
3 weeks ago
4 weeks ago
1 month ago
4 weeks ago
1 month ago
1 month ago
4 weeks ago
1 month ago
4 weeks ago
4 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
1 week ago
4 weeks ago
3 weeks ago
4 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
3 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  1. package member_center
  2. import (
  3. "applet/app/db"
  4. "applet/app/e"
  5. "applet/app/md/member_center"
  6. svc2 "applet/app/svc"
  7. svc "applet/app/svc/member_center"
  8. "applet/app/utils"
  9. "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
  10. "errors"
  11. "fmt"
  12. "github.com/gin-gonic/gin"
  13. "strings"
  14. )
  15. // UserManagementGetUserList
  16. // @Summary 制度中心-会员中心-用户管理-用户信息管理(获取)
  17. // @Tags 会员中心
  18. // @Description 用户信息管理(获取)
  19. // @Accept json
  20. // @Produce json
  21. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  22. // @Param req body md.UserManagementGetUserListReq true "分页信息必填"
  23. // @Success 200 {object} md.UserManagementGetUserListResp "具体数据"
  24. // @Failure 400 {object} md.Response "具体错误"
  25. // @Router /api/memberCenter/userManagement/getUserList [post]
  26. func UserManagementGetUserList(c *gin.Context) {
  27. var req *md.UserManagementGetUserListReq
  28. if err := c.ShouldBindJSON(&req); err != nil {
  29. e.OutErr(c, e.ERR_INVALID_ARGS, err.Error())
  30. return
  31. }
  32. levelDb := implement.NewUserLevelDb(db.Db)
  33. levels, err1 := levelDb.UserLevelAllByAsc()
  34. if err1 != nil {
  35. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  36. return
  37. }
  38. levelsList := make([]map[string]interface{}, 0)
  39. levelsMap := make(map[int]string)
  40. for _, level := range levels {
  41. levelsList = append(levelsList, map[string]interface{}{
  42. "id": level.Id,
  43. "name": level.LevelName,
  44. })
  45. levelsMap[level.Id] = level.LevelName
  46. }
  47. tagDb := implement.NewUserTagDb(db.Db)
  48. tags, err2 := tagDb.UserTagAllByAsc()
  49. if err2 != nil {
  50. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  51. return
  52. }
  53. tagsList := make([]map[string]interface{}, 0)
  54. tagsMap := make(map[int]string)
  55. for _, tag := range tags {
  56. tagsList = append(tagsList, map[string]interface{}{
  57. "id": tag.Id,
  58. "name": tag.TagName,
  59. })
  60. tagsMap[tag.Id] = tag.TagName
  61. }
  62. stateList := []map[string]interface{}{
  63. {
  64. "name": "正常",
  65. "value": "1",
  66. },
  67. {
  68. "name": "冻结",
  69. "value": "2",
  70. },
  71. }
  72. users, total, err3 := svc.UserManagementGetUsers(req)
  73. if err3 != nil {
  74. e.OutErr(c, e.ERR_DB_ORM, err3.Error())
  75. return
  76. }
  77. userIDs := make([]int64, len(users))
  78. for i, user := range users {
  79. userIDs[i] = user.Id
  80. }
  81. recordsDb := implement.NewUserTagRecordsDb(db.Db)
  82. records, err := recordsDb.UserTagRecordsFindByParams(map[string]interface{}{
  83. "key": "uid",
  84. "value": userIDs,
  85. })
  86. if err != nil {
  87. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  88. return
  89. }
  90. var levelCounts []md.LevelCount
  91. err4 := db.Db.Table("user").Select("level, Count(*) AS count").GroupBy("level").Find(&levelCounts)
  92. if err4 != nil {
  93. e.OutErr(c, e.ERR_DB_ORM, err4.Error())
  94. return
  95. }
  96. userMap := make(map[int64]int, len(users))
  97. list := make([]md.UserManagementGetUserListNode, len(users))
  98. for i, user := range users {
  99. list[i] = md.UserManagementGetUserListNode{
  100. ID: user.Id,
  101. Sex: user.Sex,
  102. Avatar: svc2.GetOssUrl(user.Avatar),
  103. Nickname: user.Nickname,
  104. Phone: user.Phone,
  105. IsRealName: user.IsRealName,
  106. InviteCode: user.SystemInviteCode,
  107. ParentID: user.ParentUid,
  108. ParentInviteCode: user.ParentSystemInviteCode,
  109. ParentPhone: user.ParentPhone,
  110. RegisterTime: user.CreateAt,
  111. Memo: user.Memo,
  112. Wechat: user.UnionId,
  113. RegisterType: user.RegisterType,
  114. State: user.State,
  115. LastLoginAt: user.UpdateAt,
  116. }
  117. var tempTagList []md.TagNode
  118. list[i].Tag = tempTagList
  119. userMap[user.Id] = i
  120. level, ok := levelsMap[user.Level]
  121. if ok {
  122. list[i].LevelName = level
  123. }
  124. }
  125. for _, record := range *records {
  126. tempTagNode := md.TagNode{
  127. TagID: record.TagId,
  128. TagName: tagsMap[record.TagId],
  129. }
  130. list[userMap[record.Uid]].Tag = append(list[userMap[record.Uid]].Tag, tempTagNode)
  131. }
  132. resp := md.UserManagementGetUserListResp{
  133. LevelsList: levelsList,
  134. TagsList: tagsList,
  135. StateList: stateList,
  136. List: list,
  137. Paginate: md.Paginate{
  138. Limit: req.Limit,
  139. Page: req.Page,
  140. Total: total,
  141. },
  142. }
  143. e.OutSuc(c, resp, nil)
  144. }
  145. // UserManagementUpdateUserInfo
  146. // @Summary 制度中心-会员中心-用户管理-用户信息管理(更新)
  147. // @Tags 会员中心
  148. // @Description 用户信息管理(更新)
  149. // @Accept json
  150. // @Produce json
  151. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  152. // @Param req body md.UserManagementUpdateUserInfoReq true "用户ID 必传"
  153. // @Success 200 {int} "修改数据行数"
  154. // @Failure 400 {object} md.Response "具体错误"
  155. // @Router /api/memberCenter/userManagement/updateUserInfo [post]
  156. func UserManagementUpdateUserInfo(c *gin.Context) {
  157. var req *md.UserManagementUpdateUserInfoReq
  158. if err := c.ShouldBindJSON(&req); err != nil {
  159. e.OutErr(c, e.ERR_INVALID_ARGS, err.Error())
  160. return
  161. }
  162. affected, err := svc.UserManagementUpdateUserInfo(db.Db, req)
  163. if err != nil {
  164. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  165. return
  166. }
  167. e.OutSuc(c, affected, nil)
  168. }
  169. // UserManagementGetOneBasic
  170. // @Summary 制度中心-会员中心-用户管理-会员明细概况(获取)
  171. // @Tags 会员中心
  172. // @Description 会员明细概况(获取)
  173. // @Accept json
  174. // @Produce json
  175. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  176. // @Param uid query string true "用户 ID"
  177. // @Success 200 {object} md.UserManagementGetOneBasicResp "会员明细概况具体数据"
  178. // @Failure 400 {object} md.Response "具体错误"
  179. // @Router /api/memberCenter/userManagement/userData [get]
  180. func UserManagementGetOneBasic(c *gin.Context) {
  181. uid := c.Query("uid")
  182. userDb := implement.NewUserDb(db.Db)
  183. user, err := userDb.UserGetOneByParams(map[string]interface{}{
  184. "key": "id",
  185. "value": uid,
  186. })
  187. if err != nil {
  188. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  189. return
  190. }
  191. // 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. //2. 查询标签列表
  208. tagDb := implement.NewUserTagDb(db.Db)
  209. tags, err2 := tagDb.UserTagAllByAsc()
  210. if err2 != nil {
  211. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  212. return
  213. }
  214. tagsList := make([]map[string]interface{}, 0)
  215. tagsMap := make(map[int]string)
  216. for _, tag := range tags {
  217. tagsList = append(tagsList, map[string]interface{}{
  218. "id": tag.Id,
  219. "name": tag.TagName,
  220. })
  221. tagsMap[tag.Id] = tag.TagName
  222. }
  223. //3. 查询父用户信息
  224. parent, err := userDb.UserGetOneByParams(map[string]interface{}{
  225. "key": "id",
  226. "value": user.ParentUid,
  227. })
  228. if err != nil {
  229. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  230. return
  231. }
  232. //4. 查询用户标签
  233. recordsDb := implement.NewUserTagRecordsDb(db.Db)
  234. userTagRecords, err := recordsDb.UserTagRecordsFindByParams(map[string]interface{}{
  235. "key": "uid",
  236. "value": uid,
  237. })
  238. if err != nil {
  239. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  240. return
  241. }
  242. resp := md.UserManagementGetOneBasicResp{
  243. TagsList: tagsList,
  244. LevelsList: levelsList,
  245. BasicInfo: md.BasicInfoNode{
  246. Avatar: svc2.GetOssUrl(user.Avatar),
  247. Sex: user.Sex,
  248. Nickname: user.Nickname,
  249. LevelId: user.Level,
  250. Phone: user.Phone,
  251. UnionId: user.UnionId,
  252. Password: user.Password,
  253. State: user.State,
  254. Memo: user.Memo,
  255. },
  256. OtherInfo: md.OtherNode{
  257. LastLoginIp: user.LastLoginIp,
  258. LastLoginAt: user.UpdateAt,
  259. CreateAt: user.CreateAt,
  260. },
  261. }
  262. tagList := make([]md.TagNode, len(*userTagRecords))
  263. if *userTagRecords != nil {
  264. for i, records := range *userTagRecords {
  265. tagList[i].TagID = records.TagId
  266. tagList[i].TagName = tagsMap[records.TagId]
  267. }
  268. }
  269. resp.BasicInfo.Tag = tagList
  270. if parent != nil {
  271. resp.BasicInfo.ParentUid = parent.Id
  272. resp.BasicInfo.ParentName = parent.Nickname
  273. resp.BasicInfo.ParentPhone = parent.Phone
  274. }
  275. level, ok := levelsMap[user.Level]
  276. if ok {
  277. resp.BasicInfo.LevelName = level
  278. }
  279. e.OutSuc(c, resp, nil)
  280. }
  281. // UserManagementGetFans
  282. // @Summary 制度中心-会员中心-用户管理-会员明细粉丝情况(获取)
  283. // @Tags 会员中心
  284. // @Description 会员明细粉丝情况(获取)
  285. // @Accept json
  286. // @Produce json
  287. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  288. // @Param uid query string true "用户 ID"
  289. // @Param type query string true "粉丝类型(1.全部 2.直推 3.二代 4.二代以后)"
  290. // @Param limit query string true "每页大小"
  291. // @Param page query string true "页数"
  292. // @Success 200 {object} md.UserManagementGetFansResp "具体数据"
  293. // @Failure 400 {object} md.Response "具体错误"
  294. // @Router /api/memberCenter/userManagement/getFans [get]
  295. func UserManagementGetFans(c *gin.Context) {
  296. uid := c.Query("uid")
  297. fansType := c.Query("type")
  298. limit := c.Query("limit")
  299. page := c.Query("page")
  300. //1. 查询符合情况用户 ID
  301. relateDb := implement.NewUserRelateDb(db.Db)
  302. var level int
  303. switch fansType {
  304. case "0":
  305. level = 0
  306. case "1":
  307. level = 1
  308. case "2":
  309. level = 2
  310. default:
  311. level = 3
  312. }
  313. relates, total, err := relateDb.PageFindUserRelateByParentUidAndLevel(utils.StrToInt64(uid), utils.StrToInt(page), utils.StrToInt(limit), level)
  314. if err != nil {
  315. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  316. return
  317. }
  318. userIDs := make([]int64, len(*relates))
  319. for i, relate := range *relates {
  320. userIDs[i] = relate.Uid
  321. }
  322. //2. 查询所属代数
  323. platoonUserRelationDb := implement.NewPublicPlatoonUserRelationDb(db.Db)
  324. levelTotals, err := platoonUserRelationDb.PublicPlatoonUserRelationFindByParamsByPage(map[string]interface{}{
  325. "key": "uid",
  326. "value": userIDs,
  327. }, utils.StrToInt(page), utils.StrToInt(limit))
  328. if err != nil {
  329. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  330. return
  331. }
  332. levelTotalMap := make(map[int64]int)
  333. for _, levelTotal := range *levelTotals {
  334. levelTotalMap[levelTotal.Uid] = levelTotal.LevelTotal
  335. }
  336. //3. 查询可提现余额
  337. walletDb := implement.NewUserWalletDb(db.Db)
  338. wallets, err := walletDb.FindUserWalletByParams(map[string]interface{}{
  339. "key": uid,
  340. "value": userIDs,
  341. })
  342. if err != nil {
  343. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  344. return
  345. }
  346. walletMap := make(map[int64]string)
  347. for _, wallet := range *wallets {
  348. walletMap[wallet.Uid] = wallet.Amount
  349. }
  350. //4. 查询累计收益
  351. var incomeMap = map[int64]string{}
  352. if len(*relates) > 0 {
  353. userIDStrs := make([]string, len(*relates))
  354. for i, id := range userIDs {
  355. userIDStrs[i] = utils.Int64ToStr(id)
  356. }
  357. sql := "SELECT SUM(amount) as total, uid FROM `user_wallet_flow` WHERE uid in (%s) AND direction = 1 Group BY uid"
  358. results, err := db.QueryNativeString(db.Db, fmt.Sprintf(sql, strings.Join(userIDStrs, ",")))
  359. if err != nil {
  360. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  361. return
  362. }
  363. for _, res := range results {
  364. incomeMap[utils.StrToInt64(res["uid"])] = res["total"]
  365. }
  366. }
  367. //5. 查询用户信息
  368. userDb := implement.NewUserDb(db.Db)
  369. users, err := userDb.UserFindByParams(map[string]interface{}{
  370. "key": "uid",
  371. "value": userIDs,
  372. })
  373. if err != nil {
  374. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  375. return
  376. }
  377. list := make([]md.FansNode, len(users))
  378. for i, user := range users {
  379. list[i] = md.FansNode{
  380. ID: user.Id,
  381. Nickname: user.Nickname,
  382. Phone: user.Phone,
  383. RegisterAt: user.CreateAt,
  384. }
  385. val, ok := incomeMap[user.Id]
  386. if ok {
  387. list[i].TotalIncome = val
  388. }
  389. levelTotal, ok := levelTotalMap[user.Id]
  390. if ok {
  391. list[i].LevelTotal = levelTotal
  392. }
  393. amount, ok := walletMap[user.Id]
  394. if ok {
  395. list[i].Amount = amount
  396. }
  397. }
  398. resp := md.UserManagementGetFansResp{
  399. List: list,
  400. Paginate: md.Paginate{
  401. Limit: utils.StrToInt(limit),
  402. Page: utils.StrToInt(page),
  403. Total: total,
  404. },
  405. }
  406. e.OutSuc(c, resp, nil)
  407. }
  408. // UserManagementGetBalanceDetail
  409. // @Summary 制度中心-会员中心-用户管理-会员明细(余额获取)
  410. // @Tags 会员中心
  411. // @Description 会员明细(余额获取)
  412. // @Accept json
  413. // @Produce json
  414. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  415. // @Param uid query string true "用户 ID"
  416. // @Param limit query string true "每页大小"
  417. // @Param page query string true "页数"
  418. // @Success 200 {object} md.UserManagementGetBalanceDetailResp "具体数据"
  419. // @Failure 400 {object} md.Response "具体错误"
  420. // @Router /api/memberCenter/userManagement/balanceDetail [get]
  421. func UserManagementGetBalanceDetail(c *gin.Context) {
  422. uid := c.Query("uid")
  423. page := c.DefaultQuery("page", "1")
  424. limit := c.DefaultQuery("limit", "10")
  425. walletFlowDb := implement.NewUserWalletFlowDb(db.Db)
  426. walletFlows, total, err := walletFlowDb.UserWalletFlowFindByParams(map[string]interface{}{
  427. "key": "uid",
  428. "value": uid,
  429. }, utils.StrToInt(page), utils.StrToInt(limit))
  430. if err != nil {
  431. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  432. return
  433. }
  434. kindMap := map[int]string{
  435. 1: "管理员操作增加余额",
  436. 2: "管理员操作扣除余额",
  437. 3: "蛋蛋能量兑换余额",
  438. 4: "余额兑换蛋蛋能量",
  439. }
  440. list := make([]md.BalanceDetailNode, len(*walletFlows))
  441. for i, flow := range *walletFlows {
  442. list[i] = md.BalanceDetailNode{
  443. ID: flow.Id,
  444. Amount: flow.Amount,
  445. AfterAmount: flow.AfterAmount,
  446. Kind: kindMap[flow.Kind],
  447. CreateAt: flow.CreateAt,
  448. }
  449. }
  450. resp := md.UserManagementGetBalanceDetailResp{
  451. List: list,
  452. Paginate: md.Paginate{
  453. Limit: utils.StrToInt(limit),
  454. Page: utils.StrToInt(page),
  455. Total: total,
  456. },
  457. }
  458. e.OutSuc(c, resp, nil)
  459. }
  460. // UserManagementGetVirtualCoinDetail
  461. // @Summary 制度中心-会员中心-用户管理-会员明细(积分明细获取)
  462. // @Tags 会员中心
  463. // @Description 会员明细(积分明细获取)
  464. // @Accept json
  465. // @Produce json
  466. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  467. // @Param uid query string true "用户 ID"
  468. // @Param coinId query string true "货币 ID"
  469. // @Param limit query string true "每页大小"
  470. // @Param page query string true "页数"
  471. // @Success 200 {object} md.UserManagementGetVirtualCoinDetailResp "具体数据"
  472. // @Failure 400 {object} md.Response "具体错误"
  473. // @Router /api/memberCenter/userManagement/getVirtualCoinDetail [get]
  474. func UserManagementGetVirtualCoinDetail(c *gin.Context) {
  475. page := c.DefaultQuery("page", "1")
  476. limit := c.DefaultQuery("limit", "10")
  477. uid := c.Query("uid")
  478. coinID := c.Query("coinId")
  479. coinDb := implement.NewVirtualCoinDb(db.Db)
  480. coins, err := coinDb.VirtualCoinFindAll()
  481. if err != nil {
  482. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  483. return
  484. }
  485. if coins == nil {
  486. e.OutErr(c, e.ERR_NO_DATA, errors.New("未初始化货币"))
  487. return
  488. }
  489. coinsList := make([]map[string]interface{}, len(coins))
  490. coinsMap := map[int]string{}
  491. for i, coin := range coins {
  492. coinsList[i] = map[string]interface{}{
  493. "coinID": coin.Id,
  494. "name": coin.Name,
  495. }
  496. coinsMap[coin.Id] = coin.Name
  497. }
  498. // 传入不存在的货币类型时 默认为第一种货币类型
  499. var reqCoinID int
  500. _, ok := coinsMap[utils.StrToInt(coinID)]
  501. if !ok {
  502. reqCoinID = coinsList[0]["coinID"].(int)
  503. } else {
  504. reqCoinID = utils.StrToInt(coinID)
  505. }
  506. flowDb := implement.NewUserVirtualCoinFlowDb(db.Db)
  507. flows, total, err := flowDb.UserVirtualCoinFlowFindByCoinAndUser(utils.StrToInt(page), utils.StrToInt(limit), reqCoinID, utils.StrToInt64(uid), "", "", 0, false, 0)
  508. if err != nil {
  509. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  510. return
  511. }
  512. list := make([]md.VirtualCoinDetailNode, len(flows))
  513. for i, flow := range flows {
  514. list[i] = md.VirtualCoinDetailNode{
  515. Uid: flow.Uid,
  516. Amount: flow.Amount,
  517. AfterAmount: flow.AfterAmount,
  518. Direction: flow.Direction,
  519. CreateAt: flow.CreateAt,
  520. }
  521. }
  522. resp := md.UserManagementGetVirtualCoinDetailResp{
  523. CoinList: coinsList,
  524. List: list,
  525. Paginate: md.Paginate{
  526. Limit: utils.StrToInt(limit),
  527. Page: utils.StrToInt(page),
  528. Total: total,
  529. },
  530. }
  531. e.OutSuc(c, resp, nil)
  532. }