This commit is contained in:
@@ -3,6 +3,10 @@ package service
|
||||
import (
|
||||
"blazing/cool"
|
||||
"blazing/modules/config/model"
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
type SptService struct {
|
||||
@@ -18,6 +22,9 @@ func NewSptService() *SptService {
|
||||
AddOrderby: map[string]string{
|
||||
"task_id": "asc",
|
||||
},
|
||||
ModifyResult: func(ctx g.Ctx, data interface{}) interface{} {
|
||||
return syncSptAcquireByEnable(data)
|
||||
},
|
||||
},
|
||||
PageQueryOp: &cool.QueryOp{
|
||||
FieldEQ: []string{"is_enable", "task_id"},
|
||||
@@ -25,7 +32,46 @@ func NewSptService() *SptService {
|
||||
AddOrderby: map[string]string{
|
||||
"task_id": "asc",
|
||||
},
|
||||
ModifyResult: func(ctx g.Ctx, data interface{}) interface{} {
|
||||
return syncSptAcquireByEnable(data)
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (s *SptService) ModifyBefore(ctx context.Context, method string, param g.MapStrAny) (err error) {
|
||||
switch method {
|
||||
case "Add", "Update":
|
||||
if isEnable, ok := param["is_enable"]; ok {
|
||||
enableVal := gconv.Int32(isEnable)
|
||||
param["online"] = enableVal
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func syncSptAcquireByEnable(data interface{}) interface{} {
|
||||
if data == nil {
|
||||
return data
|
||||
}
|
||||
|
||||
if pageMap, ok := data.(g.Map); ok {
|
||||
if rawList, hasList := pageMap["list"]; hasList {
|
||||
pageMap["list"] = syncSptRows(rawList)
|
||||
}
|
||||
return pageMap
|
||||
}
|
||||
|
||||
return syncSptRows(data)
|
||||
}
|
||||
|
||||
func syncSptRows(raw interface{}) interface{} {
|
||||
rows := gconv.SliceMap(raw)
|
||||
for _, row := range rows {
|
||||
enableVal := gconv.Int32(row["is_enable"])
|
||||
row["online"] = enableVal
|
||||
row["can_get"] = enableVal
|
||||
}
|
||||
return rows
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user