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

175 lines
4.7 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. "code.fnuoos.com/EggPlanet/egg_models.git/src/model"
  10. "github.com/gin-gonic/gin"
  11. "github.com/syyongx/php2go"
  12. )
  13. // UserInfo
  14. // @Summary 用户信息
  15. // @Tags 用户信息
  16. // @Description 用户信息
  17. // @Accept json
  18. // @Produce json
  19. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  20. // @Success 200 {object} md.UserInfoResp "具体数据"
  21. // @Failure 400 {object} md.Response "具体错误"
  22. // @Router /api/v1/userInfo [get]
  23. func UserInfo(c *gin.Context) {
  24. user := svc.GetUser(c)
  25. res := md.UserInfoResp{
  26. Id: utils.Int64ToStr(user.Id),
  27. Phone: user.Phone,
  28. Nickname: user.Phone,
  29. InviteCode: user.SystemInviteCode,
  30. IsBindExtend: "0",
  31. }
  32. if user.Avatar == "" {
  33. user.Avatar = svc.GetSysCfgStr("default_avatar")
  34. }
  35. if user.Avatar != "" {
  36. res.HeadImg = svc.GetOssUrl(user.Avatar)
  37. }
  38. if user.CustomInviteCode != "" {
  39. res.InviteCode = user.CustomInviteCode
  40. }
  41. if user.ParentUid > 0 {
  42. res.IsBindExtend = "1"
  43. }
  44. e.OutSuc(c, res, nil)
  45. return
  46. }
  47. // InviteCodeUserInfo
  48. // @Summary 邀请码获取用户信息
  49. // @Tags 登录注册
  50. // @Description 邀请码获取用户信息
  51. // @Accept json
  52. // @Produce json
  53. // @Param req body md.InviteCodeUserInfoReq true "注册参数"
  54. // @Success 200 {object} md.InviteCodeUserInfoResp "具体数据"
  55. // @Failure 400 {object} md.Response "具体错误"
  56. // @Router /api/v1/inviteCode/userInfo [post]
  57. func InviteCodeUserInfo(c *gin.Context) {
  58. var req md.InviteCodeUserInfoReq
  59. err := c.ShouldBindJSON(&req)
  60. if err != nil {
  61. err = svc.HandleValidateErr(err)
  62. err1 := err.(e.E)
  63. e.OutErr(c, err1.Code, err1.Error())
  64. return
  65. }
  66. if req.InviteCode == "" {
  67. e.OutErr(c, 400, e.NewErr(400, "邀请码不能为空"))
  68. return
  69. }
  70. userDb := implement.NewUserDb(db.Db)
  71. user, err := userDb.UserGetOneByParams(map[string]interface{}{
  72. "key": "system_invite_code",
  73. "value": req.InviteCode,
  74. })
  75. if user == nil {
  76. user, _ = userDb.UserGetOneByParams(map[string]interface{}{
  77. "key": "custom_invite_code",
  78. "value": req.InviteCode,
  79. })
  80. if user == nil {
  81. e.OutErr(c, 400, e.NewErr(400, "用户不存在"))
  82. return
  83. }
  84. }
  85. nickname := user.Nickname
  86. if nickname == "" {
  87. nickname = user.Phone
  88. }
  89. if php2go.IsNumeric(nickname) {
  90. nickname = utils.HideTrueName(user.Nickname)
  91. }
  92. user = svc.UserImg(user)
  93. res := md.InviteCodeUserInfoResp{
  94. Nickname: nickname,
  95. HeadImg: user.Avatar,
  96. }
  97. e.OutSuc(c, res, nil)
  98. return
  99. }
  100. // UserBindParent
  101. // @Summary 绑定上级-要登陆的
  102. // @Tags 登录注册
  103. // @Description 绑定上级
  104. // @Accept json
  105. // @Produce json
  106. // @Param req body md.InviteCodeUserInfoReq true "注册参数"
  107. // @Success 200 {string} "具体数据"
  108. // @Failure 400 {object} md.Response "具体错误"
  109. // @Router /api/v1/memberCenter/bindParent [post]
  110. func UserBindParent(c *gin.Context) {
  111. var req md.InviteCodeUserInfoReq
  112. err := c.ShouldBindJSON(&req)
  113. if err != nil {
  114. err = svc.HandleValidateErr(err)
  115. err1 := err.(e.E)
  116. e.OutErr(c, err1.Code, err1.Error())
  117. return
  118. }
  119. if req.InviteCode == "" {
  120. e.OutErr(c, 400, e.NewErr(400, "邀请码不能为空"))
  121. return
  122. }
  123. userDb := implement.NewUserDb(db.Db)
  124. user, err := userDb.UserGetOneByParams(map[string]interface{}{
  125. "key": "system_invite_code",
  126. "value": req.InviteCode,
  127. })
  128. if user == nil {
  129. user, _ = userDb.UserGetOneByParams(map[string]interface{}{
  130. "key": "custom_invite_code",
  131. "value": req.InviteCode,
  132. })
  133. if user == nil {
  134. e.OutErr(c, 400, e.NewErr(400, "用户不存在"))
  135. return
  136. }
  137. }
  138. ownUser := svc.GetUser(c)
  139. if ownUser.ParentUid > 0 {
  140. e.OutErr(c, 400, e.NewErr(400, "已有导师"))
  141. return
  142. }
  143. if user.Id == ownUser.Id {
  144. e.OutErr(c, 400, e.NewErr(400, "不能绑定自己"))
  145. return
  146. }
  147. ownUser.ParentUid = user.Id
  148. _, err = db.Db.Where("id=?", ownUser.Id).Cols("parent_uid").Update(ownUser)
  149. if err != nil {
  150. e.OutErr(c, 400, e.NewErr(400, "绑定失败,请重试"))
  151. return
  152. }
  153. initLV := 1
  154. ur := new(model.UserRelate)
  155. ur.ParentUid = user.Id
  156. ur.Uid = ownUser.Id
  157. ur.Level = initLV
  158. ur.InviteTime = ownUser.CreateAt
  159. userRelateDb := implement.NewUserRelateDb(db.Db)
  160. _, err = userRelateDb.UserRelateInsert(ur)
  161. if err != nil {
  162. e.OutErr(c, e.ERR_DB_ORM, err)
  163. return
  164. }
  165. // 插入多级关联
  166. go svc.RoutineMultiRelate(ur.ParentUid, ur.Uid, initLV)
  167. //TODO 绑定成功后 加群之类的怎么处理
  168. e.OutSuc(c, "success", nil)
  169. return
  170. }