coin.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. package http
  2. import (
  3. "strconv"
  4. "time"
  5. "go-common/app/interface/main/web/model"
  6. "go-common/library/ecode"
  7. "go-common/library/log/infoc"
  8. bm "go-common/library/net/http/blademaster"
  9. )
  10. func coins(c *bm.Context) {
  11. var (
  12. mid, aid int64
  13. err error
  14. )
  15. params := c.Request.Form
  16. midStr, _ := c.Get("mid")
  17. mid = midStr.(int64)
  18. aidStr := params.Get("aid")
  19. if aid, err = strconv.ParseInt(aidStr, 10, 64); err != nil {
  20. c.JSON(nil, ecode.RequestErr)
  21. return
  22. }
  23. c.JSON(webSvc.Coins(c, mid, aid))
  24. }
  25. func addCoin(c *bm.Context) {
  26. var (
  27. mid, aid, multiply int64
  28. err error
  29. like bool
  30. actLike = "cointolike"
  31. )
  32. params := c.Request.Form
  33. aidStr := params.Get("aid")
  34. multiStr := params.Get("multiply")
  35. avTypeStr := params.Get("avtype")
  36. business := params.Get("business")
  37. upIDStr := params.Get("upid")
  38. selectLikeStr := params.Get("select_like")
  39. selectLike, _ := strconv.Atoi(selectLikeStr)
  40. midStr, _ := c.Get("mid")
  41. mid = midStr.(int64)
  42. ck := c.Request.Header.Get("Cookie")
  43. if aid, err = strconv.ParseInt(aidStr, 10, 64); err != nil || aid <= 0 {
  44. c.JSON(nil, ecode.RequestErr)
  45. return
  46. }
  47. if multiply, err = strconv.ParseInt(multiStr, 10, 64); err != nil || multiply <= 0 {
  48. c.JSON(nil, ecode.RequestErr)
  49. return
  50. }
  51. upID, _ := strconv.ParseInt(upIDStr, 10, 64)
  52. avtype, _ := strconv.ParseInt(avTypeStr, 10, 64)
  53. if avtype == 0 {
  54. avtype = model.CoinAddArcType
  55. }
  56. if avtype != model.CoinAddArcType && avtype != model.CoinAddArtType {
  57. c.JSON(nil, ecode.RequestErr)
  58. return
  59. }
  60. if avtype == model.CoinAddArtType && upID == 0 {
  61. c.JSON(nil, ecode.RequestErr)
  62. return
  63. }
  64. if business != "" {
  65. if business == model.CoinArcBusiness {
  66. avtype = model.CoinAddArcType
  67. } else if business == model.CoinArtBusiness {
  68. avtype = model.CoinAddArtType
  69. } else {
  70. c.JSON(nil, ecode.RequestErr)
  71. return
  72. }
  73. } else {
  74. switch avtype {
  75. case model.CoinAddArcType:
  76. business = model.CoinArcBusiness
  77. case model.CoinAddArtType:
  78. business = model.CoinArtBusiness
  79. default:
  80. c.JSON(nil, ecode.RequestErr)
  81. return
  82. }
  83. }
  84. ua := c.Request.UserAgent()
  85. refer := c.Request.Referer()
  86. if like, err = webSvc.AddCoin(c, aid, mid, upID, multiply, avtype, business, ck, ua, refer, time.Now(), selectLike); err == nil {
  87. if webSvc.CheatInfoc != nil {
  88. itemType := infoc.ItemTypeAv
  89. if avtype == model.CoinAddArtType {
  90. itemType = "article"
  91. }
  92. webSvc.CheatInfoc.InfoAntiCheat2(c, strconv.FormatInt(upID, 10), strconv.FormatInt(aid, 10), strconv.FormatInt(mid, 10), strconv.FormatInt(aid, 10), itemType, "coin", "")
  93. if like {
  94. webSvc.CheatInfoc.InfoAntiCheat2(c, strconv.FormatInt(upID, 10), strconv.FormatInt(aid, 10), strconv.FormatInt(mid, 10), strconv.FormatInt(aid, 10), "av", actLike, "")
  95. }
  96. }
  97. }
  98. c.JSON(struct {
  99. Like bool `json:"like"`
  100. }{Like: like}, err)
  101. }
  102. func coinExp(c *bm.Context) {
  103. midStr, _ := c.Get("mid")
  104. mid := midStr.(int64)
  105. c.JSON(webSvc.CoinExp(c, mid))
  106. }
  107. func coinList(c *bm.Context) {
  108. var (
  109. ls []*model.CoinArc
  110. count int
  111. err error
  112. )
  113. v := new(struct {
  114. Mid int64 `form:"mid" validate:"min=1"`
  115. Pn int `form:"pn" default:"1" validate:"min=1"`
  116. Ps int `form:"ps" default:"20" validate:"min=1"`
  117. })
  118. if err = c.Bind(v); err != nil {
  119. return
  120. }
  121. if ls, count, err = webSvc.CoinList(c, v.Mid, v.Pn, v.Ps); err != nil {
  122. c.JSON(nil, err)
  123. return
  124. }
  125. c.JSONMap(map[string]interface{}{
  126. "count": count,
  127. "data": ls,
  128. }, err)
  129. }