addInvoiceRecord.go 1.5 KB

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