feat: 新增养成管理后台
This commit is contained in:
@@ -0,0 +1,155 @@
|
||||
package sysin
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"github.com/gogf/gf/v2/encoding/gjson"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
|
||||
"hotgo/internal/model/input/form"
|
||||
)
|
||||
|
||||
type CultivateStageRuleEditInp struct {
|
||||
Id uint64 `json:"id"`
|
||||
Stage string `json:"stage"`
|
||||
NextStage string `json:"nextStage"`
|
||||
RequiredPoints uint `json:"requiredPoints"`
|
||||
WaterPoints uint `json:"waterPoints"`
|
||||
FertilizePoints uint `json:"fertilizePoints"`
|
||||
AllowedActions []string `json:"allowedActions"`
|
||||
ImageFileId string `json:"imageFileId"`
|
||||
AnimationFileId string `json:"animationFileId"`
|
||||
ProgressTextTemplate string `json:"progressTextTemplate"`
|
||||
CompletionText string `json:"completionText"`
|
||||
SortNo int `json:"sortNo"`
|
||||
}
|
||||
|
||||
type CultivateFlowerEditInp struct {
|
||||
Id uint64 `json:"id"`
|
||||
FlowerCode string `json:"flowerCode"`
|
||||
FlowerName string `json:"flowerName"`
|
||||
FlowerDesc string `json:"flowerDesc"`
|
||||
IconFileId string `json:"iconFileId"`
|
||||
Status string `json:"status"`
|
||||
DailyWaterLimit uint `json:"dailyWaterLimit"`
|
||||
DailyFertilizeLimit uint `json:"dailyFertilizeLimit"`
|
||||
ShareConfig *gjson.Json `json:"shareConfig"`
|
||||
SortNo int `json:"sortNo"`
|
||||
StageRules []*CultivateStageRuleEditInp `json:"stageRules"`
|
||||
}
|
||||
|
||||
func (in *CultivateFlowerEditInp) Filter(ctx context.Context) error {
|
||||
in.FlowerCode = strings.TrimSpace(in.FlowerCode)
|
||||
in.FlowerName = strings.TrimSpace(in.FlowerName)
|
||||
if in.FlowerCode == "" || in.FlowerName == "" {
|
||||
return gerror.New("花种编码和名称不能为空")
|
||||
}
|
||||
validStatus := map[string]bool{"online": true, "offline": true, "activity_only": true, "maintenance": true}
|
||||
if !validStatus[in.Status] {
|
||||
return gerror.New("花种状态不正确")
|
||||
}
|
||||
if len(in.StageRules) == 0 {
|
||||
return gerror.New("至少配置一个成长阶段")
|
||||
}
|
||||
validStage := map[string]bool{"seed": true, "sprout": true, "bud": true, "bloom": true}
|
||||
validAction := map[string]bool{"water": true, "fertilize": true}
|
||||
seen := map[string]bool{}
|
||||
for _, rule := range in.StageRules {
|
||||
if rule == nil || !validStage[rule.Stage] {
|
||||
return gerror.New("成长阶段不正确")
|
||||
}
|
||||
if seen[rule.Stage] {
|
||||
return gerror.New("成长阶段不能重复")
|
||||
}
|
||||
seen[rule.Stage] = true
|
||||
if rule.Stage != "bloom" && rule.RequiredPoints == 0 {
|
||||
return gerror.New("非开花阶段升级阈值必须大于0")
|
||||
}
|
||||
if rule.NextStage != "" && !validStage[rule.NextStage] {
|
||||
return gerror.New("下一阶段不正确")
|
||||
}
|
||||
if rule.Stage != "bloom" && len(rule.AllowedActions) == 0 {
|
||||
return gerror.New("非开花阶段至少允许一种成长动作")
|
||||
}
|
||||
for _, action := range rule.AllowedActions {
|
||||
if !validAction[action] {
|
||||
return gerror.New("成长动作不正确")
|
||||
}
|
||||
}
|
||||
}
|
||||
stage := "seed"
|
||||
visited := map[string]bool{}
|
||||
for stage != "" {
|
||||
if visited[stage] {
|
||||
return gerror.New("成长阶段链不能形成循环")
|
||||
}
|
||||
visited[stage] = true
|
||||
var next string
|
||||
found := false
|
||||
for _, r := range in.StageRules {
|
||||
if r.Stage == stage {
|
||||
next = r.NextStage
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
return gerror.New("成长阶段链必须从 seed 连续配置")
|
||||
}
|
||||
stage = next
|
||||
}
|
||||
if !visited["bloom"] {
|
||||
return gerror.New("成长阶段链必须以 bloom 结束")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type CultivateFlowerListInp struct {
|
||||
form.PageReq
|
||||
FlowerCode string `json:"flowerCode"`
|
||||
FlowerName string `json:"flowerName"`
|
||||
Status string `json:"status"`
|
||||
ConfigVersion string `json:"configVersion"`
|
||||
CreatedAt []*gtime.Time `json:"createdAt"`
|
||||
}
|
||||
|
||||
func (*CultivateFlowerListInp) Filter(context.Context) error { return nil }
|
||||
|
||||
type CultivateFlowerListModel struct {
|
||||
Id uint64 `json:"id"`
|
||||
FlowerCode string `json:"flowerCode"`
|
||||
FlowerName string `json:"flowerName"`
|
||||
FlowerDesc string `json:"flowerDesc"`
|
||||
IconFileId string `json:"iconFileId"`
|
||||
Status string `json:"status"`
|
||||
ConfigVersion string `json:"configVersion"`
|
||||
DailyWaterLimit uint `json:"dailyWaterLimit"`
|
||||
DailyFertilizeLimit uint `json:"dailyFertilizeLimit"`
|
||||
SortNo int `json:"sortNo"`
|
||||
StageCount int `json:"stageCount"`
|
||||
CreatedAt *gtime.Time `json:"createdAt"`
|
||||
UpdatedAt *gtime.Time `json:"updatedAt"`
|
||||
}
|
||||
|
||||
type CultivateFlowerViewInp struct {
|
||||
Id uint64 `json:"id" v:"required#ID不能为空"`
|
||||
}
|
||||
|
||||
func (*CultivateFlowerViewInp) Filter(context.Context) error { return nil }
|
||||
|
||||
type CultivateFlowerViewModel struct {
|
||||
CultivateFlowerEditInp
|
||||
ConfigVersion string `json:"configVersion"`
|
||||
CreatedAt *gtime.Time `json:"createdAt"`
|
||||
UpdatedAt *gtime.Time `json:"updatedAt"`
|
||||
}
|
||||
|
||||
type CultivateFlowerStatusInp struct {
|
||||
Id uint64 `json:"id" v:"required#ID不能为空"`
|
||||
Status string `json:"status" v:"required|in:online,offline,activity_only,maintenance#状态不能为空|状态不正确"`
|
||||
Reason string `json:"reason"`
|
||||
}
|
||||
|
||||
func (*CultivateFlowerStatusInp) Filter(context.Context) error { return nil }
|
||||
Reference in New Issue
Block a user