crm_config.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. package system
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "eta/eta_forum_admin/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. IsShow int `description:"是否在配置页面展示,1展示,0 不展示"`
  25. ValType int `description:"1-字符串;2-数值;3-字符串数组;4-富文本;"`
  26. Necessary int `description:"是否必填:0-否;1-是"`
  27. Remark string `description:"备注"`
  28. }
  29. func GetConfigValueByCode(configCode string) (total int, err error) {
  30. o := orm.NewOrm()
  31. sql := ` SELECT config_value FROM crm_config WHERE config_code=? `
  32. err = o.Raw(sql, configCode).QueryRow(&total)
  33. return
  34. }
  35. type ConfUpdateItem struct {
  36. ConfigCode string `description:"详情Code"`
  37. ConfigValue string `description:"详情"`
  38. }
  39. // 修改
  40. func CrmConfigUpdate(newValue, configCode string) (err error) {
  41. o := orm.NewOrm()
  42. sql := `UPDATE crm_config SET config_value=? WHERE config_code= ?`
  43. _, err = o.Raw(sql, newValue, configCode).Exec()
  44. return
  45. }
  46. // ConfigClassifyId
  47. // @Description: 后台配置的报告id
  48. type ConfigClassifyId struct {
  49. Debug int `json:"debug"`
  50. Release int `json:"release"`
  51. }
  52. func GetCrmConfigDetailByCode(configCode string) (item CrmConfig, err error) {
  53. o := orm.NewOrm()
  54. sql := ` SELECT * FROM crm_config WHERE config_code=? `
  55. err = o.Raw(sql, configCode).QueryRow(&item)
  56. return
  57. }
  58. // GetReportClassifyIdByConfigKey
  59. // @Description: 获取关联的报告id
  60. // @author: Roc
  61. // @datetime 2024-06-18 14:10:27
  62. // @param configKey string
  63. // @return classifyId int
  64. // @return err error
  65. func GetReportClassifyIdByConfigKey(configKey string) (classifyId int, err error) {
  66. // 别问为啥要从配置里拿=_=!
  67. conf, e := GetCrmConfigDetailByCode(configKey)
  68. if e != nil {
  69. err = errors.New("获取配置的id失败, Err: " + e.Error())
  70. return
  71. }
  72. if conf.ConfigValue == "" {
  73. err = errors.New("ID配置有误")
  74. return
  75. }
  76. type TwoWeekIdConf struct {
  77. Debug []int
  78. Release []int
  79. }
  80. classifyIdConf := new(ConfigClassifyId)
  81. if e = json.Unmarshal([]byte(conf.ConfigValue), &classifyIdConf); e != nil {
  82. err = errors.New("解析ID配置失败, Err: " + e.Error())
  83. return
  84. }
  85. if utils.RunMode == "debug" {
  86. classifyId = classifyIdConf.Debug
  87. } else {
  88. classifyId = classifyIdConf.Release
  89. }
  90. return
  91. }
  92. type ResourceResp struct {
  93. ResourceUrl string `description:"资源地址"`
  94. }
  95. // GetCrmConfig 获取基础配置
  96. func GetCrmConfig() (list []*CrmConfig, err error) {
  97. o := orm.NewOrm()
  98. sql := `SELECT * FROM crm_config`
  99. _, err = o.Raw(sql).QueryRows(&list)
  100. return
  101. }
  102. // UpdateCrmConfigMulti 批量修改配置
  103. func UpdateCrmConfigMulti(items []ConfUpdateItem) (err error) {
  104. o := orm.NewOrm()
  105. p, err := o.Raw("UPDATE crm_config SET config_value = ? WHERE config_code = ?").Prepare()
  106. if err != nil {
  107. return
  108. }
  109. defer func() {
  110. _ = p.Close()
  111. }()
  112. for _, v := range items {
  113. _, err = p.Exec(v.ConfigValue, v.ConfigCode)
  114. if err != nil {
  115. return
  116. }
  117. }
  118. return
  119. }