business_conf.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package models
  2. import (
  3. "eta/eta_hub/utils"
  4. "fmt"
  5. "github.com/beego/beego/v2/client/orm"
  6. "html"
  7. "time"
  8. )
  9. const (
  10. BusinessConfUseXf = "UseXf"
  11. BusinessConfXfAppid = "XfAppid"
  12. BusinessConfXfApiKey = "XfApiKey"
  13. BusinessConfXfApiSecret = "XfApiSecret"
  14. BusinessConfXfVcn = "XfVcn"
  15. BusinessConfEnPptCoverImgs = "EnPptCoverImgs"
  16. BusinessConfIsReportApprove = "IsReportApprove"
  17. BusinessConfReportApproveType = "ReportApproveType"
  18. )
  19. const (
  20. BusinessConfReportApproveTypeEta = "eta"
  21. BusinessConfReportApproveTypeOther = "other"
  22. )
  23. // BusinessConf 商户配置表
  24. type BusinessConf struct {
  25. Id int `orm:"column(id);pk"`
  26. ConfKey string `description:"配置Key"`
  27. ConfVal string `description:"配置值"`
  28. ValType int `description:"1-字符串;2-数值;3-字符串数组;4-富文本;"`
  29. Necessary int `description:"是否必填:0-否;1-是"`
  30. Remark string `description:"备注"`
  31. CreateTime time.Time
  32. }
  33. // GetBusinessConf 获取商家配置
  34. func GetBusinessConf() (list map[string]string, err error) {
  35. list = make(map[string]string)
  36. var items []*BusinessConf
  37. o := orm.NewOrm()
  38. sql := `SELECT * FROM business_conf`
  39. _, err = o.Raw(sql).QueryRows(&items)
  40. if err != nil {
  41. return
  42. }
  43. for _, v := range items {
  44. if v.ValType == 4 {
  45. list[v.ConfKey] = html.UnescapeString(v.ConfVal)
  46. continue
  47. }
  48. list[v.ConfKey] = v.ConfVal
  49. }
  50. return
  51. }
  52. func GetBusinessConfByKey(key string) (item *BusinessConf, err error) {
  53. o := orm.NewOrm()
  54. sql := fmt.Sprintf(`SELECT * FROM business_conf WHERE conf_key = ? LIMIT 1`)
  55. err = o.Raw(sql, key).QueryRow(&item)
  56. return
  57. }
  58. // InitUseMongoConf
  59. // @Description:
  60. // @author: Roc
  61. // @datetime 2024-07-01 13:49:09
  62. func InitUseMongoConf() {
  63. useMongo, e := GetBusinessConfByKey("UseMongo")
  64. if e != nil {
  65. return
  66. }
  67. if useMongo.ConfVal == `true` {
  68. utils.UseMongo = true
  69. }
  70. }