company_config.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package company
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "eta_gn/eta_api/utils"
  6. "github.com/beego/beego/v2/client/orm"
  7. )
  8. const (
  9. ConfAreaCodeListKey = "area_code_list" // 手机号区号列表
  10. ConfEnAuthRoleKey = "en_auth_role" // 英文权限角色配置Key
  11. )
  12. type CrmConfig struct {
  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. func GetConfigDetailByCode(configCode string) (item CrmConfig, err error) {
  29. o := orm.NewOrm()
  30. sql := ` SELECT config_value FROM crm_config WHERE config_code=? `
  31. err = o.Raw(sql, configCode).QueryRow(&item)
  32. return
  33. }
  34. // ConfEnAuthRole 配置-英文权限角色
  35. type ConfEnAuthRole struct {
  36. RoleCode string `description:"角色编码"`
  37. RoleName string `description:"角色名称"`
  38. SyncCrm bool `description:"是否同步CRM"`
  39. }
  40. // ConfigClassifyId
  41. // @Description: 后台配置的报告id
  42. type ConfigClassifyId struct {
  43. Debug int `json:"debug"`
  44. Release int `json:"release"`
  45. }
  46. // GetReportClassifyIdByConfigKey
  47. // @Description: 获取关联的报告id
  48. // @author: Roc
  49. // @datetime 2024-06-18 14:10:27
  50. // @param configKey string
  51. // @return classifyId int
  52. // @return err error
  53. func GetReportClassifyIdByConfigKey(configKey string) (classifyId int, err error) {
  54. // 别问为啥要从配置里拿=_=!
  55. conf, e := GetConfigDetailByCode(configKey)
  56. if e != nil {
  57. err = errors.New("获取配置的id失败, Err: " + e.Error())
  58. return
  59. }
  60. if conf.ConfigValue == "" {
  61. err = errors.New("ID配置有误")
  62. return
  63. }
  64. type TwoWeekIdConf struct {
  65. Debug []int
  66. Release []int
  67. }
  68. classifyIdConf := new(ConfigClassifyId)
  69. if e = json.Unmarshal([]byte(conf.ConfigValue), &classifyIdConf); e != nil {
  70. err = errors.New("解析ID配置失败, Err: " + e.Error())
  71. return
  72. }
  73. if utils.RunMode == "debug" {
  74. classifyId = classifyIdConf.Debug
  75. } else {
  76. classifyId = classifyIdConf.Release
  77. }
  78. return
  79. }