refund.go 968 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package bus
  2. import (
  3. "context"
  4. "pay/db"
  5. "pay/db/repo"
  6. "pay/utils"
  7. "github.com/nats-io/nats.go"
  8. "go.mongodb.org/mongo-driver/bson/primitive"
  9. "infish.cn/comm"
  10. "infish.cn/comm/pay"
  11. )
  12. // 创建订单退款申请
  13. func PayRefundCreate() *comm.NatsMsgReplyer {
  14. refund := pay.ReFund{}
  15. utils.ConsoleFormat(pay.PayRefundCreateApi)
  16. return &comm.NatsMsgReplyer{
  17. Subject: pay.PayRefundCreateApi,
  18. Entity: func() interface{} { return &refund },
  19. Cb2: func(_ *nats.Msg, entity interface{}) (interface{}, error) {
  20. refund := entity.(*pay.ReFund)
  21. ctx := context.Background()
  22. res, err := createRefund(ctx, refund)
  23. return res, err
  24. },
  25. }
  26. }
  27. func createRefund(ctx context.Context, refund *pay.ReFund) (id primitive.ObjectID, err error) {
  28. _id, err := repo.RepoAddDoc(&repo.RepoSession{Ctx: ctx, Client: db.GMongoDb}, repo.CollectionRefund, &refund)
  29. if err != nil {
  30. return primitive.NilObjectID, err
  31. }
  32. id, err = primitive.ObjectIDFromHex(_id)
  33. return
  34. }