addInvoiceRecord.go 1.5 KB

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