notify.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. package http
  2. import (
  3. "encoding/json"
  4. "go-common/app/service/main/vip/model"
  5. "go-common/library/ecode"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. )
  9. const (
  10. _payNotifySuccess = "SUCCESS"
  11. _payNotifyFail = "FAIL"
  12. )
  13. func notify(c *bm.Context) {
  14. d := new(model.PayCallBackResult)
  15. if err := c.Bind(d); err != nil {
  16. log.Error("pr.Bind err(%+v)", err)
  17. return
  18. }
  19. if d.TradeNO == "" {
  20. c.JSON(nil, ecode.RequestErr)
  21. return
  22. }
  23. if d.OutTradeNO == "" {
  24. c.JSON(nil, ecode.RequestErr)
  25. return
  26. }
  27. if d.TradeStatus != model.TradeSuccess {
  28. c.JSON(nil, ecode.RequestErr)
  29. return
  30. }
  31. if err := vipSvc.PayNotify(c, d); err != nil {
  32. log.Error("s.PayNotify err(%+v)", err)
  33. c.JSON(nil, err)
  34. return
  35. }
  36. c.JSON(nil, nil)
  37. }
  38. func notify2(c *bm.Context) {
  39. var (
  40. err error
  41. )
  42. arg := new(struct {
  43. MsgContent string `form:"msgContent" validate:"required"`
  44. })
  45. if err = c.Bind(arg); err != nil {
  46. log.Error("c.Bind err(%+v)", err)
  47. c.Writer.Write([]byte(_payNotifyFail))
  48. return
  49. }
  50. p := &model.PayNotifyContent{}
  51. if err = json.Unmarshal([]byte(arg.MsgContent), p); err != nil {
  52. c.Writer.Write([]byte(_payNotifyFail))
  53. return
  54. }
  55. if err = vipSvc.PayNotify2(c, p); err != nil {
  56. log.Error("s.PayNotify2 err(%+v)", err)
  57. if err == ecode.VipOrderAlreadyHandlerErr {
  58. c.Writer.Write([]byte(_payNotifySuccess))
  59. return
  60. }
  61. c.Writer.Write([]byte(_payNotifyFail))
  62. return
  63. }
  64. c.Writer.Write([]byte(_payNotifySuccess))
  65. }
  66. func signNotify(c *bm.Context) {
  67. var (
  68. err error
  69. )
  70. arg := new(struct {
  71. MsgContent string `form:"msgContent" validate:"required"`
  72. })
  73. if err = c.Bind(arg); err != nil {
  74. return
  75. }
  76. p := new(model.PaySignNotify)
  77. if err = json.Unmarshal([]byte(arg.MsgContent), p); err != nil {
  78. c.Writer.Write([]byte(_payNotifyFail))
  79. return
  80. }
  81. if err = vipSvc.PaySignNotify(c, p); err != nil {
  82. log.Error("vip.paySignNotify(%+v) error(%+v)", p, err)
  83. c.Writer.Write([]byte(_payNotifyFail))
  84. return
  85. }
  86. c.Writer.Write([]byte(_payNotifySuccess))
  87. }
  88. func refundOrderNotify(c *bm.Context) {
  89. var (
  90. err error
  91. )
  92. arg := new(struct {
  93. MsgContent string `form:"msgContent" validate:"required"`
  94. })
  95. if err = c.Bind(arg); err != nil {
  96. return
  97. }
  98. p := new(model.PayRefundNotify)
  99. log.Info("refun order notify params:%+v", arg.MsgContent)
  100. if err = json.Unmarshal([]byte(arg.MsgContent), p); err != nil {
  101. log.Error("error(%+v)", err)
  102. c.Writer.Write([]byte(_payNotifyFail))
  103. return
  104. }
  105. if err = vipSvc.RefundNotify(c, p); err != nil {
  106. log.Error("vip.refundNotify(%+v) error(%+v)", arg.MsgContent, err)
  107. c.Writer.Write([]byte(_payNotifyFail))
  108. return
  109. }
  110. c.Writer.Write([]byte(_payNotifySuccess))
  111. }