diff --git a/domain/model/invite_m/invite_apply.go b/domain/model/invite_m/invite_apply.go new file mode 100644 index 0000000000000000000000000000000000000000..e2b2d6e077bdaf2ab2caa53d0845f65af670ff22 --- /dev/null +++ b/domain/model/invite_m/invite_apply.go @@ -0,0 +1,22 @@ +package invite_m + +import "git.hilo.cn/hilo-common/domain" + +type InviteApply struct { + Id uint64 `json:"id"` + UserId uint64 `json:"user_id"` + NewUserId uint64 `json:"new_user_id"` + Platform string `json:"platform"` + RechargeInfo string `json:"recharge_info"` + Status uint8 `json:"status"` // 状态0.未审核1.已通过2.已拒绝 + VideoUrl string `json:"video_url"` +} + +func CreateInviteApply(model *domain.Model, userId, newUserId uint64, platform, recharge, videoUrl string) error { + err := model.DB().Create(InviteApply{UserId: userId, NewUserId: newUserId, Platform: platform, RechargeInfo: recharge, VideoUrl: videoUrl}).Error + if err != nil { + model.Log.Errorf("CreateInviteApply err:%v", err) + return err + } + return nil +} diff --git a/myerr/bizerr/bizCode.go b/myerr/bizerr/bizCode.go index e8f79c51197138e234dfcb17e1f94bb97c859f9d..17dad29cbe0e77d6d4e4c5cab8f652277bf56121 100755 --- a/myerr/bizerr/bizCode.go +++ b/myerr/bizerr/bizCode.go @@ -26,6 +26,8 @@ var ( // 群组 GroupNotFound = myerr.NewBusinessCode(14001, "Group not found", myerr.BusinessData{}) // 找不到该群 - CpAlreadyInvite = myerr.NewBusinessCode(50120, "Already invited", myerr.BusinessData{}) // 已经发送过邀请了 - CpHaveCancelNoDeal = myerr.NewBusinessCode(50121, "You have a cancel apply", myerr.BusinessData{}) // 有接触申请需要处理 + CpAlreadyInvite = myerr.NewBusinessCode(50120, "Already invited", myerr.BusinessData{}) // 已经发送过邀请了 + CpHaveCancelNoDeal = myerr.NewBusinessCode(50121, "You have a cancel apply", myerr.BusinessData{}) // 有接触申请需要处理 + InviteApplyNoPermission = myerr.NewBusinessCode(50122, "This user does not have invitation permission", myerr.BusinessData{}) // 该用户没有邀请权限 + InviteApplyAlreadyInvited = myerr.NewBusinessCode(50123, "Already invited by someone else", myerr.BusinessData{}) // 已经被别人邀请了 ) diff --git "a/mysql/\346\226\260\344\272\272\346\264\276\345\257\271\347\224\263\350\257\267.sql" "b/mysql/\346\226\260\344\272\272\346\264\276\345\257\271\347\224\263\350\257\267.sql" index 587d67a6ce1a5314b65d076d7e2f725411ff04d5..6d675afcf60cb2a3d1ec50357159f213a091b0d7 100644 --- "a/mysql/\346\226\260\344\272\272\346\264\276\345\257\271\347\224\263\350\257\267.sql" +++ "b/mysql/\346\226\260\344\272\272\346\264\276\345\257\271\347\224\263\350\257\267.sql" @@ -2,13 +2,16 @@ CREATE TABLE `invite_apply` ( `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id', `user_id` bigint NOT NULL COMMENT '发起申请者', `new_user_id` bigint NOT NULL COMMENT '被邀请的人', - `platform` tinyint unsigned NOT NULL COMMENT '从那个平台过来', - `status` tinyint unsigned NOT NULL COMMENT '状态1.未接受2.已接受3.拒接导致退费4.过期导致退费', + `platform` varchar(20) NOT NULL COMMENT '从那个平台过来', + `recharge_info` varchar(50) NOT NULL COMMENT '新用户在其它平台充值的标志', + `status` tinyint unsigned NOT NULL COMMENT '状态0.未审核1.已通过2.已拒绝', + `video_url` varchar(400) NOT NULL COMMENT '上传的视频url', `created_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `updated_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`), - KEY `uid_idx` (`user_id`) USING BTREE, - KEY `uid2_idx` (`invite_user_id`) USING BTREE, - KEY `status_idx` (`status`) USING BTREE, + KEY `user_id` (`user_id`) USING BTREE, + KEY `new_user_id` (`new_user_id`) USING BTREE, + KEY `platform` (`platform`) USING BTREE, + KEY `status` (`status`) USING BTREE, KEY `created_time` (`created_time`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='新人邀请申请'; \ No newline at end of file diff --git a/route/invite_r/party_invite.go b/route/invite_r/party_invite.go index efbf88b8b030ecd390e3a6d5b046480c5d53c5f9..4793e1dac8a6cfdc6db885eb1ea77e0590c1c8ab 100644 --- a/route/invite_r/party_invite.go +++ b/route/invite_r/party_invite.go @@ -1,16 +1,90 @@ package invite_r import ( + "git.hilo.cn/hilo-common/domain" "git.hilo.cn/hilo-common/mycontext" "github.com/gin-gonic/gin" + "hilo-user/domain/model/invite_m" + "hilo-user/domain/model/promotion_m" + "hilo-user/domain/model/user_m" + "hilo-user/myerr/bizerr" + "hilo-user/resp" ) -// @Tags 新人排队申请 +// @Tags 新人邀请 // @Summary 提交申请 -// @Param externalId formData string true "对方的externalId" -// @Param type formData int true "类型1.撤销2.接受" +// @Param newUserCode formData string true "被邀请人id" +// @Param platform formData string true "平台" +// @Param recharge formData string true "充值金额" +// @Param userCode formData string true "邀请人id" +// @Param videoUrl formData string true "充值金额" // @Success 200 -// @Router /v2/cp/relation/cancel/reply [post] -func InvitePartyReply(c *gin.Context) (*mycontext.MyContext, error) { +// @Router /v2/user/invite/apply [post] +func InviteApply(c *gin.Context) (*mycontext.MyContext, error) { + myCtx := mycontext.CreateMyContext(c.Keys) + type paramStr struct { + NewUserCode string `form:"newUserCode" binding:"required"` + Platform string `form:"platform" binding:"required"` + Recharge string `form:"recharge" binding:"required"` + UserCode string `form:"userCode" binding:"required"` + VideoUrl string `form:"videoUrl" binding:"required"` + } + + var param paramStr + if err := c.ShouldBind(¶m); err != nil { + return myCtx, err + } + model := domain.CreateModelContext(myCtx) + // 平台是否填写正确 + platforms := promotion_m.GetPromotionPlatforms(model) + var existsPlatform bool + for _, v := range platforms { + if v == param.Platform { + existsPlatform = true + } + } + if !existsPlatform { + model.Log.Errorf("InviteApply param:%v", param) + return myCtx, bizerr.InvalidParameter + } + // code 是否存在 + newUser, err := user_m.GetUserByCode(model, param.NewUserCode) + if err != nil { + model.Log.Errorf("InviteApply param:%v", param) + return myCtx, err + } + user, err := user_m.GetUserByCode(model, param.UserCode) + if err != nil { + model.Log.Errorf("InviteApply param:%v", param) + return myCtx, err + } + if newUser.ID == 0 || user.ID == 0 { + model.Log.Errorf("InviteApply param:%v", param) + return myCtx, bizerr.InvalidParameter + } + // 邀请人是否有资格邀请 + if !promotion_m.IsPromotionAgent(model, user.ID) { + model.Log.Errorf("InviteApply 没有邀请资格 param:%v", param) + return myCtx, bizerr.InviteApplyNoPermission + } + // 被邀请人是否符合条件 + isInvite, err := promotion_m.IsPromotionInvitee(model, user.ID) + if err != nil { + model.Log.Errorf("InviteApply param:%v", param) + return myCtx, err + } + if isInvite { + model.Log.Errorf("InviteApply 已经被别人邀请了 param:%v", param) + return myCtx, bizerr.InviteApplyAlreadyInvited + } + // 插入邀请表 + err = invite_m.CreateInviteApply(model, user.ID, newUser.ID, param.Platform, param.Recharge, param.VideoUrl) + if err != nil { + model.Log.Errorf("InviteApply param:%v", param) + return myCtx, err + } + + resp.ResponseOk(c, nil) + return myCtx, nil } diff --git a/route/router.go b/route/router.go index b88d04b7ba37f333d1f3968bde1c8406c404f4ad..02060b6a5b7255f3922677f6e4c997e069e407d2 100755 --- a/route/router.go +++ b/route/router.go @@ -12,6 +12,7 @@ import ( "hilo-user/domain/model/msg_m" "hilo-user/resp" "hilo-user/route/cp_r" + "hilo-user/route/invite_r" "hilo-user/route/user_r" ) @@ -52,6 +53,10 @@ func InitRouter() *gin.Engine { //cp.GET("/relation/detail", wrapper(cp_r.CpDetailPage)) cp.GET("/im/check", wrapper(cp_r.CheckCpImExpire)) } + userV2 := v2.Group("/user") + { + userV2.GET("/invite/apply", wrapper(invite_r.InviteApply)) + } inner := r.Group("/inner") inner.Use(ExceptionHandle, LoggerHandle) innerUser := inner.Group("/user")