micro_roadshow.go 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. }
  104. resp := new(models.MicroRoadShowListResp)
  105. page := paging.GetPaging(currentIndex, pageSize, total)
  106. resp.List = list
  107. resp.Paging = page
  108. br.Ret = 200
  109. br.Success = true
  110. br.Msg = "获取成功"
  111. br.Data = resp
  112. }
  113. // @Title 记录用户浏览音频回放接口
  114. // @Description 记录用户浏览音频回放接口
  115. // @Param request body models.ActivityIdRep true "type json string"
  116. // @Success Ret=200 {object} models.AppointmentResp
  117. // @router /videoHistory/add [post]
  118. func (this *MicroRoadShowController) VideoHistoryAdd() {
  119. br := new(models.BaseResponse).Init()
  120. defer func() {
  121. this.Data["json"] = br
  122. this.ServeJSON()
  123. }()
  124. user := this.User
  125. if user == nil {
  126. br.Msg = "请登录"
  127. br.ErrMsg = "请登录,用户信息为空"
  128. br.Ret = 408
  129. return
  130. }
  131. uid := user.UserId
  132. var req models.AddVideoHistoryReq
  133. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  134. if err != nil {
  135. br.Msg = "参数解析异常!"
  136. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  137. return
  138. }
  139. videoId := req.VideoId
  140. playSeconds := req.PlaySeconds
  141. var sellerName string
  142. sellerName, err = models.GetCompanySellerName(user.CompanyId)
  143. if err != nil {
  144. br.Msg = "报名失败!"
  145. br.ErrMsg = "获取对应销售失败,Err:" + err.Error()
  146. return
  147. }
  148. item := models.CygxMicroRoadshowVideoHistory{
  149. VideoId: videoId,
  150. UserId: uid,
  151. Mobile: user.Mobile,
  152. Email: user.Email,
  153. CompanyId: user.CompanyId,
  154. CompanyName: user.CompanyName,
  155. RealName: user.RealName,
  156. SellerName: sellerName,
  157. PlaySeconds: strconv.Itoa(playSeconds),
  158. CreateTime: time.Now(),
  159. ModifyTime: time.Now(),
  160. }
  161. if playSeconds != 0 {
  162. lastItem, err := models.GetLastCygxMicroRoadshowVideoHistory(videoId, user.UserId)
  163. if err != nil {
  164. br.Msg = "操作失败"
  165. br.ErrMsg = "操作失败,GetLastCygxMicroRoadshowVideoHistory Err:" + err.Error()
  166. return
  167. }
  168. err = models.UpdateLastCygxActivityVideoHistory(strconv.Itoa(playSeconds), lastItem.Id)
  169. if err != nil {
  170. br.Msg = "更新失败"
  171. br.ErrMsg = "更新失败,UpdateLastCygxActivityVideoHistory Err:" + err.Error()
  172. return
  173. }
  174. } else {
  175. err = models.AddCygxMicroRoadshowVideoHistory(&item)
  176. if err != nil {
  177. br.Msg = "操作失败"
  178. br.ErrMsg = "操作失败,Err:" + err.Error()
  179. return
  180. }
  181. }
  182. br.Ret = 200
  183. br.Success = true
  184. br.Msg = "操作成功"
  185. return
  186. }