business_conf.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package models
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "html"
  6. "time"
  7. )
  8. const (
  9. BusinessConfCompanyName = "CompanyName"
  10. BusinessConfCompanyWatermark = "CompanyWatermark"
  11. BusinessConfWatermarkChart = "WatermarkChart"
  12. )
  13. // FromSceneMap 数据源名称与数据源ID的对应关系
  14. var FromSceneMap = map[int]string{
  15. 1: "SmartReportSheetSize",
  16. 2: "ReportSheetSize",
  17. 3: "EnReportSheetSize",
  18. 4: "CnPptSheetSize",
  19. 5: "EnPptSheetSize",
  20. }
  21. // BusinessConf 商户配置表
  22. type BusinessConf struct {
  23. Id int `orm:"column(id);pk"`
  24. ConfKey string `description:"配置Key"`
  25. ConfVal string `description:"配置值"`
  26. ValType int `description:"1-字符串;2-数值;3-字符串数组;4-富文本;"`
  27. Necessary int `description:"是否必填:0-否;1-是"`
  28. Remark string `description:"备注"`
  29. CreateTime time.Time
  30. }
  31. // GetBusinessConf 获取商家配置
  32. func GetBusinessConf() (list map[string]string, err error) {
  33. list = make(map[string]string)
  34. var items []*BusinessConf
  35. o := orm.NewOrm()
  36. sql := `SELECT * FROM business_conf`
  37. _, err = o.Raw(sql).QueryRows(&items)
  38. if err != nil {
  39. return
  40. }
  41. for _, v := range items {
  42. if v.ValType == 4 {
  43. list[v.ConfKey] = html.UnescapeString(v.ConfVal)
  44. continue
  45. }
  46. list[v.ConfKey] = v.ConfVal
  47. }
  48. return
  49. }
  50. func GetBusinessConfByKey(key string) (item *BusinessConf, err error) {
  51. o := orm.NewOrm()
  52. sql := fmt.Sprintf(`SELECT * FROM business_conf WHERE conf_key = ? LIMIT 1`)
  53. err = o.Raw(sql, key).QueryRow(&item)
  54. return
  55. }