diff --git a/app/hdl/hdl_user.go b/app/hdl/hdl_user.go index 7b01c63..20c0376 100644 --- a/app/hdl/hdl_user.go +++ b/app/hdl/hdl_user.go @@ -99,3 +99,61 @@ func InviteCodeUserInfo(c *gin.Context) { 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 + } + //TODO 绑定成功后 加群之类的怎么处理 + e.OutSuc(c, "success", nil) + return +} diff --git a/app/router/router.go b/app/router/router.go index 29b616b..adb5e72 100644 --- a/app/router/router.go +++ b/app/router/router.go @@ -76,6 +76,7 @@ func route(r *gin.RouterGroup) { r.Use(mw.Auth) // 以下接口需要JWT验证 rComm(r.Group("/comm")) r.POST("/advertising/check", hdl.AdvertisingCheck) //广告位判断能不能看 + rHomePage := r.Group("/homePage") { rHomePage.GET("/index", hdl.HomePage) // 主页 @@ -97,6 +98,7 @@ func route(r *gin.RouterGroup) { rMemberCenter := r.Group("/memberCenter") { rMemberCenter.GET("/getBasic", hdl.MemberCenterGetBasic) // 会员中心-基础数据 + rMemberCenter.POST("/bindParent", hdl.UserBindParent) //绑定上级 } rPointsCenter := r.Group("/pointsCenter") // 积分中心 { diff --git a/docs/docs.go b/docs/docs.go index 98d440a..eb822de 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -1394,6 +1394,46 @@ const docTemplate = `{ } } }, + "/api/v1/memberCenter/bindParent": { + "post": { + "description": "绑定上级", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "登录注册" + ], + "summary": "绑定上级-要登陆的", + "parameters": [ + { + "description": "注册参数", + "name": "req", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/md.InviteCodeUserInfoReq" + } + } + ], + "responses": { + "200": { + "description": "具体数据", + "schema": { + "type": "string" + } + }, + "400": { + "description": "具体错误", + "schema": { + "$ref": "#/definitions/md.Response" + } + } + } + } + }, "/api/v1/memberCenter/getBasic": { "get": { "description": "基础数据(获取)", @@ -3963,7 +4003,7 @@ const docTemplate = `{ "type": "integer" }, "to_user_ids": { - "description": "红包给到哪些用户(专属红包)", + "description": "红包给到哪些im用户id(专属红包)", "type": "array", "items": { "type": "integer" diff --git a/docs/swagger.json b/docs/swagger.json index 830c572..26333e0 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -1387,6 +1387,46 @@ } } }, + "/api/v1/memberCenter/bindParent": { + "post": { + "description": "绑定上级", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "登录注册" + ], + "summary": "绑定上级-要登陆的", + "parameters": [ + { + "description": "注册参数", + "name": "req", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/md.InviteCodeUserInfoReq" + } + } + ], + "responses": { + "200": { + "description": "具体数据", + "schema": { + "type": "string" + } + }, + "400": { + "description": "具体错误", + "schema": { + "$ref": "#/definitions/md.Response" + } + } + } + } + }, "/api/v1/memberCenter/getBasic": { "get": { "description": "基础数据(获取)", @@ -3956,7 +3996,7 @@ "type": "integer" }, "to_user_ids": { - "description": "红包给到哪些用户(专属红包)", + "description": "红包给到哪些im用户id(专属红包)", "type": "array", "items": { "type": "integer" diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 48dc2d6..8963daf 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -1019,7 +1019,7 @@ definitions: description: 消息发送时间戳,精确到毫秒 type: integer to_user_ids: - description: 红包给到哪些用户(专属红包) + description: 红包给到哪些im用户id(专属红包) items: type: integer type: array @@ -2225,6 +2225,32 @@ paths: summary: 登陆 tags: - 登录注册 + /api/v1/memberCenter/bindParent: + post: + consumes: + - application/json + description: 绑定上级 + parameters: + - description: 注册参数 + in: body + name: req + required: true + schema: + $ref: '#/definitions/md.InviteCodeUserInfoReq' + produces: + - application/json + responses: + "200": + description: 具体数据 + schema: + type: string + "400": + description: 具体错误 + schema: + $ref: '#/definitions/md.Response' + summary: 绑定上级-要登陆的 + tags: + - 登录注册 /api/v1/memberCenter/getBasic: get: consumes: