mh_server/model/config.go

185 lines
4.5 KiB
Go
Raw Normal View History

2021-06-30 02:12:05 +00:00
package model
import (
"encoding/json"
2022-01-16 08:56:20 +00:00
"errors"
2021-12-25 08:38:30 +00:00
"github.com/codinl/go-logger"
2021-06-30 02:12:05 +00:00
)
//go:generate goqueryset -in config.go
// gen:qs
type Config struct {
Model
Name string `gorm:"unique_index;not null"`
2021-11-01 03:32:23 +00:00
Value string `gorm:"size:65535;not null"`
2021-06-30 02:12:05 +00:00
}
func (m *Config) TableName() string {
return "config"
}
2021-12-25 08:38:30 +00:00
type PayConfig struct {
MemberFee uint32 `json:"member_fee"`
DepositFee uint32 `json:"deposit_fee"`
NotifyUrl string `json:"notify_url"`
2021-06-30 02:12:05 +00:00
}
2021-12-25 08:38:30 +00:00
const (
2022-01-16 08:56:20 +00:00
ConfigNamePay = "pay_config" // 支付配置
ConfigNameMember = "member_config" // 会员配置
2021-12-25 08:38:30 +00:00
)
2021-06-30 02:12:05 +00:00
2021-12-25 08:38:30 +00:00
func PayConfigInfo() (*PayConfig, error) {
payConfig := new(PayConfig)
var configAllocation Config
err := NewConfigQuerySet(DB).NameEq(ConfigNamePay).One(&configAllocation)
2021-06-30 02:12:05 +00:00
if err != nil {
2021-12-25 08:38:30 +00:00
logger.Error("err:", err)
return payConfig, err
2021-06-30 02:12:05 +00:00
}
2021-12-25 08:38:30 +00:00
err = json.Unmarshal([]byte(configAllocation.Value), payConfig)
2021-06-30 02:12:05 +00:00
if err != nil {
2021-12-25 08:38:30 +00:00
logger.Error("err:", err)
return payConfig, err
2021-06-30 02:12:05 +00:00
}
2021-12-25 08:38:30 +00:00
return payConfig, nil
2021-06-30 02:12:05 +00:00
}
2022-01-16 08:56:20 +00:00
type MemberConfig struct {
MemberLever uint32 `json:"member_lever"` // 会员等级
MemberFee uint32 `json:"member_fee"` // 会员费
MemberDeposit uint32 `json:"member_deposit"` // 押金
CardMax uint32 `json:"card_max"`
}
func MemberConfigInfo() ([]MemberConfig, error) {
var memberConfigs []MemberConfig
var configAllocation Config
err := NewConfigQuerySet(DB).NameEq(ConfigNameMember).One(&configAllocation)
if err != nil {
logger.Error("err:", err)
return memberConfigs, err
}
err = json.Unmarshal([]byte(configAllocation.Value), &memberConfigs)
if err != nil {
logger.Error("err:", err)
return memberConfigs, err
}
return memberConfigs, nil
}
func GetMemberConfig(level uint32) (*MemberConfig, error) {
if level == 3 {
level = 2
}
info, err := MemberConfigInfo()
if err != nil {
return nil, err
}
for _, config := range info {
if config.MemberLever == level {
return &config, nil
}
}
return nil, errors.New("level err")
}
2021-12-25 08:38:30 +00:00
//type ConfigInterface interface {
// Encode() string
2021-06-30 02:12:05 +00:00
//}
2021-12-25 08:38:30 +00:00
//type CheckConfig struct {
// Check uint8 `json:"check"`
2021-06-30 02:12:05 +00:00
//}
2021-12-25 08:38:30 +00:00
//func (c *CheckConfig) Encode() string {
2021-06-30 02:12:05 +00:00
// configBytes, err := json.Marshal(c)
// if err != nil {
// return ""
// }
// return string(configBytes)
//}
2021-12-25 08:38:30 +00:00
//
//type AutoChargeMobileConfig struct {
// IsOpen uint8 `json:"is_open"`
2021-06-30 02:12:05 +00:00
//}
//
2021-12-25 08:38:30 +00:00
//func (c *AutoChargeMobileConfig) Encode() string {
2021-06-30 02:12:05 +00:00
// configBytes, err := json.Marshal(c)
// if err != nil {
// return ""
// }
// return string(configBytes)
//}
2021-12-25 08:38:30 +00:00
//
//type StepConfig struct {
// InitStep uint32 `json:"init_step"`
// InviteStepAward uint32 `json:"invite_step_award"`
// StepDayLimit uint32 `json:"step_day_limit"`
// StepToVmRate float64 `json:"step_to_vm_rate"`
// InviteAwardRate float64 `json:"invite_award_rate"`
// InviteAwardRateLimit float64 `json:"invite_award_rate_limit"`
// SuperMemberRm uint32 `json:"super_member_rm"`
//}
//
//func (c *StepConfig) Encode() string {
// configBytes, err := json.Marshal(c)
// if err != nil {
// return ""
// }
// return string(configBytes)
//}
//
////type FBConfig struct {
//// AssistanceValidityTerm uint32 `json:"assistance_validity_term"` // 邀请倒计时
//// Postage uint32 `json:"postage"` // 邮费
//// AssistanceFee uint32 `json:"assistance_fee"` // 每人拆红包
//// OrderAssistanceFee uint32 `json:"order_assistance_fee"` // 订单邀请拆红包
//// ActivityExpire string `json:"activity_expire"` // 活动过期时间
////}
////
////type FOConfig struct {
//// ActivityExpire string `json:"activity_expire"` // 活动过期时间
////}
////
////func (c *FBConfig) Encode() string {
//// configBytes, err := json.Marshal(c)
//// if err != nil {
//// return ""
//// }
//// return string(configBytes)
////}
//
//type InviteLotteryConfig struct {
// Name string `json:"name"` // 名字
// Image string `json:"image"` // 图片
// DrawTime uint32 `json:"draw_time"` // 开奖的分钟数
// SponsorId uint32 `json:"sponsor_id"` // 赞助商ID
// NeedNum uint32 `json:"need_num"` // 需要的邀请数
// IsShow uint8 `json:"is_show"` // 上下架
//}
//
//func (c *InviteLotteryConfig) Encode() string {
// configBytes, err := json.Marshal(c)
// if err != nil {
// return ""
// }
// return string(configBytes)
//}
//
////type TargetUserConfig struct {
//// List map[uint32]bool `json:"list"`
////}
////
////func (c *TargetUserConfig) Encode() string {
//// configBytes, err := json.Marshal(c)
//// if err != nil {
//// return ""
//// }
//// return string(configBytes)
////}