micro_roadshow.go 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886
  1. package services
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "fmt"
  6. "hongze/hongze_clpt/models"
  7. "hongze/hongze_clpt/utils"
  8. "strconv"
  9. "strings"
  10. "time"
  11. )
  12. // GetMicroRoadShowDefaultImgConfig 获取微路演默认图/分享图配置
  13. func GetMicroRoadShowDefaultImgConfig() (audioMap, videoMap, audioShareMap, videoShareMap map[int]string, err error) {
  14. audioMap = make(map[int]string, 0)
  15. videoMap = make(map[int]string, 0)
  16. audioShareMap = make(map[int]string, 0)
  17. videoShareMap = make(map[int]string, 0)
  18. key := models.MicroRoadshowDefaultImgKey
  19. conf, e := models.GetConfigByCode(key)
  20. if e != nil {
  21. err = errors.New("获取微路演默认图配置失败, Err: " + e.Error())
  22. return
  23. }
  24. if conf.ConfigValue == "" {
  25. err = errors.New("获取微路演默认图配置有误")
  26. return
  27. }
  28. list := new(models.MicroRoadShowDefaultImgList)
  29. if e = json.Unmarshal([]byte(conf.ConfigValue), &list); e != nil {
  30. err = errors.New("微路演默认图配置配置值解析失败, Err: " + e.Error())
  31. return
  32. }
  33. audioList := list.Audio
  34. for i := range audioList {
  35. audioMap[audioList[i].ChartPermissionId] = audioList[i].ImgUrl
  36. audioShareMap[audioList[i].ChartPermissionId] = audioList[i].ShareImg
  37. }
  38. videoList := list.Video
  39. for i := range videoList {
  40. videoMap[videoList[i].ChartPermissionId] = videoList[i].ImgUrl
  41. videoShareMap[videoList[i].ChartPermissionId] = videoList[i].ShareImg
  42. }
  43. return
  44. }
  45. func GetindustryVideo(user *models.WxUserItem, industrialManagementId int) (industryVideo *models.MicroVideoSimpleInfo, AuthInfo *models.UserPermissionAuthInfo, err error) {
  46. total, e := models.GetMicroRoadshowVideoByIndustryIdCount(industrialManagementId)
  47. if e != nil {
  48. err = errors.New("获取产业关联的视频失败,GetMicroRoadshowVideoByIndustryIdCount " + e.Error())
  49. return
  50. }
  51. if total == 0 {
  52. return
  53. }
  54. // 用户权限
  55. authInfo, permissionArr, e := GetUserRaiPermissionInfo(user.UserId, user.CompanyId)
  56. if e != nil {
  57. err = errors.New("获取用户权限失败,GetUserRaiPermissionInfo " + e.Error())
  58. return
  59. }
  60. videoSimple := new(models.MicroVideoSimpleInfo)
  61. // 权限
  62. var au *models.UserPermissionAuthInfo
  63. video, e := models.GetMicroRoadshowVideoByIndustryId(industrialManagementId)
  64. if e != nil {
  65. err = errors.New("获取产业关联的视频失败,GetMicroRoadshowVideoByIndustryId " + e.Error())
  66. return
  67. } else {
  68. videoSimple.Id = video.VideoId
  69. videoSimple.Title = "5min【" + video.IndustryName + "】逻辑解析"
  70. videoSimple.BackgroundImg = video.ImgUrl
  71. videoSimple.DetailImgUrl = video.DetailImgUrl
  72. if videoSimple.BackgroundImg == "" {
  73. // 获取默认图配置
  74. _, videoMap, _, _, e := GetMicroRoadShowDefaultImgConfig()
  75. if e != nil {
  76. err = errors.New("获取视频默认配置图失败,GetMicroRoadshowVideoByIndustryId " + e.Error())
  77. return
  78. }
  79. videoSimple.BackgroundImg = videoMap[video.ChartPermissionId]
  80. }
  81. videoSimple.PlaySeconds = video.VideoDuration
  82. videoSimple.ResourceUrl = video.VideoUrl
  83. au = new(models.UserPermissionAuthInfo)
  84. au.SellerName = authInfo.SellerName
  85. au.SellerMobile = authInfo.SellerMobile
  86. au.HasPermission = authInfo.HasPermission
  87. au.OperationMode = authInfo.OperationMode
  88. if au.HasPermission == 1 {
  89. // 非宏观权限进一步判断是否有权限
  90. if video.ChartPermissionId != utils.HONG_GUAN_ID && !utils.InArrayByStr(permissionArr, video.ChartPermissionName) {
  91. au.HasPermission = 2
  92. }
  93. }
  94. // 无权限的弹框提示
  95. if au.HasPermission != 1 {
  96. if au.OperationMode == UserPermissionOperationModeCall {
  97. au.PopupMsg = UserPermissionPopupMsgCallMicroVideo
  98. } else {
  99. au.PopupMsg = UserPermissionPopupMsgApplyMicroVideo
  100. }
  101. videoSimple.ResourceUrl = ""
  102. }
  103. }
  104. videoSimple.Type = 3
  105. industryVideo = videoSimple
  106. AuthInfo = au
  107. return
  108. }
  109. // GetindustryVideoDetailById 通过视频ID获取视频详情
  110. func GetindustryVideoDetailById(user *models.WxUserItem, videoId int) (industryVideo *models.MicroVideoSimpleInfo, AuthInfo *models.UserPermissionAuthInfo, err error) {
  111. total, e := models.GetMicroRoadshowVideoByVideoIdCount(videoId)
  112. if e != nil {
  113. err = errors.New("获取产业关联的视频失败,GetMicroRoadshowVideoByIndustryIdCount " + e.Error())
  114. return
  115. }
  116. if total == 0 {
  117. err = errors.New("视频不存在,或已取消发布")
  118. return
  119. }
  120. // 用户权限
  121. authInfo, permissionArr, e := GetUserRaiPermissionInfo(user.UserId, user.CompanyId)
  122. if e != nil {
  123. err = errors.New("获取用户权限失败,GetUserRaiPermissionInfo " + e.Error())
  124. return
  125. }
  126. videoSimple := new(models.MicroVideoSimpleInfo)
  127. // 权限
  128. var au *models.UserPermissionAuthInfo
  129. video, e := models.GetMicroRoadshowVideoById(videoId)
  130. if e != nil {
  131. err = errors.New("获取产业关联的视频失败,GetMicroRoadshowVideoByIndustryId " + e.Error())
  132. return
  133. } else {
  134. videoSimple.Id = video.VideoId
  135. videoSimple.Title = "5min【" + video.IndustryName + "】逻辑解析"
  136. videoSimple.BackgroundImg = video.ImgUrl
  137. videoSimple.DetailImgUrl = video.DetailImgUrl
  138. if videoSimple.BackgroundImg == "" {
  139. // 获取默认图配置
  140. _, videoMap, _, _, e := GetMicroRoadShowDefaultImgConfig()
  141. if e != nil {
  142. err = errors.New("获取视频默认配置图失败,GetMicroRoadshowVideoByIndustryId " + e.Error())
  143. return
  144. }
  145. videoSimple.BackgroundImg = videoMap[video.ChartPermissionId]
  146. }
  147. videoSimple.PlaySeconds = video.VideoDuration
  148. videoSimple.ResourceUrl = video.VideoUrl
  149. au = new(models.UserPermissionAuthInfo)
  150. au.SellerName = authInfo.SellerName
  151. au.SellerMobile = authInfo.SellerMobile
  152. au.HasPermission = authInfo.HasPermission
  153. au.OperationMode = authInfo.OperationMode
  154. if au.HasPermission == 1 {
  155. // 非宏观权限进一步判断是否有权限
  156. if video.ChartPermissionId != utils.HONG_GUAN_ID && !utils.InArrayByStr(permissionArr, video.ChartPermissionName) {
  157. au.HasPermission = 2
  158. }
  159. }
  160. // 无权限的弹框提示
  161. if au.HasPermission != 1 {
  162. if au.OperationMode == UserPermissionOperationModeCall {
  163. au.PopupMsg = UserPermissionPopupMsgCallMicroVideo
  164. } else {
  165. au.PopupMsg = UserPermissionPopupMsgApplyMicroVideo
  166. }
  167. videoSimple.ResourceUrl = ""
  168. }
  169. }
  170. videoSimple.Type = 3
  171. industryVideo = videoSimple
  172. AuthInfo = au
  173. return
  174. }
  175. // GetMicroRoadshowVideoMap 获取已经发布的微路演的产业ID
  176. func GetMicroRoadshowVideoMap() (items map[int]int, err error) {
  177. list, e := models.GetMicroRoadshowVideoList()
  178. if e != nil && e.Error() != utils.ErrNoRow() {
  179. err = errors.New("获取已经发布的微路演的产业失败,GetMicroRoadshowVideoList " + e.Error())
  180. return
  181. }
  182. mapindustrialId := make(map[int]int)
  183. for _, v := range list {
  184. mapindustrialId[v.IndustryId] = v.IndustryId
  185. }
  186. items = mapindustrialId
  187. return
  188. }
  189. // GetMicroRoadShowPageList 获取微路演列表添加活动视频 更新与8.1版本
  190. func GetMicroRoadShowPageListV8(pageSize, currentIndex, audioId, videoId, activityVideoId int, filter, keywords string) (respList []*models.MicroRoadShowPageList, total int, err error) {
  191. var e error
  192. // 根据每页数据量获取音视频配比
  193. startSize := utils.StartIndex(currentIndex, pageSize)
  194. videoList := make([]*models.MicroRoadShowPageList, 0)
  195. if keywords != "" {
  196. keywords = "%" + keywords + "%"
  197. }
  198. //音频的查询
  199. var audioCond string
  200. var audioPars []interface{}
  201. // 如果筛选条件为指定视频ID或只看视频则不做音频查询
  202. // 活动已发布且已结束
  203. audioCond += ` AND b.publish_status = 1 AND b.active_state = 3`
  204. //活动音频,设置有效时间为30天,失效后该活动就不再支持音频回放。有效期起始时间为活动的开始时间
  205. //endTime := time.Now().AddDate(0, 0, -30).Format("2006-01-02 15:04:05")
  206. //audioCond += ` AND b.activity_time > ? `
  207. //audioPars = append(audioPars, endTime)
  208. if keywords != "" {
  209. audioCond += ` AND ( a.voice_name LIKE ? OR b.label LIKE ? )`
  210. audioPars = append(audioPars, keywords, keywords)
  211. }
  212. if audioId > 0 {
  213. audioCond += ` AND a.activity_voice_id = ?`
  214. audioPars = append(audioPars, audioId)
  215. }
  216. //}
  217. //视频的处理
  218. var videoCond string
  219. var videoCondAct string
  220. var videoPars []interface{}
  221. var videoParsAct []interface{}
  222. if keywords != "" {
  223. videoCond += ` AND video_name LIKE ?`
  224. videoPars = append(videoPars, keywords)
  225. videoCondAct += ` AND ( video_name LIKE ? OR art.label LIKE ? )`
  226. videoParsAct = append(videoParsAct, keywords, keywords)
  227. }
  228. if videoId > 0 {
  229. videoCond += ` AND video_id = ?`
  230. videoPars = append(videoPars, videoId)
  231. }
  232. if activityVideoId > 0 {
  233. videoCondAct += ` AND video_id = ?`
  234. videoParsAct = append(videoParsAct, activityVideoId)
  235. }
  236. //如果传了路演的或者活动的视频ID只查询一个
  237. if videoId > 0 {
  238. videoCondAct += ` AND video_id = 0 `
  239. audioCond += ` AND a.activity_voice_id = 0 `
  240. }
  241. if activityVideoId > 0 {
  242. videoCond += ` AND video_id = 0 `
  243. audioCond += ` AND a.activity_voice_id = 0 `
  244. }
  245. if audioId > 0 {
  246. videoCondAct += ` AND video_id = 0 `
  247. videoCond += ` AND video_id = 0 `
  248. }
  249. if strings.Contains(filter, "1") && !strings.Contains(filter, "2") {
  250. audioCond += ` AND a.activity_voice_id = 0 `
  251. } else if !strings.Contains(filter, "1") && strings.Contains(filter, "2") {
  252. videoCondAct += ` AND video_id = 0 `
  253. videoCond += ` AND video_id = 0 `
  254. }
  255. if strings.Contains(filter, "3") && !strings.Contains(filter, "4") {
  256. audioCond += ` AND a.activity_voice_id = 0 `
  257. videoCondAct += ` AND video_id = 0 `
  258. } else if strings.Contains(filter, "3") && !strings.Contains(filter, "4") {
  259. videoCond += ` AND video_id = 0 `
  260. }
  261. //if filter == "1" {
  262. // audioCond += ` AND a.activity_voice_id = 0 `
  263. //} else if filter == "2" {
  264. // videoCondAct += ` AND video_id = 0 `
  265. // videoCond += ` AND video_id = 0 `
  266. //}
  267. videoCond += ` AND publish_status = 1`
  268. total, videoList, e = models.GetMicroRoadShowVideoPageListV8(startSize, pageSize, videoCond, videoPars, videoCondAct, videoParsAct, audioCond, audioPars, audioId, videoId, activityVideoId, 0)
  269. if e != nil {
  270. err = errors.New("获取微路演音视频列表失败, Err: " + e.Error())
  271. return
  272. }
  273. if total == 0 {
  274. return
  275. }
  276. var activityIds []int
  277. for _, v := range videoList {
  278. if v.Type == 2 {
  279. activityIds = append(activityIds, v.ActivityId)
  280. }
  281. }
  282. if len(activityIds) > 0 {
  283. // 获取活动关联的产业
  284. var groupCond string
  285. var groupPars []interface{}
  286. groupCond += ` AND a.activity_id IN (` + utils.GetOrmInReplace(len(activityIds)) + `)`
  287. groupPars = append(groupPars, activityIds)
  288. groups, e := models.GetActivityIndustryRelationList(groupCond, groupPars)
  289. if e != nil {
  290. err = errors.New("获取活动产业关联列表失败, Err: " + e.Error())
  291. return
  292. }
  293. activityIndustryMap := make(map[int]int, 0)
  294. for _, v := range groups {
  295. activityIndustryMap[v.ActivityId] = v.IndustrialManagementId
  296. }
  297. for _, v := range videoList {
  298. if v.Type == 2 {
  299. v.IndustrialManagementId = activityIndustryMap[v.ActivityId]
  300. }
  301. }
  302. }
  303. respList = videoList
  304. return
  305. }
  306. // GetMicroRoadShowPageList 获取微路演列表添加活动视频 更新与8.1版本
  307. func GetMicroRoadShowPageListV12(pageSize, currentIndex, sourceId, tableType int, filter, keywords, searchType, chartPermissionIds string) (respList []*models.MicroRoadShowPageList, total int, err error) {
  308. //Type int `description:"类型: 1-活动音频; 2-活动视频; 3-产业视频; 4-系列问答"`
  309. var e error
  310. // 根据每页数据量获取音视频配比
  311. startSize := utils.StartIndex(currentIndex, pageSize)
  312. videoList := make([]*models.MicroRoadShowPageList, 0)
  313. var audioAct string // 活动音频 1
  314. var audioActPars []interface{}
  315. var videoAct string // 活动视频 2
  316. var videoActPars []interface{}
  317. //视频的处理
  318. var videoMico string //产业视频 3
  319. var videoMicoPars []interface{}
  320. var conditionAskserie string // 系列问答 4
  321. var askseriePars []interface{}
  322. if sourceId > 0 && tableType > 0 {
  323. //先给不相干的表查询ID = 0
  324. audioAct += ` AND b.chart_permission_id = 0 `
  325. videoAct += ` AND b.chart_permission_id = 0`
  326. videoMico += ` AND a.chart_permission_id = 0 `
  327. conditionAskserie += ` AND a.chart_permission_id = 0 `
  328. switch tableType {
  329. case 1:
  330. audioAct += ` OR a.activity_id = ` + strconv.Itoa(sourceId)
  331. case 2:
  332. videoAct += ` OR a.activity_id = ` + strconv.Itoa(sourceId)
  333. case 3:
  334. videoMico += ` OR a.video_id = ` + strconv.Itoa(sourceId)
  335. case 4:
  336. conditionAskserie += ` OR a.askserie_video_id = ` + strconv.Itoa(sourceId)
  337. }
  338. }
  339. if filter == "1" {
  340. audioAct += ` AND b.chart_permission_id = 0 `
  341. } else if filter == "2" {
  342. videoAct += ` AND b.chart_permission_id = 0`
  343. videoMico += ` AND a.chart_permission_id = 0 `
  344. conditionAskserie += ` AND a.chart_permission_id = 0 `
  345. }
  346. if searchType != "" {
  347. // @Param SearchType string int true "搜索类型: 1-路演回放; 2-问答系列; 3-调研反馈 多个用 , 隔开"
  348. videoMico += ` AND a.chart_permission_id = 0 ` // 产业视频不在搜索范围内
  349. if strings.Contains(searchType, "1") && !strings.Contains(searchType, "3") {
  350. audioAct += ` AND a.file_type = 1 `
  351. videoAct += ` AND a.file_type = 1 `
  352. }
  353. if !strings.Contains(searchType, "1") && strings.Contains(searchType, "3") {
  354. audioAct += ` AND a.file_type = 2 `
  355. videoAct += ` AND a.file_type = 2 `
  356. }
  357. if !strings.Contains(searchType, "2") {
  358. conditionAskserie += ` AND a.chart_permission_id = 0 `
  359. }
  360. if !strings.Contains(searchType, "3") && !strings.Contains(searchType, "1") {
  361. audioAct += ` AND b.chart_permission_id = 0 `
  362. videoAct += ` AND b.chart_permission_id = 0 `
  363. }
  364. }
  365. if keywords != "" {
  366. keywords = "%" + keywords + "%"
  367. audioAct += ` AND a.voice_name LIKE ? `
  368. videoAct += ` AND a.video_name LIKE ? `
  369. videoMico += ` AND a.video_name LIKE ? `
  370. conditionAskserie += ` AND a.video_name LIKE ? `
  371. audioActPars = append(audioActPars, keywords)
  372. videoActPars = append(videoActPars, keywords)
  373. videoMicoPars = append(videoMicoPars, keywords)
  374. askseriePars = append(askseriePars, keywords)
  375. }
  376. //行业筛选
  377. if chartPermissionIds != "" {
  378. audioAct += ` AND b.chart_permission_id IN (` + chartPermissionIds + `)`
  379. videoAct += ` AND b.chart_permission_id IN (` + chartPermissionIds + `)`
  380. videoMico += ` AND a.chart_permission_id IN (` + chartPermissionIds + `)`
  381. conditionAskserie += ` AND a.chart_permission_id IN (` + chartPermissionIds + `)`
  382. }
  383. //发布状态
  384. audioAct += ` AND b.publish_status = 1 AND b.chart_permission_id != 31 AND a.is_hide = 0 `
  385. videoAct += ` AND b.publish_status = 1 AND b.chart_permission_id != 31 AND a.is_hide = 0 `
  386. videoMico += ` AND a.publish_status = 1 AND a.chart_permission_id != 31 `
  387. conditionAskserie += ` AND a.publish_status = 1 AND a.chart_permission_id != 31 `
  388. total, videoList, e = models.GetMicroRoadShowVideoPageListV12(startSize, pageSize, audioAct, audioActPars, videoAct, videoActPars, videoMico, videoMicoPars, conditionAskserie, askseriePars)
  389. if e != nil {
  390. err = errors.New("获取微路演音视频列表失败, Err: " + e.Error())
  391. return
  392. }
  393. for _, v := range videoList {
  394. v.LabelType = v.Type
  395. if v.Type == 1 || v.Type == 2 {
  396. v.LabelType = v.ActivityFileType
  397. }
  398. }
  399. respList = videoList
  400. return
  401. }
  402. // GetMicroRoadShowPageListIkWord 添加IK分词联想词 获取微路演列表添加活动视频 更新与8.1版本
  403. func CountMicroRoadShowPageListIkWord(audioId, videoId, activityVideoId int, keywordArr []string, filter string) (total int, err error) {
  404. var e error
  405. var keywords string
  406. if len(keywordArr) > 0 {
  407. keywords = KeyWordArrSqlRegexpAll(keywordArr)
  408. }
  409. //if keywords == "" {
  410. // return
  411. //}
  412. //音频的查询
  413. var audioCond string
  414. var audioPars []interface{}
  415. // 如果筛选条件为指定视频ID或只看视频则不做音频查询
  416. //if videoId > 0 || activityVideoId > 0 || filter == 1 {
  417. // audioCond += ` AND a.activity_voice_id = 0 `
  418. //} else {
  419. // 活动已发布且已结束
  420. audioCond += ` AND b.publish_status = 1 AND b.active_state = 3`
  421. if keywords != "" {
  422. audioCond += ` AND (a.voice_name REGEXP ? OR b.label REGEXP ? ) `
  423. audioPars = append(audioPars, keywords, keywords)
  424. }
  425. if audioId > 0 {
  426. audioCond += ` AND a.activity_voice_id = ?`
  427. audioPars = append(audioPars, audioId)
  428. }
  429. //视频的处理
  430. var videoCond string
  431. var videoCondAct string
  432. var videoPars []interface{}
  433. var videoParsAct []interface{}
  434. //if audioId > 0 || filter == 2 {
  435. // videoCond = ""
  436. //} else {
  437. if keywords != "" {
  438. videoCond += ` AND video_name REGEXP ?`
  439. videoPars = append(videoPars, keywords)
  440. videoCondAct += ` AND ( video_name REGEXP ? OR art.label REGEXP ? )`
  441. videoParsAct = append(videoParsAct, keywords, keywords)
  442. }
  443. if videoId > 0 {
  444. videoCond += ` AND video_id = ?`
  445. videoPars = append(videoPars, videoId)
  446. }
  447. if activityVideoId > 0 {
  448. videoCondAct += ` AND video_id = ?`
  449. videoParsAct = append(videoParsAct, activityVideoId)
  450. }
  451. //如果传了路演的或者活动的视频ID只查询一个
  452. if videoId > 0 {
  453. videoCondAct += ` AND video_id = 0 `
  454. audioCond += ` AND a.activity_voice_id = 0 `
  455. }
  456. if activityVideoId > 0 {
  457. videoCond += ` AND video_id = 0 `
  458. audioCond += ` AND a.activity_voice_id = 0 `
  459. }
  460. if audioId > 0 {
  461. videoCondAct += ` AND video_id = 0 `
  462. videoCond += ` AND video_id = 0 `
  463. }
  464. if strings.Contains(filter, "1") && !strings.Contains(filter, "2") {
  465. audioCond += ` AND a.activity_voice_id = 0 `
  466. } else if !strings.Contains(filter, "1") && strings.Contains(filter, "2") {
  467. videoCondAct += ` AND video_id = 0 `
  468. videoCond += ` AND video_id = 0 `
  469. }
  470. if strings.Contains(filter, "3") && !strings.Contains(filter, "4") {
  471. audioCond += ` AND a.activity_voice_id = 0 `
  472. videoCondAct += ` AND video_id = 0 `
  473. } else if strings.Contains(filter, "3") && !strings.Contains(filter, "4") {
  474. videoCond += ` AND video_id = 0 `
  475. }
  476. //
  477. //if filter == "1" {
  478. // audioCond += ` AND a.activity_voice_id = 0 `
  479. //} else if filter == "2" {
  480. // videoCondAct += ` AND video_id = 0 `
  481. // videoCond += ` AND video_id = 0 `
  482. //}
  483. videoCond += ` AND publish_status = 1`
  484. //}
  485. total, e = models.CountMicroRoadShowVideoPageList(videoCond, videoPars, videoCondAct, videoParsAct, audioCond, audioPars)
  486. if e != nil {
  487. err = errors.New("获取微路演音视频列表失败, Err: " + e.Error())
  488. return
  489. }
  490. return
  491. }
  492. // GetMicroRoadShowPageListIkWord 添加IK分词联想词 获取微路演列表添加活动视频 更新与8.1版本
  493. func GetMicroRoadShowPageListIkWord(startSize, pageSize, audioId, videoId, activityVideoId int, keywordArr []string, filter, keywords string) (respList []*models.MicroRoadShowPageList, err error) {
  494. videoList := make([]*models.MicroRoadShowPageList, 0)
  495. var e error
  496. var keywordsIk string
  497. if len(keywordArr) > 1 {
  498. keywordsIk = KeyWordArrSqlRegexp(keywordArr)
  499. }
  500. if keywords != "" {
  501. keywords = "%" + keywords + "%"
  502. }
  503. //音频的查询
  504. var audioCond string
  505. var audioPars []interface{}
  506. // 如果筛选条件为指定视频ID或只看视频则不做音频查询
  507. //if videoId > 0 || activityVideoId > 0 || filter == 1 {
  508. // audioCond += ` AND a.activity_voice_id = 0 `
  509. //} else {
  510. // 活动已发布且已结束
  511. audioCond += ` AND b.publish_status = 1 AND b.active_state = 3`
  512. if keywordsIk != "" {
  513. audioCond += ` AND ( a.voice_name REGEXP ? OR b.label REGEXP ? )`
  514. audioCond += ` AND ( a.voice_name NOT LIKE ? AND b.label NOT LIKE ? )`
  515. audioPars = append(audioPars, keywordsIk, keywordsIk, keywords, keywords)
  516. }
  517. if audioId > 0 {
  518. audioCond += ` AND a.activity_voice_id = ?`
  519. audioPars = append(audioPars, audioId)
  520. }
  521. //视频的处理
  522. var videoCond string
  523. var videoCondAct string
  524. var videoPars []interface{}
  525. var videoParsAct []interface{}
  526. //if audioId > 0 || filter == 2 {
  527. // videoCond = ""
  528. //} else {
  529. if keywordsIk != "" {
  530. videoCond += ` AND video_name REGEXP ?`
  531. videoPars = append(videoPars, keywordsIk)
  532. videoCondAct += ` AND ( v.video_name REGEXP ? OR art.label REGEXP ? )`
  533. videoCondAct += ` AND ( v.video_name NOT LIKE ? AND art.label NOT LIKE ? )`
  534. videoParsAct = append(videoParsAct, keywordsIk, keywordsIk, keywords, keywords)
  535. }
  536. if videoId > 0 {
  537. videoCond += ` AND video_id = ?`
  538. videoPars = append(videoPars, videoId)
  539. }
  540. if activityVideoId > 0 {
  541. videoCondAct += ` AND video_id = ?`
  542. videoParsAct = append(videoParsAct, activityVideoId)
  543. }
  544. //如果传了路演的或者活动的视频ID只查询一个
  545. if videoId > 0 {
  546. videoCondAct += ` AND video_id = 0 `
  547. audioCond += ` AND a.activity_voice_id = 0 `
  548. }
  549. if activityVideoId > 0 {
  550. videoCond += ` AND video_id = 0 `
  551. audioCond += ` AND a.activity_voice_id = 0 `
  552. }
  553. if audioId > 0 {
  554. videoCondAct += ` AND video_id = 0 `
  555. videoCond += ` AND video_id = 0 `
  556. }
  557. if strings.Contains(filter, "1") && !strings.Contains(filter, "2") {
  558. audioCond += ` AND a.activity_voice_id = 0 `
  559. } else if !strings.Contains(filter, "1") && strings.Contains(filter, "2") {
  560. videoCondAct += ` AND video_id = 0 `
  561. videoCond += ` AND video_id = 0 `
  562. }
  563. if strings.Contains(filter, "3") && !strings.Contains(filter, "4") {
  564. audioCond += ` AND a.activity_voice_id = 0 `
  565. videoCondAct += ` AND video_id = 0 `
  566. } else if strings.Contains(filter, "3") && !strings.Contains(filter, "4") {
  567. videoCond += ` AND video_id = 0 `
  568. }
  569. //if filter == "1" {
  570. // audioCond += ` AND a.activity_voice_id = 0 `
  571. //} else if filter == "2" {
  572. // videoCondAct += ` AND video_id = 0 `
  573. // videoCond += ` AND video_id = 0 `
  574. //}
  575. videoCond += ` AND publish_status = 1`
  576. //}
  577. videoList, e = models.GetMicroRoadShowVideoPageListIkWord(startSize, pageSize, videoCond, videoPars, videoCondAct, videoParsAct, audioCond, audioPars, audioId, videoId, activityVideoId, 0)
  578. if e != nil {
  579. err = errors.New("获取微路演音视频列表失败分词, Err: " + e.Error())
  580. return
  581. }
  582. respList = videoList
  583. return
  584. }
  585. // 用户微路演视频回放操作操作行为,模板消息推送
  586. func MicroRoadshowVideoUserRmind(user *models.WxUserItem, videoId int) (err error) {
  587. defer func() {
  588. if err != nil {
  589. go utils.SendAlarmMsg("用户音视频回放操作操作行为,模板消息推送失败"+err.Error(), 2)
  590. }
  591. }()
  592. countUser, err := models.GetUserRemind(user.UserId)
  593. if err != nil {
  594. return err
  595. }
  596. if countUser == 0 {
  597. return err
  598. }
  599. var first string
  600. var keyword1 string
  601. var keyword2 string
  602. var keyword3 string
  603. var keyword4 string
  604. var remark string
  605. //获取销售手机号
  606. sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  607. if err != nil && err.Error() != utils.ErrNoRow() {
  608. return err
  609. }
  610. if sellerItemQy != nil {
  611. sllerAndShareMobileArr, e := GetCompanySellerAndShareMobileByRai(user.CompanyId) //获取所属销售以及对应销售的手机号
  612. if e != nil {
  613. err = errors.New("GetCompanySellerAndShareMobileByRai, Err: " + e.Error())
  614. return
  615. }
  616. sllerAndShareMobiles := strings.Join(sllerAndShareMobileArr, ",")
  617. openIdList, e := models.GetWxOpenIdByMobileList(sllerAndShareMobiles)
  618. if e != nil {
  619. err = errors.New("GetSellerByAdminId, Err: " + e.Error())
  620. return
  621. }
  622. videoInfo, e := models.GetMicroRoadshowVideoByVideoId(videoId)
  623. if e != nil {
  624. err = errors.New("GetCygxActivitySpecialDetailById, Err: " + e.Error())
  625. return
  626. }
  627. if videoInfo == nil {
  628. return
  629. }
  630. first = fmt.Sprint(user.RealName, "--", user.CompanyName, ",有新的互动:播放微路演详视频")
  631. keyword1 = videoInfo.VideoName
  632. keyword2 = fmt.Sprint("互动:播放微路演详视频,", user.RealName, "--", user.CompanyName)
  633. remark = "点击查看微路演详情"
  634. openIdArr := make([]string, 0)
  635. for _, v := range openIdList {
  636. openIdArr = append(openIdArr, v.OpenId)
  637. }
  638. redirectUrl := utils.WX_MSG_PATH_ACTIVITY_INDUSTRYR_EPORT + strconv.Itoa(videoInfo.IndustryId)
  639. sendInfo := new(SendWxTemplate)
  640. sendInfo.First = first
  641. sendInfo.Keyword1 = keyword1
  642. sendInfo.Keyword2 = keyword2
  643. sendInfo.Keyword3 = keyword3
  644. sendInfo.Keyword4 = keyword4
  645. sendInfo.Remark = remark
  646. sendInfo.TemplateId = utils.WxMsgTemplateIdArticleUserRemind
  647. sendInfo.RedirectUrl = redirectUrl
  648. sendInfo.RedirectTarget = 3
  649. sendInfo.Resource = strconv.Itoa(videoId)
  650. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
  651. sendInfo.OpenIdArr = openIdArr
  652. err = PublicSendTemplateMsg(sendInfo)
  653. if err != nil {
  654. return
  655. }
  656. }
  657. return
  658. }
  659. // GetindustryVideoDetailById 通过视频ID获取视频详情
  660. func GetAskserieVideoDetailById(user *models.WxUserItem, askserieVideoId int) (industryVideo *models.MicroVideoSimpleInfo, AuthInfo *models.UserPermissionAuthInfo, err error) {
  661. total, e := models.GetCygxAskserieVideoCountByVideoId(askserieVideoId)
  662. if e != nil {
  663. err = errors.New("获取产业关联的视频失败,GetCygxAskserieVideoCountByVideoId " + e.Error())
  664. return
  665. }
  666. if total == 0 {
  667. err = errors.New("视频不存在,或已取消发布")
  668. return
  669. }
  670. // 用户权限
  671. authInfo, permissionArr, e := GetUserRaiPermissionInfo(user.UserId, user.CompanyId)
  672. if e != nil {
  673. err = errors.New("获取用户权限失败,GetUserRaiPermissionInfo " + e.Error())
  674. return
  675. }
  676. videoSimple := new(models.MicroVideoSimpleInfo)
  677. // 权限
  678. var au *models.UserPermissionAuthInfo
  679. video, e := models.GetCygxAskserieVideoDetail(askserieVideoId)
  680. if e != nil {
  681. err = errors.New("获取产业关联的视频失败,GetMicroRoadshowVideoByIndustryId " + e.Error())
  682. return
  683. } else {
  684. videoSimple.Id = video.AskserieVideoId
  685. videoSimple.Title = video.VideoName
  686. videoSimple.BackgroundImg = video.BackgroundImg
  687. videoSimple.DetailImgUrl = video.ShareImg
  688. if videoSimple.BackgroundImg == "" {
  689. // 获取默认图配置
  690. _, videoMap, _, _, e := GetMicroRoadShowDefaultImgConfig()
  691. if e != nil {
  692. err = errors.New("获取视频默认配置图失败,GetMicroRoadshowVideoByIndustryId " + e.Error())
  693. return
  694. }
  695. videoSimple.BackgroundImg = videoMap[video.ChartPermissionId]
  696. }
  697. videoSimple.PlaySeconds = video.VideoDuration
  698. videoSimple.ResourceUrl = video.VideoUrl
  699. au = new(models.UserPermissionAuthInfo)
  700. au.SellerName = authInfo.SellerName
  701. au.SellerMobile = authInfo.SellerMobile
  702. au.HasPermission = authInfo.HasPermission
  703. au.OperationMode = authInfo.OperationMode
  704. if au.HasPermission == 1 {
  705. // 非宏观权限进一步判断是否有权限
  706. if video.ChartPermissionId != utils.HONG_GUAN_ID && !utils.InArrayByStr(permissionArr, video.ChartPermissionName) {
  707. au.HasPermission = 2
  708. }
  709. }
  710. // 无权限的弹框提示
  711. if au.HasPermission != 1 {
  712. if au.OperationMode == UserPermissionOperationModeCall {
  713. au.PopupMsg = UserPermissionPopupMsgCallMicroVideo
  714. } else {
  715. au.PopupMsg = UserPermissionPopupMsgApplyMicroVideo
  716. }
  717. videoSimple.ResourceUrl = ""
  718. }
  719. }
  720. videoSimple.Type = 4
  721. industryVideo = videoSimple
  722. AuthInfo = au
  723. return
  724. }
  725. // 记录产业视频播放记录
  726. func AddMicroRoadshowVideoRecord(user *models.WxUserItem, videoId, playSeconds int) {
  727. // 十分钟之内的合并
  728. key := utils.CYGX_VIDEO_HISTORY_KEY + utils.CYGX_OBJ_ROADSHOW + strconv.Itoa(videoId) + "_" + strconv.Itoa(user.UserId)
  729. if utils.Rc.IsExist(key) {
  730. return
  731. }
  732. utils.Rc.Put(key, 1, 10*time.Minute)
  733. var err error
  734. defer func() {
  735. if err != nil {
  736. go utils.SendAlarmMsg(fmt.Sprint("记录用户活动音频播放记录失败 AddMicroRoadshowVideoRecord Err:", err.Error(), "videoId:", videoId, "UserId:", user.UserId), 2)
  737. }
  738. }()
  739. item := new(models.CygxMicroRoadshowVideoHistory)
  740. item.UserId = user.UserId
  741. item.RealName = user.RealName
  742. item.VideoId = videoId
  743. item.PlaySeconds = strconv.Itoa(playSeconds)
  744. item.Mobile = user.Mobile
  745. item.Email = user.Email
  746. item.CompanyId = user.CompanyId
  747. item.CompanyName = user.CompanyName
  748. item.CreateTime = time.Now()
  749. item.ModifyTime = time.Now()
  750. item.RegisterPlatform = utils.REGISTER_PLATFORM
  751. sellerItem, e := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  752. if e != nil && e.Error() != utils.ErrNoRow() {
  753. err = errors.New("GetSellerByCompanyIdCheckFicc, Err: " + e.Error())
  754. return
  755. }
  756. if sellerItem != nil {
  757. item.SellerName = sellerItem.RealName
  758. }
  759. e = models.AddCygxMicroRoadshowVideoHistory(item)
  760. if e != nil {
  761. err = errors.New("AddCygxMicroRoadshowVideoHistory, Err: " + e.Error())
  762. return
  763. }
  764. e = models.UpdateCygxActivityVideoCounts(videoId)
  765. if e != nil {
  766. err = errors.New("UpdateCygxActivityVideoCounts, Err: " + e.Error())
  767. return
  768. }
  769. go MicroRoadshowVideoUserRmind(user, videoId)
  770. return
  771. }
  772. // 记录所有微路演音视频播放记录
  773. func AddAllCygxVoiceAndVideoHistory(user *models.WxUserItem, sourceId, sourceType, playSeconds int) {
  774. var err error
  775. defer func() {
  776. if err != nil {
  777. go utils.SendAlarmMsg(fmt.Sprint("记录所有微路演音视频播放记录失败 AddAllCygxVoiceAndVideoHistory Err:", err.Error(), "sourceId:", sourceId, "UserId:", user.UserId), 2)
  778. }
  779. }()
  780. item := new(models.CygxVoiceAndVideoHistory)
  781. item.UserId = user.UserId
  782. item.RealName = user.RealName
  783. item.SourceId = sourceId
  784. item.SourceType = sourceType
  785. item.PlaySeconds = strconv.Itoa(playSeconds)
  786. item.Mobile = user.Mobile
  787. item.Email = user.Email
  788. item.CompanyId = user.CompanyId
  789. item.CompanyName = user.CompanyName
  790. item.CreateTime = time.Now()
  791. item.ModifyTime = time.Now()
  792. item.RegisterPlatform = utils.REGISTER_PLATFORM
  793. sellerItem, e := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  794. if e != nil && e.Error() != utils.ErrNoRow() {
  795. err = errors.New("GetSellerByCompanyIdCheckFicc, Err: " + e.Error())
  796. return
  797. }
  798. if sellerItem != nil {
  799. item.SellerName = sellerItem.RealName
  800. }
  801. _, e = models.AddCygxVoiceAndVideoHistory(item)
  802. if e != nil {
  803. err = errors.New("AddCygxVoiceAndVideoHistory, Err: " + e.Error())
  804. return
  805. }
  806. return
  807. }
  808. // 获取满足路演回放的活动类型
  809. func GetActivityLYHFMapByActivityIds(activityIds []int) (mapResp map[int]bool) {
  810. var err error
  811. defer func() {
  812. if err != nil {
  813. go utils.SendAlarmMsg("获取满足路演回放的活动类型 GetActivityLYHFMapByActivityIds,失败,活动ID:"+fmt.Sprint(activityIds)+err.Error(), 2)
  814. }
  815. }()
  816. var condition string
  817. var pars []interface{}
  818. lenArr := len(activityIds)
  819. if lenArr == 0 {
  820. return
  821. }
  822. condition = ` AND activity_id IN (` + utils.GetOrmInReplace(lenArr) + `) `
  823. pars = append(pars, activityIds)
  824. list, e := models.GetActivityListByCondition(condition, pars)
  825. if e != nil {
  826. err = errors.New("GetIndustrialManagementNewList, Err: " + e.Error())
  827. return
  828. }
  829. mapResp = make(map[int]bool, 0)
  830. for _, v := range list {
  831. mapResp[v.ActivityId] = true
  832. }
  833. return
  834. }