createSpecialLogistics.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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/model/http_model"
  7. "youngee_b_api/service"
  8. "youngee_b_api/util"
  9. )
  10. func WrapCreateSpecialLogisticsHandler(ctx *gin.Context) {
  11. handler := newCreateSpecialLogisticsHandler(ctx)
  12. baseRun(handler)
  13. }
  14. type CreateSpecialLogistics struct {
  15. ctx *gin.Context
  16. req *http_model.CreateSpecialLogisticsRequest
  17. resp *http_model.CommonResponse
  18. }
  19. func (c CreateSpecialLogistics) getContext() *gin.Context {
  20. return c.ctx
  21. }
  22. func (c CreateSpecialLogistics) getResponse() interface{} {
  23. return c.resp
  24. }
  25. func (c CreateSpecialLogistics) getRequest() interface{} {
  26. return c.req
  27. }
  28. func (c CreateSpecialLogistics) run() {
  29. data := http_model.CreateSpecialLogisticsRequest{}
  30. data = *c.req
  31. isUpdate := data.IsUpdate
  32. if isUpdate == 0 {
  33. res, err := service.Logistics.CreateSpecialLogistics(c.ctx, data)
  34. if err != nil {
  35. logrus.Errorf("[CreateSpecialLogistics] call Create err:%+v\n", err)
  36. util.HandlerPackErrorResp(c.resp, consts.ErrorInternal, "")
  37. logrus.Info("CreateSpecialLogistics fail,req:%+v", c.req)
  38. return
  39. }
  40. c.resp.Message = "成功添加物流信息"
  41. c.resp.Data = res
  42. } else {
  43. res, err := service.Logistics.UpdateSpecialLogistics(c.ctx, data)
  44. if err != nil {
  45. logrus.Errorf("[CreateSpecialLogistics] call Create err:%+v\n", err)
  46. util.HandlerPackErrorResp(c.resp, consts.ErrorInternal, "")
  47. logrus.Info("CreateSpecialLogistics fail,req:%+v", c.req)
  48. return
  49. }
  50. c.resp.Message = "成功修改物流信息"
  51. c.resp.Data = res
  52. }
  53. }
  54. func (c CreateSpecialLogistics) checkParam() error {
  55. return nil
  56. }
  57. func newCreateSpecialLogisticsHandler(ctx *gin.Context) *CreateSpecialLogistics {
  58. return &CreateSpecialLogistics{
  59. ctx: ctx,
  60. req: http_model.NewCreateSpecialLogisticsRequest(),
  61. resp: http_model.NewCreateSpecialLogisticsResponse(),
  62. }
  63. }