trade.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. package http
  2. import (
  3. api "go-common/app/interface/main/ugcpay/api/http"
  4. "go-common/app/interface/main/ugcpay/model"
  5. bm "go-common/library/net/http/blademaster"
  6. )
  7. func tradeCreate(ctx *bm.Context) {
  8. var (
  9. err error
  10. arg = &api.ArgTradeCreate{}
  11. resp = &api.RespTradeCreate{}
  12. mid, _ = ctx.Get("mid")
  13. platform = ctx.Request.FormValue("platform")
  14. )
  15. if err = ctx.Bind(arg); err != nil {
  16. return
  17. }
  18. if resp.OrderID, resp.PayData, err = srv.TradeCreate(ctx, mid.(int64), platform, arg.OID, arg.OType, arg.Currency); err != nil {
  19. ctx.JSON(nil, err)
  20. return
  21. }
  22. ctx.JSON(resp, err)
  23. }
  24. func tradeQuery(ctx *bm.Context) {
  25. var (
  26. err error
  27. arg = &api.ArgTradeOrder{}
  28. resp *api.RespTradeOrder
  29. order *model.TradeOrder
  30. )
  31. if err = ctx.Bind(arg); err != nil {
  32. return
  33. }
  34. if order, err = srv.TradeQuery(ctx, arg.OrderID); err != nil {
  35. ctx.JSON(nil, err)
  36. return
  37. }
  38. resp = &api.RespTradeOrder{
  39. OrderID: order.OrderID,
  40. MID: order.MID,
  41. Biz: order.Biz,
  42. Platform: order.Platform,
  43. OID: order.OID,
  44. OType: order.OType,
  45. Fee: order.Fee,
  46. Currency: order.Currency,
  47. PayID: order.PayID,
  48. State: order.State,
  49. Reason: order.Reason,
  50. }
  51. ctx.JSON(resp, err)
  52. }
  53. func tradeConfirm(ctx *bm.Context) {
  54. var (
  55. err error
  56. arg = &api.ArgTradeOrder{}
  57. resp *api.RespTradeOrder
  58. order *model.TradeOrder
  59. )
  60. if err = ctx.Bind(arg); err != nil {
  61. return
  62. }
  63. if order, err = srv.TradeConfirm(ctx, arg.OrderID); err != nil {
  64. ctx.JSON(nil, err)
  65. return
  66. }
  67. resp = &api.RespTradeOrder{
  68. OrderID: order.OrderID,
  69. MID: order.MID,
  70. Biz: order.Biz,
  71. Platform: order.Platform,
  72. OID: order.OID,
  73. OType: order.OType,
  74. Fee: order.Fee,
  75. Currency: order.Currency,
  76. PayID: order.PayID,
  77. State: order.State,
  78. Reason: order.Reason,
  79. }
  80. ctx.JSON(resp, err)
  81. }
  82. func tradeCancel(ctx *bm.Context) {
  83. var (
  84. err error
  85. arg = &api.ArgTradeOrder{}
  86. )
  87. if err = ctx.Bind(arg); err != nil {
  88. return
  89. }
  90. ctx.JSON(nil, srv.TradeCancel(ctx, arg.OrderID))
  91. }