base_from_smm_classify.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "eta/eta_index_lib/models"
  5. "eta/eta_index_lib/utils"
  6. "strconv"
  7. )
  8. // @Title 查询/新增分类
  9. // @Description 查询/新增分类接口
  10. // @Param request body models.AddSmmClassifyReq true "type json string"
  11. // @Success 200 {object} models.EdbClassify
  12. // @router /smm_classify/get_or_add [post]
  13. func (this *SmmController) SmmGetOrAdd() {
  14. br := new(models.BaseResponse).Init()
  15. defer func() {
  16. this.Data["json"] = br
  17. this.ServeJSON()
  18. }()
  19. var req models.AddSmmClassifyReq
  20. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  21. if err != nil {
  22. br.Msg = "参数解析异常!"
  23. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  24. return
  25. }
  26. if req.ClassifyName == "" {
  27. br.Msg = "请输入分类名称"
  28. br.IsSendEmail = false
  29. return
  30. }
  31. if req.ParentId < 0 {
  32. br.Msg = "参数错误"
  33. br.IsSendEmail = false
  34. return
  35. }
  36. sysUserId := utils.InitAdminId
  37. sysUserName := utils.InitAdminName
  38. if req.SysUserId > 0 {
  39. sysUserId = strconv.Itoa(req.SysUserId)
  40. }
  41. if req.SysUserRealName != `` {
  42. sysUserName = req.SysUserRealName
  43. }
  44. //添加指标
  45. edbClassify, err, errMsg := models.SaveSmmClassify(req.ClassifyName, req.ParentId, req.Level, sysUserId, sysUserName)
  46. if errMsg != `` {
  47. br.Msg = errMsg
  48. br.ErrMsg = errMsg
  49. if err != nil {
  50. br.ErrMsg = errMsg + ";Err:" + err.Error()
  51. } else {
  52. br.IsSendEmail = false
  53. }
  54. return
  55. }
  56. br.Ret = 200
  57. br.Msg = "保存成功"
  58. br.Success = true
  59. br.Data = edbClassify
  60. }