advice.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "hongze/hongze_mfyx/models"
  5. "strconv"
  6. "time"
  7. )
  8. // 优化建议
  9. type AdviceController struct {
  10. BaseAuthController
  11. }
  12. // @Title 新增优化建议
  13. // @Description 新增优化建议接口
  14. // @Param request body models.AddCygxAdviceReq true "type json string"
  15. // @Success Ret=200 新增成功
  16. // @router /add [post]
  17. func (this *AdviceController) ApplyApprove() {
  18. br := new(models.BaseResponse).Init()
  19. defer func() {
  20. this.Data["json"] = br
  21. this.ServeJSON()
  22. }()
  23. user := this.User
  24. if user == nil {
  25. br.Msg = "请登录"
  26. br.ErrMsg = "请登录,SysUser Is Empty"
  27. br.Ret = 408
  28. return
  29. }
  30. var req models.AddCygxAdviceReq
  31. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  32. if err != nil {
  33. br.Msg = "参数解析异常!"
  34. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  35. return
  36. }
  37. if req.Advice == "" {
  38. br.Msg = "建议内容不可为空"
  39. return
  40. }
  41. companyDetail, err := models.GetCompanyDetailById(user.CompanyId)
  42. if err != nil {
  43. br.Msg = "新增优化建议失败!"
  44. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  45. return
  46. }
  47. if companyDetail == nil {
  48. br.Msg = "新增优化建议失败!"
  49. br.ErrMsg = "客户不存在,uid:" + strconv.Itoa(user.UserId)
  50. return
  51. }
  52. item := new(models.CygxAdvice)
  53. item.UserId = user.UserId
  54. item.UserRealName = user.RealName
  55. item.CompanyId = user.CompanyId
  56. item.CompanyName = companyDetail.CompanyName
  57. item.SalesRealName = companyDetail.SellerName
  58. item.Advice = req.Advice
  59. item.AdviceImgUrl = req.AdviceImgUrl
  60. item.CreateTime = time.Now()
  61. item.Mobile = user.Mobile
  62. item.Email = user.Email
  63. _, err = models.AddCygxAdvice(item)
  64. if err != nil {
  65. br.Msg = "新增优化建议失败"
  66. br.ErrMsg = "新增优化建议失败,Err:" + err.Error()
  67. return
  68. }
  69. br.Ret = 200
  70. br.Success = true
  71. br.Msg = "新增成功"
  72. }