mask.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. package http
  2. import (
  3. "strconv"
  4. "go-common/library/ecode"
  5. bm "go-common/library/net/http/blademaster"
  6. "go-common/library/xstr"
  7. )
  8. func maskState(c *bm.Context) {
  9. var (
  10. p = c.Request.Form
  11. oid, tp int64
  12. err error
  13. )
  14. if oid, err = strconv.ParseInt(p.Get("oid"), 10, 64); err != nil {
  15. c.JSON(nil, ecode.RequestErr)
  16. return
  17. }
  18. if tp, err = strconv.ParseInt(p.Get("type"), 10, 64); err != nil {
  19. c.JSON(nil, ecode.RequestErr)
  20. return
  21. }
  22. open, mobile, web, err := dmSvc.MaskState(c, int32(tp), oid)
  23. res := map[string]interface{}{}
  24. res["open"] = open
  25. res["mobile"] = mobile
  26. res["web"] = web
  27. c.JSON(res, err)
  28. }
  29. func updateMaskState(c *bm.Context) {
  30. var (
  31. p = c.Request.Form
  32. oid, tp, plat, state int64
  33. err error
  34. )
  35. if oid, err = strconv.ParseInt(p.Get("oid"), 10, 64); err != nil {
  36. c.JSON(nil, ecode.RequestErr)
  37. return
  38. }
  39. if tp, err = strconv.ParseInt(p.Get("type"), 10, 64); err != nil {
  40. c.JSON(nil, ecode.RequestErr)
  41. return
  42. }
  43. if plat, err = strconv.ParseInt(p.Get("plat"), 10, 64); err != nil {
  44. c.JSON(nil, ecode.RequestErr)
  45. return
  46. }
  47. if state, err = strconv.ParseInt(p.Get("state"), 10, 64); err != nil {
  48. c.JSON(nil, ecode.RequestErr)
  49. return
  50. }
  51. err = dmSvc.UpdateMaskState(c, int32(tp), oid, int8(plat), int32(state))
  52. c.JSON(nil, err)
  53. }
  54. func generateMask(c *bm.Context) {
  55. var (
  56. p = c.Request.Form
  57. oid, tp, plat int64
  58. err error
  59. )
  60. if oid, err = strconv.ParseInt(p.Get("oid"), 10, 64); err != nil {
  61. c.JSON(nil, ecode.RequestErr)
  62. return
  63. }
  64. if tp, err = strconv.ParseInt(p.Get("type"), 10, 64); err != nil {
  65. c.JSON(nil, ecode.RequestErr)
  66. return
  67. }
  68. if plat, err = strconv.ParseInt(p.Get("plat"), 10, 64); err != nil {
  69. c.JSON(nil, ecode.RequestErr)
  70. return
  71. }
  72. err = dmSvc.GenerateMask(c, int32(tp), oid, int8(plat))
  73. c.JSON(nil, err)
  74. }
  75. func maskUps(c *bm.Context) {
  76. var (
  77. p = c.Request.Form
  78. pn = int64(1)
  79. ps = int64(50)
  80. err error
  81. )
  82. if p.Get("pn") != "" {
  83. if pn, err = strconv.ParseInt(p.Get("pn"), 10, 64); err != nil || pn <= 0 {
  84. c.JSON(nil, ecode.RequestErr)
  85. return
  86. }
  87. }
  88. if p.Get("ps") != "" {
  89. if ps, err = strconv.ParseInt(p.Get("ps"), 10, 64); err != nil || ps <= 0 {
  90. c.JSON(nil, ecode.RequestErr)
  91. return
  92. }
  93. }
  94. c.JSON(dmSvc.MaskUps(c, pn, ps))
  95. }
  96. func maskUpOpen(c *bm.Context) {
  97. var (
  98. p = c.Request.Form
  99. comment = p.Get("comment")
  100. mids []int64
  101. state int64
  102. err error
  103. )
  104. if mids, err = xstr.SplitInts(p.Get("mids")); err != nil {
  105. c.JSON(nil, ecode.RequestErr)
  106. return
  107. }
  108. if state, err = strconv.ParseInt(p.Get("state"), 10, 64); err != nil {
  109. c.JSON(nil, ecode.RequestErr)
  110. return
  111. }
  112. err = dmSvc.MaskUpOpen(c, mids, int32(state), comment)
  113. c.JSON(nil, err)
  114. }