Reviewed-on: https://git.openi.org.cn/OpenI/aiforge/pulls/2941 Reviewed-by: ychao_1983 <ychao_1983@sina.com>tags/v1.22.9.2^2
| @@ -1,6 +1,7 @@ | |||||
| package models | package models | ||||
| import ( | import ( | ||||
| "code.gitea.io/gitea/modules/log" | |||||
| "code.gitea.io/gitea/modules/timeutil" | "code.gitea.io/gitea/modules/timeutil" | ||||
| "strconv" | "strconv" | ||||
| "strings" | "strings" | ||||
| @@ -456,3 +457,22 @@ func GetAdminRewardRecordShowList(opts *RewardRecordListOpts) (RewardRecordShowL | |||||
| RewardRecordShowList(r).loadAttribute(true) | RewardRecordShowList(r).loadAttribute(true) | ||||
| return r, count, nil | return r, count, nil | ||||
| } | } | ||||
| func IsWechatOpenIdRewarded(wechatOpenId string) bool { | |||||
| actions := make([]Action, 0) | |||||
| err := x.Where(" op_type = ? and content = ?", ActionBindWechat, wechatOpenId).Find(&actions) | |||||
| if err != nil { | |||||
| log.Error("IsWechatOpenIdRewarded find actions err.%v", err) | |||||
| return true | |||||
| } | |||||
| if len(actions) == 0 { | |||||
| return false | |||||
| } | |||||
| actionIds := make([]int64, len(actions)) | |||||
| for i, v := range actions { | |||||
| actionIds[i] = v.ID | |||||
| } | |||||
| n, _ := x.Where(builder.Eq{"source_type": SourceTypeAccomplishTask}.And(builder.In("source_id", actionIds))).Count(&RewardOperateRecord{}) | |||||
| return n > 0 | |||||
| } | |||||
| @@ -98,5 +98,5 @@ func UnbindWechatOpenId(userId int64, oldWechatOpenID string) error { | |||||
| } | } | ||||
| func CountWechatBindLog(wechatOpenId string, action WechatBindAction) (int64, error) { | func CountWechatBindLog(wechatOpenId string, action WechatBindAction) (int64, error) { | ||||
| return x.Where("wechat_open_id = ? and action = ?", action, wechatOpenId).Count(&WechatBindLog{}) | |||||
| return x.Where("wechat_open_id = ? and action = ?", wechatOpenId, action).Count(&WechatBindLog{}) | |||||
| } | } | ||||
| @@ -42,7 +42,8 @@ func Accomplish(action models.Action) { | |||||
| return | return | ||||
| } | } | ||||
| //if wechatOpenId has been bound before,the action can not get reward | //if wechatOpenId has been bound before,the action can not get reward | ||||
| if n > 1 { | |||||
| if n > 1 && models.IsWechatOpenIdRewarded(action.Content) { | |||||
| log.Debug("the wechat account has been bound before,wechatOpenId = %s", action.Content) | log.Debug("the wechat account has been bound before,wechatOpenId = %s", action.Content) | ||||
| return | return | ||||
| } | } | ||||