蛋蛋星球 后台端
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 

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