micro_roadshow.go 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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. // 微路演列表
  49. list, total, e := services.GetMicroRoadShowPageList(pageSize, currentIndex, audioId, videoId, keywords)
  50. if e != nil {
  51. br.Msg = "获取失败"
  52. br.ErrMsg = "获取微路演列表失败, Err: " + e.Error()
  53. return
  54. }
  55. // 用户权限
  56. authInfo, permissionArr, e := services.GetUserRaiPermissionInfo(user.UserId, user.CompanyId)
  57. if e != nil {
  58. br.Msg = "获取失败"
  59. br.ErrMsg = "获取用户权限失败, Err: " + e.Error()
  60. return
  61. }
  62. // 获取默认图配置
  63. audioMap, videoMap, e := services.GetMicroRoadShowDefaultImgConfig()
  64. if e != nil {
  65. br.Msg = "获取失败"
  66. br.ErrMsg = "获取微路演列表失败, Err: " + e.Error()
  67. return
  68. }
  69. for i := range list {
  70. // 权限
  71. au := new(models.UserPermissionAuthInfo)
  72. au.SellerName = authInfo.SellerName
  73. au.SellerMobile = authInfo.SellerMobile
  74. au.HasPermission = authInfo.HasPermission
  75. if authInfo.HasPermission == 1 {
  76. if !utils.InArrayByStr(permissionArr, list[i].ChartPermissionName) {
  77. au.HasPermission = 2
  78. }
  79. }
  80. if authInfo.HasPermission == 2 {
  81. if list[i].Type == 1 {
  82. au.PopupMsg = services.UserPermissionPopupMsgCallActivity
  83. } else {
  84. au.PopupMsg = services.UserPermissionPopupMsgCallMicroVideo
  85. }
  86. }
  87. if authInfo.HasPermission == 3 {
  88. if list[i].Type == 1 {
  89. au.PopupMsg = services.UserPermissionPopupMsgApplyActivity
  90. } else {
  91. au.PopupMsg = services.UserPermissionPopupMsgApplyMicroVideo
  92. }
  93. }
  94. list[i].AuthInfo = au
  95. // 默认图
  96. if list[i].BackgroundImg == "" {
  97. if list[i].Type == 1 {
  98. list[i].BackgroundImg = audioMap[list[i].ChartPermissionId]
  99. } else {
  100. list[i].BackgroundImg = videoMap[list[i].ChartPermissionId]
  101. }
  102. }
  103. list[i].PublishTime = utils.StrTimeToTime(list[i].PublishTime).Format(utils.FormatDate)
  104. }
  105. resp := new(models.MicroRoadShowListResp)
  106. page := paging.GetPaging(currentIndex, pageSize, total)
  107. resp.List = list
  108. resp.Paging = page
  109. br.Ret = 200
  110. br.Success = true
  111. br.Msg = "获取成功"
  112. br.Data = resp
  113. }
  114. // @Title 记录用户浏览音频回放接口
  115. // @Description 记录用户浏览音频回放接口
  116. // @Param request body models.ActivityIdRep true "type json string"
  117. // @Success Ret=200 {object} models.AppointmentResp
  118. // @router /videoHistory/add [post]
  119. func (this *MicroRoadShowController) VideoHistoryAdd() {
  120. br := new(models.BaseResponse).Init()
  121. defer func() {
  122. this.Data["json"] = br
  123. this.ServeJSON()
  124. }()
  125. user := this.User
  126. if user == nil {
  127. br.Msg = "请登录"
  128. br.ErrMsg = "请登录,用户信息为空"
  129. br.Ret = 408
  130. return
  131. }
  132. uid := user.UserId
  133. var req models.AddVideoHistoryReq
  134. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  135. if err != nil {
  136. br.Msg = "参数解析异常!"
  137. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  138. return
  139. }
  140. videoId := req.VideoId
  141. playSeconds := req.PlaySeconds
  142. var sellerName string
  143. sellerName, err = models.GetCompanySellerName(user.CompanyId)
  144. if err != nil {
  145. br.Msg = "报名失败!"
  146. br.ErrMsg = "获取对应销售失败,Err:" + err.Error()
  147. return
  148. }
  149. item := models.CygxMicroRoadshowVideoHistory{
  150. VideoId: videoId,
  151. UserId: uid,
  152. Mobile: user.Mobile,
  153. Email: user.Email,
  154. CompanyId: user.CompanyId,
  155. CompanyName: user.CompanyName,
  156. RealName: user.RealName,
  157. SellerName: sellerName,
  158. PlaySeconds: strconv.Itoa(playSeconds),
  159. CreateTime: time.Now(),
  160. ModifyTime: time.Now(),
  161. }
  162. if playSeconds != 0 {
  163. lastItem, err := models.GetLastCygxMicroRoadshowVideoHistory(videoId, user.UserId)
  164. if err != nil {
  165. br.Msg = "操作失败"
  166. br.ErrMsg = "操作失败,GetLastCygxMicroRoadshowVideoHistory Err:" + err.Error()
  167. return
  168. }
  169. err = models.UpdateLastCygxActivityVideoHistory(strconv.Itoa(playSeconds), lastItem.Id)
  170. if err != nil {
  171. br.Msg = "更新失败"
  172. br.ErrMsg = "更新失败,UpdateLastCygxActivityVideoHistory Err:" + err.Error()
  173. return
  174. }
  175. } else {
  176. err = models.AddCygxMicroRoadshowVideoHistory(&item)
  177. if err != nil {
  178. br.Msg = "操作失败"
  179. br.ErrMsg = "操作失败,Err:" + err.Error()
  180. return
  181. }
  182. }
  183. br.Ret = 200
  184. br.Success = true
  185. br.Msg = "操作成功"
  186. return
  187. }