Browse Source

#1249

update
pull/2941/head
chenyifan01 2 years ago
parent
commit
603bb1ef2c
3 changed files with 23 additions and 2 deletions
  1. +20
    -0
      models/reward_operate_record.go
  2. +1
    -1
      models/wechat_bind.go
  3. +2
    -1
      services/task/task.go

+ 20
- 0
models/reward_operate_record.go View File

@@ -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
}

+ 1
- 1
models/wechat_bind.go View File

@@ -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{})
}

+ 2
- 1
services/task/task.go View File

@@ -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
}


Loading…
Cancel
Save