order.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. // query := map[string]interface{}{"project":"queenshow"}
  14. func PayOrderCreate() *comm.NatsMsgReplyer {
  15. order := &pay.Order{}
  16. utils.ConsoleFormat(pay.PayOrderCreateApi)
  17. return &comm.NatsMsgReplyer{
  18. Subject: pay.PayOrderCreateApi,
  19. Entity: func() interface{} { return &order },
  20. Cb2: func(_ *nats.Msg, entity interface{}) (interface{}, error) {
  21. order := entity.(*pay.Order)
  22. ctx := context.Background()
  23. res, err := createOrder(ctx, order)
  24. return res, err
  25. },
  26. }
  27. }
  28. func createOrder(ctx context.Context, order *pay.Order) (id primitive.ObjectID, err error) {
  29. _id, err := repo.RepoAddDoc(&repo.RepoSession{Ctx: ctx, Client: db.GMongoDb}, repo.CollectionOrder, &order)
  30. if err != nil {
  31. return primitive.NilObjectID, err
  32. }
  33. id, err = primitive.ObjectIDFromHex(_id)
  34. return
  35. }
  36. // 获取订单信息
  37. // query := map[string]interface{}{"_id":"xxx"}
  38. func PayOrderDetail() *comm.NatsMsgReplyer {
  39. qmap := make(map[string]interface{})
  40. utils.ConsoleFormat(pay.PayOrderDetailApi)
  41. return &comm.NatsMsgReplyer{
  42. Subject: pay.PayOrderDetailApi,
  43. Entity: func() interface{} { return &qmap },
  44. Cb2: func(_ *nats.Msg, entity interface{}) (interface{}, error) {
  45. query := entity.(*map[string]interface{})
  46. ctx := context.Background()
  47. res, err := getPayOrder(ctx, *query)
  48. return res, err
  49. },
  50. }
  51. }
  52. func getPayOrder(ctx context.Context, query map[string]interface{}) (order *pay.Order, err error) {
  53. _, err = repo.RepoSeachDoc(&repo.RepoSession{Ctx: ctx, Client: db.GMongoDb}, &repo.DocSearchOptions{
  54. CollectName: repo.CollectionOrder,
  55. Query: query,
  56. }, &order)
  57. return
  58. }