diff --git a/models/reward_admin_log.go b/models/reward_admin_log.go index b1a55af13..24e3b8c47 100644 --- a/models/reward_admin_log.go +++ b/models/reward_admin_log.go @@ -2,7 +2,6 @@ package models import ( "code.gitea.io/gitea/modules/timeutil" - "strings" ) const ( @@ -24,6 +23,11 @@ type RewardAdminLog struct { CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"` } +type AdminLogAndUser struct { + AdminRewardAdminLog RewardAdminLog `xorm:"extends"` + User User `xorm:"extends"` +} + func getRewardAdminLog(ra *RewardAdminLog) (*RewardAdminLog, error) { has, err := x.Get(ra) if err != nil { @@ -50,12 +54,16 @@ func GetRewardAdminLogByLogIds(logIds []string) ([]RewardAdminLog, error) { if len(logIds) == 0 { return nil, nil } - adminLogs := make([]RewardAdminLog, 0) - err := x.SQL("select rdl.id,rdl.log_id,rdl.amount,rdl.reward_type,rdl.remark,rdl.status,rdl.target_user_id,rdl.creator_id,u.name as creator_name "+ - "from reward_admin_log rdl left join public.user u on rdl.creator_id = u.id "+ - "where rdl.log_id in (?)", strings.Join(logIds, ",")).Find(&adminLogs) + adminLogs := make([]AdminLogAndUser, 0) + err := x.Table("reward_admin_log").Join("LEFT", "user", "reward_admin_log.creator_id = public.user.id").In("reward_admin_log.log_id", logIds).Find(&adminLogs) if err != nil { return nil, err } - return adminLogs, nil + r := make([]RewardAdminLog, len(adminLogs)) + for i, v := range adminLogs { + temp := v.AdminRewardAdminLog + temp.CreatorName = v.User.Name + r[i] = temp + } + return r, nil }