#2975 修复积分bug

Merged
ychao_1983 merged 6 commits from point-v2 into V20220926 1 year ago
  1. +10
    -3
      models/reward_operate_record.go
  2. +20
    -2
      services/task/task.go

+ 10
- 3
models/reward_operate_record.go View File

@@ -3,6 +3,7 @@ package models
import (
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/timeutil"
"fmt"
"strconv"
"strings"
"xorm.io/builder"
@@ -130,21 +131,27 @@ func (l RewardRecordShowList) loadAction() error {
return nil
}
actionIds := make([]int64, 0)
actionIdMap := make(map[int64]*RewardOperateRecordShow, 0)
for _, r := range l {
if r.SourceType != SourceTypeAccomplishTask.Name() {
continue
}
i, _ := strconv.ParseInt(r.SourceId, 10, 64)
actionIds = append(actionIds, i)
actionIdMap[i] = r
}
actions, err := GetActionByIds(actionIds)
if err != nil {
return err
}
actionIdMap := make(map[string]*Action, 0)
for _, v := range actions {
actionIdMap[v.ID].Action = v.ToShow()
actionIdMap[fmt.Sprint(v.ID)] = v
}

for i, r := range l {
act := actionIdMap[r.SourceId]
if act != nil {
l[i].Action = act.ToShow()
}
}
return nil
}


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

@@ -61,7 +61,7 @@ func Accomplish(action models.Action) {
actions = append(actions, models.Action{
ID: action.ID,
OpType: models.ActionDatasetRecommended,
ActUserID: action.UserID,
ActUserID: action.ActUserID,
UserID: user.ID,
RepoID: action.RepoID,
Content: action.Content,
@@ -85,7 +85,11 @@ func accomplish(action models.Action, taskType models.TaskType) error {
log.Error("PANIC:%v", combinedErr)
}
}()
log.Info("accomplish start. actionId=%d userId= %d", action.ID, action.UserID)
userId := action.UserID
if !isUserAvailable(userId) {
return nil
}

//get task config
config, err := GetTaskConfig(string(taskType))
@@ -127,7 +131,7 @@ func accomplish(action models.Action, taskType models.TaskType) error {
Type: models.GetRewardTypeInstance(config.AwardType),
},
TargetUserId: userId,
RequestId: fmt.Sprint(action.ID),
RequestId: fmt.Sprintf("%d_%d", action.ID, userId),
OperateType: models.OperateTypeIncrease,
RejectPolicy: models.FillUp,
})
@@ -143,3 +147,17 @@ func isLimited(userId int64, config *models.TaskConfig, rejectPolicy models.Limi
return false

}

func isUserAvailable(userId int64) bool {
if userId < 1 {
return false
}
user, err := models.GetUserByID(userId)
if err != nil || user == nil {
return false
}
if user.IsOrganization() {
return false
}
return true
}

Loading…
Cancel
Save