From 7f668b6474cede0fb29c3262cf9a3507632b3218 Mon Sep 17 00:00:00 2001 From: chenweijian <820961417@qq.com> Date: Thu, 24 Aug 2023 17:33:38 +0800 Subject: [PATCH] Fix/party apply --- domain/model/invite_m/invite_apply.go | 15 +++++++++++++++ myerr/bizerr/bizCode.go | 13 +++++++------ route/invite_r/party_invite.go | 18 +++++++++++++++++- 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/domain/model/invite_m/invite_apply.go b/domain/model/invite_m/invite_apply.go index d876f4f..c457889 100644 --- a/domain/model/invite_m/invite_apply.go +++ b/domain/model/invite_m/invite_apply.go @@ -3,6 +3,7 @@ package invite_m import ( "git.hilo.cn/hilo-common/domain" "git.hilo.cn/hilo-common/resource/mysql" + "git.hilo.cn/hilo-common/utils" "gorm.io/gorm" "time" ) @@ -84,3 +85,17 @@ func GetInviteApplyNumByType(model *domain.Model, gType int, beginTime, endTime } return int(count), nil } + +// 今日已提交次数 +func TodayInviteApplyCount(model *domain.Model, userId mysql.ID) (int64, error) { + start, end := utils.DayStartEnd(time.Now()) + var count int64 + if err := model.Db.Model(InviteApply{}). + Where("user_id = ?", userId). + Where("created_time >= ? and created_time <= ?", start.Format(utils.DATETIME_FORMAT), end.Format(utils.DATETIME_FORMAT)). + Count(&count).Error; err != nil { + return 0, err + } + // err == nil, record exists + return count, nil +} diff --git a/myerr/bizerr/bizCode.go b/myerr/bizerr/bizCode.go index d5a056d..945e12b 100755 --- a/myerr/bizerr/bizCode.go +++ b/myerr/bizerr/bizCode.go @@ -27,10 +27,11 @@ 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{}) // 有接触申请需要处理 - InviteApplyNoPermission = myerr.NewBusinessCode(50122, "This user does not have invitation permission", myerr.BusinessData{}) // 该用户没有邀请权限 - InviteApplyAlreadyInvited = myerr.NewBusinessCode(50123, "Already invited by someone else", myerr.BusinessData{}) // 已经被别人邀请了 - InviteApplyCodeInvalid = myerr.NewBusinessCode(50124, "user id invalid", myerr.BusinessData{}) // 邀请人用户id错误 - InviteApplyNewCodeInvalid = myerr.NewBusinessCode(50125, "user id invalid", myerr.BusinessData{}) // 被邀请人用户id错误 + 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{}) // 已经被别人邀请了 + InviteApplyCodeInvalid = myerr.NewBusinessCode(50124, "user id invalid", myerr.BusinessData{}) // 邀请人用户id错误 + InviteApplyNewCodeInvalid = myerr.NewBusinessCode(50125, "user id invalid", myerr.BusinessData{}) // 被邀请人用户id错误 + InviteApplyTimes = myerr.NewBusinessCode(50126, "Your application today has reached the upper limit, please wait for tomorrow to continue the application", myerr.BusinessData{}) // 今日邀请次数太多 ) diff --git a/route/invite_r/party_invite.go b/route/invite_r/party_invite.go index 5ddff63..4bdf121 100644 --- a/route/invite_r/party_invite.go +++ b/route/invite_r/party_invite.go @@ -43,12 +43,25 @@ func InviteApply(c *gin.Context) (*mycontext.MyContext, error) { if err != nil { return myCtx, err } + model := domain.CreateModelContext(myCtx) + // 每日最多提交10次 + noLimitTimesMap := map[uint64]struct{}{1770691: {}, 2264431: {}, 7283111: {}} + if _, ok := noLimitTimesMap[myUserId]; !ok { + // 今日提交次数 + times, err := invite_m.TodayInviteApplyCount(model, myUserId) + if err != nil { + model.Log.Errorf("InviteApply myUserId:%v, err:%v", myUserId, err) + return myCtx, err + } + if times >= 10 { + return myCtx, bizerr.InviteApplyTimes + } + } 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 @@ -72,6 +85,9 @@ func InviteApply(c *gin.Context) (*mycontext.MyContext, error) { model.Log.Errorf("InviteApply param:%v", param) return myCtx, bizerr.InviteApplyCodeInvalid } + if user.ID != myUserId { //只能自己提交 + return myCtx, bizerr.InvalidParameter + } if newUser.ID == 0 || user.ID == 0 { model.Log.Errorf("InviteApply param:%v", param) return myCtx, bizerr.InvalidParameter -- 2.22.0