mini_config.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package models
  2. import (
  3. "html"
  4. "time"
  5. "github.com/beego/beego/v2/client/orm"
  6. )
  7. const ConfAreaCodeListKey = "AreaCodeList" // 手机号区号列表
  8. type MiniConfig struct {
  9. ConfigID int `description:"配置id"`
  10. ConfigCode string `description:"配置编码"` // 配置编码
  11. ConfigValue string `description:"配置值"` // 配置值
  12. ValType int `description:"配置类型"` // 配置类型
  13. Remark string `description:"备注信息"` // 备注信息
  14. CreateTime time.Time `description:"创建时间"` // 创建时间
  15. }
  16. func GetConfigDetailByCode(configCode string) (config_value string, err error) {
  17. o := orm.NewOrm()
  18. sql := ` SELECT config_value FROM mini_config WHERE config_code=? `
  19. err = o.Raw(sql, configCode).QueryRow(&config_value)
  20. return
  21. }
  22. // GetMiniConf 获取小程序配置
  23. func GetMiniConf() (list map[string]string, err error) {
  24. list = make(map[string]string)
  25. var items []*MiniConfig
  26. o := orm.NewOrm()
  27. sql := `SELECT * FROM mini_config `
  28. _, err = o.Raw(sql).QueryRows(&items)
  29. if err != nil {
  30. return
  31. }
  32. for _, v := range items {
  33. if v.ValType == 4 {
  34. list[v.ConfigCode] = html.UnescapeString(v.ConfigValue)
  35. continue
  36. }
  37. list[v.ConfigCode] = v.ConfigValue
  38. }
  39. return
  40. }
  41. // GetMiniConf 获取eta的服务的配置
  42. func GetEtaConf() (list map[string]string, err error) {
  43. list = make(map[string]string)
  44. var items []*BusinessConf
  45. o := orm.NewOrmUsingDB("eta")
  46. sql := `SELECT * FROM business_conf`
  47. _, err = o.Raw(sql).QueryRows(&items)
  48. if err != nil {
  49. return
  50. }
  51. for _, v := range items {
  52. if v.ValType == 4 {
  53. list[v.ConfKey] = html.UnescapeString(v.ConfVal)
  54. continue
  55. }
  56. list[v.ConfKey] = v.ConfVal
  57. }
  58. return
  59. }