123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- package controllers
- import (
- "encoding/json"
- "eta/eta_forum_admin/models"
- "eta/eta_forum_admin/models/system"
- "strings"
- )
- // CrmConfigController 基础配置
- type CrmConfigController struct {
- BaseAuthController
- }
- // Save
- // @Title 保存配置
- // @Description 保存配置
- // @Param request body map[string]interface{} true "type json string"
- // @Success 200 Ret=200 操作成功
- // @router /save [post]
- func (this *CrmConfigController) Save() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req map[string]interface{}
- if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + e.Error()
- return
- }
- // 获取配置信息
- list, e := system.GetCrmConfig()
- if e != nil {
- br.Msg = "保存失败"
- br.ErrMsg = "获取配置列表失败, Err: " + e.Error()
- return
- }
- confMap := make(map[string]*system.CrmConfig)
- for _, v := range list {
- if v.IsShow == 1 {
- confMap[v.ConfigCode] = v
- }
- }
- // 根据配置类型取值
- updates := make([]system.ConfUpdateItem, 0)
- for k, v := range req {
- // 过滤掉表中没有的key
- conf := confMap[k]
- if conf == nil {
- continue
- }
- str, ok := v.(string)
- if !ok {
- continue
- }
- str = strings.TrimSpace(str)
- if conf.Necessary == 1 && str == "" {
- br.Msg = conf.Remark + "不可为空"
- return
- }
- updates = append(updates, system.ConfUpdateItem{
- ConfigCode: k,
- ConfigValue: str,
- })
- }
- if len(updates) > 0 {
- if e = system.UpdateCrmConfigMulti(updates); e != nil {
- br.Msg = "保存失败"
- br.ErrMsg = "保存商家配置失败, Err: " + e.Error()
- return
- }
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- }
- // Fetch
- // @Title 获取配置
- // @Description 获取配置
- // @Success 200 Ret=200 获取成功
- // @router /fetch [get]
- func (this *CrmConfigController) Fetch() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- // 获取配置信息
- tmpList, e := system.GetCrmConfig()
- if e != nil {
- br.Msg = "保存失败"
- br.ErrMsg = "获取配置列表失败, Err: " + e.Error()
- return
- }
- list := make(map[string]string)
- for _, v := range tmpList {
- if v.IsShow == 1 {
- list[v.ConfigCode] = v.ConfigValue
- }
- }
- br.Data = list
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- }
|