yb_apply.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "hongze/hongze_api/models"
  5. "hongze/hongze_api/services"
  6. )
  7. //报告
  8. type YbApplyController struct {
  9. BaseAuthController
  10. }
  11. // @Title 申请
  12. // @Description 发起申请接口
  13. // @Success 200
  14. // @router /ybApply [post]
  15. func (this *YbApplyController) YbApply() {
  16. br := new(models.BaseResponse).Init()
  17. defer func() {
  18. this.Data["json"] = br
  19. this.ServeJSON()
  20. }()
  21. user := this.User
  22. if user == nil {
  23. br.Msg = "请登录"
  24. br.ErrMsg = "请登录,用户信息为空"
  25. br.Ret = 408
  26. return
  27. }
  28. var req models.YbApplyReq
  29. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  30. if err != nil {
  31. br.Msg = "参数解析异常!"
  32. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  33. return
  34. }
  35. if req.CompanyName == "" {
  36. br.Msg = "公司名称不能为空"
  37. return
  38. }
  39. if req.RealName == "" {
  40. req.RealName = user.RealName
  41. }
  42. if req.RealName == "" {
  43. br.Msg = "姓名不能为空"
  44. return
  45. }
  46. err, brMsg, brErrMsg := services.AddYbApply(user.UserId, user.CompanyId, user.Mobile, user.Email, req)
  47. if err != nil || brMsg != ""{
  48. if brMsg != ""{
  49. br.Msg = brMsg
  50. br.ErrMsg = brErrMsg
  51. return
  52. }else{
  53. br.Msg = "申请失败"
  54. br.ErrMsg = "申请失败" + err.Error()
  55. return
  56. }
  57. }
  58. br.Ret = 200
  59. br.Success = true
  60. br.Msg = "操作成功"
  61. br.Data = nil
  62. }