From 603bb1ef2ce9025921cf6b66d782ea156669ae34 Mon Sep 17 00:00:00 2001 From: chenyifan01 Date: Fri, 23 Sep 2022 16:23:52 +0800 Subject: [PATCH] #1249 update --- models/reward_operate_record.go | 20 ++++++++++++++++++++ models/wechat_bind.go | 2 +- services/task/task.go | 3 ++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/models/reward_operate_record.go b/models/reward_operate_record.go index 1992eccba..da1b6a589 100644 --- a/models/reward_operate_record.go +++ b/models/reward_operate_record.go @@ -1,6 +1,7 @@ package models import ( + "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/timeutil" "strconv" "strings" @@ -456,3 +457,22 @@ func GetAdminRewardRecordShowList(opts *RewardRecordListOpts) (RewardRecordShowL RewardRecordShowList(r).loadAttribute(true) 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 +} diff --git a/models/wechat_bind.go b/models/wechat_bind.go index ea005e0a6..99a38c5c3 100644 --- a/models/wechat_bind.go +++ b/models/wechat_bind.go @@ -98,5 +98,5 @@ func UnbindWechatOpenId(userId int64, oldWechatOpenID string) 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{}) } diff --git a/services/task/task.go b/services/task/task.go index ed320a3c5..194a43649 100644 --- a/services/task/task.go +++ b/services/task/task.go @@ -42,7 +42,8 @@ func Accomplish(action models.Action) { return } //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) return }