1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- package models
- import (
- "eta/eta_mini_api/utils"
- "github.com/beego/beego/v2/client/orm"
- "html"
- "strconv"
- "time"
- )
- var (
- BusinessConfMap map[string]string
- )
- const (
- BusinessConfReportChartExpiredTime = "ReportChartExpiredTime" // 图表有效期鉴权时间,单位:分钟
- BusinessConfIsOpenChartExpired = "IsOpenChartExpired" // 是否开启图表权限
- )
- // BusinessConf 商户配置表
- type BusinessConf struct {
- Id int `orm:"column(id);pk" gorm:"column:id;primaryKey;autoIncrement"` //`orm:"column(id);pk" gorm:"primaryKey" `
- ConfKey string `gorm:"column:conf_key"` //`description:"配置Key"`
- ConfVal string `gorm:"column:conf_val"` //`description:"配置值"`
- ValType int `gorm:"column:val_type"` //`description:"1-字符串;2-数值;3-字符串数组;4-富文本;"`
- Necessary int `gorm:"column:necessary"` //`description:"是否必填:0-否;1-是"`
- Remark string `gorm:"column:remark"` // `description:"备注"`
- CreateTime time.Time `gorm:"column:create_time"`
- }
- func (b *BusinessConf) TableName() string {
- return "business_conf"
- }
- // GetItemByConfKey 获取配置项
- func (b *BusinessConf) GetItemByConfKey(key string) (item *BusinessConf, err error) {
- sql := `SELECT * FROM business_conf WHERE conf_key = ? `
- err = orm.NewOrmUsingDB("eta").Raw(sql, key).QueryRow(&item)
- return
- }
- // GetBusinessConf 获取商家配置
- func GetBusinessConf() (list map[string]string, err error) {
- list = make(map[string]string)
- var items []*BusinessConf
- sql := `SELECT * FROM business_conf`
- _, err = orm.NewOrmUsingDB("eta").Raw(sql).QueryRows(&items)
- if err != nil {
- return
- }
- for _, v := range items {
- if v.ValType == 4 {
- list[v.ConfKey] = html.UnescapeString(v.ConfVal)
- continue
- }
- list[v.ConfKey] = v.ConfVal
- }
- return
- }
- func InitBusinessConf() {
- var e error
- BusinessConfMap, e = GetBusinessConf()
- if e != nil {
- return
- }
- // 图表有效期的过期时间
- if BusinessConfMap[BusinessConfReportChartExpiredTime] != "" {
- reportChartExpiredTime, _ := strconv.Atoi(BusinessConfMap[BusinessConfReportChartExpiredTime])
- if reportChartExpiredTime <= 0 {
- reportChartExpiredTime = 30
- }
- utils.BusinessConfReportChartExpiredTime = time.Duration(reportChartExpiredTime) * time.Minute
- } else {
- utils.BusinessConfReportChartExpiredTime = 30 * time.Minute
- }
- }
|