company_config.go 2.0 KB

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