company_config.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package company
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "eta/eta_mobile/utils"
  6. "github.com/beego/beego/v2/client/orm"
  7. )
  8. const (
  9. ConfAreaCodeListKey = "area_code_list" // 手机号区号列表
  10. )
  11. type CrmConfig struct {
  12. ConfigValue string `description:"详情"`
  13. }
  14. func GetConfigValueByCode(configCode string) (total int, err error) {
  15. o := orm.NewOrm()
  16. sql := ` SELECT config_value FROM crm_config WHERE config_code=? `
  17. err = o.Raw(sql, configCode).QueryRow(&total)
  18. return
  19. }
  20. // 修改
  21. func CrmConfigUpdate(newValue, configCode string) (err error) {
  22. o := orm.NewOrm()
  23. sql := `UPDATE crm_config SET config_value=? WHERE config_code= ?`
  24. _, err = o.Raw(sql, newValue, configCode).Exec()
  25. return
  26. }
  27. func GetConfigDetailByCode(configCode string) (item CrmConfig, err error) {
  28. o := orm.NewOrm()
  29. sql := ` SELECT config_value FROM crm_config WHERE config_code=? `
  30. err = o.Raw(sql, configCode).QueryRow(&item)
  31. return
  32. }
  33. // ConfigClassifyId
  34. // @Description: 后台配置的报告id
  35. type ConfigClassifyId struct {
  36. Debug int `json:"debug"`
  37. Release int `json:"release"`
  38. }
  39. // GetReportClassifyIdByConfigKey
  40. // @Description: 获取关联的报告id
  41. // @author: Roc
  42. // @datetime 2024-06-18 14:10:27
  43. // @param configKey string
  44. // @return classifyId int
  45. // @return err error
  46. func GetReportClassifyIdByConfigKey(configKey string) (classifyId int, err error) {
  47. // 别问为啥要从配置里拿=_=!
  48. conf, e := GetConfigDetailByCode(configKey)
  49. if e != nil {
  50. err = errors.New("获取配置的id失败, Err: " + e.Error())
  51. return
  52. }
  53. if conf.ConfigValue == "" {
  54. err = errors.New("ID配置有误")
  55. return
  56. }
  57. type TwoWeekIdConf struct {
  58. Debug []int
  59. Release []int
  60. }
  61. classifyIdConf := new(ConfigClassifyId)
  62. if e = json.Unmarshal([]byte(conf.ConfigValue), &classifyIdConf); e != nil {
  63. err = errors.New("解析ID配置失败, Err: " + e.Error())
  64. return
  65. }
  66. if utils.RunMode == "debug" {
  67. classifyId = classifyIdConf.Debug
  68. } else {
  69. classifyId = classifyIdConf.Release
  70. }
  71. return
  72. }