micro_roadshow.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. package services
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "hongze/hongze_clpt/models"
  6. "hongze/hongze_clpt/utils"
  7. "strings"
  8. )
  9. // GetMicroRoadShowDefaultImgConfig 获取微路演默认图/分享图配置
  10. func GetMicroRoadShowDefaultImgConfig() (audioMap, videoMap, audioShareMap, videoShareMap map[int]string, err error) {
  11. audioMap = make(map[int]string, 0)
  12. videoMap = make(map[int]string, 0)
  13. audioShareMap = make(map[int]string, 0)
  14. videoShareMap = make(map[int]string, 0)
  15. key := models.MicroRoadshowDefaultImgKey
  16. conf, e := models.GetConfigByCode(key)
  17. if e != nil {
  18. err = errors.New("获取微路演默认图配置失败, Err: " + e.Error())
  19. return
  20. }
  21. if conf.ConfigValue == "" {
  22. err = errors.New("获取微路演默认图配置有误")
  23. return
  24. }
  25. list := new(models.MicroRoadShowDefaultImgList)
  26. if e = json.Unmarshal([]byte(conf.ConfigValue), &list); e != nil {
  27. err = errors.New("微路演默认图配置配置值解析失败, Err: " + e.Error())
  28. return
  29. }
  30. audioList := list.Audio
  31. for i := range audioList {
  32. audioMap[audioList[i].ChartPermissionId] = audioList[i].ImgUrl
  33. audioShareMap[audioList[i].ChartPermissionId] = audioList[i].ShareImg
  34. }
  35. videoList := list.Video
  36. for i := range videoList {
  37. videoMap[videoList[i].ChartPermissionId] = videoList[i].ImgUrl
  38. videoShareMap[videoList[i].ChartPermissionId] = videoList[i].ShareImg
  39. }
  40. return
  41. }
  42. func GetindustryVideo(user *models.WxUserItem, industrialManagementId int) (industryVideo *models.MicroVideoSimpleInfo, AuthInfo *models.UserPermissionAuthInfo, err error) {
  43. total, e := models.GetMicroRoadshowVideoByIndustryIdCount(industrialManagementId)
  44. if e != nil {
  45. err = errors.New("获取产业关联的视频失败,GetMicroRoadshowVideoByIndustryIdCount " + e.Error())
  46. return
  47. }
  48. if total == 0 {
  49. return
  50. }
  51. // 用户权限
  52. authInfo, permissionArr, e := GetUserRaiPermissionInfo(user.UserId, user.CompanyId)
  53. if e != nil {
  54. err = errors.New("获取用户权限失败,GetUserRaiPermissionInfo " + e.Error())
  55. return
  56. }
  57. videoSimple := new(models.MicroVideoSimpleInfo)
  58. // 权限
  59. var au *models.UserPermissionAuthInfo
  60. video, e := models.GetMicroRoadshowVideoByIndustryId(industrialManagementId)
  61. if e != nil {
  62. err = errors.New("获取产业关联的视频失败,GetMicroRoadshowVideoByIndustryId " + e.Error())
  63. return
  64. } else {
  65. videoSimple.Id = video.VideoId
  66. videoSimple.Title = "5min【" + video.IndustryName + "】逻辑解析"
  67. videoSimple.BackgroundImg = video.ImgUrl
  68. videoSimple.DetailImgUrl = video.DetailImgUrl
  69. if videoSimple.BackgroundImg == "" {
  70. // 获取默认图配置
  71. _, videoMap, _, _, e := GetMicroRoadShowDefaultImgConfig()
  72. if e != nil {
  73. err = errors.New("获取视频默认配置图失败,GetMicroRoadshowVideoByIndustryId " + e.Error())
  74. return
  75. }
  76. videoSimple.BackgroundImg = videoMap[video.ChartPermissionId]
  77. }
  78. videoSimple.PlaySeconds = video.VideoDuration
  79. videoSimple.ResourceUrl = video.VideoUrl
  80. au = new(models.UserPermissionAuthInfo)
  81. au.SellerName = authInfo.SellerName
  82. au.SellerMobile = authInfo.SellerMobile
  83. au.HasPermission = authInfo.HasPermission
  84. au.OperationMode = authInfo.OperationMode
  85. if au.HasPermission == 1 {
  86. // 非宏观权限进一步判断是否有权限
  87. if video.ChartPermissionId != utils.HONG_GUAN_ID && !utils.InArrayByStr(permissionArr, video.ChartPermissionName) {
  88. au.HasPermission = 2
  89. }
  90. }
  91. // 无权限的弹框提示
  92. if au.HasPermission != 1 {
  93. if au.OperationMode == UserPermissionOperationModeCall {
  94. au.PopupMsg = UserPermissionPopupMsgCallMicroVideo
  95. } else {
  96. au.PopupMsg = UserPermissionPopupMsgApplyMicroVideo
  97. }
  98. videoSimple.ResourceUrl = ""
  99. }
  100. }
  101. industryVideo = videoSimple
  102. AuthInfo = au
  103. return
  104. }
  105. //GetindustryVideoDetailById 通过视频ID获取视频详情
  106. func GetindustryVideoDetailById(user *models.WxUserItem, videoId int) (industryVideo *models.MicroVideoSimpleInfo, AuthInfo *models.UserPermissionAuthInfo, err error) {
  107. total, e := models.GetMicroRoadshowVideoByVideoIdCount(videoId)
  108. if e != nil {
  109. err = errors.New("获取产业关联的视频失败,GetMicroRoadshowVideoByIndustryIdCount " + e.Error())
  110. return
  111. }
  112. if total == 0 {
  113. err = errors.New("视频不存在,或已取消发布")
  114. return
  115. }
  116. // 用户权限
  117. authInfo, permissionArr, e := GetUserRaiPermissionInfo(user.UserId, user.CompanyId)
  118. if e != nil {
  119. err = errors.New("获取用户权限失败,GetUserRaiPermissionInfo " + e.Error())
  120. return
  121. }
  122. videoSimple := new(models.MicroVideoSimpleInfo)
  123. // 权限
  124. var au *models.UserPermissionAuthInfo
  125. video, e := models.GetMicroRoadshowVideoById(videoId)
  126. if e != nil {
  127. err = errors.New("获取产业关联的视频失败,GetMicroRoadshowVideoByIndustryId " + e.Error())
  128. return
  129. } else {
  130. videoSimple.Id = video.VideoId
  131. videoSimple.Title = "5min【" + video.IndustryName + "】逻辑解析"
  132. videoSimple.BackgroundImg = video.ImgUrl
  133. videoSimple.DetailImgUrl = video.DetailImgUrl
  134. if videoSimple.BackgroundImg == "" {
  135. // 获取默认图配置
  136. _, videoMap, _, _, e := GetMicroRoadShowDefaultImgConfig()
  137. if e != nil {
  138. err = errors.New("获取视频默认配置图失败,GetMicroRoadshowVideoByIndustryId " + e.Error())
  139. return
  140. }
  141. videoSimple.BackgroundImg = videoMap[video.ChartPermissionId]
  142. }
  143. videoSimple.PlaySeconds = video.VideoDuration
  144. videoSimple.ResourceUrl = video.VideoUrl
  145. au = new(models.UserPermissionAuthInfo)
  146. au.SellerName = authInfo.SellerName
  147. au.SellerMobile = authInfo.SellerMobile
  148. au.HasPermission = authInfo.HasPermission
  149. au.OperationMode = authInfo.OperationMode
  150. if au.HasPermission == 1 {
  151. // 非宏观权限进一步判断是否有权限
  152. if video.ChartPermissionId != utils.HONG_GUAN_ID && !utils.InArrayByStr(permissionArr, video.ChartPermissionName) {
  153. au.HasPermission = 2
  154. }
  155. }
  156. // 无权限的弹框提示
  157. if au.HasPermission != 1 {
  158. if au.OperationMode == UserPermissionOperationModeCall {
  159. au.PopupMsg = UserPermissionPopupMsgCallMicroVideo
  160. } else {
  161. au.PopupMsg = UserPermissionPopupMsgApplyMicroVideo
  162. }
  163. videoSimple.ResourceUrl = ""
  164. }
  165. }
  166. industryVideo = videoSimple
  167. AuthInfo = au
  168. return
  169. }
  170. //GetMicroRoadshowVideoMap 获取已经发布的微路演的产业ID
  171. func GetMicroRoadshowVideoMap() (items map[int]int, err error) {
  172. list, e := models.GetMicroRoadshowVideoList()
  173. if e != nil && e.Error() != utils.ErrNoRow() {
  174. err = errors.New("获取已经发布的微路演的产业失败,GetMicroRoadshowVideoList " + e.Error())
  175. return
  176. }
  177. mapindustrialId := make(map[int]int)
  178. for _, v := range list {
  179. mapindustrialId[v.IndustryId] = v.IndustryId
  180. }
  181. items = mapindustrialId
  182. return
  183. }
  184. // GetMicroRoadShowPageList 获取微路演列表添加活动视频 更新与8.1版本
  185. func GetMicroRoadShowPageListV8(pageSize, currentIndex, audioId, videoId, activityVideoId int, filter, keywords string) (respList []*models.MicroRoadShowPageList, total int, err error) {
  186. var e error
  187. // 根据每页数据量获取音视频配比
  188. startSize := utils.StartIndex(currentIndex, pageSize)
  189. videoList := make([]*models.MicroRoadShowPageList, 0)
  190. if keywords != "" {
  191. keywords = "%" + keywords + "%"
  192. }
  193. //音频的查询
  194. var audioCond string
  195. var audioPars []interface{}
  196. // 如果筛选条件为指定视频ID或只看视频则不做音频查询
  197. // @Param Filter query string false "筛选条件 为空:全部 1:视频 2:音频 3:逻辑解析 4:路演回放 多个用 , 隔开"
  198. if (videoId > 0 || activityVideoId > 0 || (!strings.Contains(filter, "2") && !strings.Contains(filter, "4"))) && filter != "" {
  199. audioCond += ` AND a.activity_voice_id = 0 `
  200. } else {
  201. // 活动已发布且已结束
  202. audioCond += ` AND b.publish_status = 1 AND b.active_state = 3`
  203. //活动音频,设置有效时间为30天,失效后该活动就不再支持音频回放。有效期起始时间为活动的开始时间
  204. //endTime := time.Now().AddDate(0, 0, -30).Format("2006-01-02 15:04:05")
  205. //audioCond += ` AND b.activity_time > ? `
  206. //audioPars = append(audioPars, endTime)
  207. if keywords != "" {
  208. audioCond += ` AND a.voice_name LIKE ? OR b.label LIKE ?`
  209. audioPars = append(audioPars, keywords, keywords)
  210. }
  211. if audioId > 0 {
  212. audioCond += ` AND a.activity_voice_id = ?`
  213. audioPars = append(audioPars, audioId)
  214. }
  215. }
  216. //活动视频的处理
  217. var videoCondAct string
  218. var videoParsAct []interface{}
  219. if (audioId > 0 || videoId > 0 || (!strings.Contains(filter, "1") && !strings.Contains(filter, "4"))) && filter != "" {
  220. videoCondAct = "AND video_id = 0 "
  221. } else {
  222. if keywords != "" {
  223. videoCondAct += ` AND video_name LIKE ?`
  224. videoParsAct = append(videoParsAct, keywords)
  225. }
  226. if activityVideoId > 0 {
  227. videoCondAct += ` AND video_id = ?`
  228. videoParsAct = append(videoParsAct, activityVideoId)
  229. }
  230. videoCondAct += ` AND publish_status = 1`
  231. }
  232. //产业视频的处理
  233. var videoCond string
  234. var videoPars []interface{}
  235. if (audioId > 0 || videoId > 0 || (!strings.Contains(filter, "1") && !strings.Contains(filter, "3"))) && filter != "" {
  236. videoCond += ` AND video_id = 0 `
  237. } else {
  238. if keywords != "" {
  239. videoCond += ` AND video_name LIKE ?`
  240. videoPars = append(videoPars, keywords)
  241. }
  242. if videoId > 0 {
  243. videoCond += ` AND video_id = ?`
  244. videoPars = append(videoPars, videoId)
  245. }
  246. videoCond += ` AND publish_status = 1`
  247. }
  248. total, videoList, e = models.GetMicroRoadShowVideoPageListV8(startSize, pageSize, videoCond, videoPars, videoCondAct, videoParsAct, audioCond, audioPars, audioId, videoId, activityVideoId, 0)
  249. if e != nil {
  250. err = errors.New("获取微路演音视频列表失败, Err: " + e.Error())
  251. return
  252. }
  253. if total == 0 {
  254. return
  255. }
  256. var activityIds []int
  257. for _, v := range videoList {
  258. if v.Type == 2 {
  259. activityIds = append(activityIds, v.ActivityId)
  260. }
  261. }
  262. if len(activityIds) > 0 {
  263. // 获取活动关联的产业
  264. var groupCond string
  265. var groupPars []interface{}
  266. groupCond += ` AND a.activity_id IN (` + utils.GetOrmInReplace(len(activityIds)) + `)`
  267. groupPars = append(groupPars, activityIds)
  268. groups, e := models.GetActivityIndustryRelationList(groupCond, groupPars)
  269. if e != nil {
  270. err = errors.New("获取活动产业关联列表失败, Err: " + e.Error())
  271. return
  272. }
  273. activityIndustryMap := make(map[int]int, 0)
  274. for _, v := range groups {
  275. activityIndustryMap[v.ActivityId] = v.IndustrialManagementId
  276. }
  277. for _, v := range videoList {
  278. if v.Type == 2 {
  279. v.IndustrialManagementId = activityIndustryMap[v.ActivityId]
  280. }
  281. }
  282. }
  283. respList = videoList
  284. return
  285. }