micro_roadshow.go 3.7 KB

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