Files
bl/modules/config/service/sign.go

81 lines
1.8 KiB
Go
Raw Normal View History

package service
import (
"blazing/cool"
"blazing/modules/config/model"
"context"
"fmt"
"sort"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/util/gconv"
)
var signStageDays = map[uint32]struct{}{
0: {},
1: {},
3: {},
7: {},
14: {},
30: {},
}
type SignInService struct {
*cool.Service
}
func NewSignInService() *SignInService {
return &SignInService{
&cool.Service{
Model: model.NewSignIn(),
PageQueryOp: &cool.QueryOp{
FieldEQ: []string{"sign_type", "stage_days", "cdk_id", "is_enable"},
KeyWordField: []string{"remark"},
},
ListQueryOp: &cool.QueryOp{
FieldEQ: []string{"sign_type", "stage_days", "cdk_id", "is_enable"},
},
},
}
}
func (s *SignInService) ModifyBefore(ctx context.Context, method string, param g.MapStrAny) (err error) {
if method == "Delete" {
return nil
}
signType := gconv.Uint32(param["sign_type"])
if signType != model.SignTypeTotal && signType != model.SignTypeContinuous {
return fmt.Errorf("签到类别非法只支持1(累计)或2(连续)")
}
stageDays := gconv.Uint32(param["stage_days"])
if _, ok := signStageDays[stageDays]; !ok {
return fmt.Errorf("签到阶段仅支持0、1、3、7、14、30天")
}
cdkID := gconv.Uint32(param["cdk_id"])
if cdkID == 0 {
return fmt.Errorf("cdk_id不能为空")
}
if NewCdkService().GetByID(cdkID) == nil {
return fmt.Errorf("绑定的CDK不存在")
}
return nil
}
func (s *SignInService) GetEnabled() []model.SignIn {
var items []model.SignIn
dbm_enable(s.Model).Scan(&items)
sort.Slice(items, func(i, j int) bool {
if items[i].SignType != items[j].SignType {
return items[i].SignType < items[j].SignType
}
if items[i].StageDays != items[j].StageDays {
return items[i].StageDays < items[j].StageDays
}
return items[i].CdkID < items[j].CdkID
})
return items
}