|
|
@@ -111,129 +111,94 @@ const Semicolon = ";" |
|
|
|
type RewardOperateOrderBy string |
|
|
|
|
|
|
|
const ( |
|
|
|
RewardOrderByIDDesc RewardOperateOrderBy = "id desc" |
|
|
|
RewardOrderByIDDesc RewardOperateOrderBy = "reward_operate_record.id desc" |
|
|
|
) |
|
|
|
|
|
|
|
type RewardRecordList []*RewardOperateRecord |
|
|
|
type RewardRecordShowList []*RewardOperateRecordShow |
|
|
|
|
|
|
|
func (l *RewardRecordList) ToShow() (RewardRecordShowList, error) { |
|
|
|
actionMap, err := l.GetRewardRecordAction() |
|
|
|
CloudbrainMap, err := l.GetRewardRecordCloudbrainTask() |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
result := make([]*RewardOperateRecordShow, 0) |
|
|
|
for _, v := range *l { |
|
|
|
temp := v.ToShow() |
|
|
|
switch v.SourceType { |
|
|
|
case SourceTypeAccomplishTask.Name(): |
|
|
|
temp.Action = actionMap[v.SourceId].ToShow() |
|
|
|
case SourceTypeRunCloudbrainTask.Name(): |
|
|
|
temp.Cloudbrain = CloudbrainMap[v.SourceId].ToShow() |
|
|
|
} |
|
|
|
result = append(result, &temp) |
|
|
|
} |
|
|
|
|
|
|
|
return result, nil |
|
|
|
func (l RewardRecordShowList) loadAttribute() { |
|
|
|
l.loadAction() |
|
|
|
l.loadCloudbrain() |
|
|
|
} |
|
|
|
|
|
|
|
func (l *RewardRecordList) GetRewardRecordAction() (map[string]*Action, error) { |
|
|
|
if len(*l) == 0 { |
|
|
|
return nil, nil |
|
|
|
func (l RewardRecordShowList) loadAction() error { |
|
|
|
if len(l) == 0 { |
|
|
|
return nil |
|
|
|
} |
|
|
|
actionIds := make([]int64, 0) |
|
|
|
for _, r := range *l { |
|
|
|
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 nil, err |
|
|
|
return err |
|
|
|
} |
|
|
|
result := make(map[string]*Action, 0) |
|
|
|
for _, v := range actions { |
|
|
|
result[fmt.Sprint(v.ID)] = v |
|
|
|
} |
|
|
|
return result, nil |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
func (l *RewardRecordList) GetRewardRecordAdminLog() (map[string]*RewardAdminLog, error) { |
|
|
|
if len(*l) == 0 { |
|
|
|
return nil, nil |
|
|
|
} |
|
|
|
logIds := make([]string, 0) |
|
|
|
for _, r := range *l { |
|
|
|
if r.SourceType != SourceTypeAdminOperate.Name() { |
|
|
|
continue |
|
|
|
} |
|
|
|
logIds = append(logIds, r.SourceId) |
|
|
|
} |
|
|
|
logs, err := GetRewardAdminLogByLogIds(logIds) |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
actionIdMap[v.ID].Action = v.ToShow() |
|
|
|
} |
|
|
|
result := make(map[string]*RewardAdminLog, 0) |
|
|
|
for _, v := range logs { |
|
|
|
result[fmt.Sprint(v.LogId)] = v |
|
|
|
} |
|
|
|
return result, nil |
|
|
|
|
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
func (l *RewardRecordList) GetRewardRecordCloudbrainTask() (map[string]*Cloudbrain, error) { |
|
|
|
if len(*l) == 0 { |
|
|
|
return nil, nil |
|
|
|
func (l RewardRecordShowList) loadCloudbrain() error { |
|
|
|
if len(l) == 0 { |
|
|
|
return nil |
|
|
|
} |
|
|
|
cloudbrainIds := make([]int64, 0) |
|
|
|
for _, r := range *l { |
|
|
|
cloudbrainMap := make(map[int64]*RewardOperateRecordShow, 0) |
|
|
|
for _, r := range l { |
|
|
|
if r.SourceType != SourceTypeRunCloudbrainTask.Name() { |
|
|
|
continue |
|
|
|
} |
|
|
|
i, _ := strconv.ParseInt(r.SourceId, 10, 64) |
|
|
|
cloudbrainIds = append(cloudbrainIds, i) |
|
|
|
cloudbrainMap[i] = r |
|
|
|
} |
|
|
|
cloudbrains, err := GetCloudbrainByIds(cloudbrainIds) |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
return err |
|
|
|
} |
|
|
|
var ids []int64 |
|
|
|
for _, task := range cloudbrains { |
|
|
|
ids = append(ids, task.RepoID) |
|
|
|
} |
|
|
|
repositoryMap, err := GetRepositoriesMapByIDs(ids) |
|
|
|
result := make(map[string]*Cloudbrain, 0) |
|
|
|
if err == nil { |
|
|
|
for _, v := range cloudbrains { |
|
|
|
v.Repo = repositoryMap[v.RepoID] |
|
|
|
result[fmt.Sprint(v.ID)] = v |
|
|
|
} |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
for _, v := range cloudbrains { |
|
|
|
v.Repo = repositoryMap[v.RepoID] |
|
|
|
cloudbrainMap[v.ID].Cloudbrain = v.ToShow() |
|
|
|
} |
|
|
|
return result, nil |
|
|
|
|
|
|
|
return nil |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
type RewardOperateRecord struct { |
|
|
|
ID int64 `xorm:"pk autoincr"` |
|
|
|
SerialNo string `xorm:"INDEX NOT NULL"` |
|
|
|
UserId int64 `xorm:"INDEX NOT NULL"` |
|
|
|
Amount int64 `xorm:"NOT NULL"` |
|
|
|
LossAmount int64 |
|
|
|
Tittle string |
|
|
|
RewardType string `xorm:"NOT NULL"` |
|
|
|
SourceType string `xorm:"NOT NULL"` |
|
|
|
SourceId string `xorm:"INDEX NOT NULL"` |
|
|
|
RequestId string `xorm:"INDEX NOT NULL"` |
|
|
|
OperateType string `xorm:"NOT NULL"` |
|
|
|
Status string `xorm:"NOT NULL"` |
|
|
|
Remark string |
|
|
|
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"` |
|
|
|
UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"` |
|
|
|
LastOperateUnix timeutil.TimeStamp `xorm:"INDEX"` |
|
|
|
ID int64 `xorm:"pk autoincr"` |
|
|
|
SerialNo string `xorm:"INDEX NOT NULL"` |
|
|
|
UserId int64 `xorm:"INDEX NOT NULL"` |
|
|
|
Amount int64 `xorm:"NOT NULL"` |
|
|
|
LossAmount int64 |
|
|
|
Tittle string |
|
|
|
RewardType string `xorm:"NOT NULL"` |
|
|
|
SourceType string `xorm:"NOT NULL"` |
|
|
|
SourceId string `xorm:"INDEX NOT NULL"` |
|
|
|
SourceTemplateId string |
|
|
|
RequestId string `xorm:"INDEX NOT NULL"` |
|
|
|
OperateType string `xorm:"NOT NULL"` |
|
|
|
Status string `xorm:"NOT NULL"` |
|
|
|
Remark string |
|
|
|
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"` |
|
|
|
UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"` |
|
|
|
LastOperateUnix timeutil.TimeStamp `xorm:"INDEX"` |
|
|
|
} |
|
|
|
|
|
|
|
type AdminRewardOperateReq struct { |
|
|
@@ -244,31 +209,22 @@ type AdminRewardOperateReq struct { |
|
|
|
RewardType RewardType |
|
|
|
} |
|
|
|
|
|
|
|
func (r RewardOperateRecord) ToShow() RewardOperateRecordShow { |
|
|
|
return RewardOperateRecordShow{ |
|
|
|
SerialNo: r.SerialNo, |
|
|
|
OperateType: r.OperateType, |
|
|
|
Amount: r.Amount, |
|
|
|
Remark: r.Remark, |
|
|
|
Status: r.Status, |
|
|
|
SourceType: r.SourceType, |
|
|
|
LastOperateDate: r.LastOperateUnix, |
|
|
|
LossAmount: r.LossAmount, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
type RewardOperateRecordShow struct { |
|
|
|
SerialNo string |
|
|
|
Status string |
|
|
|
OperateType string |
|
|
|
SourceId string |
|
|
|
Amount int64 |
|
|
|
LossAmount int64 |
|
|
|
BalanceAfter int64 |
|
|
|
Remark string |
|
|
|
SourceType string |
|
|
|
UserName string |
|
|
|
LastOperateDate timeutil.TimeStamp |
|
|
|
UnitPrice int64 |
|
|
|
SuccessCount int |
|
|
|
Action *ActionShow |
|
|
|
Cloudbrain *CloudbrainShow |
|
|
|
AdminLog *RewardAdminLog |
|
|
|
} |
|
|
|
|
|
|
|
func getPointOperateRecord(tl *RewardOperateRecord) (*RewardOperateRecord, error) { |
|
|
@@ -326,6 +282,7 @@ func SumRewardAmountInTaskPeriod(rewardType string, sourceType string, userId in |
|
|
|
type RewardOperateContext struct { |
|
|
|
SourceType SourceType |
|
|
|
SourceId string |
|
|
|
SourceTemplateId string |
|
|
|
Tittle string |
|
|
|
Remark string |
|
|
|
Reward Reward |
|
|
@@ -361,12 +318,18 @@ func AppendRemark(remark, appendStr string) string { |
|
|
|
type RewardRecordListOpts struct { |
|
|
|
ListOptions |
|
|
|
UserId int64 |
|
|
|
UserName string |
|
|
|
OperateType RewardOperateType |
|
|
|
RewardType RewardType |
|
|
|
SourceType string |
|
|
|
ActionType int |
|
|
|
SerialNo string |
|
|
|
OrderBy RewardOperateOrderBy |
|
|
|
IsAdmin bool |
|
|
|
Status string |
|
|
|
} |
|
|
|
|
|
|
|
func GetRewardRecordList(opts RewardRecordListOpts) (RewardRecordList, int64, error) { |
|
|
|
func (opts *RewardRecordListOpts) toCond() builder.Cond { |
|
|
|
if opts.Page <= 0 { |
|
|
|
opts.Page = 1 |
|
|
|
} |
|
|
@@ -375,25 +338,91 @@ func GetRewardRecordList(opts RewardRecordListOpts) (RewardRecordList, int64, er |
|
|
|
opts.OrderBy = RewardOrderByIDDesc |
|
|
|
} |
|
|
|
|
|
|
|
r := make([]*RewardOperateRecord, 0) |
|
|
|
cond := builder.NewCond() |
|
|
|
if opts.UserId > 0 { |
|
|
|
cond = cond.And(builder.Eq{"user_id": opts.UserId}) |
|
|
|
cond = cond.And(builder.Eq{"reward_operate_record.user_id": opts.UserId}) |
|
|
|
} |
|
|
|
if opts.OperateType != OperateTypeNull { |
|
|
|
cond = cond.And(builder.Eq{"operate_type": opts.OperateType.Name()}) |
|
|
|
cond = cond.And(builder.Eq{"reward_operate_record.operate_type": opts.OperateType.Name()}) |
|
|
|
} |
|
|
|
if opts.SourceType != "" { |
|
|
|
cond = cond.And(builder.Eq{"reward_operate_record.source_type": opts.SourceType}) |
|
|
|
} |
|
|
|
if opts.SourceType == SourceTypeAccomplishTask.Name() { |
|
|
|
if opts.ActionType > 0 { |
|
|
|
cond = cond.And(builder.Eq{"reward_operate_record.source_template_id": fmt.Sprint(opts.ActionType)}) |
|
|
|
} |
|
|
|
} |
|
|
|
if opts.SerialNo != "" { |
|
|
|
cond = cond.And(builder.Like{"reward_operate_record.serial_no", opts.SerialNo}) |
|
|
|
} |
|
|
|
if opts.Status != "" { |
|
|
|
cond = cond.And(builder.Like{"reward_operate_record.status", opts.Status}) |
|
|
|
} |
|
|
|
|
|
|
|
cond = cond.And(builder.Eq{"reward_operate_record.reward_type": opts.RewardType.Name()}) |
|
|
|
cond = cond.And(builder.Gt{"reward_operate_record.amount": 0}) |
|
|
|
return cond |
|
|
|
} |
|
|
|
|
|
|
|
type TestTT struct { |
|
|
|
SerialNo string |
|
|
|
UserId int64 |
|
|
|
Amount int64 |
|
|
|
UserName string |
|
|
|
} |
|
|
|
|
|
|
|
func GetRewardRecordShowList(opts *RewardRecordListOpts) (RewardRecordShowList, int64, error) { |
|
|
|
cond := opts.toCond() |
|
|
|
count, err := x.Where(cond).Count(&RewardOperateRecord{}) |
|
|
|
if err != nil { |
|
|
|
return nil, 0, err |
|
|
|
} |
|
|
|
cond = cond.And(builder.Eq{"reward_type": opts.RewardType.Name()}) |
|
|
|
cond = cond.And(builder.Gt{"amount": 0}) |
|
|
|
r := make([]*RewardOperateRecordShow, 0) |
|
|
|
err = x.Table("reward_operate_record").Cols("reward_operate_record.source_id", "reward_operate_record.serial_no", |
|
|
|
"reward_operate_record.status", "reward_operate_record.operate_type", "reward_operate_record.amount", |
|
|
|
"reward_operate_record.loss_amount", "reward_operate_record.remark", "reward_operate_record.source_type", |
|
|
|
"reward_operate_record.last_operate_unix as last_operate_date"). |
|
|
|
Where(cond).Limit(opts.PageSize, (opts.Page-1)*opts.PageSize).OrderBy(string(opts.OrderBy)).Find(&r) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
return nil, 0, err |
|
|
|
} |
|
|
|
RewardRecordShowList(r).loadAttribute() |
|
|
|
return r, count, nil |
|
|
|
} |
|
|
|
|
|
|
|
func GetAdminRewardRecordShowList(opts *RewardRecordListOpts) (RewardRecordShowList, int64, error) { |
|
|
|
cond := opts.toCond() |
|
|
|
count, err := x.Where(cond).Count(&RewardOperateRecord{}) |
|
|
|
if err != nil { |
|
|
|
return nil, 0, err |
|
|
|
} |
|
|
|
r := make([]*RewardOperateRecordShow, 0) |
|
|
|
switch opts.OperateType { |
|
|
|
case OperateTypeIncrease: |
|
|
|
err = x.Table("reward_operate_record").Cols("reward_operate_record.source_id", "reward_operate_record.serial_no", |
|
|
|
"reward_operate_record.status", "reward_operate_record.operate_type", "reward_operate_record.amount", |
|
|
|
"reward_operate_record.loss_amount", "reward_operate_record.remark", "reward_operate_record.source_type", |
|
|
|
"reward_operate_record.last_operate_unix as last_operate_date", "public.user.name as user_name", |
|
|
|
"point_account_log.balance_after"). |
|
|
|
Join("LEFT", "public.user", "reward_operate_record.user_id = public.user.id"). |
|
|
|
Join("LEFT", "point_account_log", " reward_operate_record.serial_no = point_account_log.source_id"). |
|
|
|
Where(cond).Limit(opts.PageSize, (opts.Page-1)*opts.PageSize).OrderBy(string(opts.OrderBy)).Find(&r) |
|
|
|
case OperateTypeDecrease: |
|
|
|
err = x.Table("reward_operate_record").Cols("reward_operate_record.source_id", "reward_operate_record.serial_no", |
|
|
|
"reward_operate_record.status", "reward_operate_record.operate_type", "reward_operate_record.amount", |
|
|
|
"reward_operate_record.loss_amount", "reward_operate_record.remark", "reward_operate_record.source_type", |
|
|
|
"reward_operate_record.last_operate_unix as last_operate_date", "public.user.name as user_name", |
|
|
|
"reward_periodic_task.amount as unit_price", "reward_periodic_task.success_count"). |
|
|
|
Join("LEFT", "public.user", "reward_operate_record.user_id = public.user.id"). |
|
|
|
Join("LEFT", "reward_periodic_task", "reward_operate_record.serial_no = reward_periodic_task.operate_serial_no"). |
|
|
|
Where(cond).Limit(opts.PageSize, (opts.Page-1)*opts.PageSize).OrderBy(string(opts.OrderBy)).Find(&r) |
|
|
|
} |
|
|
|
|
|
|
|
err = x.Where(cond).Limit(opts.PageSize, (opts.Page-1)*opts.PageSize).OrderBy(string(opts.OrderBy)).Find(&r) |
|
|
|
if err != nil { |
|
|
|
return nil, 0, err |
|
|
|
} |
|
|
|
RewardRecordShowList(r).loadAttribute() |
|
|
|
return r, count, nil |
|
|
|
} |