wallet.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. package http
  2. import (
  3. "strconv"
  4. "go-common/app/service/live/wallet/model"
  5. "go-common/library/ecode"
  6. bm "go-common/library/net/http/blademaster"
  7. )
  8. func getBasicParam(c *bm.Context) *model.BasicParam {
  9. bp := new(model.BasicParam)
  10. var err error
  11. bp.TransactionId = c.Request.Form.Get("transaction_id")
  12. bp.BizCode = c.Request.Form.Get("biz_code")
  13. bp.Area, err = strconv.ParseInt(c.Request.Form.Get("area_id"), 10, 64)
  14. if err != nil {
  15. bp.Area = 0
  16. }
  17. bp.Source = c.Request.Form.Get("source")
  18. bp.BizSource = c.Request.Form.Get("biz_source")
  19. bp.MetaData = c.Request.Form.Get("metadata")
  20. bp.Reason, err = strconv.ParseInt(c.Request.Form.Get("biz_reason"), 10, 64)
  21. if err != nil {
  22. bp.Reason = 0
  23. }
  24. bp.Version, err = strconv.ParseInt(c.Request.Form.Get("version"), 10, 64)
  25. if err != nil {
  26. bp.Version = 0
  27. }
  28. return bp
  29. }
  30. func getWithMetal(c *bm.Context) (withMetal int, err error) {
  31. withMetalStr := c.Request.Form.Get("with_metal")
  32. if withMetalStr == "" {
  33. withMetal = 0
  34. return
  35. }
  36. // check params
  37. withMetal, err = strconv.Atoi(withMetalStr)
  38. if err != nil || (withMetal != 0 && withMetal != 1) {
  39. err = ecode.RequestErr
  40. return
  41. }
  42. return
  43. }
  44. func get(c *bm.Context) {
  45. uidStr := c.Request.Form.Get("uid")
  46. // check params
  47. uid, err := strconv.ParseInt(uidStr, 10, 64)
  48. if err != nil || uid <= 0 {
  49. c.JSON(nil, ecode.RequestErr)
  50. return
  51. }
  52. withMetal, err := getWithMetal(c)
  53. if err != nil {
  54. c.JSON(nil, ecode.RequestErr)
  55. return
  56. }
  57. bp := getBasicParam(c)
  58. platform := c.Request.Header.Get("platform")
  59. c.JSON(walletSvr.Get(c, bp, uid, platform, withMetal))
  60. }
  61. func delCache(c *bm.Context) {
  62. uidStr := c.Request.Form.Get("uid")
  63. // check params
  64. uid, err := strconv.ParseInt(uidStr, 10, 64)
  65. if err != nil || uid <= 0 {
  66. c.JSON(nil, ecode.RequestErr)
  67. return
  68. }
  69. bp := getBasicParam(c)
  70. c.JSON(walletSvr.DelCache(c, bp, uid))
  71. }
  72. func getAll(c *bm.Context) {
  73. uidStr := c.Request.Form.Get("uid")
  74. // check params
  75. uid, err := strconv.ParseInt(uidStr, 10, 64)
  76. if err != nil || uid <= 0 {
  77. c.JSON(nil, ecode.RequestErr)
  78. return
  79. }
  80. withMetal, err := getWithMetal(c)
  81. if err != nil {
  82. c.JSON(nil, ecode.RequestErr)
  83. return
  84. }
  85. bp := getBasicParam(c)
  86. platform := c.Request.Header.Get("platform")
  87. c.JSON(walletSvr.GetAll(c, bp, uid, platform, withMetal))
  88. }
  89. func getTid(c *bm.Context) {
  90. typeStr := c.Request.Form.Get("type")
  91. // check params
  92. serviceType64, err := strconv.ParseInt(typeStr, 10, 64)
  93. serviceType := int32(serviceType64)
  94. if err != nil || serviceType < 0 {
  95. c.JSON(nil, ecode.RequestErr)
  96. return
  97. }
  98. params := c.Request.Form.Get("params")
  99. if params == "" {
  100. c.JSON(nil, ecode.RequestErr)
  101. return
  102. }
  103. bp := getBasicParam(c)
  104. c.JSON(walletSvr.GetTid(c, bp, 0, serviceType, params))
  105. }
  106. func recharge(c *bm.Context) {
  107. bp := getBasicParam(c)
  108. platform := c.Request.Header.Get("platform")
  109. arg := &model.RechargeOrPayForm{}
  110. if err := c.Bind(arg); err != nil {
  111. return
  112. }
  113. c.JSON(walletSvr.Recharge(c, bp, arg.Uid, platform, arg))
  114. }
  115. func modify(c *bm.Context) {
  116. bp := getBasicParam(c)
  117. platform := c.Request.Header.Get("platform")
  118. arg := &model.RechargeOrPayForm{}
  119. if err := c.Bind(arg); err != nil {
  120. return
  121. }
  122. c.JSON(walletSvr.Modify(c, bp, arg.Uid, platform, arg))
  123. }
  124. func pay(c *bm.Context) {
  125. bp := getBasicParam(c)
  126. platform := c.Request.Header.Get("platform")
  127. arg := &model.RechargeOrPayForm{}
  128. if err := c.Bind(arg); err != nil {
  129. return
  130. }
  131. var reason interface{}
  132. reasonFromHttp := c.Request.Form.Get("reason")
  133. if reasonFromHttp == "" {
  134. reason = nil
  135. } else {
  136. reason = reasonFromHttp
  137. }
  138. c.JSON(walletSvr.Pay(c, bp, arg.Uid, platform, arg, reason))
  139. }
  140. func exchange(c *bm.Context) {
  141. bp := getBasicParam(c)
  142. platform := c.Request.Header.Get("platform")
  143. arg := &model.ExchangeForm{}
  144. if err := c.Bind(arg); err != nil {
  145. return
  146. }
  147. c.JSON(walletSvr.Exchange(c, bp, arg.Uid, platform, arg))
  148. }
  149. func query(c *bm.Context) {
  150. bp := getBasicParam(c)
  151. platform := c.Request.Header.Get("platform")
  152. if platform == "" {
  153. platform = "pc"
  154. }
  155. tid := c.Request.Form.Get("transaction_id")
  156. if tid == "" {
  157. c.JSON(nil, ecode.RequestErr)
  158. return
  159. }
  160. uidStr := c.Request.Form.Get("uid")
  161. uid, err := strconv.ParseInt(uidStr, 10, 64)
  162. if err != nil || uid <= 0 {
  163. uid = 0
  164. return
  165. }
  166. c.JSON(walletSvr.Query(c, bp, uid, platform, tid))
  167. }
  168. func recordCoinStream(c *bm.Context) {
  169. bp := getBasicParam(c)
  170. platform := c.Request.Header.Get("platform")
  171. arg := &model.RecordCoinStreamForm{}
  172. if err := c.Bind(arg); err != nil {
  173. return
  174. }
  175. c.JSON(walletSvr.RecordCoinStream(c, bp, arg.Uid, platform, arg))
  176. }