addReceiveInfo.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package handler
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "github.com/sirupsen/logrus"
  5. "youngee_b_api/consts"
  6. "youngee_b_api/db"
  7. "youngee_b_api/middleware"
  8. "youngee_b_api/model/http_model"
  9. "youngee_b_api/util"
  10. )
  11. func WrapAddReceiveInfoHandler(ctx *gin.Context) {
  12. handler := newAddReceiveInfoHandler(ctx)
  13. baseRun(handler)
  14. }
  15. type AddReceiveInfoHandler struct {
  16. ctx *gin.Context
  17. req *http_model.AddReceiveInfoRequest
  18. resp *http_model.CommonResponse
  19. }
  20. func (a AddReceiveInfoHandler) getContext() *gin.Context {
  21. return a.ctx
  22. }
  23. func (a AddReceiveInfoHandler) getResponse() interface{} {
  24. return a.resp
  25. }
  26. func (a AddReceiveInfoHandler) getRequest() interface{} {
  27. return a.req
  28. }
  29. func (a AddReceiveInfoHandler) run() {
  30. auth := middleware.GetSessionAuth(a.ctx)
  31. enterpriseID := auth.EnterpriseID
  32. err := db.AddReceiveInfo(a.ctx, enterpriseID, a.req)
  33. if err != nil {
  34. // 数据库查询失败,返回5001
  35. logrus.Errorf("[AddReceiveInfoHandler] call AddReceiveInfo err:%+v\n", err)
  36. util.HandlerPackErrorResp(a.resp, consts.ErrorInternal, "")
  37. logrus.Info("AddReceiveInfo fail,req:%+v", a.req)
  38. return
  39. }
  40. a.resp.Message = "新增发票信息成功"
  41. }
  42. func (a AddReceiveInfoHandler) checkParam() error {
  43. return nil
  44. }
  45. func newAddReceiveInfoHandler(ctx *gin.Context) *AddReceiveInfoHandler {
  46. return &AddReceiveInfoHandler{
  47. ctx: ctx,
  48. req: http_model.NewAddReceiveInfoRequest(),
  49. resp: http_model.NewAddReceiveInfoResponse(),
  50. }
  51. }