News.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package controllers
  2. import (
  3. "ColdVerify_server/conf"
  4. "ColdVerify_server/lib"
  5. "ColdVerify_server/models/Account"
  6. "ColdVerify_server/models/System"
  7. beego "github.com/beego/beego/v2/server/web"
  8. "math"
  9. )
  10. type NewsController struct {
  11. beego.Controller
  12. }
  13. // 列表 -
  14. func (c *NewsController) List() {
  15. // 验证登录 User_is, User_r
  16. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  17. if !User_is {
  18. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  19. c.ServeJSON()
  20. return
  21. }
  22. // 分页参数 初始化
  23. page, _ := c.GetInt("page")
  24. if page < 1 {
  25. page = 1
  26. }
  27. page_z, _ := c.GetInt("page_z")
  28. if page_z < 1 {
  29. page_z = conf.Page_size
  30. }
  31. // 查询
  32. T_title := c.GetString("T_title")
  33. T_Tag, _ := c.GetInt("T_Tag")
  34. List, cnt := System.Read_News_List(User_r.T_uuid, T_title, T_Tag, page, page_z)
  35. var r_jsons lib.R_JSONS
  36. page_size := math.Ceil(float64(cnt) / float64(page_z))
  37. r_jsons.List = List
  38. r_jsons.Page = page
  39. r_jsons.Page_size = int(page_size)
  40. r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
  41. r_jsons.Num = int(cnt)
  42. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  43. c.ServeJSON()
  44. return
  45. }
  46. func (c *NewsController) See() {
  47. // 验证登录 User_is, User_r
  48. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  49. if !User_is {
  50. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  51. c.ServeJSON()
  52. return
  53. }
  54. Id, _ := c.GetInt("Id")
  55. if Id == 0 {
  56. c.Data["json"] = lib.JSONS{Code: 201, Msg: "Id Err!"}
  57. c.ServeJSON()
  58. return
  59. }
  60. if err := System.Update_News_Tag(Id, User_r.T_uuid); err != nil {
  61. c.Data["json"] = lib.JSONS{Code: 200, Msg: "修改失败!"}
  62. c.ServeJSON()
  63. return
  64. }
  65. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  66. c.ServeJSON()
  67. return
  68. }