micro_roadshow.go 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "hongze/hongze_cygx/models"
  6. "hongze/hongze_cygx/services"
  7. "hongze/hongze_cygx/utils"
  8. "strconv"
  9. "time"
  10. )
  11. // 微路演
  12. type MicroRoadShowController struct {
  13. BaseAuthController
  14. }
  15. // @Title 微路演列表
  16. // @Description 微路演列表接口
  17. // @Param PageSize query int true "每页数据条数"
  18. // @Param CurrentIndex query int true "当前页页码,从1开始"
  19. // @Param KeyWord query string false "搜索关键词"
  20. // @Param AudioId query int false "音频ID"
  21. // @Param VideoId query int false "视频ID"
  22. // @Param AudioIds query string false "活动音频IDs"
  23. // @Param ActivityVideoIds query string false "活动视频IDs"
  24. // @Param VideoIds query string false "视频IDs"
  25. // @Param ActivityVideoId query int false "活动视频ID"
  26. // @Param Filter query int false "筛选条件 0:全部 1:视频 2:音频"
  27. // @Success 200 {object} models.HomeListResp
  28. // @router /list [get]
  29. func (this *MicroRoadShowController) List() {
  30. br := new(models.BaseResponse).Init()
  31. defer func() {
  32. this.Data["json"] = br
  33. this.ServeJSON()
  34. }()
  35. user := this.User
  36. if user == nil {
  37. br.Msg = "请登录"
  38. br.ErrMsg = "请登录,用户信息为空"
  39. br.Ret = 408
  40. return
  41. }
  42. pageSize, _ := this.GetInt("PageSize")
  43. currentIndex, _ := this.GetInt("CurrentIndex")
  44. keywords := this.GetString("KeyWord")
  45. audioId, _ := this.GetInt("AudioId")
  46. videoId, _ := this.GetInt("VideoId")
  47. audioIds := this.GetString("AudioIds")
  48. videoIds := this.GetString("VideoIds")
  49. activityVideoIds := this.GetString("ActivityVideoIds")
  50. activityVideoId, _ := this.GetInt("ActivityVideoId")
  51. filter, _ := this.GetInt("Filter", 0)
  52. if pageSize <= 0 {
  53. pageSize = utils.PageSize20
  54. }
  55. if currentIndex <= 0 {
  56. currentIndex = 1
  57. }
  58. // 微路演列表
  59. list, total, e := services.GetMicroRoadShowPageListV8(pageSize, currentIndex, audioId, videoId, activityVideoId, filter, keywords, audioIds, videoIds, activityVideoIds)
  60. if e != nil {
  61. br.Msg = "获取失败"
  62. br.ErrMsg = "获取微路演列表失败, Err: " + e.Error()
  63. return
  64. }
  65. for _, item := range list {
  66. if item.Type == 1 {
  67. //音频
  68. count, err := models.GetVoiceCollectCount(user.UserId, item.Id)
  69. if err != nil {
  70. br.Msg = "获取数据失败!"
  71. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  72. return
  73. }
  74. if count > 0 {
  75. item.IsCollect = true
  76. }
  77. } else if item.Type == 2 {
  78. //活动视频
  79. count, err := models.GetActivityVideoCollectCount(user.UserId, item.Id)
  80. if err != nil {
  81. br.Msg = "获取数据失败!"
  82. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  83. return
  84. }
  85. if count > 0 {
  86. item.IsCollect = true
  87. }
  88. } else if item.Type == 3 {
  89. //微路演视频
  90. count, err := models.GetVideoCollectCount(user.UserId, item.Id)
  91. if err != nil {
  92. br.Msg = "获取数据失败!"
  93. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  94. return
  95. }
  96. if count > 0 {
  97. item.IsCollect = true
  98. }
  99. }
  100. }
  101. // 用户权限
  102. authInfo, permissionArr, e := services.GetUserRaiPermissionInfo(user.UserId, user.CompanyId)
  103. if e != nil {
  104. br.Msg = "获取失败"
  105. br.ErrMsg = "获取用户权限失败, Err: " + e.Error()
  106. return
  107. }
  108. // 获取默认图配置
  109. audioMap, videoMap, audioShareMap, videoShareMap, e := services.GetMicroRoadShowDefaultImgConfig()
  110. if e != nil {
  111. br.Msg = "获取失败"
  112. br.ErrMsg = "获取微路演列表失败, Err: " + e.Error()
  113. return
  114. }
  115. for i := range list {
  116. // 权限
  117. au := new(models.UserPermissionAuthInfo)
  118. au.SellerName = authInfo.SellerName
  119. au.SellerMobile = authInfo.SellerMobile
  120. au.HasPermission = authInfo.HasPermission
  121. au.OperationMode = authInfo.OperationMode
  122. if au.HasPermission == 1 {
  123. // 非宏观权限进一步判断是否有权限
  124. if list[i].ChartPermissionId != utils.HONG_GUAN_ID && !utils.InArrayByStr(permissionArr, list[i].ChartPermissionName) {
  125. au.HasPermission = 2
  126. }
  127. }
  128. // 无权限的弹框提示
  129. if au.HasPermission != 1 {
  130. if au.OperationMode == services.UserPermissionOperationModeCall {
  131. if list[i].Type == 1 {
  132. au.PopupMsg = services.UserPermissionPopupMsgCallActivity
  133. } else {
  134. au.PopupMsg = services.UserPermissionPopupMsgCallMicroVideo
  135. }
  136. } else {
  137. if list[i].Type == 1 {
  138. au.PopupMsg = services.UserPermissionPopupMsgApplyActivity
  139. } else {
  140. au.PopupMsg = services.UserPermissionPopupMsgApplyMicroVideo
  141. }
  142. }
  143. }
  144. list[i].AuthInfo = au
  145. list[i].PublishTime = utils.StrTimeToTime(list[i].PublishTime).Format(utils.FormatDate)
  146. // 默认图
  147. if list[i].BackgroundImg == "" {
  148. if list[i].Type == 1 {
  149. list[i].BackgroundImg = audioMap[list[i].ChartPermissionId]
  150. } else {
  151. list[i].BackgroundImg = videoMap[list[i].ChartPermissionId]
  152. }
  153. }
  154. // 分享图
  155. if list[i].ShareImg == "" {
  156. if list[i].Type == 1 {
  157. list[i].ShareImg = audioShareMap[list[i].ChartPermissionId]
  158. } else {
  159. list[i].ShareImg = videoShareMap[list[i].ChartPermissionId]
  160. }
  161. }
  162. //修改产业视频的标题
  163. //if list[i].Type == 3 && list[i].IndustryName != "" {
  164. // list[i].Title = "5min" + "【" + list[i].IndustryName + "】" + "逻辑解析"
  165. //}
  166. }
  167. resp := new(models.MicroRoadShowListResp)
  168. page := paging.GetPaging(currentIndex, pageSize, total)
  169. resp.List = list
  170. resp.Paging = page
  171. br.Ret = 200
  172. br.Success = true
  173. br.Msg = "获取成功"
  174. br.Data = resp
  175. }
  176. // @Title 记录用户浏览音频回放接口
  177. // @Description 记录用户浏览音频回放接口
  178. // @Param request body models.ActivityIdRep true "type json string"
  179. // @Success Ret=200 {object} models.AppointmentResp
  180. // @router /videoHistory/add [post]
  181. func (this *MicroRoadShowController) VideoHistoryAdd() {
  182. br := new(models.BaseResponse).Init()
  183. defer func() {
  184. this.Data["json"] = br
  185. this.ServeJSON()
  186. }()
  187. user := this.User
  188. if user == nil {
  189. br.Msg = "请登录"
  190. br.ErrMsg = "请登录,用户信息为空"
  191. br.Ret = 408
  192. return
  193. }
  194. uid := user.UserId
  195. var req models.AddVideoHistoryReq
  196. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  197. if err != nil {
  198. br.Msg = "参数解析异常!"
  199. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  200. return
  201. }
  202. videoId := req.VideoId
  203. playSeconds := req.PlaySeconds
  204. sourceType := req.SourceType
  205. if sourceType == 0 {
  206. sourceType = 1
  207. }
  208. var sellerName string
  209. sellerName, err = models.GetCompanySellerName(user.CompanyId)
  210. if err != nil {
  211. br.Msg = "报名失败!"
  212. br.ErrMsg = "获取对应销售失败,Err:" + err.Error()
  213. return
  214. }
  215. if sourceType == 1 {
  216. item := models.CygxMicroRoadshowVideoHistory{
  217. VideoId: videoId,
  218. UserId: uid,
  219. Mobile: user.Mobile,
  220. Email: user.Email,
  221. CompanyId: user.CompanyId,
  222. CompanyName: user.CompanyName,
  223. RealName: user.RealName,
  224. SellerName: sellerName,
  225. PlaySeconds: strconv.Itoa(playSeconds),
  226. CreateTime: time.Now(),
  227. ModifyTime: time.Now(),
  228. }
  229. if playSeconds != 0 {
  230. lastItem, err := models.GetLastCygxMicroRoadshowVideoHistory(videoId, user.UserId)
  231. if err != nil {
  232. br.Msg = "操作失败"
  233. br.ErrMsg = "操作失败,GetLastCygxMicroRoadshowVideoHistory Err:" + err.Error()
  234. return
  235. }
  236. err = models.UpdateLastCygxActivityVideoHistory(strconv.Itoa(playSeconds), lastItem.Id)
  237. if err != nil {
  238. br.Msg = "更新失败"
  239. br.ErrMsg = "更新失败,UpdateLastCygxActivityVideoHistory Err:" + err.Error()
  240. return
  241. }
  242. } else {
  243. err = models.AddCygxMicroRoadshowVideoHistory(&item)
  244. if err != nil {
  245. br.Msg = "操作失败"
  246. br.ErrMsg = "操作失败,Err:" + err.Error()
  247. return
  248. }
  249. err = models.UpdateCygxActivityVideoCounts(videoId)
  250. if err != nil {
  251. br.Msg = "更新失败"
  252. br.ErrMsg = "更新失败,Err:" + err.Error()
  253. return
  254. }
  255. }
  256. } else if sourceType == 2 {
  257. err = services.AddActivityVideoHistory(user, videoId)
  258. if err != nil {
  259. br.Msg = "更新失败"
  260. br.ErrMsg = "更新失败,AddActivityVideoHistory Err:" + err.Error()
  261. return
  262. }
  263. }
  264. br.Ret = 200
  265. br.Success = true
  266. br.Msg = "操作成功"
  267. return
  268. }
  269. // @Title 微路演新增留言
  270. // @Description 微路演新增留言接口
  271. // @Param request body models.AddVideoCommnetReq true "type json string"
  272. // @Success Ret=200 {object} models.AppointmentResp
  273. // @router /comment/add [post]
  274. func (this *MicroRoadShowController) CommentAdd() {
  275. br := new(models.BaseResponse).Init()
  276. defer func() {
  277. this.Data["json"] = br
  278. this.ServeJSON()
  279. }()
  280. user := this.User
  281. if user == nil {
  282. br.Msg = "请登录"
  283. br.ErrMsg = "请登录,用户信息为空"
  284. br.Ret = 408
  285. return
  286. }
  287. uid := user.UserId
  288. var req models.AddVideoCommnetReq
  289. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  290. if err != nil {
  291. br.Msg = "参数解析异常!"
  292. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  293. return
  294. }
  295. sourceType := req.SourceType
  296. if sourceType == 0 {
  297. sourceType = 1
  298. }
  299. item := models.CygxArticleComment{
  300. UserId: uid,
  301. CreateTime: time.Now(),
  302. RealName: user.RealName,
  303. Mobile: user.Mobile,
  304. Email: user.Email,
  305. CompanyId: user.CompanyId,
  306. CompanyName: user.CompanyName,
  307. Content: req.Content,
  308. Title: req.Title,
  309. VideoId: req.Id,
  310. }
  311. if sourceType == 1 {
  312. item.IndustryId = req.Id
  313. } else if sourceType == 2 {
  314. item.ActivityId = req.Id
  315. } else if sourceType == 3 {
  316. item.VideoId = req.Id
  317. microVideo, e := models.GetMicroRoadshowVideoById(req.Id)
  318. if e != nil {
  319. br.Msg = "操作失败"
  320. br.ErrMsg = "微路演视频信息有误, 不存在的VideoId: " + strconv.Itoa(req.Id)
  321. return
  322. }
  323. item.IndustryId = microVideo.IndustryId
  324. }
  325. _, err = models.AddArticleComment(&item)
  326. if err != nil {
  327. br.Msg = "提交失败"
  328. br.ErrMsg = "提交留言失败,Err:" + err.Error()
  329. return
  330. }
  331. services.SendWxMsgWithMicroRoadshowAsk(req, user)
  332. br.Ret = 200
  333. br.Success = true
  334. br.Msg = "操作成功"
  335. return
  336. }
  337. // @Title 微路演收藏
  338. // @Description 微路演收藏
  339. // @Param request body models.MicroRoadshowCollectReq true "type json string"
  340. // @Success 200 {object} models.FontsCollectResp
  341. // @router /collect [post]
  342. func (this *MicroRoadShowController) Collect() {
  343. br := new(models.BaseResponse).Init()
  344. defer func() {
  345. this.Data["json"] = br
  346. this.ServeJSON()
  347. }()
  348. user := this.User
  349. if user == nil {
  350. br.Msg = "请重新登录"
  351. br.Ret = 408
  352. return
  353. }
  354. uid := user.UserId
  355. var req models.MicroRoadshowCollectReq
  356. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  357. if err != nil {
  358. br.Msg = "参数解析异常!"
  359. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  360. return
  361. }
  362. if req.SourceType == 1 {
  363. _, err := models.GetCygxActivityVoiceById(req.Id)
  364. if err != nil {
  365. br.Msg = "获取信息失败"
  366. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  367. return
  368. }
  369. count, err := models.GetVoiceCollectCount(uid, req.Id)
  370. if err != nil {
  371. br.Msg = "获取数据失败!"
  372. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  373. return
  374. }
  375. resp := new(models.ArticleCollectResp)
  376. if count <= 0 {
  377. item := new(models.CygxArticleCollect)
  378. item.ActivityVoiceId = req.Id
  379. item.UserId = uid
  380. item.CreateTime = time.Now()
  381. item.Mobile = user.Mobile
  382. item.Email = user.Email
  383. item.CompanyId = user.CompanyId
  384. item.CompanyName = user.CompanyName
  385. item.RealName = user.RealName
  386. _, err = models.AddCygxArticleCollect(item)
  387. if err != nil {
  388. br.Msg = "收藏失败"
  389. br.ErrMsg = "收藏失败,Err:" + err.Error()
  390. return
  391. }
  392. br.Msg = "收藏成功"
  393. resp.Status = 1
  394. // 文章收藏消息发送
  395. //go services.ArticleUserRemind(user, detail, 2)
  396. } else {
  397. err = models.RemoveVoiceCollect(uid, req.Id)
  398. if err != nil {
  399. br.Msg = "取消收藏失败"
  400. br.ErrMsg = "取消收藏失败,Err:" + err.Error()
  401. return
  402. }
  403. br.Msg = "已取消收藏"
  404. resp.Status = 2
  405. }
  406. collectTotal, err := models.GetVoiceCollectUsersCount(req.Id)
  407. if err != nil {
  408. br.Msg = "获取数据失败"
  409. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  410. return
  411. }
  412. resp.CollectCount = collectTotal
  413. br.Ret = 200
  414. br.Success = true
  415. br.Data = resp
  416. } else if req.SourceType == 2 {
  417. _, err := models.GetCygxActivityVideoById(req.Id)
  418. if err != nil {
  419. br.Msg = "获取信息失败"
  420. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  421. return
  422. }
  423. count, err := models.GetActivityVideoCollectCount(uid, req.Id)
  424. if err != nil {
  425. br.Msg = "获取数据失败!"
  426. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  427. return
  428. }
  429. resp := new(models.ArticleCollectResp)
  430. if count <= 0 {
  431. item := new(models.CygxArticleCollect)
  432. item.ActivityVideoId = req.Id
  433. item.UserId = uid
  434. item.CreateTime = time.Now()
  435. item.Mobile = user.Mobile
  436. item.Email = user.Email
  437. item.CompanyId = user.CompanyId
  438. item.CompanyName = user.CompanyName
  439. item.RealName = user.RealName
  440. _, err = models.AddCygxArticleCollect(item)
  441. if err != nil {
  442. br.Msg = "收藏失败"
  443. br.ErrMsg = "收藏失败,Err:" + err.Error()
  444. return
  445. }
  446. br.Msg = "收藏成功"
  447. resp.Status = 1
  448. // 文章收藏消息发送
  449. //go services.ArticleUserRemind(user, detail, 2)
  450. } else {
  451. err = models.RemoveActivityVideoCollect(uid, req.Id)
  452. if err != nil {
  453. br.Msg = "取消收藏失败"
  454. br.ErrMsg = "取消收藏失败,Err:" + err.Error()
  455. return
  456. }
  457. br.Msg = "已取消收藏"
  458. resp.Status = 2
  459. }
  460. collectTotal, err := models.GetActivityVideoCollectUsersCount(req.Id)
  461. if err != nil {
  462. br.Msg = "获取数据失败"
  463. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  464. return
  465. }
  466. resp.CollectCount = collectTotal
  467. br.Ret = 200
  468. br.Success = true
  469. br.Data = resp
  470. } else if req.SourceType == 3 {
  471. _, err := models.GetMicroRoadshowVideoById(req.Id)
  472. if err != nil {
  473. br.Msg = "获取信息失败"
  474. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  475. return
  476. }
  477. count, err := models.GetVideoCollectCount(uid, req.Id)
  478. if err != nil {
  479. br.Msg = "获取数据失败!"
  480. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  481. return
  482. }
  483. resp := new(models.ArticleCollectResp)
  484. if count <= 0 {
  485. item := new(models.CygxArticleCollect)
  486. item.VideoId = req.Id
  487. item.UserId = uid
  488. item.CreateTime = time.Now()
  489. item.Mobile = user.Mobile
  490. item.Email = user.Email
  491. item.CompanyId = user.CompanyId
  492. item.CompanyName = user.CompanyName
  493. item.RealName = user.RealName
  494. _, err = models.AddCygxArticleCollect(item)
  495. if err != nil {
  496. br.Msg = "收藏失败"
  497. br.ErrMsg = "收藏失败,Err:" + err.Error()
  498. return
  499. }
  500. br.Msg = "收藏成功"
  501. resp.Status = 1
  502. // 文章收藏消息发送
  503. //go services.ArticleUserRemind(user, detail, 2)
  504. } else {
  505. err = models.RemoveVideoCollect(uid, req.Id)
  506. if err != nil {
  507. br.Msg = "取消收藏失败"
  508. br.ErrMsg = "取消收藏失败,Err:" + err.Error()
  509. return
  510. }
  511. br.Msg = "已取消收藏"
  512. resp.Status = 2
  513. }
  514. collectTotal, err := models.GetVideoCollectUsersCount(req.Id)
  515. if err != nil {
  516. br.Msg = "获取数据失败"
  517. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  518. return
  519. }
  520. resp.CollectCount = collectTotal
  521. br.Ret = 200
  522. br.Success = true
  523. br.Data = resp
  524. }
  525. }