micro_roadshow.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  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. // 活动已发布且已结束
  198. audioCond += ` AND b.publish_status = 1 AND b.active_state = 3`
  199. //活动音频,设置有效时间为30天,失效后该活动就不再支持音频回放。有效期起始时间为活动的开始时间
  200. //endTime := time.Now().AddDate(0, 0, -30).Format("2006-01-02 15:04:05")
  201. //audioCond += ` AND b.activity_time > ? `
  202. //audioPars = append(audioPars, endTime)
  203. if keywords != "" {
  204. audioCond += ` AND ( a.voice_name LIKE ? OR b.label LIKE ? )`
  205. audioPars = append(audioPars, keywords, keywords)
  206. }
  207. if audioId > 0 {
  208. audioCond += ` AND a.activity_voice_id = ?`
  209. audioPars = append(audioPars, audioId)
  210. }
  211. //}
  212. //视频的处理
  213. var videoCond string
  214. var videoCondAct string
  215. var videoPars []interface{}
  216. var videoParsAct []interface{}
  217. if keywords != "" {
  218. videoCond += ` AND video_name LIKE ?`
  219. videoPars = append(videoPars, keywords)
  220. videoCondAct += ` AND ( video_name LIKE ? OR art.label LIKE ? )`
  221. videoParsAct = append(videoParsAct, keywords, keywords)
  222. }
  223. if videoId > 0 {
  224. videoCond += ` AND video_id = ?`
  225. videoPars = append(videoPars, videoId)
  226. }
  227. if activityVideoId > 0 {
  228. videoCondAct += ` AND video_id = ?`
  229. videoParsAct = append(videoParsAct, activityVideoId)
  230. }
  231. //如果传了路演的或者活动的视频ID只查询一个
  232. if videoId > 0 {
  233. videoCondAct += ` AND video_id = 0 `
  234. audioCond += ` AND a.activity_voice_id = 0 `
  235. }
  236. if activityVideoId > 0 {
  237. videoCond += ` AND video_id = 0 `
  238. audioCond += ` AND a.activity_voice_id = 0 `
  239. }
  240. if audioId > 0 {
  241. videoCondAct += ` AND video_id = 0 `
  242. videoCond += ` AND video_id = 0 `
  243. }
  244. if strings.Contains(filter, "1") && !strings.Contains(filter, "2") {
  245. audioCond += ` AND a.activity_voice_id = 0 `
  246. } else if !strings.Contains(filter, "1") && strings.Contains(filter, "2") {
  247. videoCondAct += ` AND video_id = 0 `
  248. videoCond += ` AND video_id = 0 `
  249. }
  250. if strings.Contains(filter, "3") && !strings.Contains(filter, "4") {
  251. audioCond += ` AND a.activity_voice_id = 0 `
  252. videoCondAct += ` AND video_id = 0 `
  253. } else if strings.Contains(filter, "3") && !strings.Contains(filter, "4") {
  254. videoCond += ` AND video_id = 0 `
  255. }
  256. //if filter == "1" {
  257. // audioCond += ` AND a.activity_voice_id = 0 `
  258. //} else if filter == "2" {
  259. // videoCondAct += ` AND video_id = 0 `
  260. // videoCond += ` AND video_id = 0 `
  261. //}
  262. videoCond += ` AND publish_status = 1`
  263. total, videoList, e = models.GetMicroRoadShowVideoPageListV8(startSize, pageSize, videoCond, videoPars, videoCondAct, videoParsAct, audioCond, audioPars, audioId, videoId, activityVideoId, 0)
  264. if e != nil {
  265. err = errors.New("获取微路演音视频列表失败, Err: " + e.Error())
  266. return
  267. }
  268. if total == 0 {
  269. return
  270. }
  271. var activityIds []int
  272. for _, v := range videoList {
  273. if v.Type == 2 {
  274. activityIds = append(activityIds, v.ActivityId)
  275. }
  276. }
  277. if len(activityIds) > 0 {
  278. // 获取活动关联的产业
  279. var groupCond string
  280. var groupPars []interface{}
  281. groupCond += ` AND a.activity_id IN (` + utils.GetOrmInReplace(len(activityIds)) + `)`
  282. groupPars = append(groupPars, activityIds)
  283. groups, e := models.GetActivityIndustryRelationList(groupCond, groupPars)
  284. if e != nil {
  285. err = errors.New("获取活动产业关联列表失败, Err: " + e.Error())
  286. return
  287. }
  288. activityIndustryMap := make(map[int]int, 0)
  289. for _, v := range groups {
  290. activityIndustryMap[v.ActivityId] = v.IndustrialManagementId
  291. }
  292. for _, v := range videoList {
  293. if v.Type == 2 {
  294. v.IndustrialManagementId = activityIndustryMap[v.ActivityId]
  295. }
  296. }
  297. }
  298. respList = videoList
  299. return
  300. }
  301. // GetMicroRoadShowPageListIkWord 添加IK分词联想词 获取微路演列表添加活动视频 更新与8.1版本
  302. func CountMicroRoadShowPageListIkWord(audioId, videoId, activityVideoId int, keywordArr []string, filter string) (total int, err error) {
  303. var e error
  304. var keywords string
  305. if len(keywordArr) > 0 {
  306. keywords = KeyWordArrSqlRegexpAll(keywordArr)
  307. }
  308. //if keywords == "" {
  309. // return
  310. //}
  311. //音频的查询
  312. var audioCond string
  313. var audioPars []interface{}
  314. // 如果筛选条件为指定视频ID或只看视频则不做音频查询
  315. //if videoId > 0 || activityVideoId > 0 || filter == 1 {
  316. // audioCond += ` AND a.activity_voice_id = 0 `
  317. //} else {
  318. // 活动已发布且已结束
  319. audioCond += ` AND b.publish_status = 1 AND b.active_state = 3`
  320. if keywords != "" {
  321. audioCond += ` AND (a.voice_name REGEXP ? OR b.label REGEXP ? ) `
  322. audioPars = append(audioPars, keywords, keywords)
  323. }
  324. if audioId > 0 {
  325. audioCond += ` AND a.activity_voice_id = ?`
  326. audioPars = append(audioPars, audioId)
  327. }
  328. //视频的处理
  329. var videoCond string
  330. var videoCondAct string
  331. var videoPars []interface{}
  332. var videoParsAct []interface{}
  333. //if audioId > 0 || filter == 2 {
  334. // videoCond = ""
  335. //} else {
  336. if keywords != "" {
  337. videoCond += ` AND video_name REGEXP ?`
  338. videoPars = append(videoPars, keywords)
  339. videoCondAct += ` AND ( video_name REGEXP ? OR art.label REGEXP ? )`
  340. videoParsAct = append(videoParsAct, keywords, keywords)
  341. }
  342. if videoId > 0 {
  343. videoCond += ` AND video_id = ?`
  344. videoPars = append(videoPars, videoId)
  345. }
  346. if activityVideoId > 0 {
  347. videoCondAct += ` AND video_id = ?`
  348. videoParsAct = append(videoParsAct, activityVideoId)
  349. }
  350. //如果传了路演的或者活动的视频ID只查询一个
  351. if videoId > 0 {
  352. videoCondAct += ` AND video_id = 0 `
  353. audioCond += ` AND a.activity_voice_id = 0 `
  354. }
  355. if activityVideoId > 0 {
  356. videoCond += ` AND video_id = 0 `
  357. audioCond += ` AND a.activity_voice_id = 0 `
  358. }
  359. if audioId > 0 {
  360. videoCondAct += ` AND video_id = 0 `
  361. videoCond += ` AND video_id = 0 `
  362. }
  363. if strings.Contains(filter, "1") && !strings.Contains(filter, "2") {
  364. audioCond += ` AND a.activity_voice_id = 0 `
  365. } else if !strings.Contains(filter, "1") && strings.Contains(filter, "2") {
  366. videoCondAct += ` AND video_id = 0 `
  367. videoCond += ` AND video_id = 0 `
  368. }
  369. if strings.Contains(filter, "3") && !strings.Contains(filter, "4") {
  370. audioCond += ` AND a.activity_voice_id = 0 `
  371. videoCondAct += ` AND video_id = 0 `
  372. } else if strings.Contains(filter, "3") && !strings.Contains(filter, "4") {
  373. videoCond += ` AND video_id = 0 `
  374. }
  375. //
  376. //if filter == "1" {
  377. // audioCond += ` AND a.activity_voice_id = 0 `
  378. //} else if filter == "2" {
  379. // videoCondAct += ` AND video_id = 0 `
  380. // videoCond += ` AND video_id = 0 `
  381. //}
  382. videoCond += ` AND publish_status = 1`
  383. //}
  384. total, e = models.CountMicroRoadShowVideoPageList(videoCond, videoPars, videoCondAct, videoParsAct, audioCond, audioPars)
  385. if e != nil {
  386. err = errors.New("获取微路演音视频列表失败, Err: " + e.Error())
  387. return
  388. }
  389. return
  390. }
  391. // GetMicroRoadShowPageListIkWord 添加IK分词联想词 获取微路演列表添加活动视频 更新与8.1版本
  392. func GetMicroRoadShowPageListIkWord(startSize, pageSize, audioId, videoId, activityVideoId int, keywordArr []string, filter, keywords string) (respList []*models.MicroRoadShowPageList, err error) {
  393. videoList := make([]*models.MicroRoadShowPageList, 0)
  394. var e error
  395. var keywordsIk string
  396. if len(keywordArr) > 1 {
  397. keywordsIk = KeyWordArrSqlRegexp(keywordArr)
  398. }
  399. if keywords != "" {
  400. keywords = "%" + keywords + "%"
  401. }
  402. //音频的查询
  403. var audioCond string
  404. var audioPars []interface{}
  405. // 如果筛选条件为指定视频ID或只看视频则不做音频查询
  406. //if videoId > 0 || activityVideoId > 0 || filter == 1 {
  407. // audioCond += ` AND a.activity_voice_id = 0 `
  408. //} else {
  409. // 活动已发布且已结束
  410. audioCond += ` AND b.publish_status = 1 AND b.active_state = 3`
  411. if keywordsIk != "" {
  412. audioCond += ` AND ( a.voice_name REGEXP ? OR b.label REGEXP ? )`
  413. audioCond += ` AND ( a.voice_name NOT LIKE ? AND b.label NOT LIKE ? )`
  414. audioPars = append(audioPars, keywordsIk, keywordsIk, keywords, keywords)
  415. }
  416. if audioId > 0 {
  417. audioCond += ` AND a.activity_voice_id = ?`
  418. audioPars = append(audioPars, audioId)
  419. }
  420. //视频的处理
  421. var videoCond string
  422. var videoCondAct string
  423. var videoPars []interface{}
  424. var videoParsAct []interface{}
  425. //if audioId > 0 || filter == 2 {
  426. // videoCond = ""
  427. //} else {
  428. if keywordsIk != "" {
  429. videoCond += ` AND video_name REGEXP ?`
  430. videoPars = append(videoPars, keywordsIk)
  431. videoCondAct += ` AND ( v.video_name REGEXP ? OR art.label REGEXP ? )`
  432. videoCondAct += ` AND ( v.video_name NOT LIKE ? AND art.label NOT LIKE ? )`
  433. videoParsAct = append(videoParsAct, keywordsIk, keywordsIk, keywords, keywords)
  434. }
  435. if videoId > 0 {
  436. videoCond += ` AND video_id = ?`
  437. videoPars = append(videoPars, videoId)
  438. }
  439. if activityVideoId > 0 {
  440. videoCondAct += ` AND video_id = ?`
  441. videoParsAct = append(videoParsAct, activityVideoId)
  442. }
  443. //如果传了路演的或者活动的视频ID只查询一个
  444. if videoId > 0 {
  445. videoCondAct += ` AND video_id = 0 `
  446. audioCond += ` AND a.activity_voice_id = 0 `
  447. }
  448. if activityVideoId > 0 {
  449. videoCond += ` AND video_id = 0 `
  450. audioCond += ` AND a.activity_voice_id = 0 `
  451. }
  452. if audioId > 0 {
  453. videoCondAct += ` AND video_id = 0 `
  454. videoCond += ` AND video_id = 0 `
  455. }
  456. if strings.Contains(filter, "1") && !strings.Contains(filter, "2") {
  457. audioCond += ` AND a.activity_voice_id = 0 `
  458. } else if !strings.Contains(filter, "1") && strings.Contains(filter, "2") {
  459. videoCondAct += ` AND video_id = 0 `
  460. videoCond += ` AND video_id = 0 `
  461. }
  462. if strings.Contains(filter, "3") && !strings.Contains(filter, "4") {
  463. audioCond += ` AND a.activity_voice_id = 0 `
  464. videoCondAct += ` AND video_id = 0 `
  465. } else if strings.Contains(filter, "3") && !strings.Contains(filter, "4") {
  466. videoCond += ` AND video_id = 0 `
  467. }
  468. //if filter == "1" {
  469. // audioCond += ` AND a.activity_voice_id = 0 `
  470. //} else if filter == "2" {
  471. // videoCondAct += ` AND video_id = 0 `
  472. // videoCond += ` AND video_id = 0 `
  473. //}
  474. videoCond += ` AND publish_status = 1`
  475. //}
  476. videoList, e = models.GetMicroRoadShowVideoPageListIkWord(startSize, pageSize, videoCond, videoPars, videoCondAct, videoParsAct, audioCond, audioPars, audioId, videoId, activityVideoId, 0)
  477. if e != nil {
  478. err = errors.New("获取微路演音视频列表失败分词, Err: " + e.Error())
  479. return
  480. }
  481. respList = videoList
  482. return
  483. }