蛋蛋星球-客户端
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.
 
 
 
 

160 lines
4.3 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. }
  99. // UserBindParent
  100. // @Summary 绑定上级-要登陆的
  101. // @Tags 登录注册
  102. // @Description 绑定上级
  103. // @Accept json
  104. // @Produce json
  105. // @Param req body md.InviteCodeUserInfoReq true "注册参数"
  106. // @Success 200 {string} "具体数据"
  107. // @Failure 400 {object} md.Response "具体错误"
  108. // @Router /api/v1/memberCenter/bindParent [post]
  109. func UserBindParent(c *gin.Context) {
  110. var req md.InviteCodeUserInfoReq
  111. err := c.ShouldBindJSON(&req)
  112. if err != nil {
  113. err = svc.HandleValidateErr(err)
  114. err1 := err.(e.E)
  115. e.OutErr(c, err1.Code, err1.Error())
  116. return
  117. }
  118. if req.InviteCode == "" {
  119. e.OutErr(c, 400, e.NewErr(400, "邀请码不能为空"))
  120. return
  121. }
  122. userDb := implement.NewUserDb(db.Db)
  123. user, err := userDb.UserGetOneByParams(map[string]interface{}{
  124. "key": "system_invite_code",
  125. "value": req.InviteCode,
  126. })
  127. if user == nil {
  128. user, _ = userDb.UserGetOneByParams(map[string]interface{}{
  129. "key": "custom_invite_code",
  130. "value": req.InviteCode,
  131. })
  132. if user == nil {
  133. e.OutErr(c, 400, e.NewErr(400, "用户不存在"))
  134. return
  135. }
  136. }
  137. ownUser := svc.GetUser(c)
  138. if ownUser.ParentUid > 0 {
  139. e.OutErr(c, 400, e.NewErr(400, "已有导师"))
  140. return
  141. }
  142. if user.Id == ownUser.Id {
  143. e.OutErr(c, 400, e.NewErr(400, "不能绑定自己"))
  144. return
  145. }
  146. ownUser.ParentUid = user.Id
  147. _, err = db.Db.Where("id=?", ownUser.Id).Cols("parent_uid").Update(ownUser)
  148. if err != nil {
  149. e.OutErr(c, 400, e.NewErr(400, "绑定失败,请重试"))
  150. return
  151. }
  152. //TODO 绑定成功后 加群之类的怎么处理
  153. e.OutSuc(c, "success", nil)
  154. return
  155. }