micro_roadshow.go 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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. // @Param ActivityVideoId query int false "活动视频ID"
  23. // @Success 200 {object} models.HomeListResp
  24. // @router /list [get]
  25. func (this *MicroRoadShowController) List() {
  26. br := new(models.BaseResponse).Init()
  27. defer func() {
  28. this.Data["json"] = br
  29. this.ServeJSON()
  30. }()
  31. user := this.User
  32. if user == nil {
  33. br.Msg = "请登录"
  34. br.ErrMsg = "请登录,用户信息为空"
  35. br.Ret = 408
  36. return
  37. }
  38. pageSize, _ := this.GetInt("PageSize")
  39. currentIndex, _ := this.GetInt("CurrentIndex")
  40. keywords := this.GetString("KeyWord")
  41. audioId, _ := this.GetInt("AudioId")
  42. videoId, _ := this.GetInt("VideoId")
  43. activityVideoId, _ := this.GetInt("ActivityVideoId")
  44. if pageSize <= 0 {
  45. pageSize = utils.PageSize20
  46. }
  47. if currentIndex <= 0 {
  48. currentIndex = 1
  49. }
  50. // 微路演列表
  51. list, total, e := services.GetMicroRoadShowPageListV8(pageSize, currentIndex, audioId, videoId, activityVideoId, keywords)
  52. if e != nil {
  53. br.Msg = "获取失败"
  54. br.ErrMsg = "获取微路演列表失败, Err: " + e.Error()
  55. return
  56. }
  57. // 用户权限
  58. authInfo, permissionArr, e := services.GetUserRaiPermissionInfo(user.UserId, user.CompanyId)
  59. if e != nil {
  60. br.Msg = "获取失败"
  61. br.ErrMsg = "获取用户权限失败, Err: " + e.Error()
  62. return
  63. }
  64. // 获取默认图配置
  65. audioMap, videoMap, audioShareMap, videoShareMap, e := services.GetMicroRoadShowDefaultImgConfig()
  66. if e != nil {
  67. br.Msg = "获取失败"
  68. br.ErrMsg = "获取微路演列表失败, Err: " + e.Error()
  69. return
  70. }
  71. for i := range list {
  72. // 权限
  73. au := new(models.UserPermissionAuthInfo)
  74. au.SellerName = authInfo.SellerName
  75. au.SellerMobile = authInfo.SellerMobile
  76. au.HasPermission = authInfo.HasPermission
  77. au.OperationMode = authInfo.OperationMode
  78. if au.HasPermission == 1 {
  79. // 非宏观权限进一步判断是否有权限
  80. if list[i].ChartPermissionId != utils.HONG_GUAN_ID && !utils.InArrayByStr(permissionArr, list[i].ChartPermissionName) {
  81. au.HasPermission = 2
  82. }
  83. }
  84. // 无权限的弹框提示
  85. if au.HasPermission != 1 {
  86. if au.OperationMode == services.UserPermissionOperationModeCall {
  87. if list[i].Type == 1 {
  88. au.PopupMsg = services.UserPermissionPopupMsgCallActivity
  89. } else {
  90. au.PopupMsg = services.UserPermissionPopupMsgCallMicroVideo
  91. }
  92. } else {
  93. if list[i].Type == 1 {
  94. au.PopupMsg = services.UserPermissionPopupMsgApplyActivity
  95. } else {
  96. au.PopupMsg = services.UserPermissionPopupMsgApplyMicroVideo
  97. }
  98. }
  99. }
  100. list[i].AuthInfo = au
  101. list[i].PublishTime = utils.StrTimeToTime(list[i].PublishTime).Format(utils.FormatDate)
  102. // 默认图
  103. if list[i].BackgroundImg == "" {
  104. if list[i].Type == 1 {
  105. list[i].BackgroundImg = audioMap[list[i].ChartPermissionId]
  106. } else {
  107. list[i].BackgroundImg = videoMap[list[i].ChartPermissionId]
  108. }
  109. }
  110. // 分享图
  111. if list[i].Type == 1 {
  112. list[i].ShareImg = audioShareMap[list[i].ChartPermissionId]
  113. } else {
  114. list[i].ShareImg = videoShareMap[list[i].ChartPermissionId]
  115. }
  116. }
  117. resp := new(models.MicroRoadShowListResp)
  118. page := paging.GetPaging(currentIndex, pageSize, total)
  119. resp.List = list
  120. resp.Paging = page
  121. br.Ret = 200
  122. br.Success = true
  123. br.Msg = "获取成功"
  124. br.Data = resp
  125. }
  126. // @Title 记录用户浏览音频回放接口
  127. // @Description 记录用户浏览音频回放接口
  128. // @Param request body models.ActivityIdRep true "type json string"
  129. // @Success Ret=200 {object} models.AppointmentResp
  130. // @router /videoHistory/add [post]
  131. func (this *MicroRoadShowController) VideoHistoryAdd() {
  132. br := new(models.BaseResponse).Init()
  133. defer func() {
  134. this.Data["json"] = br
  135. this.ServeJSON()
  136. }()
  137. user := this.User
  138. if user == nil {
  139. br.Msg = "请登录"
  140. br.ErrMsg = "请登录,用户信息为空"
  141. br.Ret = 408
  142. return
  143. }
  144. uid := user.UserId
  145. var req models.AddVideoHistoryReq
  146. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  147. if err != nil {
  148. br.Msg = "参数解析异常!"
  149. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  150. return
  151. }
  152. videoId := req.VideoId
  153. playSeconds := req.PlaySeconds
  154. sourceType := req.SourceType
  155. if sourceType == 0 {
  156. sourceType = 1
  157. }
  158. var sellerName string
  159. sellerName, err = models.GetCompanySellerName(user.CompanyId)
  160. if err != nil {
  161. br.Msg = "报名失败!"
  162. br.ErrMsg = "获取对应销售失败,Err:" + err.Error()
  163. return
  164. }
  165. if sourceType == 1 {
  166. item := models.CygxMicroRoadshowVideoHistory{
  167. VideoId: videoId,
  168. UserId: uid,
  169. Mobile: user.Mobile,
  170. Email: user.Email,
  171. CompanyId: user.CompanyId,
  172. CompanyName: user.CompanyName,
  173. RealName: user.RealName,
  174. SellerName: sellerName,
  175. PlaySeconds: strconv.Itoa(playSeconds),
  176. CreateTime: time.Now(),
  177. ModifyTime: time.Now(),
  178. }
  179. if playSeconds != 0 {
  180. lastItem, err := models.GetLastCygxMicroRoadshowVideoHistory(videoId, user.UserId)
  181. if err != nil {
  182. br.Msg = "操作失败"
  183. br.ErrMsg = "操作失败,GetLastCygxMicroRoadshowVideoHistory Err:" + err.Error()
  184. return
  185. }
  186. err = models.UpdateLastCygxActivityVideoHistory(strconv.Itoa(playSeconds), lastItem.Id)
  187. if err != nil {
  188. br.Msg = "更新失败"
  189. br.ErrMsg = "更新失败,UpdateLastCygxActivityVideoHistory Err:" + err.Error()
  190. return
  191. }
  192. } else {
  193. err = models.AddCygxMicroRoadshowVideoHistory(&item)
  194. if err != nil {
  195. br.Msg = "操作失败"
  196. br.ErrMsg = "操作失败,Err:" + err.Error()
  197. return
  198. }
  199. err = models.UpdateCygxActivityVideoCounts(videoId)
  200. if err != nil {
  201. br.Msg = "更新失败"
  202. br.ErrMsg = "更新失败,Err:" + err.Error()
  203. return
  204. }
  205. }
  206. } else if sourceType == 2 {
  207. err = services.AddActivityVideoHistory(user, videoId)
  208. if err != nil {
  209. br.Msg = "更新失败"
  210. br.ErrMsg = "更新失败,AddActivityVideoHistory Err:" + err.Error()
  211. return
  212. }
  213. }
  214. br.Ret = 200
  215. br.Success = true
  216. br.Msg = "操作成功"
  217. return
  218. }