withdraw.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package http
  2. import (
  3. "sync"
  4. "go-common/library/ecode"
  5. "go-common/library/log"
  6. bm "go-common/library/net/http/blademaster"
  7. )
  8. var (
  9. mapLock sync.Mutex
  10. // Lock withdraw lock
  11. Lock map[int64]*sync.Mutex
  12. )
  13. func getWithdraw(c *bm.Context) {
  14. v := new(struct {
  15. DateVersion string `form:"dateVersion" validate:"required"`
  16. Page int `form:"pageNo" default:"1" validate:"min=1"`
  17. Size int `form:"size" default:"15" validate:"min=1"`
  18. })
  19. if err := c.Bind(v); err != nil {
  20. return
  21. }
  22. from := (v.Page - 1) * v.Size
  23. count, data, err := svc.GetWithdraw(c, v.DateVersion, from, v.Size)
  24. if err != nil {
  25. log.Error("growup svc.upWithdraw error(%v)", err)
  26. c.JSON(nil, err)
  27. return
  28. }
  29. Lock = make(map[int64]*sync.Mutex)
  30. c.JSON(map[string]interface{}{
  31. "page": v.Page,
  32. "total_count": count,
  33. "data": data,
  34. }, nil)
  35. }
  36. func withdrawSuccess(c *bm.Context) {
  37. v := new(struct {
  38. OrderNo int64 `form:"order_no" validate:"required"`
  39. TradeStatus int `form:"trade_status" validate:"required"`
  40. })
  41. if err := c.Bind(v); err != nil {
  42. return
  43. }
  44. lock := getLock(v.OrderNo)
  45. lock.Lock()
  46. defer lock.Unlock()
  47. err := svc.WithdrawSuccess(c, v.OrderNo, v.TradeStatus)
  48. if err != nil {
  49. log.Error("growup svc.WithdrawSuccess error(%v)", err)
  50. }
  51. c.JSON(nil, err)
  52. }
  53. func getLock(orderNo int64) *sync.Mutex {
  54. mapLock.Lock()
  55. defer mapLock.Unlock()
  56. if Lock == nil {
  57. Lock = make(map[int64]*sync.Mutex)
  58. }
  59. if _, ok := Lock[orderNo]; !ok {
  60. Lock[orderNo] = new(sync.Mutex)
  61. }
  62. return Lock[orderNo]
  63. }
  64. func withdrawDetail(c *bm.Context) {
  65. midI, ok := c.Get("mid")
  66. if !ok {
  67. c.JSON(nil, ecode.NoLogin)
  68. return
  69. }
  70. mid, _ := midI.(int64)
  71. data, err := svc.WithdrawDetail(c, mid)
  72. if err != nil {
  73. log.Error("growup svc.WithdrawDetail error(%v)", err)
  74. c.JSON(nil, err)
  75. return
  76. }
  77. c.JSON(data, nil)
  78. }