crm_config.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. package system
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "eta/eta_forum_hub/utils"
  6. "github.com/beego/beego/v2/client/orm"
  7. )
  8. const (
  9. ConfAreaCodeListKey = "area_code_list" // 手机号区号列表
  10. CrmConfigLoginSmsTpId = "LoginSmsTpId"
  11. CrmConfigLoginSmsGjTpId = "LoginSmsGjTpId"
  12. CrmConfigSmsJhgnAppKey = "SmsJhgnAppKey"
  13. CrmConfigSmsJhgjAppKey = "SmsJhgjAppKey"
  14. CrmConfigLoginSmsTplContent = "LoginSmsTplContent"
  15. CrmConfigSmsJhgjVariable = "SmsJhgjVariable" // 聚合国际短信变量
  16. CrmConfigICPLicense = "ICPLicense"
  17. CrmConfigLogoCN = "LogoCN"
  18. CrmConfigLogoCNMini = "LogoCNMini"
  19. CrmConfigCompanyWatermark = "CompanyWatermark"
  20. )
  21. type CrmConfig struct {
  22. ConfigCode string `description:"详情Code"`
  23. ConfigValue string `description:"详情"`
  24. }
  25. func GetConfigValueByCode(configCode string) (total int, err error) {
  26. o := orm.NewOrm()
  27. sql := ` SELECT config_value FROM crm_config WHERE config_code=? `
  28. err = o.Raw(sql, configCode).QueryRow(&total)
  29. return
  30. }
  31. // 修改
  32. func CrmConfigUpdate(newValue, configCode string) (err error) {
  33. o := orm.NewOrm()
  34. sql := `UPDATE crm_config SET config_value=? WHERE config_code= ?`
  35. _, err = o.Raw(sql, newValue, configCode).Exec()
  36. return
  37. }
  38. // ConfigClassifyId
  39. // @Description: 后台配置的报告id
  40. type ConfigClassifyId struct {
  41. Debug int `json:"debug"`
  42. Release int `json:"release"`
  43. }
  44. func GetCrmConfigDetailByCode(configCode string) (item *CrmConfig, err error) {
  45. o := orm.NewOrm()
  46. sql := ` SELECT * FROM crm_config WHERE config_code=? `
  47. err = o.Raw(sql, configCode).QueryRow(&item)
  48. return
  49. }
  50. // GetCrmConfig 获取基础配置
  51. func GetCrmConfig() (list map[string]string, err error) {
  52. list = make(map[string]string)
  53. var items []*CrmConfig
  54. o := orm.NewOrm()
  55. sql := `SELECT * FROM crm_config`
  56. _, err = o.Raw(sql).QueryRows(&items)
  57. if err != nil {
  58. return
  59. }
  60. for _, v := range items {
  61. list[v.ConfigCode] = v.ConfigValue
  62. }
  63. return
  64. }
  65. // GetReportClassifyIdByConfigKey
  66. // @Description: 获取关联的报告id
  67. // @author: Roc
  68. // @datetime 2024-06-18 14:10:27
  69. // @param configKey string
  70. // @return classifyId int
  71. // @return err error
  72. func GetReportClassifyIdByConfigKey(configKey string) (classifyId int, err error) {
  73. // 别问为啥要从配置里拿=_=!
  74. conf, e := GetCrmConfigDetailByCode(configKey)
  75. if e != nil {
  76. err = errors.New("获取配置的id失败, Err: " + e.Error())
  77. return
  78. }
  79. if conf.ConfigValue == "" {
  80. err = errors.New("ID配置有误")
  81. return
  82. }
  83. type TwoWeekIdConf struct {
  84. Debug []int
  85. Release []int
  86. }
  87. classifyIdConf := new(ConfigClassifyId)
  88. if e = json.Unmarshal([]byte(conf.ConfigValue), &classifyIdConf); e != nil {
  89. err = errors.New("解析ID配置失败, Err: " + e.Error())
  90. return
  91. }
  92. if utils.RunMode == "debug" {
  93. classifyId = classifyIdConf.Debug
  94. } else {
  95. classifyId = classifyIdConf.Release
  96. }
  97. return
  98. }
  99. type BaseInfoResp struct {
  100. Icp string `description:"Icp信息"`
  101. //ETATitle *CrmConfig `description:"eta系统名称"`
  102. // TabName *CrmConfig `description:"tab页名称"`
  103. LogoCn string `description:"中文logo"`
  104. //LogoEn *CrmConfig `description:"英文logo"`
  105. LogoCnMini string `description:"中文logoMini"`
  106. // LogoEnMini *CrmConfig `description:"英文logoMini"`
  107. }