Commit 2b397c98 authored by chenweijian's avatar chenweijian

Merge branch 'fix/party_apply' into 'master'

Fix/party apply

See merge request !31
parents 5eeb5c19 7f668b64
......@@ -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
}
......@@ -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{}) // 今日邀请次数太多
)
......@@ -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(&param); 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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment