web.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. package http
  2. import (
  3. "strconv"
  4. "time"
  5. "go-common/library/ecode"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. "go-common/library/net/metadata"
  9. )
  10. //func getUpStatus(c *bm.Context) {
  11. // params := c.Request.Form
  12. // midStr := params.Get("mid")
  13. // mid, err := strconv.ParseInt(midStr, 10, 64)
  14. // if err != nil {
  15. // log.Error("strconv.ParseInt mid(%s) error(%v)", midStr, err)
  16. // c.JSON(nil, ecode.RequestErr)
  17. // return
  18. // }
  19. // if mid <= 0 {
  20. // log.Error("http.getUpStatus mid(%d) <= 0", mid)
  21. // c.JSON(nil, ecode.RequestErr)
  22. // return
  23. // }
  24. //
  25. // data, err := svc.GetUpStatus(c, mid)
  26. // if err != nil {
  27. // log.Error("svc.GetUpStatus mid(%v), error(%v)", err)
  28. // c.JSON(nil, err)
  29. // return
  30. // }
  31. // c.JSON(data, nil)
  32. //}
  33. func getUpStatus(c *bm.Context) {
  34. ip := metadata.String(c, metadata.RemoteIP)
  35. midI, ok := c.Get("mid")
  36. if !ok {
  37. c.JSON(nil, ecode.NoLogin)
  38. return
  39. }
  40. mid, _ := midI.(int64)
  41. data, err := svc.GetUpStatus(c, mid, ip)
  42. if err != nil {
  43. log.Error("svc.GetUpStatus mid(%v), error(%v)", err)
  44. c.JSON(nil, err)
  45. return
  46. }
  47. c.JSON(data, nil)
  48. }
  49. func join(c *bm.Context) {
  50. params := c.Request.Form
  51. midStr := params.Get("mid")
  52. mid, err := strconv.ParseInt(midStr, 10, 64)
  53. if err != nil {
  54. log.Error("strconv.ParseInt mid(%s) error(%v)", midStr, err)
  55. c.JSON(nil, ecode.RequestErr)
  56. return
  57. }
  58. if mid <= 0 {
  59. log.Error("http.getUpStatus mid(%d) <= 0", mid)
  60. c.JSON(nil, ecode.RequestErr)
  61. return
  62. }
  63. accountType, err := strconv.Atoi(params.Get("account_type"))
  64. if err != nil {
  65. log.Error("strconv.Atoi account_type(%s) error(%v)", accountType, err)
  66. c.JSON(nil, ecode.RequestErr)
  67. return
  68. }
  69. signType, err := strconv.Atoi(params.Get("sign_type"))
  70. if err != nil {
  71. log.Error("strconv.Atoi sign_type(%s) error(%v)", signType, err)
  72. c.JSON(nil, ecode.RequestErr)
  73. return
  74. }
  75. err = svc.JoinAv(c, accountType, mid, signType)
  76. if err != nil {
  77. log.Error("svc.AddUp accountType(%d) mid(%d) signType(%d) error(%v)", accountType, mid, signType, err)
  78. }
  79. c.JSON(nil, err)
  80. }
  81. func upCharge(c *bm.Context) {
  82. midI, ok := c.Get("mid")
  83. if !ok {
  84. c.JSON(nil, ecode.NoLogin)
  85. return
  86. }
  87. mid, _ := midI.(int64)
  88. data, err := svc.GetUpCharge(c, mid, time.Now())
  89. if err != nil {
  90. log.Error("growup svc.GetUpCharge error(%v)", err)
  91. c.JSON(nil, err)
  92. return
  93. }
  94. c.JSON(data, nil)
  95. }
  96. func quit(c *bm.Context) {
  97. params := c.Request.Form
  98. midStr := params.Get("mid")
  99. mid, err := strconv.ParseInt(midStr, 10, 64)
  100. if err != nil {
  101. log.Error("strconv.ParseInt mid(%s) error(%v)", midStr, err)
  102. c.JSON(nil, ecode.RequestErr)
  103. return
  104. }
  105. if mid <= 0 {
  106. log.Error("svc.quit mid(%d) <= 0", mid)
  107. c.JSON(nil, ecode.RequestErr)
  108. return
  109. }
  110. reason := params.Get("reason")
  111. err = svc.Quit(c, mid, reason)
  112. if err != nil {
  113. log.Error("svc.Quit mid(%d) error(%v)", mid, err)
  114. }
  115. c.JSON(nil, err)
  116. }
  117. func quit1(c *bm.Context) {
  118. v := new(struct {
  119. Reason string `form:"reason"`
  120. })
  121. if err := c.Bind(v); err != nil {
  122. return
  123. }
  124. midI, ok := c.Get("mid")
  125. if !ok {
  126. c.JSON(nil, ecode.NoLogin)
  127. return
  128. }
  129. mid, _ := midI.(int64)
  130. err := svc.Quit(c, mid, v.Reason)
  131. if err != nil {
  132. log.Error("svc.Quit mid(%d) error(%v)", mid, err)
  133. }
  134. c.JSON(nil, err)
  135. }
  136. func banner(c *bm.Context) {
  137. data, err := svc.GetBanner(c)
  138. if err != nil {
  139. log.Error("svc.Banner error(%v)", err)
  140. c.JSON(nil, err)
  141. return
  142. }
  143. c.JSON(data, nil)
  144. }
  145. func upBill(c *bm.Context) {
  146. midI, ok := c.Get("mid")
  147. if !ok {
  148. c.JSON(nil, ecode.NoLogin)
  149. return
  150. }
  151. mid, _ := midI.(int64)
  152. data, err := svc.UpBill(c, mid)
  153. if err != nil {
  154. log.Error("svc.UpBill mid(%d) error(%v)", mid, err)
  155. c.JSON(nil, err)
  156. return
  157. }
  158. c.JSON(data, nil)
  159. }
  160. func upYear(c *bm.Context) {
  161. midI, ok := c.Get("mid")
  162. if !ok {
  163. c.JSON(nil, ecode.NoLogin)
  164. return
  165. }
  166. mid, _ := midI.(int64)
  167. data, err := svc.UpYear(c, mid)
  168. if err != nil {
  169. log.Error("svc.UpYear mid(%d) error(%v)", mid, err)
  170. c.JSON(nil, err)
  171. return
  172. }
  173. c.JSON(data, nil)
  174. }