|
- 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"
- "code.fnuoos.com/EggPlanet/egg_models.git/src/model"
- "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
- }
-
- // UserBindParent
- // @Summary 绑定上级-要登陆的
- // @Tags 登录注册
- // @Description 绑定上级
- // @Accept json
- // @Produce json
- // @Param req body md.InviteCodeUserInfoReq true "注册参数"
- // @Success 200 {string} "具体数据"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/v1/memberCenter/bindParent [post]
- func UserBindParent(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
- }
- }
- ownUser := svc.GetUser(c)
- if ownUser.ParentUid > 0 {
- e.OutErr(c, 400, e.NewErr(400, "已有导师"))
- return
- }
- if user.Id == ownUser.Id {
- e.OutErr(c, 400, e.NewErr(400, "不能绑定自己"))
- return
- }
- ownUser.ParentUid = user.Id
- _, err = db.Db.Where("id=?", ownUser.Id).Cols("parent_uid").Update(ownUser)
- if err != nil {
- e.OutErr(c, 400, e.NewErr(400, "绑定失败,请重试"))
- return
- }
- initLV := 1
- ur := new(model.UserRelate)
- ur.ParentUid = user.Id
- ur.Uid = ownUser.Id
- ur.Level = initLV
- ur.InviteTime = ownUser.CreateAt
- userRelateDb := implement.NewUserRelateDb(db.Db)
- _, err = userRelateDb.UserRelateInsert(ur)
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err)
- return
- }
- // 插入多级关联
- go svc.RoutineMultiRelate(ur.ParentUid, ur.Uid, initLV)
- //TODO 绑定成功后 加群之类的怎么处理
- e.OutSuc(c, "success", nil)
- return
- }
|