micro_roadshow.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "hongze/hongze_cygx/models"
  6. "hongze/hongze_cygx/services"
  7. "hongze/hongze_cygx/utils"
  8. "strconv"
  9. "time"
  10. )
  11. // 微路演
  12. type MicroRoadShowController struct {
  13. BaseAuthController
  14. }
  15. // @Title 微路演列表
  16. // @Description 微路演列表接口
  17. // @Param PageSize query int true "每页数据条数"
  18. // @Param CurrentIndex query int true "当前页页码,从1开始"
  19. // @Param KeyWord query string false "搜索关键词"
  20. // @Param AudioId query int false "音频ID"
  21. // @Param VideoId query int false "视频ID"
  22. // @Success 200 {object} models.HomeListResp
  23. // @router /list [get]
  24. func (this *MicroRoadShowController) List() {
  25. br := new(models.BaseResponse).Init()
  26. defer func() {
  27. this.Data["json"] = br
  28. this.ServeJSON()
  29. }()
  30. user := this.User
  31. if user == nil {
  32. br.Msg = "请登录"
  33. br.ErrMsg = "请登录,用户信息为空"
  34. br.Ret = 408
  35. return
  36. }
  37. pageSize, _ := this.GetInt("PageSize")
  38. currentIndex, _ := this.GetInt("CurrentIndex")
  39. keywords := this.GetString("KeyWord")
  40. audioId, _ := this.GetInt("AudioId")
  41. videoId, _ := this.GetInt("VideoId")
  42. if pageSize <= 0 {
  43. pageSize = utils.PageSize20
  44. }
  45. if currentIndex <= 0 {
  46. currentIndex = 1
  47. }
  48. list, total, e := services.GetMicroRoadShowPageList(pageSize, currentIndex, audioId, videoId, keywords)
  49. if e != nil {
  50. br.Msg = "获取失败"
  51. br.ErrMsg = "获取微路演列表失败, Err: " + e.Error()
  52. return
  53. }
  54. resp := new(models.MicroRoadShowListResp)
  55. page := paging.GetPaging(currentIndex, pageSize, total)
  56. resp.List = list
  57. resp.Paging = page
  58. br.Ret = 200
  59. br.Success = true
  60. br.Msg = "获取成功"
  61. br.Data = resp
  62. }
  63. // @Title 记录用户浏览音频回放接口
  64. // @Description 记录用户浏览音频回放接口
  65. // @Param request body models.ActivityIdRep true "type json string"
  66. // @Success Ret=200 {object} models.AppointmentResp
  67. // @router /videoHistory/add [post]
  68. func (this *MicroRoadShowController) VideoHistoryAdd() {
  69. br := new(models.BaseResponse).Init()
  70. defer func() {
  71. this.Data["json"] = br
  72. this.ServeJSON()
  73. }()
  74. user := this.User
  75. if user == nil {
  76. br.Msg = "请登录"
  77. br.ErrMsg = "请登录,用户信息为空"
  78. br.Ret = 408
  79. return
  80. }
  81. uid := user.UserId
  82. var req models.AddVideoHistoryReq
  83. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  84. if err != nil {
  85. br.Msg = "参数解析异常!"
  86. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  87. return
  88. }
  89. videoId := req.VideoId
  90. playSeconds := req.PlaySeconds
  91. var sellerName string
  92. sellerName, err = models.GetCompanySellerName(user.CompanyId)
  93. if err != nil {
  94. br.Msg = "报名失败!"
  95. br.ErrMsg = "获取对应销售失败,Err:" + err.Error()
  96. return
  97. }
  98. item := models.CygxMicroRoadshowVideoHistory{
  99. VideoId: videoId,
  100. UserId: uid,
  101. Mobile: user.Mobile,
  102. Email: user.Email,
  103. CompanyId: user.CompanyId,
  104. CompanyName: user.CompanyName,
  105. RealName: user.RealName,
  106. SellerName: sellerName,
  107. PlaySeconds: strconv.Itoa(playSeconds),
  108. CreateTime: time.Now(),
  109. ModifyTime: time.Now(),
  110. }
  111. if playSeconds != 0 {
  112. lastItem, err := models.GetLastCygxMicroRoadshowVideoHistory(videoId, user.UserId)
  113. if err != nil {
  114. br.Msg = "操作失败"
  115. br.ErrMsg = "操作失败,GetLastCygxMicroRoadshowVideoHistory Err:" + err.Error()
  116. return
  117. }
  118. err = models.UpdateLastCygxActivityVideoHistory(strconv.Itoa(playSeconds), lastItem.Id)
  119. if err != nil {
  120. br.Msg = "更新失败"
  121. br.ErrMsg = "更新失败,UpdateLastCygxActivityVideoHistory Err:" + err.Error()
  122. return
  123. }
  124. } else {
  125. err = models.AddCygxMicroRoadshowVideoHistory(&item)
  126. if err != nil {
  127. br.Msg = "操作失败"
  128. br.ErrMsg = "操作失败,Err:" + err.Error()
  129. return
  130. }
  131. }
  132. br.Ret = 200
  133. br.Success = true
  134. br.Msg = "操作成功"
  135. return
  136. }