Browse Source

#2225

add admin log in reward record show
tags/v1.22.9.2^2
chenyifan01 3 years ago
parent
commit
ec517ba311
1 changed files with 14 additions and 6 deletions
  1. +14
    -6
      models/reward_admin_log.go

+ 14
- 6
models/reward_admin_log.go View File

@@ -2,7 +2,6 @@ package models


import ( import (
"code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/timeutil"
"strings"
) )


const ( const (
@@ -24,6 +23,11 @@ type RewardAdminLog struct {
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"` CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
} }


type AdminLogAndUser struct {
AdminRewardAdminLog RewardAdminLog `xorm:"extends"`
User User `xorm:"extends"`
}

func getRewardAdminLog(ra *RewardAdminLog) (*RewardAdminLog, error) { func getRewardAdminLog(ra *RewardAdminLog) (*RewardAdminLog, error) {
has, err := x.Get(ra) has, err := x.Get(ra)
if err != nil { if err != nil {
@@ -50,12 +54,16 @@ func GetRewardAdminLogByLogIds(logIds []string) ([]RewardAdminLog, error) {
if len(logIds) == 0 { if len(logIds) == 0 {
return nil, nil 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 { if err != nil {
return nil, err 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
} }

Loading…
Cancel
Save