micro_roadshow.go 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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, audioShareMap, videoShareMap, 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. au.OperationMode = authInfo.OperationMode
  76. if au.HasPermission == 1 {
  77. // 非宏观权限进一步判断是否有权限
  78. if list[i].ChartPermissionId != utils.HONG_GUAN_ID && !utils.InArrayByStr(permissionArr, list[i].ChartPermissionName) {
  79. au.HasPermission = 2
  80. }
  81. }
  82. // 无权限的弹框提示
  83. if au.HasPermission != 1 {
  84. if au.OperationMode == services.UserPermissionOperationModeCall {
  85. if list[i].Type == 1 {
  86. au.PopupMsg = services.UserPermissionPopupMsgCallActivity
  87. } else {
  88. au.PopupMsg = services.UserPermissionPopupMsgCallMicroVideo
  89. }
  90. } else {
  91. if list[i].Type == 1 {
  92. au.PopupMsg = services.UserPermissionPopupMsgApplyActivity
  93. } else {
  94. au.PopupMsg = services.UserPermissionPopupMsgApplyMicroVideo
  95. }
  96. }
  97. }
  98. list[i].AuthInfo = au
  99. list[i].PublishTime = utils.StrTimeToTime(list[i].PublishTime).Format(utils.FormatDate)
  100. // 默认图
  101. if list[i].BackgroundImg == "" {
  102. if list[i].Type == 1 {
  103. list[i].BackgroundImg = audioMap[list[i].ChartPermissionId]
  104. } else {
  105. list[i].BackgroundImg = videoMap[list[i].ChartPermissionId]
  106. }
  107. }
  108. // 分享图
  109. if list[i].Type == 1 {
  110. list[i].ShareImg = audioShareMap[list[i].ChartPermissionId]
  111. } else {
  112. list[i].ShareImg = videoShareMap[list[i].ChartPermissionId]
  113. }
  114. }
  115. resp := new(models.MicroRoadShowListResp)
  116. page := paging.GetPaging(currentIndex, pageSize, total)
  117. resp.List = list
  118. resp.Paging = page
  119. br.Ret = 200
  120. br.Success = true
  121. br.Msg = "获取成功"
  122. br.Data = resp
  123. }
  124. // @Title 记录用户浏览音频回放接口
  125. // @Description 记录用户浏览音频回放接口
  126. // @Param request body models.ActivityIdRep true "type json string"
  127. // @Success Ret=200 {object} models.AppointmentResp
  128. // @router /videoHistory/add [post]
  129. func (this *MicroRoadShowController) VideoHistoryAdd() {
  130. br := new(models.BaseResponse).Init()
  131. defer func() {
  132. this.Data["json"] = br
  133. this.ServeJSON()
  134. }()
  135. user := this.User
  136. if user == nil {
  137. br.Msg = "请登录"
  138. br.ErrMsg = "请登录,用户信息为空"
  139. br.Ret = 408
  140. return
  141. }
  142. uid := user.UserId
  143. var req models.AddVideoHistoryReq
  144. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  145. if err != nil {
  146. br.Msg = "参数解析异常!"
  147. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  148. return
  149. }
  150. videoId := req.VideoId
  151. playSeconds := req.PlaySeconds
  152. var sellerName string
  153. sellerName, err = models.GetCompanySellerName(user.CompanyId)
  154. if err != nil {
  155. br.Msg = "报名失败!"
  156. br.ErrMsg = "获取对应销售失败,Err:" + err.Error()
  157. return
  158. }
  159. item := models.CygxMicroRoadshowVideoHistory{
  160. VideoId: videoId,
  161. UserId: uid,
  162. Mobile: user.Mobile,
  163. Email: user.Email,
  164. CompanyId: user.CompanyId,
  165. CompanyName: user.CompanyName,
  166. RealName: user.RealName,
  167. SellerName: sellerName,
  168. PlaySeconds: strconv.Itoa(playSeconds),
  169. CreateTime: time.Now(),
  170. ModifyTime: time.Now(),
  171. }
  172. if playSeconds != 0 {
  173. lastItem, err := models.GetLastCygxMicroRoadshowVideoHistory(videoId, user.UserId)
  174. if err != nil {
  175. br.Msg = "操作失败"
  176. br.ErrMsg = "操作失败,GetLastCygxMicroRoadshowVideoHistory Err:" + err.Error()
  177. return
  178. }
  179. err = models.UpdateLastCygxActivityVideoHistory(strconv.Itoa(playSeconds), lastItem.Id)
  180. if err != nil {
  181. br.Msg = "更新失败"
  182. br.ErrMsg = "更新失败,UpdateLastCygxActivityVideoHistory Err:" + err.Error()
  183. return
  184. }
  185. } else {
  186. err = models.AddCygxMicroRoadshowVideoHistory(&item)
  187. if err != nil {
  188. br.Msg = "操作失败"
  189. br.ErrMsg = "操作失败,Err:" + err.Error()
  190. return
  191. }
  192. err = models.UpdateCygxActivityVideoCounts(videoId)
  193. if err != nil {
  194. br.Msg = "更新失败"
  195. br.ErrMsg = "更新失败,Err:" + err.Error()
  196. return
  197. }
  198. }
  199. br.Ret = 200
  200. br.Success = true
  201. br.Msg = "操作成功"
  202. return
  203. }