like.go 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  1. package http
  2. import (
  3. "strconv"
  4. "go-common/app/interface/main/activity/model/like"
  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 subject(c *bm.Context) {
  11. params := c.Request.Form
  12. sidStr := params.Get("sid")
  13. sid, err := strconv.ParseInt(sidStr, 10, 32)
  14. if err != nil {
  15. log.Error("strconv.ParseInt(%s) error(%v)", sidStr, err)
  16. c.JSON(nil, ecode.RequestErr)
  17. return
  18. }
  19. c.JSON(likeSvc.Subject(c, sid))
  20. }
  21. func vote(c *bm.Context) {
  22. var (
  23. mid int64
  24. )
  25. midStr, _ := c.Get("mid")
  26. mid = midStr.(int64)
  27. params := c.Request.Form
  28. voteStr := params.Get("vote")
  29. vote, err := strconv.ParseInt(voteStr, 10, 64)
  30. if err != nil {
  31. c.JSON(nil, ecode.RequestErr)
  32. return
  33. }
  34. stageStr := params.Get("stage")
  35. stage, err := strconv.ParseInt(stageStr, 10, 64)
  36. if err != nil {
  37. c.JSON(nil, ecode.RequestErr)
  38. return
  39. }
  40. aidStr := params.Get("aid")
  41. aid, err := strconv.ParseInt(aidStr, 10, 64)
  42. if err != nil {
  43. c.JSON(nil, ecode.RequestErr)
  44. return
  45. }
  46. if strRe, _ := likeSvc.OnlineVote(c, mid, vote, stage, aid); !strRe {
  47. c.JSON(nil, ecode.NotModified)
  48. return
  49. }
  50. c.JSON("ok", nil)
  51. }
  52. func ltime(c *bm.Context) {
  53. params := c.Request.Form
  54. sidStr := params.Get("sid")
  55. sid, err := strconv.ParseInt(sidStr, 10, 64)
  56. if err != nil {
  57. c.JSON(nil, ecode.RequestErr)
  58. return
  59. }
  60. index, err := likeSvc.Ltime(c, sid)
  61. if err != nil {
  62. log.Error("error(%v)", err)
  63. c.JSON(nil, ecode.RequestErr)
  64. return
  65. }
  66. if index == nil {
  67. c.JSON(nil, ecode.NothingFound)
  68. return
  69. }
  70. c.JSON(index, nil)
  71. }
  72. func likeAct(c *bm.Context) {
  73. p := new(like.ParamAddLikeAct)
  74. if err := c.Bind(p); err != nil {
  75. return
  76. }
  77. midStr, _ := c.Get("mid")
  78. mid := midStr.(int64)
  79. c.JSON(likeSvc.LikeAct(c, p, mid))
  80. }
  81. func storyKingAct(c *bm.Context) {
  82. p := new(like.ParamStoryKingAct)
  83. if err := c.Bind(p); err != nil {
  84. return
  85. }
  86. midStr, _ := c.Get("mid")
  87. mid := midStr.(int64)
  88. c.JSON(likeSvc.StoryKingAct(c, p, mid))
  89. }
  90. func storyKingLeft(c *bm.Context) {
  91. p := new(struct {
  92. Sid int64 `form:"sid" validate:"min=1"`
  93. })
  94. if err := c.Bind(p); err != nil {
  95. return
  96. }
  97. midStr, _ := c.Get("mid")
  98. mid := midStr.(int64)
  99. c.JSON(likeSvc.StoryKingLeftTime(c, p.Sid, mid))
  100. }
  101. func upList(c *bm.Context) {
  102. p := new(like.ParamList)
  103. if err := c.Bind(p); err != nil {
  104. return
  105. }
  106. mid := int64(0)
  107. if midStr, ok := c.Get("mid"); ok {
  108. mid = midStr.(int64)
  109. }
  110. c.JSON(likeSvc.UpList(c, p, mid))
  111. }
  112. func missionLike(c *bm.Context) {
  113. p := new(struct {
  114. Sid int64 `form:"sid" validate:"min=1"`
  115. })
  116. if err := c.Bind(p); err != nil {
  117. return
  118. }
  119. midStr, _ := c.Get("mid")
  120. mid := midStr.(int64)
  121. c.JSON(likeSvc.MissionLike(c, p.Sid, mid))
  122. }
  123. func missionLikeAct(c *bm.Context) {
  124. p := new(like.ParamMissionLikeAct)
  125. if err := c.Bind(p); err != nil {
  126. return
  127. }
  128. midStr, _ := c.Get("mid")
  129. mid := midStr.(int64)
  130. c.JSON(likeSvc.MissionLikeAct(c, p, mid))
  131. }
  132. func missionInfo(c *bm.Context) {
  133. p := new(struct {
  134. Sid int64 `form:"sid" validate:"min=1"`
  135. Lid int64 `form:"lid" validate:"min=1"`
  136. })
  137. if err := c.Bind(p); err != nil {
  138. return
  139. }
  140. midStr, _ := c.Get("mid")
  141. mid := midStr.(int64)
  142. c.JSON(likeSvc.MissionInfo(c, p.Sid, p.Lid, mid))
  143. }
  144. func missionTops(c *bm.Context) {
  145. p := new(struct {
  146. Sid int64 `form:"sid" validate:"min=1"`
  147. Num int `form:"num" validate:"min=1,max=200"`
  148. })
  149. if err := c.Bind(p); err != nil {
  150. return
  151. }
  152. c.JSON(likeSvc.MissionTops(c, p.Sid, p.Num))
  153. }
  154. func missionUser(c *bm.Context) {
  155. p := new(struct {
  156. Sid int64 `form:"sid" validate:"min=1"`
  157. Lid int64 `form:"lid" validate:"min=1"`
  158. })
  159. if err := c.Bind(p); err != nil {
  160. return
  161. }
  162. c.JSON(likeSvc.MissionUser(c, p.Sid, p.Lid))
  163. }
  164. func missionRank(c *bm.Context) {
  165. p := new(struct {
  166. Sid int64 `form:"sid" validate:"min=1"`
  167. })
  168. if err := c.Bind(p); err != nil {
  169. return
  170. }
  171. midStr, _ := c.Get("mid")
  172. mid := midStr.(int64)
  173. c.JSON(likeSvc.MissionRank(c, p.Sid, mid))
  174. }
  175. func missionFriends(c *bm.Context) {
  176. p := new(like.ParamMissionFriends)
  177. if err := c.Bind(p); err != nil {
  178. return
  179. }
  180. midStr, _ := c.Get("mid")
  181. mid := midStr.(int64)
  182. c.JSON(likeSvc.MissionFriendsList(c, p, mid))
  183. }
  184. func missionAward(c *bm.Context) {
  185. p := new(struct {
  186. Sid int64 `form:"sid" validate:"min=1"`
  187. })
  188. if err := c.Bind(p); err != nil {
  189. return
  190. }
  191. midStr, _ := c.Get("mid")
  192. mid := midStr.(int64)
  193. c.JSON(likeSvc.MissionAward(c, p.Sid, mid))
  194. }
  195. func missionAchieve(c *bm.Context) {
  196. p := new(struct {
  197. Sid int64 `form:"sid" validate:"min=1"`
  198. ID int64 `form:"id" validate:"min=1"`
  199. })
  200. if err := c.Bind(p); err != nil {
  201. return
  202. }
  203. midStr, _ := c.Get("mid")
  204. mid := midStr.(int64)
  205. c.JSON(likeSvc.MissionAchieve(c, p.Sid, p.ID, mid))
  206. }
  207. func likeActList(c *bm.Context) {
  208. v := new(struct {
  209. Sid int64 `form:"sid" validate:"min=1"`
  210. Lids []int64 `form:"lids,split" validate:"min=1,max=50,dive,min=1"`
  211. })
  212. if err := c.Bind(v); err != nil {
  213. return
  214. }
  215. mid := int64(0)
  216. if midStr, ok := c.Get("mid"); ok {
  217. mid = midStr.(int64)
  218. }
  219. c.JSON(likeSvc.LikeActList(c, v.Sid, mid, v.Lids))
  220. }
  221. func subjectInit(c *bm.Context) {
  222. v := new(struct {
  223. Sid int64 `form:"sid" validate:"min=1"`
  224. })
  225. if err := c.Bind(v); err != nil {
  226. return
  227. }
  228. c.JSON(nil, likeSvc.SubjectInitialize(c, v.Sid-1))
  229. }
  230. func likeInit(c *bm.Context) {
  231. v := new(struct {
  232. Lid int64 `form:"lid" validate:"min=1"`
  233. })
  234. if err := c.Bind(v); err != nil {
  235. return
  236. }
  237. c.JSON(nil, likeSvc.LikeInitialize(c, v.Lid-1))
  238. }
  239. func subjectLikeListInit(c *bm.Context) {
  240. v := new(struct {
  241. Sid int64 `form:"sid" validate:"min=1"`
  242. })
  243. if err := c.Bind(v); err != nil {
  244. return
  245. }
  246. c.JSON(nil, likeSvc.SubjectLikeListInitialize(c, v.Sid))
  247. }
  248. func likeActCountInit(c *bm.Context) {
  249. v := new(struct {
  250. Sid int64 `form:"sid" validate:"min=1"`
  251. })
  252. if err := c.Bind(v); err != nil {
  253. return
  254. }
  255. c.JSON(nil, likeSvc.LikeActCountInitialize(c, v.Sid))
  256. }
  257. func tagList(c *bm.Context) {
  258. var (
  259. err error
  260. cnt int
  261. list []*like.Like
  262. )
  263. v := new(struct {
  264. Sid int64 `form:"sid" validate:"min=1"`
  265. TagID int64 `form:"tag_id" validate:"min=1"`
  266. Type string `form:"type" default:"ctime"`
  267. Pn int `form:"pn" default:"1" validate:"min=1"`
  268. Ps int `form:"ps" default:"30" validate:"min=1,max=30"`
  269. })
  270. if err = c.Bind(v); err != nil {
  271. return
  272. }
  273. if v.Type != "ctime" && v.Type != "random" {
  274. c.JSON(nil, ecode.RequestErr)
  275. return
  276. }
  277. if list, cnt, err = likeSvc.TagArcList(c, v.Sid, v.TagID, v.Pn, v.Ps, v.Type, metadata.String(c, metadata.RemoteIP)); err != nil {
  278. c.JSON(nil, err)
  279. return
  280. }
  281. data := map[string]interface{}{
  282. "page": map[string]int{
  283. "num": v.Pn,
  284. "size": v.Ps,
  285. "total": cnt,
  286. },
  287. "list": list,
  288. }
  289. c.JSON(data, nil)
  290. }
  291. func regionList(c *bm.Context) {
  292. var (
  293. err error
  294. cnt int
  295. list []*like.Like
  296. )
  297. v := new(struct {
  298. Sid int64 `form:"sid" validate:"min=1"`
  299. Rid int16 `form:"rid" validate:"min=1"`
  300. Type string `form:"type" default:"ctime"`
  301. Pn int `form:"pn" default:"1" validate:"min=1"`
  302. Ps int `form:"ps" default:"30" validate:"min=1,max=30"`
  303. })
  304. if err = c.Bind(v); err != nil {
  305. return
  306. }
  307. if v.Type != "ctime" && v.Type != "random" {
  308. c.JSON(nil, ecode.RequestErr)
  309. return
  310. }
  311. if list, cnt, err = likeSvc.RegionArcList(c, v.Sid, v.Rid, v.Pn, v.Ps, v.Type, metadata.String(c, metadata.RemoteIP)); err != nil {
  312. c.JSON(nil, err)
  313. return
  314. }
  315. data := map[string]interface{}{
  316. "page": map[string]int{
  317. "num": v.Pn,
  318. "size": v.Ps,
  319. "total": cnt,
  320. },
  321. "list": list,
  322. }
  323. c.JSON(data, nil)
  324. }
  325. func tagStats(c *bm.Context) {
  326. v := new(struct {
  327. Sid int64 `form:"sid" validate:"min=1"`
  328. })
  329. if err := c.Bind(v); err != nil {
  330. return
  331. }
  332. c.JSON(likeSvc.TagLikeCounts(c, v.Sid))
  333. }
  334. func subjectStat(c *bm.Context) {
  335. v := new(struct {
  336. Sid int64 `form:"sid" validate:"min=1"`
  337. })
  338. if err := c.Bind(v); err != nil {
  339. return
  340. }
  341. c.JSON(likeSvc.SubjectStat(c, v.Sid))
  342. }
  343. func setSubjectStat(c *bm.Context) {
  344. v := new(like.SubjectStat)
  345. if err := c.Bind(v); err != nil {
  346. return
  347. }
  348. c.JSON(nil, likeSvc.SetSubjectStat(c, v))
  349. }
  350. func viewRank(c *bm.Context) {
  351. v := new(struct {
  352. Sid int64 `form:"sid" validate:"min=1"`
  353. Pn int `form:"pn" default:"1" validate:"min=1"`
  354. Ps int `form:"ps" default:"20" validate:"min=1"`
  355. })
  356. if err := c.Bind(v); err != nil {
  357. return
  358. }
  359. list, count, err := likeSvc.ViewRank(c, v.Sid, v.Pn, v.Ps)
  360. if err != nil {
  361. c.JSON(nil, err)
  362. return
  363. }
  364. data := make(map[string]interface{}, 2)
  365. data["list"] = list
  366. data["page"] = map[string]int{
  367. "pn": v.Pn,
  368. "ps": v.Ps,
  369. "count": count,
  370. }
  371. c.JSON(data, err)
  372. }
  373. func setViewRank(c *bm.Context) {
  374. v := new(struct {
  375. Sid int64 `form:"sid" validate:"min=1"`
  376. Aids []int64 `form:"aids,split" validate:"min=1,dive,min=1"`
  377. })
  378. if err := c.Bind(v); err != nil {
  379. return
  380. }
  381. c.JSON(nil, likeSvc.SetViewRank(c, v.Sid, v.Aids))
  382. }
  383. func groupData(c *bm.Context) {
  384. v := new(struct {
  385. Sid int64 `form:"sid" validate:"min=1"`
  386. })
  387. if err := c.Bind(v); err != nil {
  388. return
  389. }
  390. ck := c.Request.Header.Get("cookie")
  391. c.JSON(likeSvc.ObjectGroup(c, v.Sid, ck))
  392. }
  393. func setLikeContent(c *bm.Context) {
  394. v := new(struct {
  395. Lid int64 `form:"lid" validate:"min=1"`
  396. })
  397. if err := c.Bind(v); err != nil {
  398. return
  399. }
  400. c.JSON(nil, likeSvc.SetLikeContent(c, v.Lid))
  401. }
  402. func addLikeAct(c *bm.Context) {
  403. v := new(struct {
  404. Sid int64 `form:"sid" validate:"min=1"`
  405. Lid int64 `form:"lid" validate:"min=1"`
  406. Score int64 `form:"score" validate:"min=1"`
  407. })
  408. if err := c.Bind(v); err != nil {
  409. return
  410. }
  411. c.JSON(nil, likeSvc.AddLikeActCache(c, v.Sid, v.Lid, v.Score))
  412. }
  413. func likeActCache(c *bm.Context) {
  414. v := new(struct {
  415. Sid int64 `form:"sid" validate:"min=1"`
  416. Lid int64 `form:"lid" validate:"min=1"`
  417. })
  418. if err := c.Bind(v); err != nil {
  419. return
  420. }
  421. c.JSON(likeSvc.LikeActCache(c, v.Sid, v.Lid))
  422. }
  423. func likeOidsInfo(c *bm.Context) {
  424. v := new(struct {
  425. Type int `form:"type" validate:"min=1"`
  426. Oids []int64 `form:"oids,split" validate:"required,min=1,max=50,dive,gt=0"`
  427. })
  428. if err := c.Bind(v); err != nil {
  429. return
  430. }
  431. c.JSON(likeSvc.LikeOidsInfo(c, v.Type, v.Oids))
  432. }