region.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package http
  2. import (
  3. "go-common/app/admin/main/tv/model"
  4. "go-common/library/ecode"
  5. bm "go-common/library/net/http/blademaster"
  6. )
  7. const (
  8. _stateup = "1"
  9. _statedown = "0"
  10. )
  11. func reglist(c *bm.Context) {
  12. var (
  13. err error
  14. v = &model.Param{}
  15. )
  16. if err = c.Bind(v); err != nil {
  17. return
  18. }
  19. c.JSON(tvSrv.RegList(c, v))
  20. }
  21. func saveReg(c *bm.Context) {
  22. var (
  23. err error
  24. v = new(struct {
  25. IndexType string `form:"index_type"`
  26. IndexTid string `form:"index_tid"`
  27. Rank string `form:"rank"`
  28. Title string `form:"title" validate:"required"`
  29. PageId string `form:"page_id"`
  30. })
  31. )
  32. if err = c.Bind(v); err != nil {
  33. return
  34. }
  35. if v.PageId == "" {
  36. c.JSON(nil, tvSrv.AddReg(c, v.Title, v.IndexType, v.IndexTid, v.Rank))
  37. } else {
  38. c.JSON(nil, tvSrv.EditReg(c, v.PageId, v.Title, v.IndexType, v.IndexTid))
  39. }
  40. }
  41. func upState(c *bm.Context) {
  42. var (
  43. err error
  44. v = new(struct {
  45. Pids []int `form:"page_id,split" validate:"required,min=1,dive,gt=0"`
  46. Valid string `form:"valid" validate:"required"`
  47. })
  48. )
  49. if err = c.Bind(v); err != nil {
  50. return
  51. }
  52. if !(v.Valid == _statedown || v.Valid == _stateup) {
  53. c.JSON(nil, ecode.RequestErr)
  54. return
  55. }
  56. c.JSON(nil, tvSrv.UpState(c, v.Pids, v.Valid))
  57. }
  58. func regSort(c *bm.Context) {
  59. param := new(struct {
  60. IDs []int `form:"ids,split" validate:"required,min=1,dive,gt=0"`
  61. })
  62. if err := c.Bind(param); err != nil {
  63. return
  64. }
  65. c.JSON(nil, tvSrv.RegSort(c, param.IDs))
  66. }