web_assist.go 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. package http
  2. //assist 创作中心协管相关
  3. import (
  4. "go-common/library/ecode"
  5. bm "go-common/library/net/http/blademaster"
  6. "go-common/library/net/metadata"
  7. "strconv"
  8. "time"
  9. )
  10. func webAssists(c *bm.Context) {
  11. midI, ok := c.Get("mid")
  12. if !ok {
  13. c.JSON(nil, ecode.NoLogin)
  14. return
  15. }
  16. mid, _ := midI.(int64)
  17. ip := metadata.String(c, metadata.RemoteIP)
  18. assists, err := assistSvc.Assists(c, mid, ip)
  19. if err != nil {
  20. c.JSON(nil, err)
  21. return
  22. }
  23. c.JSON(assists, nil)
  24. }
  25. func webAssistLogs(c *bm.Context) {
  26. req := c.Request
  27. params := req.Form
  28. midI, ok := c.Get("mid")
  29. if !ok {
  30. c.JSON(nil, ecode.NoLogin)
  31. return
  32. }
  33. mid, _ := midI.(int64)
  34. ip := metadata.String(c, metadata.RemoteIP)
  35. pnStr := params.Get("pn")
  36. psStr := params.Get("ps")
  37. pn, err := strconv.ParseInt(pnStr, 10, 64)
  38. if err != nil || pn < 1 {
  39. pn = 1
  40. }
  41. ps, err := strconv.ParseInt(psStr, 10, 64)
  42. if err != nil || ps <= 10 {
  43. ps = 10
  44. }
  45. assistMidStr := params.Get("assist_mid")
  46. assistMid, err := strconv.ParseInt(assistMidStr, 10, 64)
  47. if err != nil {
  48. assistMid = 0
  49. }
  50. stimeStr := params.Get("stime")
  51. stime, err := strconv.ParseInt(stimeStr, 10, 64)
  52. if err != nil || stime <= 0 {
  53. stime = time.Now().Add(-time.Hour * 72).Unix()
  54. }
  55. etimeStr := params.Get("etime")
  56. etime, err := strconv.ParseInt(etimeStr, 10, 64)
  57. if err != nil || etime <= 0 {
  58. etime = time.Now().Unix()
  59. }
  60. assistLogs, pager, err := assistSvc.AssistLogs(c, mid, assistMid, pn, ps, stime, etime, ip)
  61. if err != nil {
  62. c.JSON(nil, err)
  63. return
  64. }
  65. c.JSONMap(map[string]interface{}{
  66. "pager": pager,
  67. "data": assistLogs,
  68. }, nil)
  69. }
  70. func webAssistAdd(c *bm.Context) {
  71. req := c.Request
  72. params := req.Form
  73. ck := c.Request.Header.Get("cookie")
  74. ak := params.Get("access_key")
  75. mainStr := params.Get("main")
  76. liveStr := params.Get("live")
  77. assistMidStr := params.Get("assist_mid")
  78. main := 1
  79. live := 0
  80. midI, ok := c.Get("mid")
  81. if !ok {
  82. c.JSON(nil, ecode.NoLogin)
  83. return
  84. }
  85. mid, _ := midI.(int64)
  86. var (
  87. err error
  88. assistMid int64
  89. m, l int
  90. )
  91. assistMid, err = strconv.ParseInt(assistMidStr, 10, 64)
  92. if err != nil || assistMid == 0 {
  93. c.JSON(nil, ecode.RequestErr)
  94. return
  95. }
  96. if mainStr != "" {
  97. m, err = strconv.Atoi(mainStr)
  98. if err != nil {
  99. c.JSON(nil, ecode.RequestErr)
  100. return
  101. }
  102. main = m
  103. }
  104. if liveStr != "" {
  105. l, err = strconv.Atoi(liveStr)
  106. if err != nil {
  107. c.JSON(nil, ecode.RequestErr)
  108. return
  109. }
  110. live = l
  111. }
  112. ip := metadata.String(c, metadata.RemoteIP)
  113. if err = assistSvc.AddAssist(c, mid, assistMid, int8(main), int8(live), ip, ak, ck); err != nil {
  114. c.JSON(nil, err)
  115. return
  116. }
  117. c.JSON(nil, nil)
  118. }
  119. func webAssistSet(c *bm.Context) {
  120. req := c.Request
  121. params := req.Form
  122. ck := c.Request.Header.Get("cookie")
  123. ak := params.Get("access_key")
  124. mainStr := params.Get("main")
  125. liveStr := params.Get("live")
  126. midI, ok := c.Get("mid")
  127. main := 1
  128. live := 0
  129. if !ok {
  130. c.JSON(nil, ecode.NoLogin)
  131. return
  132. }
  133. if mainStr != "" {
  134. m, err := strconv.Atoi(mainStr)
  135. if err != nil {
  136. c.JSON(nil, ecode.RequestErr)
  137. return
  138. }
  139. main = m
  140. }
  141. if liveStr != "" {
  142. l, err := strconv.Atoi(liveStr)
  143. if err != nil {
  144. c.JSON(nil, ecode.RequestErr)
  145. return
  146. }
  147. live = l
  148. }
  149. var (
  150. err error
  151. assistMid int64
  152. )
  153. assistMidStr := params.Get("assist_mid")
  154. assistMid, err = strconv.ParseInt(assistMidStr, 10, 64)
  155. if err != nil || assistMid == 0 {
  156. c.JSON(nil, ecode.RequestErr)
  157. return
  158. }
  159. mid, _ := midI.(int64)
  160. ip := metadata.String(c, metadata.RemoteIP)
  161. if err = assistSvc.SetAssist(c, mid, assistMid, int8(main), int8(live), ip, ak, ck); err != nil {
  162. c.JSON(nil, err)
  163. return
  164. }
  165. c.JSON(nil, nil)
  166. }
  167. func webAssistDel(c *bm.Context) {
  168. req := c.Request
  169. params := req.Form
  170. ck := c.Request.Header.Get("cookie")
  171. ak := params.Get("access_key")
  172. midI, ok := c.Get("mid")
  173. if !ok {
  174. c.JSON(nil, ecode.NoLogin)
  175. return
  176. }
  177. assistMidStr := params.Get("assist_mid")
  178. assistMid, err := strconv.ParseInt(assistMidStr, 10, 64)
  179. if err != nil || assistMid == 0 {
  180. c.JSON(nil, ecode.RequestErr)
  181. return
  182. }
  183. mid, _ := midI.(int64)
  184. ip := metadata.String(c, metadata.RemoteIP)
  185. if err := assistSvc.DelAssist(c, mid, assistMid, ip, ak, ck); err != nil {
  186. c.JSON(nil, err)
  187. return
  188. }
  189. c.JSON(nil, nil)
  190. }
  191. func webAssistLogRevoc(c *bm.Context) {
  192. req := c.Request
  193. params := req.Form
  194. ck := c.Request.Header.Get("cookie")
  195. midI, ok := c.Get("mid")
  196. if !ok {
  197. c.JSON(nil, ecode.NoLogin)
  198. return
  199. }
  200. logIDStr := params.Get("log_id")
  201. assistMidStr := params.Get("assist_mid")
  202. logID, _ := strconv.ParseInt(logIDStr, 10, 64)
  203. assistMid, _ := strconv.ParseInt(assistMidStr, 10, 64)
  204. if assistMid < 1 || logID < 1 {
  205. c.JSON(nil, ecode.RequestErr)
  206. return
  207. }
  208. mid, _ := midI.(int64)
  209. ip := metadata.String(c, metadata.RemoteIP)
  210. if err := assistSvc.RevocAssistLog(c, mid, assistMid, logID, ck, ip); err != nil {
  211. c.JSON(nil, err)
  212. return
  213. }
  214. c.JSON(nil, nil)
  215. }
  216. func webAssistStatus(c *bm.Context) {
  217. midI, ok := c.Get("mid")
  218. if !ok {
  219. c.JSON(nil, ecode.NoLogin)
  220. return
  221. }
  222. mid, _ := midI.(int64)
  223. ip := metadata.String(c, metadata.RemoteIP)
  224. status, err := assistSvc.LiveStatus(c, mid, ip)
  225. if err != nil {
  226. c.JSON(nil, err)
  227. return
  228. }
  229. c.JSON(map[string]int8{
  230. "live": status,
  231. }, nil)
  232. }