97 lines
2.7 KiB
Go
Executable File
97 lines
2.7 KiB
Go
Executable File
package model
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"errors"
|
|
"github.com/zeromicro/go-zero/core/stores/cache"
|
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
|
"nova_task/internal/consts"
|
|
"time"
|
|
)
|
|
|
|
var _ NhSystemConfigModel = (*customNhSystemConfigModel)(nil)
|
|
|
|
type (
|
|
// NhSystemConfigModel is an interface to be customized, add more methods here,
|
|
// and implement the added methods in customNhSystemConfigModel.
|
|
NhSystemConfigModel interface {
|
|
nhSystemConfigModel
|
|
GetNftStakeTaskOpenDate(ctx context.Context) (start, end time.Time, err error)
|
|
GetNftStakeTaskConf(ctx context.Context) (conf NftStakeTaskConf, err error)
|
|
GetCarvApiKey(ctx context.Context) (apiKey string, err error)
|
|
GetAdminSecret(ctx context.Context) (secret string, err error)
|
|
}
|
|
|
|
customNhSystemConfigModel struct {
|
|
*defaultNhSystemConfigModel
|
|
}
|
|
)
|
|
|
|
func (m *customNhSystemConfigModel) GetAdminSecret(ctx context.Context) (secret string, err error) {
|
|
cf, err := m.FindOneByName(ctx, consts.AdminSecret)
|
|
if err != nil {
|
|
if !errors.Is(err, sqlx.ErrNotFound) {
|
|
return "", err
|
|
}
|
|
return "", nil
|
|
}
|
|
return cf.Value, nil
|
|
}
|
|
|
|
func (m *customNhSystemConfigModel) GetCarvApiKey(ctx context.Context) (string, error) {
|
|
cf, err := m.FindOneByName(ctx, consts.CarvApiKey)
|
|
if err != nil {
|
|
if !errors.Is(err, sqlx.ErrNotFound) {
|
|
return "", err
|
|
}
|
|
return "", nil
|
|
}
|
|
return cf.Value, nil
|
|
}
|
|
|
|
// NewNhSystemConfigModel returns a model for the database table.
|
|
func NewNhSystemConfigModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) NhSystemConfigModel {
|
|
return &customNhSystemConfigModel{
|
|
defaultNhSystemConfigModel: newNhSystemConfigModel(conn, c, opts...),
|
|
}
|
|
}
|
|
|
|
func (m *customNhSystemConfigModel) GetNftStakeTaskOpenDate(ctx context.Context) (start, end time.Time, err error) {
|
|
cf, err := m.FindOneByName(ctx, consts.NftStakeTaskDate)
|
|
if err != nil {
|
|
return
|
|
}
|
|
dateConf := struct {
|
|
Start string `json:"start"`
|
|
End string `json:"end"`
|
|
}{}
|
|
err = json.Unmarshal([]byte(cf.Value), &dateConf)
|
|
if err != nil {
|
|
return
|
|
}
|
|
start, err = time.ParseInLocation(time.DateOnly, dateConf.Start, time.Local)
|
|
if err != nil {
|
|
return
|
|
}
|
|
end, err = time.ParseInLocation(time.DateTime, dateConf.End+" 23:59:59", time.Local)
|
|
return
|
|
}
|
|
|
|
type NftStakeTaskConf struct {
|
|
OccupyPercent int `json:"occupy_percent"`
|
|
LittleTarot int `json:"little_tarot"`
|
|
GreatTarot int `json:"great_tarot"`
|
|
MinCoefficient float64 `json:"min_coefficient"`
|
|
MaxCoefficient float64 `json:"max_coefficient"`
|
|
}
|
|
|
|
func (m *customNhSystemConfigModel) GetNftStakeTaskConf(ctx context.Context) (conf NftStakeTaskConf, err error) {
|
|
cf, err := m.FindOneByName(ctx, consts.NftStakeTaskConf)
|
|
if err != nil {
|
|
return
|
|
}
|
|
err = json.Unmarshal([]byte(cf.Value), &conf)
|
|
return
|
|
}
|