package models import ( "code.gitea.io/gitea/modules/timeutil" "strings" ) const ( RewardAdminLogProcessing = 1 RewardAdminLogSuccess = 2 RewardAdminLogFailed = 3 ) type RewardAdminLog struct { ID int64 `xorm:"pk autoincr"` LogId string `xorm:"INDEX NOT NULL"` Amount int64 `xorm:"NOT NULL"` RewardType string Remark string Status int TargetUserId int64 `xorm:"INDEX NOT NULL"` CreatorId int64 `xorm:"NOT NULL"` CreatorName string CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"` } func getRewardAdminLog(ra *RewardAdminLog) (*RewardAdminLog, error) { has, err := x.Get(ra) if err != nil { return nil, err } else if !has { return nil, ErrRecordNotExist{} } return ra, nil } func InsertRewardAdminLog(ra *RewardAdminLog) (int64, error) { return x.Insert(ra) } func UpdateRewardAdminLogStatus(logId string, oldStatus, newStatus int) error { _, err := x.Where("log_id = ? and status = ?", logId, oldStatus).Update(&RewardAdminLog{Status: newStatus}) if err != nil { return err } return nil } 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) if err != nil { return nil, err } return adminLogs, nil }