advice.go 2.0 KB

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