micro_roadshow.go 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734
  1. package services
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "fmt"
  6. "hongze/hongze_cygx/models"
  7. "hongze/hongze_cygx/utils"
  8. "strconv"
  9. "strings"
  10. )
  11. // GetMicroRoadShowDefaultImgConfig 获取微路演默认图/分享图配置
  12. func GetMicroRoadShowDefaultImgConfig() (audioMap, videoMap, audioShareMap, videoShareMap map[int]string, err error) {
  13. audioMap = make(map[int]string, 0)
  14. videoMap = make(map[int]string, 0)
  15. audioShareMap = make(map[int]string, 0)
  16. videoShareMap = make(map[int]string, 0)
  17. key := models.MicroRoadshowDefaultImgKey
  18. conf, e := models.GetConfigByCode(key)
  19. if e != nil {
  20. err = errors.New("获取微路演默认图配置失败, Err: " + e.Error())
  21. return
  22. }
  23. if conf.ConfigValue == "" {
  24. err = errors.New("获取微路演默认图配置有误")
  25. return
  26. }
  27. list := new(models.MicroRoadShowDefaultImgList)
  28. if e = json.Unmarshal([]byte(conf.ConfigValue), &list); e != nil {
  29. err = errors.New("微路演默认图配置配置值解析失败, Err: " + e.Error())
  30. return
  31. }
  32. audioList := list.Audio
  33. for i := range audioList {
  34. audioMap[audioList[i].ChartPermissionId] = audioList[i].ImgUrl
  35. audioShareMap[audioList[i].ChartPermissionId] = audioList[i].ShareImg
  36. }
  37. videoList := list.Video
  38. for i := range videoList {
  39. videoMap[videoList[i].ChartPermissionId] = videoList[i].ImgUrl
  40. videoShareMap[videoList[i].ChartPermissionId] = videoList[i].ShareImg
  41. }
  42. return
  43. }
  44. // GetHomeNewestList 获取首页最新列表
  45. func GetHomeNewestList(userId, companyId, startSize, pageSize int, condition string, pars []interface{}) (resp []*models.HomeArticle, total int, err error) {
  46. resp = make([]*models.HomeArticle, 0)
  47. unionList, e := models.GetHomeNewestListUnionList(condition, pars, startSize, pageSize)
  48. if e != nil {
  49. err = errors.New("获取首页最新列表失败")
  50. return
  51. }
  52. unionTotal, e := models.GetHomeNewestListUnionCount(condition, pars)
  53. if e != nil {
  54. err = errors.New("获取首页最新列表总数失败")
  55. return
  56. }
  57. total = unionTotal
  58. // 用户权限
  59. authInfo, permissionArr, e := GetUserRaiPermissionInfo(userId, companyId)
  60. if e != nil {
  61. err = errors.New("获取用户权限失败, Err: " + e.Error())
  62. return
  63. }
  64. // 获取默认图配置
  65. audioMap, videoMap, audioShareMap, videoShareMap, e := GetMicroRoadShowDefaultImgConfig()
  66. if e != nil {
  67. err = errors.New("获取微路演默认图配置失败, Err: " + e.Error())
  68. return
  69. }
  70. // 此处没有直接使用HomeArticle结构体而是多加了一层, 纯粹是为了方便前端区分纪要和微路演音频=_=!
  71. for _, v := range unionList {
  72. item := new(models.HomeArticle)
  73. item.HomeType = v.HomeType
  74. // 纪要
  75. if item.HomeType == 0 {
  76. item.ArticleId = v.ArticleId
  77. item.Title = v.Title
  78. item.TitleEn = v.TitleEn
  79. item.UpdateFrequency = v.UpdateFrequency
  80. item.CreateDate = v.CreateDate
  81. item.PublishDate = v.PublishDate
  82. item.Body = v.Body
  83. item.BodyHtml = v.BodyHtml
  84. item.Abstract = v.Abstract
  85. item.CategoryName = v.CategoryName
  86. item.SubCategoryName = v.SubCategoryName
  87. item.ExpertBackground = v.ExpertBackground
  88. item.IsResearch = v.IsResearch
  89. item.Pv = v.Pv
  90. item.ImgUrlPc = v.ImgUrlPc
  91. item.CategoryId = v.CategoryId
  92. item.HttpUrl = v.HttpUrl
  93. item.IsNeedJump = v.IsNeedJump
  94. item.Source = v.Source
  95. item.Annotation = v.Annotation
  96. }
  97. // 音频
  98. if v.HomeType == 1 {
  99. ad := new(models.MicroAudioUnionList)
  100. ad.Id = v.Id
  101. ad.AudioTitle = v.AudioTitle
  102. ad.AudioResourceUrl = v.AudioResourceUrl
  103. ad.AudioType = v.AudioType
  104. ad.AudioPublishTime = utils.StrTimeToTime(v.AudioPublishTime).Format(utils.FormatDate)
  105. ad.AudioImgUrl = v.AudioImgUrl
  106. ad.AudioChartPermissionId = v.AudioChartPermissionId
  107. ad.AudioChartPermissionName = v.AudioChartPermissionName
  108. ad.AudioPlaySeconds = v.AudioPlaySeconds
  109. ad.AudioPlaySeconds = v.AudioPlaySeconds
  110. ad.AudioActivityId = v.AudioActivityId
  111. item.MicroAudio = ad
  112. // 默认图
  113. if ad.AudioImgUrl == "" {
  114. if ad.AudioType == 1 {
  115. ad.AudioImgUrl = audioMap[ad.AudioChartPermissionId]
  116. } else {
  117. ad.AudioImgUrl = videoMap[ad.AudioChartPermissionId]
  118. }
  119. }
  120. // 分享图
  121. if ad.AudioType == 1 {
  122. ad.AudioShareImg = audioShareMap[ad.AudioChartPermissionId]
  123. } else {
  124. ad.AudioShareImg = videoShareMap[ad.AudioChartPermissionId]
  125. }
  126. // 权限
  127. au := new(models.UserPermissionAuthInfo)
  128. au.SellerName = authInfo.SellerName
  129. au.SellerMobile = authInfo.SellerMobile
  130. au.HasPermission = authInfo.HasPermission
  131. au.OperationMode = authInfo.OperationMode
  132. if au.HasPermission == 1 {
  133. // 非宏观权限进一步判断是否有权限
  134. if ad.AudioChartPermissionId != utils.HONG_GUAN_ID && !utils.InArrayByStr(permissionArr, ad.AudioChartPermissionName) {
  135. au.HasPermission = 2
  136. }
  137. }
  138. // 无权限的弹框提示
  139. if au.HasPermission != 1 {
  140. if au.OperationMode == UserPermissionOperationModeCall {
  141. if ad.AudioType == 1 {
  142. au.PopupMsg = UserPermissionPopupMsgCallActivity
  143. } else {
  144. au.PopupMsg = UserPermissionPopupMsgCallMicroVideo
  145. }
  146. } else {
  147. if ad.AudioType == 1 {
  148. au.PopupMsg = UserPermissionPopupMsgApplyActivity
  149. } else {
  150. au.PopupMsg = UserPermissionPopupMsgApplyMicroVideo
  151. }
  152. }
  153. }
  154. ad.AuthInfo = au
  155. }
  156. resp = append(resp, item)
  157. }
  158. return
  159. }
  160. // GetMicroRoadShowPageList 获取微路演列表添加活动视频 更新与8.1版本
  161. func GetMicroRoadShowPageListV8(pageSize, currentIndex, audioId, videoId, activityVideoId int, filter, keywords, audioIds, videoIds, activityVideoIds string) (respList []*models.MicroRoadShowPageList, total int, err error) {
  162. var e error
  163. // 根据每页数据量获取音视频配比
  164. startSize := utils.StartIndex(currentIndex, pageSize)
  165. videoList := make([]*models.MicroRoadShowPageList, 0)
  166. if keywords != "" {
  167. keywords = "%" + keywords + "%"
  168. }
  169. //音频的查询
  170. var audioCond string
  171. var audioPars []interface{}
  172. // 如果筛选条件为指定视频ID或只看视频则不做音频查询
  173. //if videoId > 0 || activityVideoId > 0 || filter == 1 {
  174. // audioCond = ""
  175. //} else {
  176. // 活动已发布且已结束
  177. audioCond += ` AND b.publish_status = 1 AND b.active_state = 3`
  178. //活动音频,设置有效时间为30天,失效后该活动就不再支持音频回放。有效期起始时间为活动的开始时间
  179. //endTime := time.Now().AddDate(0, 0, -30).Format("2006-01-02 15:04:05")
  180. //audioCond += ` AND b.activity_time > ? `
  181. //audioPars = append(audioPars, endTime)
  182. if keywords != "" {
  183. audioCond += ` AND ( a.voice_name LIKE ? OR b.label LIKE ? )`
  184. audioPars = append(audioPars, keywords, keywords)
  185. }
  186. if audioId > 0 {
  187. audioCond += ` AND a.activity_voice_id = ?`
  188. audioPars = append(audioPars, audioId)
  189. }
  190. if audioIds != "" {
  191. sliceId := strings.Split(audioIds, ",")
  192. var idSqlStr string
  193. for _, v := range sliceId {
  194. idSqlStr += "'" + v + "',"
  195. }
  196. idSqlStr = strings.TrimRight(idSqlStr, ",")
  197. audioCond += ` AND a.activity_voice_id IN (` + idSqlStr + `)`
  198. }
  199. //}
  200. //视频的处理
  201. var videoCond string
  202. var videoCondAct string
  203. var videoPars []interface{}
  204. var videoParsAct []interface{}
  205. //if audioId > 0 || filter == 2 {
  206. // videoCond = ""
  207. //} else {
  208. if keywords != "" {
  209. videoCond += ` AND video_name LIKE ?`
  210. videoPars = append(videoPars, keywords)
  211. videoCondAct += ` AND (video_name LIKE ? OR art.label LIKE ?)`
  212. videoParsAct = append(videoParsAct, keywords, keywords)
  213. }
  214. if videoId > 0 {
  215. videoCond += ` AND video_id = ?`
  216. videoPars = append(videoPars, videoId)
  217. }
  218. if activityVideoId > 0 {
  219. videoCondAct += ` AND video_id = ?`
  220. videoParsAct = append(videoParsAct, activityVideoId)
  221. }
  222. if activityVideoIds != "" {
  223. sliceId := strings.Split(activityVideoIds, ",")
  224. var idSqlStr string
  225. for _, v := range sliceId {
  226. idSqlStr += "'" + v + "',"
  227. }
  228. idSqlStr = strings.TrimRight(idSqlStr, ",")
  229. videoCondAct += ` AND v.video_id IN (` + idSqlStr + `)`
  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 videoIds != "" {
  257. sliceId := strings.Split(videoIds, ",")
  258. var idSqlStr string
  259. for _, v := range sliceId {
  260. idSqlStr += "'" + v + "',"
  261. }
  262. idSqlStr = strings.TrimRight(idSqlStr, ",")
  263. videoCond += ` AND video_id IN (` + idSqlStr + `)`
  264. }
  265. videoCond += ` AND publish_status = 1`
  266. //}
  267. total, videoList, e = models.GetMicroRoadShowVideoPageListV8(startSize, pageSize, videoCond, videoPars, videoCondAct, videoParsAct, audioCond, audioPars)
  268. if e != nil {
  269. err = errors.New("获取微路演音视频列表失败, Err: " + e.Error())
  270. return
  271. }
  272. respList = videoList
  273. return
  274. }
  275. // GetMicroRoadShowPageListIkWord 添加IK分词联想词 获取微路演列表添加活动视频 更新与8.1版本
  276. func CountMicroRoadShowPageListIkWord(audioId, videoId, activityVideoId int, keywordArr []string, filter, audioIds, videoIds, activityVideoIds string) (total int, err error) {
  277. var e error
  278. var keywords string
  279. if len(keywordArr) > 0 {
  280. keywords = KeyWordArrSqlRegexpAll(keywordArr)
  281. }
  282. //if keywords == "" {
  283. // return
  284. //}
  285. //音频的查询
  286. var audioCond string
  287. var audioPars []interface{}
  288. // 如果筛选条件为指定视频ID或只看视频则不做音频查询
  289. //if videoId > 0 || activityVideoId > 0 || filter == 1 {
  290. // audioCond += ` AND a.activity_voice_id = 0 `
  291. //} else {
  292. // 活动已发布且已结束
  293. audioCond += ` AND b.publish_status = 1 AND b.active_state = 3`
  294. if keywords != "" {
  295. audioCond += ` AND (a.voice_name REGEXP ? OR b.label REGEXP ? ) `
  296. audioPars = append(audioPars, keywords, keywords)
  297. }
  298. if audioId > 0 {
  299. audioCond += ` AND a.activity_voice_id = ?`
  300. audioPars = append(audioPars, audioId)
  301. }
  302. if audioIds != "" {
  303. sliceId := strings.Split(audioIds, ",")
  304. var idSqlStr string
  305. for _, v := range sliceId {
  306. idSqlStr += "'" + v + "',"
  307. }
  308. idSqlStr = strings.TrimRight(idSqlStr, ",")
  309. audioCond += ` AND a.activity_voice_id IN (` + idSqlStr + `)`
  310. }
  311. //}
  312. //视频的处理
  313. var videoCond string
  314. var videoCondAct string
  315. var videoPars []interface{}
  316. var videoParsAct []interface{}
  317. //if audioId > 0 || filter == 2 {
  318. // videoCond = ""
  319. //} else {
  320. if keywords != "" {
  321. videoCond += ` AND video_name REGEXP ? `
  322. videoPars = append(videoPars, keywords)
  323. videoCondAct += ` AND (video_name REGEXP ? OR art.label REGEXP ? )`
  324. videoParsAct = append(videoParsAct, keywords, keywords)
  325. }
  326. if videoId > 0 {
  327. videoCond += ` AND video_id = ? `
  328. videoPars = append(videoPars, videoId)
  329. }
  330. if activityVideoId > 0 {
  331. videoCondAct += ` AND video_id = ?`
  332. videoParsAct = append(videoParsAct, activityVideoId)
  333. }
  334. if activityVideoIds != "" {
  335. sliceId := strings.Split(activityVideoIds, ",")
  336. var idSqlStr string
  337. for _, v := range sliceId {
  338. idSqlStr += "'" + v + "',"
  339. }
  340. idSqlStr = strings.TrimRight(idSqlStr, ",")
  341. videoCondAct += ` AND v.video_id IN (` + idSqlStr + `)`
  342. }
  343. //如果传了路演的或者活动的视频ID只查询一个
  344. if videoId > 0 {
  345. videoCondAct += ` AND video_id = 0 `
  346. audioCond += ` AND a.activity_voice_id = 0 `
  347. }
  348. if activityVideoId > 0 {
  349. videoCond += ` AND video_id = 0 `
  350. audioCond += ` AND a.activity_voice_id = 0 `
  351. }
  352. if audioId > 0 {
  353. videoCondAct += ` AND video_id = 0 `
  354. videoCond += ` AND video_id = 0 `
  355. }
  356. if strings.Contains(filter, "1") && !strings.Contains(filter, "2") {
  357. audioCond += ` AND a.activity_voice_id = 0 `
  358. } else if !strings.Contains(filter, "1") && strings.Contains(filter, "2") {
  359. videoCondAct += ` AND video_id = 0 `
  360. videoCond += ` AND video_id = 0 `
  361. }
  362. if strings.Contains(filter, "3") && !strings.Contains(filter, "4") {
  363. audioCond += ` AND a.activity_voice_id = 0 `
  364. videoCondAct += ` AND video_id = 0 `
  365. } else if strings.Contains(filter, "3") && !strings.Contains(filter, "4") {
  366. videoCond += ` AND video_id = 0 `
  367. }
  368. if videoIds != "" {
  369. sliceId := strings.Split(videoIds, ",")
  370. var idSqlStr string
  371. for _, v := range sliceId {
  372. idSqlStr += "'" + v + "',"
  373. }
  374. idSqlStr = strings.TrimRight(idSqlStr, ",")
  375. videoCond += ` AND video_id IN (` + idSqlStr + `)`
  376. }
  377. videoCond += ` AND publish_status = 1`
  378. //}
  379. total, e = models.CountMicroRoadShowVideoPageList(videoCond, videoPars, videoCondAct, videoParsAct, audioCond, audioPars)
  380. if e != nil {
  381. err = errors.New("获取微路演音视频列表失败, Err: " + e.Error())
  382. return
  383. }
  384. return
  385. }
  386. // GetMicroRoadShowPageListIkWord 添加IK分词联想词 获取微路演列表添加活动视频 更新与8.1版本
  387. func GetMicroRoadShowPageListIkWord(startSize, pageSize, audioId, videoId, activityVideoId int, keywordArr []string, filter, audioIds, videoIds, activityVideoIds, keywords string) (respList []*models.MicroRoadShowPageList, err error) {
  388. videoList := make([]*models.MicroRoadShowPageList, 0)
  389. var e error
  390. var keywordsIk string
  391. if len(keywordArr) > 1 {
  392. keywordsIk = KeyWordArrSqlRegexp(keywordArr)
  393. }
  394. if keywords != "" {
  395. keywords = "%" + keywords + "%"
  396. }
  397. //音频的查询
  398. var audioCond string
  399. var audioPars []interface{}
  400. // 如果筛选条件为指定视频ID或只看视频则不做音频查询
  401. //if videoId > 0 || activityVideoId > 0 || filter == 1 {
  402. // audioCond += ` AND a.activity_voice_id = 0 `
  403. //} else {
  404. // 活动已发布且已结束
  405. audioCond += ` AND b.publish_status = 1 AND b.active_state = 3`
  406. if keywordsIk != "" {
  407. audioCond += ` AND ( a.voice_name REGEXP ? OR b.label REGEXP ? )`
  408. audioCond += ` AND ( a.voice_name NOT LIKE ? AND b.label NOT LIKE ? )`
  409. audioPars = append(audioPars, keywordsIk, keywordsIk, keywords, keywords)
  410. }
  411. if audioId > 0 {
  412. audioCond += ` AND a.activity_voice_id = ?`
  413. audioPars = append(audioPars, audioId)
  414. }
  415. if audioIds != "" {
  416. sliceId := strings.Split(audioIds, ",")
  417. var idSqlStr string
  418. for _, v := range sliceId {
  419. idSqlStr += "'" + v + "',"
  420. }
  421. idSqlStr = strings.TrimRight(idSqlStr, ",")
  422. audioCond += ` AND a.activity_voice_id IN (` + idSqlStr + `)`
  423. }
  424. //}
  425. //视频的处理
  426. var videoCond string
  427. var videoCondAct string
  428. var videoPars []interface{}
  429. var videoParsAct []interface{}
  430. //if audioId > 0 || filter == 2 {
  431. // videoCond = ""
  432. //} else {
  433. if keywordsIk != "" {
  434. videoCond += ` AND video_name REGEXP ?`
  435. videoPars = append(videoPars, keywordsIk)
  436. videoCondAct += ` AND ( v.video_name REGEXP ? OR art.label REGEXP ? )`
  437. videoCondAct += ` AND ( v.video_name NOT LIKE ? AND art.label NOT LIKE ? )`
  438. //videoCondAct += ` AND video_name REGEXP ?`
  439. videoParsAct = append(videoParsAct, keywordsIk, keywordsIk, keywords, keywords)
  440. }
  441. if videoId > 0 {
  442. videoCond += ` AND video_id = ?`
  443. videoPars = append(videoPars, videoId)
  444. }
  445. if activityVideoId > 0 {
  446. videoCondAct += ` AND video_id = ?`
  447. videoParsAct = append(videoParsAct, activityVideoId)
  448. }
  449. if activityVideoIds != "" {
  450. sliceId := strings.Split(activityVideoIds, ",")
  451. var idSqlStr string
  452. for _, v := range sliceId {
  453. idSqlStr += "'" + v + "',"
  454. }
  455. idSqlStr = strings.TrimRight(idSqlStr, ",")
  456. videoCondAct += ` AND v.video_id IN (` + idSqlStr + `)`
  457. }
  458. //如果传了路演的或者活动的视频ID只查询一个
  459. if videoId > 0 {
  460. videoCondAct += ` AND video_id = 0 `
  461. audioCond += ` AND a.activity_voice_id = 0 `
  462. }
  463. if activityVideoId > 0 {
  464. videoCond += ` AND video_id = 0 `
  465. audioCond += ` AND a.activity_voice_id = 0 `
  466. }
  467. if audioId > 0 {
  468. videoCondAct += ` AND video_id = 0 `
  469. videoCond += ` AND video_id = 0 `
  470. }
  471. if strings.Contains(filter, "1") && !strings.Contains(filter, "2") {
  472. audioCond += ` AND a.activity_voice_id = 0 `
  473. } else if !strings.Contains(filter, "1") && strings.Contains(filter, "2") {
  474. videoCondAct += ` AND video_id = 0 `
  475. videoCond += ` AND video_id = 0 `
  476. }
  477. if strings.Contains(filter, "3") && !strings.Contains(filter, "4") {
  478. audioCond += ` AND a.activity_voice_id = 0 `
  479. videoCondAct += ` AND video_id = 0 `
  480. } else if strings.Contains(filter, "3") && !strings.Contains(filter, "4") {
  481. videoCond += ` AND video_id = 0 `
  482. }
  483. if videoIds != "" {
  484. sliceId := strings.Split(videoIds, ",")
  485. var idSqlStr string
  486. for _, v := range sliceId {
  487. idSqlStr += "'" + v + "',"
  488. }
  489. idSqlStr = strings.TrimRight(idSqlStr, ",")
  490. videoCond += ` AND video_id IN (` + idSqlStr + `)`
  491. }
  492. videoCond += ` AND publish_status = 1`
  493. //}
  494. videoList, e = models.GetMicroRoadShowVideoPageListIkWord(startSize, pageSize, videoCond, videoPars, videoCondAct, videoParsAct, audioCond, audioPars)
  495. if e != nil {
  496. err = errors.New("获取微路演音视频列表失败分词, Err: " + e.Error())
  497. return
  498. }
  499. respList = videoList
  500. return
  501. }
  502. // 我的收藏
  503. func GetMicroRoadShowMycollect(pageSize, currentIndex int, audioIds, videoIds, activityVideoIds string) (respList []*models.MicroRoadShowPageList, total int, err error) {
  504. var e error
  505. // 根据每页数据量获取音视频配比
  506. startSize := utils.StartIndex(currentIndex, pageSize)
  507. videoList := make([]*models.MicroRoadShowPageList, 0)
  508. //音频的查询
  509. var audioCond string
  510. var audioPars []interface{}
  511. // 如果筛选条件为指定视频ID或只看视频则不做音频查询
  512. // 活动已发布且已结束
  513. audioCond += ` AND b.publish_status = 1 AND b.active_state = 3`
  514. if audioIds != "" {
  515. sliceId := strings.Split(audioIds, ",")
  516. var idSqlStr string
  517. for _, v := range sliceId {
  518. idSqlStr += "'" + v + "',"
  519. }
  520. idSqlStr = strings.TrimRight(idSqlStr, ",")
  521. audioCond += ` AND a.activity_voice_id IN (` + idSqlStr + `)`
  522. } else {
  523. audioCond += ` AND a.activity_voice_id = 0 `
  524. }
  525. //视频的处理
  526. var videoCond string
  527. var videoCondAct string
  528. if activityVideoIds != "" {
  529. sliceId := strings.Split(activityVideoIds, ",")
  530. var idSqlStr string
  531. for _, v := range sliceId {
  532. idSqlStr += "'" + v + "',"
  533. }
  534. idSqlStr = strings.TrimRight(idSqlStr, ",")
  535. videoCondAct += ` AND v.video_id IN (` + idSqlStr + `)`
  536. } else {
  537. videoCondAct += ` AND v.video_id = 0 `
  538. }
  539. var videoPars []interface{}
  540. var videoParsAct []interface{}
  541. if videoIds != "" {
  542. sliceId := strings.Split(videoIds, ",")
  543. var idSqlStr string
  544. for _, v := range sliceId {
  545. idSqlStr += "'" + v + "',"
  546. }
  547. idSqlStr = strings.TrimRight(idSqlStr, ",")
  548. videoCond += ` AND video_id IN (` + idSqlStr + `)`
  549. } else {
  550. videoCond += ` AND video_id = 0 `
  551. }
  552. videoCond += ` AND publish_status = 1`
  553. total, videoList, e = models.GetMicroRoadShowVideoPageListV8(startSize, pageSize, videoCond, videoPars, videoCondAct, videoParsAct, audioCond, audioPars)
  554. if e != nil {
  555. err = errors.New("获取微路演音视频列表失败, Err: " + e.Error())
  556. return
  557. }
  558. respList = videoList
  559. return
  560. }
  561. // GetMicroRoadshowVideoMap 获取已经发布的微路演的产业ID
  562. func GetMicroRoadshowVideoMap() (items map[int]int, err error) {
  563. list, e := models.GetMicroRoadshowVideoList()
  564. if e != nil && e.Error() != utils.ErrNoRow() {
  565. err = errors.New("获取已经发布的微路演的产业失败,GetMicroRoadshowVideoList " + e.Error())
  566. return
  567. }
  568. mapindustrialId := make(map[int]int)
  569. for _, v := range list {
  570. mapindustrialId[v.IndustryId] = v.IndustryId
  571. }
  572. items = mapindustrialId
  573. return
  574. }
  575. func GetindustryVideo(user *models.WxUserItem, industrialManagementId int) (industryVideo *models.MicroVideoSimpleInfo, AuthInfo *models.UserPermissionAuthInfo, err error) {
  576. total, e := models.GetMicroRoadshowVideoByIndustryIdCount(industrialManagementId)
  577. if e != nil {
  578. err = errors.New("获取产业关联的视频失败,GetMicroRoadshowVideoByIndustryIdCount " + e.Error())
  579. return
  580. }
  581. if total == 0 {
  582. return
  583. }
  584. // 用户权限
  585. authInfo, permissionArr, e := GetUserRaiPermissionInfo(user.UserId, user.CompanyId)
  586. if e != nil {
  587. err = errors.New("获取用户权限失败,GetUserRaiPermissionInfo " + e.Error())
  588. return
  589. }
  590. videoSimple := new(models.MicroVideoSimpleInfo)
  591. // 权限
  592. var au *models.UserPermissionAuthInfo
  593. video, e := models.GetMicroRoadshowVideoByIndustryId(industrialManagementId)
  594. if e != nil {
  595. err = errors.New("获取产业关联的视频失败,GetMicroRoadshowVideoByIndustryId " + e.Error())
  596. return
  597. } else {
  598. videoSimple.Id = video.VideoId
  599. videoSimple.Title = "5min【" + video.IndustryName + "】逻辑解析"
  600. videoSimple.BackgroundImg = video.ImgUrl
  601. videoSimple.DetailImgUrl = video.DetailImgUrl
  602. if videoSimple.BackgroundImg == "" {
  603. // 获取默认图配置
  604. _, videoMap, _, _, e := GetMicroRoadShowDefaultImgConfig()
  605. if e != nil {
  606. err = errors.New("获取视频默认配置图失败,GetMicroRoadshowVideoByIndustryId " + e.Error())
  607. return
  608. }
  609. videoSimple.BackgroundImg = videoMap[video.ChartPermissionId]
  610. }
  611. videoSimple.PlaySeconds = video.VideoDuration
  612. videoSimple.ResourceUrl = video.VideoUrl
  613. au = new(models.UserPermissionAuthInfo)
  614. au.SellerName = authInfo.SellerName
  615. au.SellerMobile = authInfo.SellerMobile
  616. au.HasPermission = authInfo.HasPermission
  617. au.OperationMode = authInfo.OperationMode
  618. if au.HasPermission == 1 {
  619. // 非宏观权限进一步判断是否有权限
  620. if video.ChartPermissionId != utils.HONG_GUAN_ID && !utils.InArrayByStr(permissionArr, video.ChartPermissionName) {
  621. au.HasPermission = 2
  622. }
  623. }
  624. // 无权限的弹框提示
  625. if au.HasPermission != 1 {
  626. if au.OperationMode == UserPermissionOperationModeCall {
  627. au.PopupMsg = UserPermissionPopupMsgCallMicroVideo
  628. } else {
  629. au.PopupMsg = UserPermissionPopupMsgApplyMicroVideo
  630. }
  631. videoSimple.ResourceUrl = ""
  632. }
  633. }
  634. industryVideo = videoSimple
  635. AuthInfo = au
  636. return
  637. }
  638. // 用户微路演视频回放操作操作行为,模板消息推送
  639. func MicroRoadshowVideoUserRmind(user *models.WxUserItem, videoId int) (err error) {
  640. defer func() {
  641. if err != nil {
  642. go utils.SendAlarmMsg("用户音视频回放操作操作行为,模板消息推送失败"+err.Error(), 2)
  643. }
  644. }()
  645. countUser, err := models.GetUserRemind(user.UserId)
  646. if err != nil {
  647. return err
  648. }
  649. if countUser == 0 {
  650. return err
  651. }
  652. var first string
  653. var keyword1 string
  654. var keyword2 string
  655. var keyword3 string
  656. var keyword4 string
  657. var remark string
  658. //获取销售手机号
  659. sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  660. if err != nil && err.Error() != utils.ErrNoRow() {
  661. return err
  662. }
  663. if sellerItemQy != nil {
  664. openIdList, e := models.GetWxOpenIdByMobileList(sellerItemQy.Mobile)
  665. if e != nil {
  666. err = errors.New("GetSellerByAdminId, Err: " + e.Error())
  667. return
  668. }
  669. videoInfo, e := models.GetMicroRoadshowVideoByVideoId(videoId)
  670. if e != nil {
  671. err = errors.New("GetCygxActivitySpecialDetailById, Err: " + e.Error())
  672. return
  673. }
  674. if videoInfo == nil {
  675. return
  676. }
  677. first = fmt.Sprint(user.RealName, "--", user.CompanyName, ",有新的互动:播放微路演详视频")
  678. keyword1 = videoInfo.VideoName
  679. keyword2 = fmt.Sprint("互动:播放微路演详视频,", user.RealName, "--", user.CompanyName)
  680. remark = "点击查看微路演详情"
  681. openIdArr := make([]string, 0)
  682. for _, v := range openIdList {
  683. openIdArr = append(openIdArr, v.OpenId)
  684. }
  685. redirectUrl := utils.WX_MSG_PATH_ACTIVITY_INDUSTRYR_EPORT + strconv.Itoa(videoInfo.IndustryId)
  686. sendInfo := new(SendWxTemplate)
  687. sendInfo.First = first
  688. sendInfo.Keyword1 = keyword1
  689. sendInfo.Keyword2 = keyword2
  690. sendInfo.Keyword3 = keyword3
  691. sendInfo.Keyword4 = keyword4
  692. sendInfo.Remark = remark
  693. sendInfo.TemplateId = utils.WxMsgTemplateIdArticleUserRemind
  694. sendInfo.RedirectUrl = redirectUrl
  695. sendInfo.RedirectTarget = 3
  696. sendInfo.Resource = strconv.Itoa(videoId)
  697. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
  698. sendInfo.OpenIdArr = openIdArr
  699. err = PublicSendTemplateMsg(sendInfo)
  700. if err != nil {
  701. return
  702. }
  703. }
  704. return
  705. }