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