|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- package hdl
-
- import (
- "applet/app/db"
- "applet/app/e"
- "applet/app/md"
- "applet/app/svc"
- "applet/app/utils"
- "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
- "github.com/gin-gonic/gin"
- "github.com/syyongx/php2go"
- )
-
- // UserInfo
- // @Summary 用户信息
- // @Tags 用户信息
- // @Description 用户信息
- // @Accept json
- // @Produce json
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @Success 200 {object} md.UserInfoResp "具体数据"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/v1/userInfo [get]
- func UserInfo(c *gin.Context) {
- user := svc.GetUser(c)
- res := md.UserInfoResp{
- Id: utils.Int64ToStr(user.Id),
- Phone: user.Phone,
- Nickname: user.Phone,
- InviteCode: user.SystemInviteCode,
- IsBindExtend: "0",
- }
- if user.Avatar == "" {
- user.Avatar = svc.GetSysCfgStr("default_avatar")
- }
- if user.Avatar != "" {
- res.HeadImg = svc.GetOssUrl(user.Avatar)
- }
- if user.CustomInviteCode != "" {
- res.InviteCode = user.CustomInviteCode
- }
- if user.ParentUid > 0 {
- res.IsBindExtend = "1"
- }
- e.OutSuc(c, res, nil)
- return
- }
-
- // InviteCodeUserInfo
- // @Summary 邀请码获取用户信息
- // @Tags 登录注册
- // @Description 邀请码获取用户信息
- // @Accept json
- // @Produce json
- // @Param req body md.InviteCodeUserInfoReq true "注册参数"
- // @Success 200 {object} md.InviteCodeUserInfoResp "具体数据"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/v1/inviteCode/userInfo [post]
- func InviteCodeUserInfo(c *gin.Context) {
- var req md.InviteCodeUserInfoReq
- err := c.ShouldBindJSON(&req)
- if err != nil {
- err = svc.HandleValidateErr(err)
- err1 := err.(e.E)
- e.OutErr(c, err1.Code, err1.Error())
- return
- }
- if req.InviteCode == "" {
- e.OutErr(c, 400, e.NewErr(400, "邀请码不能为空"))
- return
- }
- userDb := implement.NewUserDb(db.Db)
- user, err := userDb.UserGetOneByParams(map[string]interface{}{
- "key": "system_invite_code",
- "value": req.InviteCode,
- })
- if user == nil {
- user, _ = userDb.UserGetOneByParams(map[string]interface{}{
- "key": "custom_invite_code",
- "value": req.InviteCode,
- })
- if user == nil {
- e.OutErr(c, 400, e.NewErr(400, "用户不存在"))
- return
- }
- }
- nickname := user.Nickname
- if nickname == "" {
- nickname = user.Phone
- }
- if php2go.IsNumeric(nickname) {
- nickname = utils.HideTrueName(user.Nickname)
- }
- user = svc.UserImg(user)
- res := md.InviteCodeUserInfoResp{
- Nickname: nickname,
- HeadImg: user.Avatar,
- }
- e.OutSuc(c, res, nil)
- return
- }
|