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

1128 lines
34 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. admin := svc2.GetUser(c)
  269. svc2.AddAdminLog(c, admin.AdmId, "用户新增", "用户id:"+utils.Int64ToStr(user.Id)+",用户手机号:"+user.Phone, "")
  270. e.OutSuc(c, "success", nil)
  271. return
  272. }
  273. // UserManagementDelUserAlipay
  274. // @Summary 制度中心-会员中心-用户管理-删除用户支付宝
  275. // @Tags 会员中心
  276. // @Description 用户添加
  277. // @Accept json
  278. // @Produce json
  279. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  280. // @Param req body md.UserReq true "分页信息必填"
  281. // @Success 200 {string} "具体数据"
  282. // @Failure 400 {object} md.Response "具体错误"
  283. // @Router /api/memberCenter/userManagement/delUserAlipay [post]
  284. func UserManagementDelUserAlipay(c *gin.Context) {
  285. var req *md.UserReq
  286. if err := c.ShouldBindJSON(&req); err != nil {
  287. e.OutErr(c, e.ERR_INVALID_ARGS, err.Error())
  288. return
  289. }
  290. NewAlipayUserInfoDb := implement.NewAlipayUserInfoDb(db.Db)
  291. info, _ := NewAlipayUserInfoDb.GetAlipayUserInfo(utils.StrToInt64(req.Id))
  292. if info == nil {
  293. e.OutErr(c, 400, e.NewErr(400, "支付宝信息不存在"))
  294. return
  295. }
  296. oldUserName := info.UserName
  297. oldOpenId := info.OpenId
  298. db.Db.Where("id=?", info.Id).Delete(&model.AlipayUserInfo{})
  299. admin := svc2.GetUser(c)
  300. svc2.AddAdminLog(c, admin.AdmId, "用户解除支付宝", "用户id:"+utils.Int64ToStr(info.Uid)+",原支付宝:"+oldUserName+" "+oldOpenId, utils.SerializeStr(info))
  301. e.OutSuc(c, "success", nil)
  302. return
  303. }
  304. // UserManagementDelUserWechat
  305. // @Summary 制度中心-会员中心-用户管理-删除用户微信
  306. // @Tags 会员中心
  307. // @Description 用户微信
  308. // @Accept json
  309. // @Produce json
  310. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  311. // @Param req body md.UserReq true "分页信息必填"
  312. // @Success 200 {string} "具体数据"
  313. // @Failure 400 {object} md.Response "具体错误"
  314. // @Router /api/memberCenter/userManagement/delUserAlipay [post]
  315. func UserManagementDelUserWechat(c *gin.Context) {
  316. var req *md.UserReq
  317. if err := c.ShouldBindJSON(&req); err != nil {
  318. e.OutErr(c, e.ERR_INVALID_ARGS, err.Error())
  319. return
  320. }
  321. NewWxUserInfoDb := implement.NewWxUserInfoDb(db.Db)
  322. info, _ := NewWxUserInfoDb.GetWxUserInfo(utils.StrToInt64(req.Id))
  323. if info == nil {
  324. e.OutErr(c, 400, e.NewErr(400, "微信信息不存在"))
  325. return
  326. }
  327. oldUserName := info.UserName
  328. oldOpenId := info.OpenId
  329. db.Db.Where("id=?", info.Id).Delete(&model.WxUserInfo{})
  330. admin := svc2.GetUser(c)
  331. svc2.AddAdminLog(c, admin.AdmId, "用户解除微信", "用户id:"+utils.Int64ToStr(info.Uid)+",原微信:"+oldUserName+" "+oldOpenId, utils.SerializeStr(info))
  332. e.OutSuc(c, "success", nil)
  333. return
  334. }
  335. // UserManagementSetCustomInviteCode
  336. // @Summary 制度中心-会员中心-用户管理-用户自定义邀请码修改
  337. // @Tags 会员中心
  338. // @Description 用户自定义邀请码修改
  339. // @Accept json
  340. // @Produce json
  341. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  342. // @Param req body md.InviteCodeReq true "分页信息必填"
  343. // @Success 200 {string} "具体数据"
  344. // @Failure 400 {object} md.Response "具体错误"
  345. // @Router /api/memberCenter/userManagement/setCustomInviteCode [post]
  346. func UserManagementSetCustomInviteCode(c *gin.Context) {
  347. var req *md.InviteCodeReq
  348. if err := c.ShouldBindJSON(&req); err != nil {
  349. e.OutErr(c, e.ERR_INVALID_ARGS, err.Error())
  350. return
  351. }
  352. userDb := implement.NewUserDb(db.Db)
  353. user, err := userDb.GetUser(utils.StrToInt64(req.Id))
  354. if err != nil {
  355. e.OutErr(c, e.ERR_DB_ORM, err)
  356. return
  357. }
  358. if user == nil {
  359. e.OutErr(c, 400, e.NewErr(400, "账号不存在"))
  360. return
  361. }
  362. if req.CustomInviteCode == "" {
  363. e.OutErr(c, 400, e.NewErr(400, "请输入邀请码"))
  364. return
  365. }
  366. code := []string{req.CustomInviteCode}
  367. tmp, _ := userDb.UserFindByInviteCodes(code...)
  368. if tmp != nil {
  369. for _, v := range *tmp {
  370. if v.Id != user.Id {
  371. e.OutErr(c, 400, e.NewErr(400, "该邀请码已被绑定"))
  372. return
  373. }
  374. }
  375. }
  376. customTmp, _ := userDb.UserFindByCustomInviteCodes(code...)
  377. if customTmp != nil {
  378. for _, v := range *customTmp {
  379. if v.Id != user.Id {
  380. e.OutErr(c, 400, e.NewErr(400, "该邀请码已被绑定"))
  381. return
  382. }
  383. }
  384. }
  385. oldCode := user.CustomInviteCode
  386. user.CustomInviteCode = req.CustomInviteCode
  387. _, err = db.Db.Where("id=?", user.Id).Cols("custom_invite_code").Update(user)
  388. if err != nil {
  389. e.OutErr(c, 400, e.NewErr(400, "修改失败"))
  390. return
  391. }
  392. admin := svc2.GetUser(c)
  393. svc2.AddAdminLog(c, admin.AdmId, "用户邀请码修改", "用户id:"+utils.Int64ToStr(user.Id)+",原邀请码:"+oldCode+",新邀请码"+user.CustomInviteCode, "")
  394. e.OutSuc(c, "success", nil)
  395. return
  396. }
  397. // UserManagementUpdateUserInfo
  398. // @Summary 制度中心-会员中心-用户管理-用户信息管理(更新)
  399. // @Tags 会员中心
  400. // @Description 用户信息管理(更新)
  401. // @Accept json
  402. // @Produce json
  403. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  404. // @Param req body md.UserManagementUpdateUserInfoReq true "用户ID 必传"
  405. // @Success 200 {int} "修改数据行数"
  406. // @Failure 400 {object} md.Response "具体错误"
  407. // @Router /api/memberCenter/userManagement/updateUserInfo [post]
  408. func UserManagementUpdateUserInfo(c *gin.Context) {
  409. var req *md.UserManagementUpdateUserInfoReq
  410. if err := c.ShouldBindJSON(&req); err != nil {
  411. e.OutErr(c, e.ERR_INVALID_ARGS, err.Error())
  412. return
  413. }
  414. affected, err := svc.UserManagementUpdateUserInfo(c, db.Db, req)
  415. if err != nil {
  416. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  417. return
  418. }
  419. e.OutSuc(c, affected, nil)
  420. }
  421. // UserManagementGetUserRecycleList
  422. // @Summary 会员中心-用户管理-回收站列表
  423. // @Tags 会员中心
  424. // @Description 回收站列表
  425. // @Accept json
  426. // @Produce json
  427. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  428. // @Param req body md.UserManagementGetUserListReq true "分页信息必填"
  429. // @Success 200 {object} md.UserManagementGetUserListResp "具体数据"
  430. // @Failure 400 {object} md.Response "具体错误"
  431. // @Router /api/memberCenter/userManagement/userRecycleList [post]
  432. func UserManagementGetUserRecycleList(c *gin.Context) {
  433. var req *md.UserManagementGetUserListReq
  434. if err := c.ShouldBindJSON(&req); err != nil {
  435. e.OutErr(c, e.ERR_INVALID_ARGS, err.Error())
  436. return
  437. }
  438. req.IsRecycle = "1"
  439. levelDb := implement.NewUserLevelDb(db.Db)
  440. levels, err1 := levelDb.UserLevelAllByAsc()
  441. if err1 != nil {
  442. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  443. return
  444. }
  445. levelsList := make([]map[string]interface{}, 0)
  446. levelsMap := make(map[int]string)
  447. for _, level := range levels {
  448. levelsList = append(levelsList, map[string]interface{}{
  449. "id": level.Id,
  450. "name": level.LevelName,
  451. })
  452. levelsMap[level.Id] = level.LevelName
  453. }
  454. tagDb := implement.NewUserTagDb(db.Db)
  455. tags, err2 := tagDb.UserTagAllByAsc()
  456. if err2 != nil {
  457. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  458. return
  459. }
  460. tagsList := make([]map[string]interface{}, 0)
  461. tagsMap := make(map[int]string)
  462. for _, tag := range tags {
  463. tagsList = append(tagsList, map[string]interface{}{
  464. "id": tag.Id,
  465. "name": tag.TagName,
  466. })
  467. tagsMap[tag.Id] = tag.TagName
  468. }
  469. stateList := []map[string]interface{}{
  470. {
  471. "name": "正常",
  472. "value": "1",
  473. },
  474. {
  475. "name": "冻结",
  476. "value": "2",
  477. },
  478. }
  479. users, total, err3 := svc.UserManagementGetUsers(req)
  480. if err3 != nil {
  481. e.OutErr(c, e.ERR_DB_ORM, err3.Error())
  482. return
  483. }
  484. userIDs := make([]int64, len(users))
  485. for i, user := range users {
  486. userIDs[i] = user.Id
  487. }
  488. recordsDb := implement.NewUserTagRecordsDb(db.Db)
  489. records, err := recordsDb.UserTagRecordsFindByParams(map[string]interface{}{
  490. "key": "uid",
  491. "value": userIDs,
  492. })
  493. if err != nil {
  494. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  495. return
  496. }
  497. var levelCounts []md.LevelCount
  498. err4 := db.Db.Table("user").Select("level, Count(*) AS count").GroupBy("level").Find(&levelCounts)
  499. if err4 != nil {
  500. e.OutErr(c, e.ERR_DB_ORM, err4.Error())
  501. return
  502. }
  503. userMap := make(map[int64]int, len(users))
  504. list := make([]md.UserManagementGetUserListNode, len(users))
  505. for i, user := range users {
  506. list[i] = md.UserManagementGetUserListNode{
  507. ID: user.Id,
  508. Sex: user.Sex,
  509. Avatar: svc2.GetOssUrl(user.Avatar),
  510. Nickname: user.Nickname,
  511. Phone: user.Phone,
  512. IsRealName: user.IsRealName,
  513. InviteCode: user.SystemInviteCode,
  514. ParentID: user.ParentUid,
  515. ParentInviteCode: user.ParentSystemInviteCode,
  516. ParentPhone: user.ParentPhone,
  517. RegisterTime: user.CreateAt,
  518. Memo: user.Memo,
  519. Wechat: user.UnionId,
  520. RegisterType: user.RegisterType,
  521. State: user.State,
  522. LastLoginAt: user.UpdateAt,
  523. }
  524. var tempTagList []md.TagNode
  525. list[i].Tag = tempTagList
  526. userMap[user.Id] = i
  527. level, ok := levelsMap[user.Level]
  528. if ok {
  529. list[i].LevelName = level
  530. }
  531. }
  532. for _, record := range *records {
  533. tempTagNode := md.TagNode{
  534. TagID: record.TagId,
  535. TagName: tagsMap[record.TagId],
  536. }
  537. list[userMap[record.Uid]].Tag = append(list[userMap[record.Uid]].Tag, tempTagNode)
  538. }
  539. resp := md.UserManagementGetUserListResp{
  540. LevelsList: levelsList,
  541. TagsList: tagsList,
  542. StateList: stateList,
  543. List: list,
  544. Paginate: md.Paginate{
  545. Limit: req.Limit,
  546. Page: req.Page,
  547. Total: total,
  548. },
  549. }
  550. e.OutSuc(c, resp, nil)
  551. }
  552. // UserManagementUserRecycle
  553. // @Summary 会员中心-用户管理-删除到回收站
  554. // @Tags 会员中心
  555. // @Description 删除到回收站
  556. // @Accept json
  557. // @Produce json
  558. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  559. // @Param req body md.UserManagementUserInfoReq true "用户ID 必传"
  560. // @Success 200 {int} "修改数据行数"
  561. // @Failure 400 {object} md.Response "具体错误"
  562. // @Router /api/memberCenter/userManagement/userRecycle [post]
  563. func UserManagementUserRecycle(c *gin.Context) {
  564. var req *md.UserManagementUserInfoReq
  565. if err := c.ShouldBindJSON(&req); err != nil {
  566. e.OutErr(c, e.ERR_INVALID_ARGS, err.Error())
  567. return
  568. }
  569. ex := strings.Split(req.UID, ",")
  570. NewUserDb := implement.NewUserDb(db.Db)
  571. for _, v := range ex {
  572. user, _ := NewUserDb.GetUser(utils.StrToInt64(v))
  573. if user == nil {
  574. e.OutErr(c, 400, e.NewErr(400, "用户不存在"))
  575. return
  576. }
  577. user.State = 4
  578. user.RecycleParentUid = utils.StrToInt(req.ParentUid)
  579. db.Db.Where("id=?", user.Id).Cols("state,recycle_parent_uid").Update(user)
  580. // 清掉token
  581. cacheKey := fmt.Sprintf("egg_app_jwt_token:%d", user.Id)
  582. cache.SetEx(cacheKey, "", 1)
  583. admin := svc2.GetUser(c)
  584. svc2.AddAdminLog(c, admin.AdmId, "用户回收", "用户id:"+utils.Int64ToStr(user.Id)+",用户手机号:"+user.Phone+" 删除到回收站", "")
  585. }
  586. e.OutSuc(c, "success", nil)
  587. }
  588. // UserManagementUserRecycleCancel
  589. // @Summary 会员中心-用户管理-恢复到会员列表
  590. // @Tags 会员中心
  591. // @Description 恢复到会员列表
  592. // @Accept json
  593. // @Produce json
  594. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  595. // @Param req body md.UserManagementUserInfoCancelReq true "用户ID 必传"
  596. // @Success 200 {int} "修改数据行数"
  597. // @Failure 400 {object} md.Response "具体错误"
  598. // @Router /api/memberCenter/userManagement/userRecycleCancel [post]
  599. func UserManagementUserRecycleCancel(c *gin.Context) {
  600. var req *md.UserManagementUserInfoReq
  601. if err := c.ShouldBindJSON(&req); err != nil {
  602. e.OutErr(c, e.ERR_INVALID_ARGS, err.Error())
  603. return
  604. }
  605. NewUserDb := implement.NewUserDb(db.Db)
  606. ex := strings.Split(req.UID, ",")
  607. for _, v := range ex {
  608. user, _ := NewUserDb.GetUser(utils.StrToInt64(v))
  609. if user == nil {
  610. e.OutErr(c, 400, e.NewErr(400, "用户不存在"))
  611. return
  612. }
  613. user.State = 1
  614. user.RecycleParentUid = 0
  615. db.Db.Where("id=?", user.Id).Cols("state,recycle_parent_uid").Update(user)
  616. admin := svc2.GetUser(c)
  617. svc2.AddAdminLog(c, admin.AdmId, "用户恢复", "用户id:"+utils.Int64ToStr(user.Id)+",用户手机号:"+user.Phone+" 恢复到会员列表", "")
  618. }
  619. e.OutSuc(c, "success", nil)
  620. }
  621. // UserManagementUserDelete
  622. // @Summary 会员中心-用户管理-永久删除
  623. // @Tags 会员中心
  624. // @Description 删除到回收站
  625. // @Accept json
  626. // @Produce json
  627. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  628. // @Param req body md.UserManagementUserInfoReq true "用户ID 必传"
  629. // @Success 200 {int} "修改数据行数"
  630. // @Failure 400 {object} md.Response "具体错误"
  631. // @Router /api/memberCenter/userManagement/userDelete [post]
  632. func UserManagementUserDelete(c *gin.Context) {
  633. var req *md.UserManagementUserInfoReq
  634. if err := c.ShouldBindJSON(&req); err != nil {
  635. e.OutErr(c, e.ERR_INVALID_ARGS, err.Error())
  636. return
  637. }
  638. NewUserDb := implement.NewUserDb(db.Db)
  639. ex := strings.Split(req.UID, ",")
  640. ch, err := rabbit.Cfg.Pool.GetChannel()
  641. if err == nil {
  642. defer ch.Release()
  643. }
  644. for _, v := range ex {
  645. user, _ := NewUserDb.GetUser(utils.StrToInt64(v))
  646. if user == nil {
  647. e.OutErr(c, 400, e.NewErr(400, "用户不存在"))
  648. return
  649. }
  650. if user.State != 4 {
  651. e.OutErr(c, 400, e.NewErr(400, "不能删除"))
  652. return
  653. }
  654. user.State = 3
  655. db.Db.Where("id=?", user.Id).Cols("state").Update(user)
  656. tmp := model.UserDeleteInfo{
  657. Uid: int(user.Id),
  658. Phone: user.Phone,
  659. CreateAt: time.Now(),
  660. }
  661. db.Db.Insert(&tmp)
  662. err = ch.PublishV2(md2.EggUserExchange, md2.CommUserId{
  663. Uid: utils.Int64ToStr(user.Id),
  664. ParentUid: utils.IntToStr(user.RecycleParentUid),
  665. }, md2.EggUserDelete)
  666. if err != nil {
  667. ch.PublishV2(md2.EggUserExchange, md2.CommUserId{
  668. Uid: utils.Int64ToStr(user.Id),
  669. ParentUid: utils.IntToStr(user.RecycleParentUid),
  670. }, md2.EggUserDelete)
  671. }
  672. // 清掉token
  673. cacheKey := fmt.Sprintf("egg_app_jwt_token:%d", user.Id)
  674. _, err = cache.SetEx(cacheKey, "", 1)
  675. admin := svc2.GetUser(c)
  676. svc2.AddAdminLog(c, admin.AdmId, "用户永久删除", "用户id:"+utils.Int64ToStr(user.Id)+",用户手机号:"+user.Phone+" 永久删除", "")
  677. }
  678. e.OutSuc(c, "success", nil)
  679. return
  680. }
  681. // UserManagementGetOneBasic
  682. // @Summary 制度中心-会员中心-用户管理-会员明细概况(获取)
  683. // @Tags 会员中心
  684. // @Description 会员明细概况(获取)
  685. // @Accept json
  686. // @Produce json
  687. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  688. // @Param uid query string true "用户 ID"
  689. // @Success 200 {object} md.UserManagementGetOneBasicResp "会员明细概况具体数据"
  690. // @Failure 400 {object} md.Response "具体错误"
  691. // @Router /api/memberCenter/userManagement/userData [get]
  692. func UserManagementGetOneBasic(c *gin.Context) {
  693. uid := c.Query("uid")
  694. userDb := implement.NewUserDb(db.Db)
  695. user, err := userDb.UserGetOneByParams(map[string]interface{}{
  696. "key": "id",
  697. "value": uid,
  698. })
  699. if err != nil {
  700. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  701. return
  702. }
  703. // 1. 查询等级列表
  704. levelDb := implement.NewUserLevelDb(db.Db)
  705. levels, err1 := levelDb.UserLevelAllByAsc()
  706. if err1 != nil {
  707. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  708. return
  709. }
  710. levelsList := make([]map[string]interface{}, 0)
  711. levelsMap := make(map[int]string)
  712. for _, level := range levels {
  713. levelsList = append(levelsList, map[string]interface{}{
  714. "id": level.Id,
  715. "name": level.LevelName,
  716. })
  717. levelsMap[level.Id] = level.LevelName
  718. }
  719. //2. 查询标签列表
  720. tagDb := implement.NewUserTagDb(db.Db)
  721. tags, err2 := tagDb.UserTagAllByAsc()
  722. if err2 != nil {
  723. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  724. return
  725. }
  726. tagsList := make([]map[string]interface{}, 0)
  727. tagsMap := make(map[int]string)
  728. for _, tag := range tags {
  729. tagsList = append(tagsList, map[string]interface{}{
  730. "id": tag.Id,
  731. "name": tag.TagName,
  732. })
  733. tagsMap[tag.Id] = tag.TagName
  734. }
  735. //3. 查询父用户信息
  736. parent, err := userDb.UserGetOneByParams(map[string]interface{}{
  737. "key": "id",
  738. "value": user.ParentUid,
  739. })
  740. if err != nil {
  741. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  742. return
  743. }
  744. //4. 查询用户标签
  745. recordsDb := implement.NewUserTagRecordsDb(db.Db)
  746. userTagRecords, err := recordsDb.UserTagRecordsFindByParams(map[string]interface{}{
  747. "key": "uid",
  748. "value": uid,
  749. })
  750. if err != nil {
  751. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  752. return
  753. }
  754. resp := md.UserManagementGetOneBasicResp{
  755. TagsList: tagsList,
  756. LevelsList: levelsList,
  757. BasicInfo: md.BasicInfoNode{
  758. Avatar: user.Avatar,
  759. AvatarUrl: svc2.GetOssUrl(user.Avatar),
  760. Sex: user.Sex,
  761. Nickname: user.Nickname,
  762. LevelId: user.Level,
  763. Phone: user.Phone,
  764. UnionId: user.UnionId,
  765. WechatAccount: user.WechatAccount,
  766. Password: "",
  767. State: user.State,
  768. Memo: user.Memo,
  769. SystemInviteCode: user.SystemInviteCode,
  770. CustomInviteCode: user.CustomInviteCode,
  771. },
  772. OtherInfo: md.OtherNode{
  773. LastLoginIp: user.LastLoginIp,
  774. LastLoginAt: user.UpdateAt,
  775. CreateAt: user.CreateAt,
  776. },
  777. }
  778. NewAlipayUserInfoDb := implement.NewAlipayUserInfoDb(db.Db)
  779. info, _ := NewAlipayUserInfoDb.GetAlipayUserInfo(user.Id)
  780. if info != nil {
  781. resp.BasicInfo.AlipayUserName = info.UserName
  782. resp.BasicInfo.AlipayOpenId = info.OpenId
  783. }
  784. NewWxUserInfoDb := implement.NewWxUserInfoDb(db.Db)
  785. wxInfo, _ := NewWxUserInfoDb.GetWxUserInfo(user.Id)
  786. if wxInfo != nil {
  787. resp.BasicInfo.WechatUserName = wxInfo.UserName
  788. resp.BasicInfo.WechatOpenId = wxInfo.OpenId
  789. }
  790. tagList := make([]md.TagNode, len(*userTagRecords))
  791. if *userTagRecords != nil {
  792. for i, records := range *userTagRecords {
  793. tagList[i].TagID = records.TagId
  794. tagList[i].TagName = tagsMap[records.TagId]
  795. }
  796. }
  797. resp.BasicInfo.Tag = tagList
  798. if parent != nil {
  799. resp.BasicInfo.ParentUid = parent.Id
  800. resp.BasicInfo.ParentName = parent.Nickname
  801. resp.BasicInfo.ParentPhone = parent.Phone
  802. }
  803. level, ok := levelsMap[user.Level]
  804. if ok {
  805. resp.BasicInfo.LevelName = level
  806. }
  807. e.OutSuc(c, resp, nil)
  808. }
  809. // UserManagementGetFans
  810. // @Summary 制度中心-会员中心-用户管理-会员明细粉丝情况(获取)
  811. // @Tags 会员中心
  812. // @Description 会员明细粉丝情况(获取)
  813. // @Accept json
  814. // @Produce json
  815. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  816. // @Param uid query string true "用户 ID"
  817. // @Param type query string true "粉丝类型(0.全部 1.直推 2.二代 3.二代以后)"
  818. // @Param limit query string true "每页大小"
  819. // @Param page query string true "页数"
  820. // @Success 200 {object} md.UserManagementGetFansResp "具体数据"
  821. // @Failure 400 {object} md.Response "具体错误"
  822. // @Router /api/memberCenter/userManagement/getFans [get]
  823. func UserManagementGetFans(c *gin.Context) {
  824. uid := c.Query("uid")
  825. fansType := c.Query("type")
  826. limit := c.Query("limit")
  827. page := c.Query("page")
  828. //1. 查询符合情况用户 ID
  829. relateDb := implement.NewUserRelateDb(db.Db)
  830. var level int
  831. switch fansType {
  832. case "0":
  833. level = 0
  834. case "1":
  835. level = 1
  836. case "2":
  837. level = 2
  838. case "3":
  839. level = 3
  840. default:
  841. level = 0
  842. }
  843. relates, total, err := relateDb.PageFindUserRelateByParentUidAndLevel(utils.StrToInt64(uid), utils.StrToInt(page), utils.StrToInt(limit), level)
  844. if err != nil {
  845. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  846. return
  847. }
  848. userIDs := make([]int64, len(*relates))
  849. for i, relate := range *relates {
  850. userIDs[i] = relate.Uid
  851. }
  852. //2. 查询所属代数
  853. platoonUserRelationDb := implement.NewPublicPlatoonUserRelationDb(db.Db)
  854. levelTotals, err := platoonUserRelationDb.PublicPlatoonUserRelationFindByParamsByPage(map[string]interface{}{
  855. "key": "uid",
  856. "value": userIDs,
  857. }, utils.StrToInt(page), utils.StrToInt(limit))
  858. if err != nil {
  859. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  860. return
  861. }
  862. levelTotalMap := make(map[int64]int)
  863. for _, levelTotal := range *levelTotals {
  864. levelTotalMap[levelTotal.Uid] = levelTotal.LevelTotal
  865. }
  866. //3. 查询可提现余额
  867. walletDb := implement.NewUserWalletDb(db.Db)
  868. wallets, err := walletDb.FindUserWalletByParams(map[string]interface{}{
  869. "key": "uid",
  870. "value": userIDs,
  871. })
  872. if err != nil {
  873. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  874. return
  875. }
  876. walletMap := make(map[int64]string)
  877. for _, wallet := range *wallets {
  878. walletMap[wallet.Uid] = wallet.Amount
  879. }
  880. //4. 查询累计收益
  881. var incomeMap = map[int64]string{}
  882. if len(*relates) > 0 {
  883. userIDStrs := make([]string, len(*relates))
  884. for i, id := range userIDs {
  885. userIDStrs[i] = utils.Int64ToStr(id)
  886. }
  887. sql := "SELECT SUM(amount) as total, uid FROM `user_wallet_flow` WHERE uid in (%s) AND direction = 1 Group BY uid"
  888. results, err := db.QueryNativeString(db.Db, fmt.Sprintf(sql, strings.Join(userIDStrs, ",")))
  889. if err != nil {
  890. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  891. return
  892. }
  893. for _, res := range results {
  894. incomeMap[utils.StrToInt64(res["uid"])] = res["total"]
  895. }
  896. }
  897. //5. 查询用户信息
  898. userDb := implement.NewUserDb(db.Db)
  899. users, err := userDb.UserFindByParams(map[string]interface{}{
  900. "key": "id",
  901. "value": userIDs,
  902. })
  903. if err != nil {
  904. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  905. return
  906. }
  907. list := make([]md.FansNode, len(users))
  908. for i, user := range users {
  909. list[i] = md.FansNode{
  910. ID: user.Id,
  911. Nickname: user.Nickname,
  912. Phone: user.Phone,
  913. RegisterAt: user.CreateAt,
  914. }
  915. val, ok := incomeMap[user.Id]
  916. if ok {
  917. list[i].TotalIncome = val
  918. }
  919. levelTotal, ok := levelTotalMap[user.Id]
  920. if ok {
  921. list[i].LevelTotal = levelTotal
  922. }
  923. amount, ok := walletMap[user.Id]
  924. if ok {
  925. list[i].Amount = amount
  926. }
  927. }
  928. resp := md.UserManagementGetFansResp{
  929. List: list,
  930. Paginate: md.Paginate{
  931. Limit: utils.StrToInt(limit),
  932. Page: utils.StrToInt(page),
  933. Total: total,
  934. },
  935. }
  936. e.OutSuc(c, resp, nil)
  937. }
  938. // UserManagementGetBalanceDetail
  939. // @Summary 制度中心-会员中心-用户管理-会员明细(余额获取)
  940. // @Tags 会员中心
  941. // @Description 会员明细(余额获取)
  942. // @Accept json
  943. // @Produce json
  944. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  945. // @Param uid query string true "用户 ID"
  946. // @Param limit query string true "每页大小"
  947. // @Param page query string true "页数"
  948. // @Success 200 {object} md.UserManagementGetBalanceDetailResp "具体数据"
  949. // @Failure 400 {object} md.Response "具体错误"
  950. // @Router /api/memberCenter/userManagement/balanceDetail [get]
  951. func UserManagementGetBalanceDetail(c *gin.Context) {
  952. uid := c.Query("uid")
  953. page := c.DefaultQuery("page", "1")
  954. limit := c.DefaultQuery("limit", "10")
  955. walletFlowDb := implement.NewUserWalletFlowDb(db.Db)
  956. walletFlows, total, err := walletFlowDb.UserWalletFlowFindByParams(map[string]interface{}{
  957. "key": "uid",
  958. "value": uid,
  959. }, utils.StrToInt(page), utils.StrToInt(limit))
  960. if err != nil {
  961. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  962. return
  963. }
  964. kindMap := map[int]string{
  965. 1: "管理员操作增加余额",
  966. 2: "管理员操作扣除余额",
  967. 3: "蛋蛋能量兑换余额",
  968. 4: "余额兑换蛋蛋能量",
  969. }
  970. list := make([]md.BalanceDetailNode, len(*walletFlows))
  971. for i, flow := range *walletFlows {
  972. list[i] = md.BalanceDetailNode{
  973. ID: flow.Id,
  974. Amount: flow.Amount,
  975. AfterAmount: flow.AfterAmount,
  976. Kind: kindMap[flow.Kind],
  977. CreateAt: flow.CreateAt,
  978. }
  979. }
  980. resp := md.UserManagementGetBalanceDetailResp{
  981. List: list,
  982. Paginate: md.Paginate{
  983. Limit: utils.StrToInt(limit),
  984. Page: utils.StrToInt(page),
  985. Total: total,
  986. },
  987. }
  988. e.OutSuc(c, resp, nil)
  989. }
  990. // UserManagementGetVirtualCoinDetail
  991. // @Summary 制度中心-会员中心-用户管理-会员明细(积分明细获取)
  992. // @Tags 会员中心
  993. // @Description 会员明细(积分明细获取)
  994. // @Accept json
  995. // @Produce json
  996. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  997. // @Param uid query string true "用户 ID"
  998. // @Param coinId query string true "货币 ID"
  999. // @Param limit query string true "每页大小"
  1000. // @Param page query string true "页数"
  1001. // @Success 200 {object} md.UserManagementGetVirtualCoinDetailResp "具体数据"
  1002. // @Failure 400 {object} md.Response "具体错误"
  1003. // @Router /api/memberCenter/userManagement/getVirtualCoinDetail [get]
  1004. func UserManagementGetVirtualCoinDetail(c *gin.Context) {
  1005. page := c.DefaultQuery("page", "1")
  1006. limit := c.DefaultQuery("limit", "10")
  1007. uid := c.Query("uid")
  1008. coinID := c.Query("coinId")
  1009. coinDb := implement.NewVirtualCoinDb(db.Db)
  1010. coins, err := coinDb.VirtualCoinFindAll()
  1011. if err != nil {
  1012. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  1013. return
  1014. }
  1015. if coins == nil {
  1016. e.OutErr(c, e.ERR_NO_DATA, errors.New("未初始化货币"))
  1017. return
  1018. }
  1019. coinsList := make([]map[string]interface{}, len(coins))
  1020. coinsMap := map[int]string{}
  1021. for i, coin := range coins {
  1022. coinsList[i] = map[string]interface{}{
  1023. "coinID": coin.Id,
  1024. "name": coin.Name,
  1025. }
  1026. coinsMap[coin.Id] = coin.Name
  1027. }
  1028. // 传入不存在的货币类型时 默认为第一种货币类型
  1029. var reqCoinID int
  1030. _, ok := coinsMap[utils.StrToInt(coinID)]
  1031. if !ok {
  1032. reqCoinID = coinsList[0]["coinID"].(int)
  1033. } else {
  1034. reqCoinID = utils.StrToInt(coinID)
  1035. }
  1036. flowDb := implement.NewUserVirtualCoinFlowDb(db.Db)
  1037. flows, total, err := flowDb.UserVirtualCoinFlowFindByCoinAndUser(utils.StrToInt(page), utils.StrToInt(limit), reqCoinID, utils.StrToInt64(uid), "", "", 0, false, 0)
  1038. if err != nil {
  1039. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  1040. return
  1041. }
  1042. list := make([]md.VirtualCoinDetailNode, len(flows))
  1043. for i, flow := range flows {
  1044. list[i] = md.VirtualCoinDetailNode{
  1045. Uid: flow.Uid,
  1046. Amount: flow.Amount,
  1047. AfterAmount: flow.AfterAmount,
  1048. Direction: flow.Direction,
  1049. CreateAt: flow.CreateAt,
  1050. }
  1051. }
  1052. resp := md.UserManagementGetVirtualCoinDetailResp{
  1053. CoinList: coinsList,
  1054. List: list,
  1055. Paginate: md.Paginate{
  1056. Limit: utils.StrToInt(limit),
  1057. Page: utils.StrToInt(page),
  1058. Total: total,
  1059. },
  1060. }
  1061. e.OutSuc(c, resp, nil)
  1062. }