123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- package system
- import (
- "encoding/json"
- "errors"
- "eta/eta_forum_admin/utils"
- "github.com/beego/beego/v2/client/orm"
- )
- const (
- ConfAreaCodeListKey = "area_code_list" // 手机号区号列表
- CrmConfigLoginSmsTpId = "LoginSmsTpId"
- CrmConfigLoginSmsGjTpId = "LoginSmsGjTpId"
- CrmConfigSmsJhgnAppKey = "SmsJhgnAppKey"
- CrmConfigSmsJhgjAppKey = "SmsJhgjAppKey"
- CrmConfigLoginSmsTplContent = "LoginSmsTplContent"
- CrmConfigSmsJhgjVariable = "SmsJhgjVariable" // 聚合国际短信变量
- CrmConfigICPLicense = "ICPLicense"
- CrmConfigLogoCN = "LogoCN"
- CrmConfigLogoCNMini = "LogoCNMini"
- CrmConfigCompanyWatermark = "CompanyWatermark"
- )
- type CrmConfig struct {
- ConfigCode string `description:"详情Code"`
- ConfigValue string `description:"详情"`
- IsShow int `description:"是否在配置页面展示,1展示,0 不展示"`
- ValType int `description:"1-字符串;2-数值;3-字符串数组;4-富文本;"`
- Necessary int `description:"是否必填:0-否;1-是"`
- Remark string `description:"备注"`
- }
- func GetConfigValueByCode(configCode string) (total int, err error) {
- o := orm.NewOrm()
- sql := ` SELECT config_value FROM crm_config WHERE config_code=? `
- err = o.Raw(sql, configCode).QueryRow(&total)
- return
- }
- type ConfUpdateItem struct {
- ConfigCode string `description:"详情Code"`
- ConfigValue string `description:"详情"`
- }
- // 修改
- func CrmConfigUpdate(newValue, configCode string) (err error) {
- o := orm.NewOrm()
- sql := `UPDATE crm_config SET config_value=? WHERE config_code= ?`
- _, err = o.Raw(sql, newValue, configCode).Exec()
- return
- }
- // ConfigClassifyId
- // @Description: 后台配置的报告id
- type ConfigClassifyId struct {
- Debug int `json:"debug"`
- Release int `json:"release"`
- }
- func GetCrmConfigDetailByCode(configCode string) (item CrmConfig, err error) {
- o := orm.NewOrm()
- sql := ` SELECT * FROM crm_config WHERE config_code=? `
- err = o.Raw(sql, configCode).QueryRow(&item)
- return
- }
- // GetReportClassifyIdByConfigKey
- // @Description: 获取关联的报告id
- // @author: Roc
- // @datetime 2024-06-18 14:10:27
- // @param configKey string
- // @return classifyId int
- // @return err error
- func GetReportClassifyIdByConfigKey(configKey string) (classifyId int, err error) {
- // 别问为啥要从配置里拿=_=!
- conf, e := GetCrmConfigDetailByCode(configKey)
- if e != nil {
- err = errors.New("获取配置的id失败, Err: " + e.Error())
- return
- }
- if conf.ConfigValue == "" {
- err = errors.New("ID配置有误")
- return
- }
- type TwoWeekIdConf struct {
- Debug []int
- Release []int
- }
- classifyIdConf := new(ConfigClassifyId)
- if e = json.Unmarshal([]byte(conf.ConfigValue), &classifyIdConf); e != nil {
- err = errors.New("解析ID配置失败, Err: " + e.Error())
- return
- }
- if utils.RunMode == "debug" {
- classifyId = classifyIdConf.Debug
- } else {
- classifyId = classifyIdConf.Release
- }
- return
- }
- type ResourceResp struct {
- ResourceUrl string `description:"资源地址"`
- }
- // GetCrmConfig 获取基础配置
- func GetCrmConfig() (list []*CrmConfig, err error) {
- o := orm.NewOrm()
- sql := `SELECT * FROM crm_config`
- _, err = o.Raw(sql).QueryRows(&list)
- return
- }
- // UpdateCrmConfigMulti 批量修改配置
- func UpdateCrmConfigMulti(items []ConfUpdateItem) (err error) {
- o := orm.NewOrm()
- p, err := o.Raw("UPDATE crm_config SET config_value = ? WHERE config_code = ?").Prepare()
- if err != nil {
- return
- }
- defer func() {
- _ = p.Close()
- }()
- for _, v := range items {
- _, err = p.Exec(v.ConfigValue, v.ConfigCode)
- if err != nil {
- return
- }
- }
- return
- }
|