ep_content.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. package http
  2. import (
  3. "go-common/app/admin/main/tv/model"
  4. "go-common/library/ecode"
  5. "go-common/library/log"
  6. bm "go-common/library/net/http/blademaster"
  7. )
  8. func createEP(c *bm.Context) {
  9. var (
  10. err error
  11. epc = &model.TVEpContent{}
  12. )
  13. if err = c.Bind(epc); err != nil {
  14. return
  15. }
  16. exist := model.Content{}
  17. tvSrv.DB.Where("epid=?", epc.ID).First(&exist)
  18. if exist.ID <= 0 { // data not exist, brand new data
  19. if err = tvSrv.DB.Create(epc.ToContent(true)).Error; err != nil {
  20. log.Error("tvSrv.createEP error(%v)", err)
  21. c.JSON(nil, err)
  22. return
  23. }
  24. if err = tvSrv.DB.Create(epc).Error; err != nil {
  25. log.Error("tvSrv.createEP error(%v)", err)
  26. c.JSON(nil, err)
  27. return
  28. }
  29. } else {
  30. // data exists, but was deleted
  31. if exist.IsDeleted == 1 {
  32. if err = tvSrv.EpDel(epc.ID, 0); err != nil {
  33. c.JSON(nil, err)
  34. return
  35. }
  36. }
  37. // data exist, so we update
  38. if err := tvSrv.DB.Model(&model.TVEpContent{}).Where("id=?", epc.ID).Update(epc).Error; err != nil {
  39. log.Error("tvSrv.modifyEP error(%v)", err)
  40. c.JSON(nil, err)
  41. return
  42. }
  43. if err := tvSrv.DB.Model(&model.TVEpContent{}).Where("id=?", epc.ID).Update(map[string]string{"long_title": epc.LongTitle, "title": epc.Title, "cover": epc.Cover}).Error; err != nil {
  44. log.Error("tvSrv.modifyEP error(%v)", err)
  45. c.JSON(nil, err)
  46. return
  47. }
  48. lic := epc.ToContent(false)
  49. if err := tvSrv.DB.Model(&model.Content{}).Where("epid=?", epc.ID).Update(lic).Error; err != nil {
  50. log.Error("tvSrv.modifyEP error(%v)", err)
  51. c.JSON(nil, err)
  52. return
  53. }
  54. if err := tvSrv.DB.Model(&model.Content{}).Where("epid=?", epc.ID).Update(map[string]string{"title": lic.Title, "subtitle": lic.Subtitle, "desc": lic.Desc, "cover": lic.Cover}).Error; err != nil {
  55. log.Error("tvSrv.modifyEP error(%v)", err)
  56. c.JSON(nil, err)
  57. return
  58. }
  59. if err := tvSrv.EpCheck(&exist); err != nil { // manage ep's check status
  60. c.JSON(nil, err)
  61. return
  62. }
  63. }
  64. renderErrMsg(c, 0, "0")
  65. log.Info("createEP success(%v)", epc)
  66. }
  67. func removeEP(c *bm.Context) {
  68. var (
  69. req = c.Request.PostForm
  70. err error
  71. id = parseInt(req.Get("id"))
  72. )
  73. exist := model.Content{}
  74. if err = tvSrv.DB.Where("epid=?", id).Where("is_deleted=?", 0).First(&exist).Error; err != nil {
  75. c.JSON(nil, err)
  76. return
  77. }
  78. if err = tvSrv.EpDel(id, 1); err != nil {
  79. c.JSON(nil, err)
  80. return
  81. }
  82. if err = tvSrv.EpCheck(&exist); err != nil { // manage ep's check status
  83. c.JSON(nil, err)
  84. return
  85. }
  86. log.Info("removeEP success(%v)", exist)
  87. renderErrMsg(c, 0, "0")
  88. }
  89. func createSeason(c *bm.Context) {
  90. var (
  91. err error
  92. eps = &model.TVEpSeason{}
  93. )
  94. if err = c.Bind(eps); err != nil {
  95. return
  96. }
  97. if err = tvSrv.SnUpdate(c, eps); err != nil {
  98. c.JSON(nil, err)
  99. return
  100. }
  101. renderErrMsg(c, 0, "0")
  102. }
  103. func removeSeason(c *bm.Context) {
  104. var (
  105. req = c.Request.PostForm
  106. err error
  107. id = parseInt(req.Get("id"))
  108. )
  109. exist := model.TVEpSeason{}
  110. if err = tvSrv.DB.Where("id=?", id).Where("is_deleted=?", 0).First(&exist).Error; err != nil {
  111. renderErrMsg(c, ecode.RequestErr.Code(), "Data not exist")
  112. return
  113. }
  114. if err = tvSrv.SeasonRemove(&exist); err != nil {
  115. c.JSON(nil, err)
  116. return
  117. }
  118. log.Info("removeSeason success(%v)", exist)
  119. renderErrMsg(c, 0, "0")
  120. }
  121. func act(c *bm.Context, action int) {
  122. param := new(struct {
  123. CID int64 `form:"cid" validate:"required"`
  124. })
  125. if err := c.Bind(param); err != nil {
  126. return
  127. }
  128. c.JSON(nil, tvSrv.EpAct(c, param.CID, action))
  129. }
  130. func online(c *bm.Context) {
  131. act(c, 1)
  132. }
  133. func hidden(c *bm.Context) {
  134. act(c, 0)
  135. }