蛋蛋星球-客户端
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

102 行
2.6 KiB

  1. package hdl
  2. import (
  3. "applet/app/db"
  4. "applet/app/e"
  5. "applet/app/md"
  6. "applet/app/svc"
  7. "applet/app/utils"
  8. "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
  9. "github.com/gin-gonic/gin"
  10. "github.com/syyongx/php2go"
  11. )
  12. // UserInfo
  13. // @Summary 用户信息
  14. // @Tags 用户信息
  15. // @Description 用户信息
  16. // @Accept json
  17. // @Produce json
  18. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  19. // @Success 200 {object} md.UserInfoResp "具体数据"
  20. // @Failure 400 {object} md.Response "具体错误"
  21. // @Router /api/v1/userInfo [get]
  22. func UserInfo(c *gin.Context) {
  23. user := svc.GetUser(c)
  24. res := md.UserInfoResp{
  25. Id: utils.Int64ToStr(user.Id),
  26. Phone: user.Phone,
  27. Nickname: user.Phone,
  28. InviteCode: user.SystemInviteCode,
  29. IsBindExtend: "0",
  30. }
  31. if user.Avatar == "" {
  32. user.Avatar = svc.GetSysCfgStr("default_avatar")
  33. }
  34. if user.Avatar != "" {
  35. res.HeadImg = svc.GetOssUrl(user.Avatar)
  36. }
  37. if user.CustomInviteCode != "" {
  38. res.InviteCode = user.CustomInviteCode
  39. }
  40. if user.ParentUid > 0 {
  41. res.IsBindExtend = "1"
  42. }
  43. e.OutSuc(c, res, nil)
  44. return
  45. }
  46. // InviteCodeUserInfo
  47. // @Summary 邀请码获取用户信息
  48. // @Tags 登录注册
  49. // @Description 邀请码获取用户信息
  50. // @Accept json
  51. // @Produce json
  52. // @Param req body md.InviteCodeUserInfoReq true "注册参数"
  53. // @Success 200 {object} md.InviteCodeUserInfoResp "具体数据"
  54. // @Failure 400 {object} md.Response "具体错误"
  55. // @Router /api/v1/inviteCode/userInfo [post]
  56. func InviteCodeUserInfo(c *gin.Context) {
  57. var req md.InviteCodeUserInfoReq
  58. err := c.ShouldBindJSON(&req)
  59. if err != nil {
  60. err = svc.HandleValidateErr(err)
  61. err1 := err.(e.E)
  62. e.OutErr(c, err1.Code, err1.Error())
  63. return
  64. }
  65. if req.InviteCode == "" {
  66. e.OutErr(c, 400, e.NewErr(400, "邀请码不能为空"))
  67. return
  68. }
  69. userDb := implement.NewUserDb(db.Db)
  70. user, err := userDb.UserGetOneByParams(map[string]interface{}{
  71. "key": "system_invite_code",
  72. "value": req.InviteCode,
  73. })
  74. if user == nil {
  75. user, _ = userDb.UserGetOneByParams(map[string]interface{}{
  76. "key": "custom_invite_code",
  77. "value": req.InviteCode,
  78. })
  79. if user == nil {
  80. e.OutErr(c, 400, e.NewErr(400, "用户不存在"))
  81. return
  82. }
  83. }
  84. nickname := user.Nickname
  85. if nickname == "" {
  86. nickname = user.Phone
  87. }
  88. if php2go.IsNumeric(nickname) {
  89. nickname = utils.HideTrueName(user.Nickname)
  90. }
  91. user = svc.UserImg(user)
  92. res := md.InviteCodeUserInfoResp{
  93. Nickname: nickname,
  94. HeadImg: user.Avatar,
  95. }
  96. e.OutSuc(c, res, nil)
  97. return
  98. }