micro_roadshow.go 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017
  1. package cygx
  2. import (
  3. "encoding/json"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "github.com/tealeg/xlsx"
  6. "hongze/hz_crm_api/controllers"
  7. "hongze/hz_crm_api/models"
  8. "hongze/hz_crm_api/models/cygx"
  9. cygxService "hongze/hz_crm_api/services/cygx"
  10. "hongze/hz_crm_api/services/elastic"
  11. "hongze/hz_crm_api/utils"
  12. "os"
  13. "path/filepath"
  14. "strings"
  15. "time"
  16. )
  17. // 活动类型
  18. type MicroRoadshowController struct {
  19. controllers.BaseAuthController
  20. }
  21. // @Title 微路演视频列表
  22. // @Description 微路演视频列表
  23. // @Success 200 {object} cygx.MicroRoadshowVideoListResp
  24. // @Param PageSize query int true "每页数据条数"
  25. // @Param CurrentIndex query int true "当前页页码,从1开始"
  26. // @Param KeyWord query string false "搜索关键词"
  27. // @Param StartDate query string false "开始时间"
  28. // @Param EndDate query string false "结束时间"
  29. // @Param PublishStatus query string false "发布状态"
  30. // @Param ChartPermissionId query string false "行业Id"
  31. // @Param VideoId query string false "视频Id"
  32. // @Param SortType query string true "如何排序,是正序还是倒序,枚举值:`asc 正序`,`desc 倒叙`"
  33. // @Param SortParam query string false "排序字段参数,用来排序的字段 "
  34. // @router /microRoadshow/video/list [get]
  35. func (this *MicroRoadshowController) List() {
  36. br := new(models.BaseResponse).Init()
  37. defer func() {
  38. this.Data["json"] = br
  39. this.ServeJSON()
  40. }()
  41. sysUser := this.SysUser
  42. if sysUser == nil {
  43. br.Msg = "请登录"
  44. br.ErrMsg = "请登录,SysUser Is Empty"
  45. br.Ret = 408
  46. return
  47. }
  48. pageSize, _ := this.GetInt("PageSize")
  49. currentIndex, _ := this.GetInt("CurrentIndex")
  50. keyWord := this.GetString("KeyWord")
  51. startDate := this.GetString("StartDate")
  52. endDate := this.GetString("EndDate")
  53. publishStatus, _ := this.GetInt("PublishStatus", -1)
  54. chartPermissionId, _ := this.GetInt("ChartPermissionId")
  55. sortParam := this.GetString("SortParam")
  56. sortType := this.GetString("SortType")
  57. keyWord = strings.Trim(keyWord, " ")
  58. keyWord = strings.Replace(keyWord, "'", "", -1)
  59. var condition string
  60. var pars []interface{}
  61. var startSize int
  62. if pageSize <= 0 {
  63. pageSize = utils.PageSize20
  64. }
  65. if currentIndex <= 0 {
  66. currentIndex = 1
  67. }
  68. startSize = paging.StartIndex(currentIndex, pageSize)
  69. if keyWord != "" {
  70. condition += ` AND (video_name LIKE '%` + keyWord + `%' ) `
  71. }
  72. if startDate != "" {
  73. condition += ` AND publish_date>=? `
  74. pars = append(pars, startDate+" 00:00:00")
  75. }
  76. if endDate != "" {
  77. condition += ` AND publish_date<=? `
  78. pars = append(pars, endDate+" 23:59:59")
  79. }
  80. if chartPermissionId > 0 {
  81. condition += ` AND chart_permission_id=? `
  82. pars = append(pars, chartPermissionId)
  83. }
  84. if publishStatus > -1 {
  85. condition += ` AND publish_status=? `
  86. pars = append(pars, publishStatus)
  87. }
  88. sortStr := ``
  89. if sortParam != "" && sortType != "" {
  90. if sortParam == "videoCounts" {
  91. if sortType == "asc" {
  92. sortStr = " ORDER BY video_counts "
  93. } else {
  94. sortStr = " ORDER BY video_counts DESC "
  95. }
  96. }
  97. } else {
  98. sortStr = " ORDER BY publish_date DESC "
  99. }
  100. total, err := cygx.GetMicroRoadshowVideoListCount(condition, pars)
  101. if err != nil {
  102. br.Msg = "获取失败"
  103. br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
  104. return
  105. }
  106. list, err := cygx.GetMicroRoadshowVideoList(condition, sortStr, pars, startSize, pageSize)
  107. if err != nil {
  108. br.Msg = "获取失败"
  109. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  110. return
  111. }
  112. respList := make([]*cygx.CygxMicroRoadshowVideoResp, 0)
  113. for _, video := range list {
  114. respItem := cygx.CygxMicroRoadshowVideoResp{
  115. VideoId: video.VideoId,
  116. VideoName: video.VideoName,
  117. ChartPermissionId: video.ChartPermissionId,
  118. ChartPermissionName: video.ChartPermissionName,
  119. IndustryId: video.IndustryId,
  120. IndustryName: video.IndustryName,
  121. PublishStatus: video.PublishStatus,
  122. ModifyDate: video.ModifyDate,
  123. PublishDate: video.PublishDate.Format(utils.FormatDate),
  124. VideoDuration: video.VideoDuration,
  125. VideoCounts: video.VideoCounts,
  126. VideoUrl: video.VideoUrl,
  127. CreateTime: video.CreateTime,
  128. ImgUrl: video.ImgUrl,
  129. ShareImgUrl: video.ShareImgUrl,
  130. DetailImgUrl: video.DetailImgUrl,
  131. CommentNum: video.CommentNum,
  132. }
  133. respList = append(respList, &respItem)
  134. }
  135. if list == nil {
  136. list = make([]*cygx.CygxMicroRoadshowVideo, 0)
  137. }
  138. resp := new(cygx.MicroRoadshowVideoListResp)
  139. page := paging.GetPaging(currentIndex, pageSize, total)
  140. resp.List = respList
  141. resp.Paging = page
  142. br.Ret = 200
  143. br.Success = true
  144. br.Msg = "获取成功"
  145. br.Data = resp
  146. }
  147. // @Title 保存视频
  148. // @Description 保存视频接口
  149. // @Param request body cygx.VideoAddReq true "type json string"
  150. // @Success 200 保存成功
  151. // @router /microRoadshow/video/add [post]
  152. func (this *MicroRoadshowController) Add() {
  153. br := new(models.BaseResponse).Init()
  154. defer func() {
  155. this.Data["json"] = br
  156. this.ServeJSON()
  157. }()
  158. sysUser := this.SysUser
  159. if sysUser == nil {
  160. br.Msg = "请登录"
  161. br.ErrMsg = "请登录,SysUser Is Empty"
  162. br.Ret = 408
  163. return
  164. }
  165. var req cygx.VideoAddReq
  166. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  167. if err != nil {
  168. br.Msg = "参数解析异常!"
  169. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  170. return
  171. }
  172. if req.VideoName == "" {
  173. br.Msg = "视频名不能为空"
  174. return
  175. }
  176. if req.VideoUrl == "" {
  177. br.Msg = "视频播放地址不能为空"
  178. return
  179. }
  180. if req.IndustryId == 0 {
  181. br.Msg = "产业不能为空"
  182. return
  183. }
  184. if req.ImgUrl == "" {
  185. br.Msg = "视频封面不能为空"
  186. return
  187. }
  188. if req.ShareImgUrl == "" {
  189. br.Msg = "视频分享图不能为空"
  190. return
  191. }
  192. if req.DetailImgUrl == "" {
  193. br.Msg = "详情页封面不能为空"
  194. return
  195. }
  196. var nameItem *cygx.PermissionNameAndIndustryName
  197. nameItem, err = cygx.GetPermissionNameAndIndustryNameByIndustryId(req.IndustryId)
  198. if err != nil {
  199. br.Msg = "查询行业及产业是否存在失败!"
  200. br.ErrMsg = "查询行业及产业是否存在失败,Err:" + err.Error()
  201. return
  202. }
  203. charInfo, errCategory := cygx.GetCategoryInfoById(nameItem.PermissionId)
  204. if errCategory != nil {
  205. br.Msg = "获取品种信息失败"
  206. br.ErrMsg = "获取品种信息失败,Err:" + errCategory.Error()
  207. return
  208. }
  209. nameItem.PermissionName = charInfo.PermissionName
  210. publishDate, err := time.Parse(utils.FormatDate, req.PublishDate)
  211. if err != nil {
  212. br.Msg = "时间格式转换失败"
  213. br.ErrMsg = "时间格式转换失败,Err:" + err.Error()
  214. return
  215. }
  216. //判断该产业下是否已经存在其他视频
  217. exist, err := cygx.GetMicroRoadshowVideoByIndustryId(req.IndustryId)
  218. if err != nil {
  219. if err.Error() != utils.ErrNoRow() {
  220. br.Msg = "查询视频详情失败"
  221. br.ErrMsg = "查询视频详情失败,Err:" + err.Error()
  222. return
  223. }
  224. } else {
  225. if req.VideoId > 0 && req.VideoId != exist.VideoId {
  226. br.Msg = "该产业下已有产业视频"
  227. return
  228. }
  229. if req.VideoId == 0 {
  230. br.Msg = "该产业下已有产业视频"
  231. return
  232. }
  233. }
  234. shareImg, _ := cygxService.MakeCygxMp4HtmlImg(req.VideoDuration, 0) //生成分享图片
  235. req.ShareImgUrl = shareImg
  236. nameItem.IndustryName = utils.RemoveFileSuffixName(nameItem.IndustryName) //去掉后缀名称
  237. if req.VideoId > 0 {
  238. //更新
  239. item := cygx.CygxMicroRoadshowVideo{
  240. VideoId: req.VideoId,
  241. VideoName: "5min" + "【" + nameItem.IndustryName + "】" + "逻辑解析",
  242. ChartPermissionId: nameItem.PermissionId,
  243. ChartPermissionName: nameItem.PermissionName,
  244. IndustryId: req.IndustryId,
  245. IndustryName: nameItem.IndustryName,
  246. ModifyDate: time.Now().Format(utils.FormatDateTime),
  247. PublishStatus: req.PublishOrSave,
  248. PublishDate: publishDate,
  249. VideoDuration: req.VideoDuration,
  250. VideoUrl: req.VideoUrl,
  251. ImgUrl: req.ImgUrl,
  252. ShareImgUrl: req.ShareImgUrl,
  253. DetailImgUrl: req.DetailImgUrl,
  254. }
  255. err = cygx.EditVideo(&item)
  256. if err != nil {
  257. br.Msg = "编辑失败"
  258. br.ErrMsg = "编辑失败,Err:" + err.Error()
  259. return
  260. }
  261. if req.PublishOrSave == 1 {
  262. go cygxService.SendWxMsgWithCygxMicroRoadshowVideo(req.VideoId)
  263. }
  264. //go cygxService.UpdateResourceData(req.VideoId, "roadshow", "update", publishDate.Format(utils.FormatDateTime))
  265. go cygxService.UpdateMicroRoadshowResourceData(req.VideoId) //写入首页最新 cygx_resource_data 表
  266. go elastic.AddComprehensiveRoadshow(req.VideoId) //Es添加微路演
  267. br.Ret = 200
  268. br.Success = true
  269. br.Msg = "编辑成功"
  270. } else {
  271. videoCount, err := cygx.GetMicroRoadshowVideoByTitle(req.VideoName)
  272. if err != nil {
  273. br.Msg = "判断标题是否存在失败!"
  274. br.ErrMsg = "判断标题是否存在失败,Err:" + err.Error()
  275. return
  276. }
  277. if videoCount > 0 {
  278. br.Msg = "标题已存在!"
  279. br.IsSendEmail = false
  280. return
  281. }
  282. item := cygx.CygxMicroRoadshowVideo{
  283. VideoName: "5min" + "【" + nameItem.IndustryName + "】" + "逻辑解析",
  284. ChartPermissionId: nameItem.PermissionId,
  285. ChartPermissionName: nameItem.PermissionName,
  286. IndustryId: req.IndustryId,
  287. IndustryName: nameItem.IndustryName,
  288. PublishStatus: req.PublishOrSave,
  289. ModifyDate: time.Now().Format(utils.FormatDateTime),
  290. PublishDate: publishDate,
  291. VideoDuration: req.VideoDuration,
  292. VideoUrl: req.VideoUrl,
  293. ImgUrl: req.ImgUrl,
  294. ShareImgUrl: req.ShareImgUrl,
  295. DetailImgUrl: req.DetailImgUrl,
  296. CreateTime: time.Now().Format(utils.FormatDateTime),
  297. }
  298. newId, err := cygx.AddMicroRoadshowVideo(&item)
  299. if err != nil {
  300. br.Msg = "保存失败"
  301. br.ErrMsg = "保存失败,Err:" + err.Error()
  302. return
  303. }
  304. if req.PublishOrSave == 1 {
  305. go cygxService.SendWxMsgWithCygxMicroRoadshowVideo(int(newId))
  306. //go cygxService.UpdateResourceData(int(newId), "roadshow", "add", publishDate.Format(utils.FormatDateTime))
  307. go cygxService.UpdateMicroRoadshowResourceData(int(newId)) //写入首页最新 cygx_resource_data 表
  308. go elastic.AddComprehensiveRoadshow(req.VideoId) //Es添加微路演
  309. }
  310. br.Ret = 200
  311. br.Success = true
  312. br.Msg = "保存成功"
  313. }
  314. }
  315. // @Title 编辑视频
  316. // @Description 编辑视频接口
  317. // @Param request body cygx.VideoEditReq true "type json string"
  318. // @Success Ret=200 编辑成功
  319. // @router /microRoadshow/video/edit [post]
  320. func (this *MicroRoadshowController) Edit() {
  321. br := new(models.BaseResponse).Init()
  322. defer func() {
  323. this.Data["json"] = br
  324. this.ServeJSON()
  325. }()
  326. sysUser := this.SysUser
  327. if sysUser == nil {
  328. br.Msg = "请登录"
  329. br.ErrMsg = "请登录,SysUser Is Empty"
  330. br.Ret = 408
  331. return
  332. }
  333. var req cygx.VideoEditReq
  334. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  335. if err != nil {
  336. br.Msg = "参数解析异常!"
  337. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  338. return
  339. }
  340. if req.VideoName == "" {
  341. br.Msg = "标题不能为空"
  342. return
  343. }
  344. if req.VideoUrl == "" {
  345. br.Msg = "视频地址不能为空"
  346. return
  347. }
  348. publishDate, err := time.Parse(utils.FormatDate, req.PublishDate)
  349. if err != nil {
  350. br.Msg = "时间格式转换失败"
  351. br.ErrMsg = "时间格式转换失败,Err:" + err.Error()
  352. return
  353. }
  354. var nameItem *cygx.PermissionNameAndIndustryName
  355. nameItem, err = cygx.GetPermissionNameAndIndustryNameByIndustryId(req.IndustryId)
  356. if err != nil {
  357. br.Msg = "查询行业及产业是否存在失败!"
  358. br.ErrMsg = "查询行业及产业是否存在失败,Err:" + err.Error()
  359. return
  360. }
  361. item := cygx.CygxMicroRoadshowVideo{
  362. VideoId: req.VideoId,
  363. VideoName: "5min" + "【" + nameItem.IndustryName + "】" + "逻辑解析",
  364. ChartPermissionId: req.ChartPermissionId,
  365. IndustryId: req.IndustryId,
  366. ModifyDate: time.Now().Format(utils.FormatDateTime),
  367. PublishDate: publishDate,
  368. VideoDuration: req.VideoDuration,
  369. VideoUrl: req.VideoUrl,
  370. }
  371. err = cygx.EditVideo(&item)
  372. if err != nil {
  373. br.Msg = "编辑失败"
  374. br.ErrMsg = "编辑失败,Err:" + err.Error()
  375. return
  376. }
  377. go elastic.AddComprehensiveRoadshow(req.VideoId) //Es添加微路演
  378. br.Ret = 200
  379. br.Success = true
  380. br.Msg = "编辑成功"
  381. }
  382. // @Title 取消视频发布
  383. // @Description 取消视频发布接口
  384. // @Param VideoId query int true "视频Id"
  385. // @Param PublishOrCancle query int true "发布或取消发布"
  386. // @Success Ret=200 发布成功
  387. // @router /microRoadshow/video/publish [get]
  388. func (this *MicroRoadshowController) PublishCancel() {
  389. br := new(models.BaseResponse).Init()
  390. defer func() {
  391. this.Data["json"] = br
  392. this.ServeJSON()
  393. }()
  394. sysUser := this.SysUser
  395. if sysUser == nil {
  396. br.Msg = "请登录"
  397. br.ErrMsg = "请登录,SysUser Is Empty"
  398. br.Ret = 408
  399. return
  400. }
  401. videoId, _ := this.GetInt("VideoId")
  402. publishOrCancle, _ := this.GetInt("PublishOrCancle")
  403. if videoId <= 0 {
  404. br.Msg = "参数错误"
  405. return
  406. }
  407. err := cygx.PublishVideoCancel(videoId, publishOrCancle)
  408. if err != nil {
  409. br.Msg = "取消发布失败"
  410. br.ErrMsg = "取消发布失败,Err:" + err.Error()
  411. return
  412. }
  413. videoInfo, _ := cygx.GetMicroRoadshowVideoByVideoId(videoId)
  414. if videoInfo == nil {
  415. br.Msg = "操作失败"
  416. br.ErrMsg = "视频ID错误"
  417. return
  418. }
  419. br.Ret = 200
  420. br.Success = true
  421. if publishOrCancle == 0 {
  422. br.Msg = "取消发布成功"
  423. //go cygxService.UpdateResourceData(int(videoId), "roadshow", "delete", time.Now().Format(utils.FormatDateTime))
  424. go cygxService.UpdateMicroRoadshowResourceData(int(videoId)) //写入首页最新 cygx_resource_data 表
  425. } else {
  426. go cygxService.SendWxMsgWithCygxMicroRoadshowVideo(videoId)
  427. //go cygxService.UpdateResourceData(int(videoId), "roadshow", "add", videoInfo.PublishDate.Format(utils.FormatDateTime))
  428. go cygxService.UpdateMicroRoadshowResourceData(int(videoId)) //写入首页最新 cygx_resource_data 表
  429. br.Msg = "发布成功"
  430. }
  431. go elastic.AddComprehensiveRoadshow(videoId) //Es添加微路演
  432. }
  433. // @Title 视频详情
  434. // @Description 视频详情接口
  435. // @Param VideoId query int true "视频Id"
  436. // @Param PageSize query int true "每页数据条数"
  437. // @Param CurrentIndex query int true "当前页页码,从1开始"
  438. // @Success Ret=200 发布成功
  439. // @router /microRoadshow/video/deatil [get]
  440. func (this *MicroRoadshowController) Deatil() {
  441. br := new(models.BaseResponse).Init()
  442. defer func() {
  443. this.Data["json"] = br
  444. this.ServeJSON()
  445. }()
  446. sysUser := this.SysUser
  447. if sysUser == nil {
  448. br.Msg = "请登录"
  449. br.ErrMsg = "请登录,SysUser Is Empty"
  450. br.Ret = 408
  451. return
  452. }
  453. videoId, _ := this.GetInt("VideoId")
  454. //pageSize, _ := this.GetInt("PageSize")
  455. //currentIndex, _ := this.GetInt("CurrentIndex")
  456. if videoId <= 0 {
  457. br.Msg = "参数错误"
  458. return
  459. }
  460. //var startSize int
  461. //if pageSize <= 0 {
  462. // pageSize = utils.PageSize20
  463. //}
  464. //if currentIndex <= 0 {
  465. // currentIndex = 1
  466. //}
  467. //startSize = paging.StartIndex(currentIndex, pageSize)
  468. var condition string
  469. var pars []interface{}
  470. condition += `AND video_id= ? `
  471. pars = append(pars, videoId)
  472. //total, err := cygx.GetMicroRoadshowVideoListCount(condition, pars)
  473. //if err != nil {
  474. // br.Msg = "获取失败"
  475. // br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
  476. // return
  477. //}
  478. list, err := cygx.GetMicroRoadshowVideoHistoryById(condition, pars)
  479. if err != nil && err.Error() != utils.ErrNoRow() {
  480. br.Msg = "获取历史详情失败"
  481. br.ErrMsg = "获取历史详情失败,Err:" + err.Error()
  482. return
  483. }
  484. for _, v := range list {
  485. v.RegisterPlatform = utils.CYGX_REGISTER_PLATFORM_MAP[v.RegisterPlatform]
  486. }
  487. //resp := new(cygx.MicroRoadshowVideoHistoryListResp)
  488. //page := paging.GetPaging(currentIndex, pageSize, total)
  489. //resp.List = list
  490. //resp.Paging = page
  491. br.Ret = 200
  492. br.Success = true
  493. br.Msg = "获取成功"
  494. br.Data = list
  495. }
  496. // @Title 微路演音频列表
  497. // @Description 微路演音频列表
  498. // @Success 200 {object} cygx.MicroRoadshowVideoListResp
  499. // @Param PageSize query int true "每页数据条数"
  500. // @Param CurrentIndex query int true "当前页页码,从1开始"
  501. // @Param KeyWord query string true "搜索关键词"
  502. // @Param StartDate query string true "开始时间"
  503. // @Param EndDate query string true "结束时间"
  504. // @Param ChartPermissionId query string true "行业Id"
  505. // @Param ActivityTypeId query string true "活动类型ID"
  506. // @Param SortType query string true "如何排序,是正序还是倒序,枚举值:`asc 正序`,`desc 倒叙`"
  507. // @Param SortParam query string false "排序字段参数,用来排序的字段 "
  508. // @router /microRoadshow/voice/list [get]
  509. func (this *MicroRoadshowController) VoiceList() {
  510. br := new(models.BaseResponse).Init()
  511. defer func() {
  512. this.Data["json"] = br
  513. this.ServeJSON()
  514. }()
  515. sysUser := this.SysUser
  516. if sysUser == nil {
  517. br.Msg = "请登录"
  518. br.ErrMsg = "请登录,SysUser Is Empty"
  519. br.Ret = 408
  520. return
  521. }
  522. pageSize, _ := this.GetInt("PageSize")
  523. currentIndex, _ := this.GetInt("CurrentIndex")
  524. keyWord := this.GetString("KeyWord")
  525. startDate := this.GetString("StartDate")
  526. endDate := this.GetString("EndDate")
  527. chartPermissionId, _ := this.GetInt("ChartPermissionId")
  528. activityTypeId, _ := this.GetInt("ActivityTypeId")
  529. sortParam := this.GetString("SortParam")
  530. sortType := this.GetString("SortType")
  531. keyWord = strings.Trim(keyWord, " ")
  532. keyWord = strings.Replace(keyWord, "'", "", -1)
  533. var condition string
  534. var pars []interface{}
  535. var startSize int
  536. if pageSize <= 0 {
  537. pageSize = utils.PageSize20
  538. }
  539. if currentIndex <= 0 {
  540. currentIndex = 1
  541. }
  542. startSize = paging.StartIndex(currentIndex, pageSize)
  543. if keyWord != "" {
  544. condition += ` AND (v.voice_name LIKE '%` + keyWord + `%' ) `
  545. }
  546. if startDate != "" {
  547. condition += ` AND a.activity_time>=? `
  548. pars = append(pars, startDate)
  549. }
  550. if endDate != "" {
  551. condition += ` AND a.activity_time<=? `
  552. pars = append(pars, endDate)
  553. }
  554. if chartPermissionId > 0 {
  555. condition += ` AND a.chart_permission_id=? `
  556. pars = append(pars, chartPermissionId)
  557. }
  558. if activityTypeId > 0 {
  559. condition += ` AND a.activity_type_id=? `
  560. pars = append(pars, activityTypeId)
  561. }
  562. sortStr := ``
  563. if sortParam != "" && sortType != "" {
  564. if sortParam == "voiceCounts" {
  565. if sortType == "asc" {
  566. sortStr = " ORDER BY v.voice_counts "
  567. } else {
  568. sortStr = " ORDER BY v.voice_counts DESC "
  569. }
  570. }
  571. } else {
  572. sortStr = " ORDER BY a.activity_time DESC "
  573. }
  574. total, err := cygx.GetMicroRoadshowVoiceListCount(condition, pars)
  575. if err != nil {
  576. br.Msg = "获取失败"
  577. br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
  578. return
  579. }
  580. list, err := cygx.GetMicroRoadshowVoiceList(condition, sortStr, pars, startSize, pageSize)
  581. if err != nil {
  582. br.Msg = "获取失败"
  583. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  584. return
  585. }
  586. resplist := make([]*cygx.CygxMicroRoadshowVoiceRsep, 0)
  587. for _, voice := range list {
  588. respItem := cygx.CygxMicroRoadshowVoiceRsep{
  589. ActivityVoiceId: voice.ActivityVoiceId,
  590. ActivityId: voice.ActivityId,
  591. VoiceName: voice.VoiceName,
  592. ChartPermissionId: voice.ChartPermissionId,
  593. ChartPermissionName: voice.ChartPermissionName,
  594. IndustryId: voice.IndustryId,
  595. IndustryName: voice.IndustryName,
  596. ModifyTime: voice.ModifyTime,
  597. PublishDate: voice.PublishDate,
  598. VoicePlaySeconds: voice.VoicePlaySeconds,
  599. VoiceCounts: voice.VoiceCounts,
  600. VoiceUrl: voice.VoiceUrl,
  601. CreateTime: voice.CreateTime,
  602. Label: voice.Label,
  603. ActivityTypeId: voice.ActivityTypeId,
  604. ActivityTypeName: voice.ActivityTypeName,
  605. ActivityTime: voice.ActivityTime.Format(utils.FormatDate),
  606. ActivityTimeText: voice.ActivityTimeText,
  607. CommentNum: voice.CommentNum,
  608. }
  609. resplist = append(resplist, &respItem)
  610. }
  611. if list == nil {
  612. list = make([]*cygx.CygxMicroRoadshowVoice, 0)
  613. }
  614. resp := new(cygx.MicroRoadshowVoiceListResp)
  615. page := paging.GetPaging(currentIndex, pageSize, total)
  616. resp.List = resplist
  617. resp.Paging = page
  618. br.Ret = 200
  619. br.Success = true
  620. br.Msg = "获取成功"
  621. br.Data = resp
  622. }
  623. // @Title 音频播放详情
  624. // @Description 音频播放详情接口
  625. // @Param VoiceId query int true "视频Id"
  626. // @Success Ret=200 发布成功
  627. // @router /microRoadshow/voice/deatil [get]
  628. func (this *MicroRoadshowController) VoiceDeatil() {
  629. br := new(models.BaseResponse).Init()
  630. defer func() {
  631. this.Data["json"] = br
  632. this.ServeJSON()
  633. }()
  634. sysUser := this.SysUser
  635. if sysUser == nil {
  636. br.Msg = "请登录"
  637. br.ErrMsg = "请登录,SysUser Is Empty"
  638. br.Ret = 408
  639. return
  640. }
  641. voiceId, _ := this.GetInt("VoiceId")
  642. videoId, _ := this.GetInt("VideoId")
  643. //参数ID做兼容
  644. if voiceId == 0 {
  645. voiceId = videoId
  646. }
  647. if voiceId <= 0 {
  648. br.Msg = "参数错误"
  649. return
  650. }
  651. var condition string
  652. var pars []interface{}
  653. condition += `AND v.activity_voice_id= ? `
  654. pars = append(pars, voiceId)
  655. list, err := cygx.GetMicroRoadshowVoiceHistoryById(condition, pars)
  656. if err != nil {
  657. br.Msg = "获取失败"
  658. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  659. return
  660. }
  661. for _, v := range list {
  662. v.RegisterPlatform = utils.CYGX_REGISTER_PLATFORM_MAP[v.RegisterPlatform]
  663. }
  664. br.Ret = 200
  665. br.Success = true
  666. br.Msg = "获取成功"
  667. br.Data = list
  668. }
  669. // @Title 留言详情excel表格下载
  670. // @Description 留言详情excel表格下载接口
  671. // @Param VideoId query int true "视频ID"
  672. // @Success 200 导出成功
  673. // @router /microRoadshow/commentListExport/video [get]
  674. func (this *MicroRoadshowController) CommentListExport() {
  675. br := new(models.BaseResponse).Init()
  676. defer func() {
  677. this.Data["json"] = br
  678. this.ServeJSON()
  679. }()
  680. sysUser := this.SysUser
  681. if sysUser == nil {
  682. br.Msg = "请登录"
  683. br.ErrMsg = "请登录,SysUser Is Empty"
  684. return
  685. }
  686. videoId, _ := this.GetInt("VideoId")
  687. videoInfo, _ := cygx.GetMicroRoadshowVideoByVideoId(videoId)
  688. if videoInfo == nil {
  689. br.Msg = "操作失败"
  690. br.ErrMsg = "视频ID错误"
  691. return
  692. }
  693. var condition string
  694. var pars []interface{}
  695. condition += ` AND activity_id = 0 AND video_id = ? `
  696. pars = append(pars, videoInfo.VideoId)
  697. list, err := cygx.GetArticleCommentListSearch(condition, pars)
  698. if err != nil {
  699. br.Msg = "获取失败"
  700. br.ErrMsg = "获取失败,Err:" + err.Error()
  701. return
  702. }
  703. //创建excel
  704. dir, err := os.Executable()
  705. exPath := filepath.Dir(dir)
  706. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  707. xlsxFile := xlsx.NewFile()
  708. if err != nil {
  709. br.Msg = "生成文件失败"
  710. br.ErrMsg = "生成文件失败"
  711. return
  712. }
  713. style := xlsx.NewStyle()
  714. alignment := xlsx.Alignment{
  715. Horizontal: "center",
  716. Vertical: "center",
  717. WrapText: true,
  718. }
  719. style.Alignment = alignment
  720. style.ApplyAlignment = true
  721. sheet, err := xlsxFile.AddSheet("名单")
  722. if err != nil {
  723. br.Msg = "新增Sheet失败"
  724. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  725. return
  726. }
  727. //标头
  728. rowTitle := sheet.AddRow()
  729. cellA := rowTitle.AddCell()
  730. cellA.Value = "姓名"
  731. cellB := rowTitle.AddCell()
  732. cellB.Value = "公司名称"
  733. cellC := rowTitle.AddCell()
  734. cellC.Value = "留言"
  735. cellD := rowTitle.AddCell()
  736. cellD.Value = "提交时间"
  737. for _, item := range list {
  738. row := sheet.AddRow()
  739. cellA := row.AddCell()
  740. cellA.Value = item.RealName
  741. cellB := row.AddCell()
  742. cellB.Value = item.CompanyName
  743. cellC := row.AddCell()
  744. cellC.Value = item.Content
  745. cellD := row.AddCell()
  746. cellD.Value = item.CreateTime
  747. }
  748. err = xlsxFile.Save(downLoadnFilePath)
  749. if err != nil {
  750. br.Msg = "保存文件失败"
  751. br.ErrMsg = "保存文件失败"
  752. return
  753. }
  754. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  755. downloadFileName := "留言列表" + randStr + ".xlsx"
  756. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  757. defer func() {
  758. os.Remove(downLoadnFilePath)
  759. }()
  760. br.Success = true
  761. br.Ret = 200
  762. br.Msg = "导出成功"
  763. }
  764. // @Title 留言详情excel表格下载
  765. // @Description 留言详情excel表格下载接口
  766. // @Param ActivityId query int true "活动Id"
  767. // @Success 200 导出成功
  768. // @router /microRoadshow/commentListExport/voice [get]
  769. func (this *MicroRoadshowController) VoiceCommentListExport() {
  770. br := new(models.BaseResponse).Init()
  771. defer func() {
  772. this.Data["json"] = br
  773. this.ServeJSON()
  774. }()
  775. sysUser := this.SysUser
  776. if sysUser == nil {
  777. br.Msg = "请登录"
  778. br.ErrMsg = "请登录,SysUser Is Empty"
  779. return
  780. }
  781. activityId, _ := this.GetInt("ActivityId")
  782. videoInfo, _ := cygx.GetMicroRoadshowVoiceById(activityId)
  783. if videoInfo == nil {
  784. br.Msg = "操作失败"
  785. br.ErrMsg = "音频ID错误"
  786. return
  787. }
  788. var condition string
  789. var pars []interface{}
  790. condition += ` AND activity_voice_id = ? `
  791. pars = append(pars, videoInfo.ActivityVoiceId)
  792. list, err := cygx.GetArticleCommentListSearch(condition, pars)
  793. if err != nil {
  794. br.Msg = "获取失败"
  795. br.ErrMsg = "获取失败,Err:" + err.Error()
  796. return
  797. }
  798. //创建excel
  799. dir, err := os.Executable()
  800. exPath := filepath.Dir(dir)
  801. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  802. xlsxFile := xlsx.NewFile()
  803. if err != nil {
  804. br.Msg = "生成文件失败"
  805. br.ErrMsg = "生成文件失败"
  806. return
  807. }
  808. style := xlsx.NewStyle()
  809. alignment := xlsx.Alignment{
  810. Horizontal: "center",
  811. Vertical: "center",
  812. WrapText: true,
  813. }
  814. style.Alignment = alignment
  815. style.ApplyAlignment = true
  816. sheet, err := xlsxFile.AddSheet("名单")
  817. if err != nil {
  818. br.Msg = "新增Sheet失败"
  819. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  820. return
  821. }
  822. //标头
  823. rowTitle := sheet.AddRow()
  824. cellA := rowTitle.AddCell()
  825. cellA.Value = "姓名"
  826. cellB := rowTitle.AddCell()
  827. cellB.Value = "公司名称"
  828. cellC := rowTitle.AddCell()
  829. cellC.Value = "留言"
  830. cellD := rowTitle.AddCell()
  831. cellD.Value = "提交时间"
  832. for _, item := range list {
  833. row := sheet.AddRow()
  834. cellA := row.AddCell()
  835. cellA.Value = item.RealName
  836. cellB := row.AddCell()
  837. cellB.Value = item.CompanyName
  838. cellC := row.AddCell()
  839. cellC.Value = item.Content
  840. cellD := row.AddCell()
  841. cellD.Value = item.CreateTime
  842. }
  843. err = xlsxFile.Save(downLoadnFilePath)
  844. if err != nil {
  845. br.Msg = "保存文件失败"
  846. br.ErrMsg = "保存文件失败"
  847. return
  848. }
  849. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  850. downloadFileName := "留言列表" + randStr + ".xlsx"
  851. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  852. defer func() {
  853. os.Remove(downLoadnFilePath)
  854. }()
  855. br.Success = true
  856. br.Ret = 200
  857. br.Msg = "导出成功"
  858. }
  859. // @Title 留言列表详情
  860. // @Description 获取留言列表详情接口
  861. // @Param VideoId query int true "视频ID"
  862. // @Success 200 {object} cygx.ArticleCommentListResp
  863. // @router /microRoadshow/commentList/video [get]
  864. func (this *MicroRoadshowController) CommentList() {
  865. br := new(models.BaseResponse).Init()
  866. defer func() {
  867. this.Data["json"] = br
  868. this.ServeJSON()
  869. }()
  870. sysUser := this.SysUser
  871. if sysUser == nil {
  872. br.Msg = "请登录"
  873. br.ErrMsg = "请登录,SysUser Is Empty"
  874. return
  875. }
  876. videoId, _ := this.GetInt("VideoId")
  877. videoInfo, _ := cygx.GetMicroRoadshowVideoByVideoId(videoId)
  878. if videoInfo == nil {
  879. br.Msg = "操作失败"
  880. br.ErrMsg = "视频ID错误"
  881. return
  882. }
  883. var condition string
  884. var pars []interface{}
  885. condition += ` AND activity_id = 0 AND video_id = ? `
  886. pars = append(pars, videoInfo.VideoId)
  887. list, err := cygx.GetArticleCommentListSearch(condition, pars)
  888. if err != nil {
  889. br.Msg = "获取失败"
  890. br.ErrMsg = "获取失败,Err:" + err.Error()
  891. return
  892. }
  893. //list, err := cygx.GetArticleCommentListByVideoId(videoId)
  894. //if err != nil {
  895. // br.Msg = "获取失败"
  896. // br.ErrMsg = "获取失败,Err:" + err.Error()
  897. // return
  898. //}
  899. resp := new(cygx.ArticleCommentListResp)
  900. resp.List = list
  901. br.Ret = 200
  902. br.Success = true
  903. br.Msg = "获取成功"
  904. br.Data = resp
  905. }
  906. // @Title 留言列表详情
  907. // @Description 获取留言列表详情接口
  908. // @Param ActivityId query int true "活动Id"
  909. // @Success 200 {object} cygx.ArticleCommentListResp
  910. // @router /microRoadshow/commentList/voice [get]
  911. func (this *MicroRoadshowController) VoiceCommentList() {
  912. br := new(models.BaseResponse).Init()
  913. defer func() {
  914. this.Data["json"] = br
  915. this.ServeJSON()
  916. }()
  917. sysUser := this.SysUser
  918. if sysUser == nil {
  919. br.Msg = "请登录"
  920. br.ErrMsg = "请登录,SysUser Is Empty"
  921. return
  922. }
  923. activityId, _ := this.GetInt("ActivityId")
  924. videoInfo, _ := cygx.GetMicroRoadshowVoiceById(activityId)
  925. if videoInfo == nil {
  926. br.Msg = "操作失败"
  927. br.ErrMsg = "音频ID错误"
  928. return
  929. }
  930. var condition string
  931. var pars []interface{}
  932. condition += ` AND activity_voice_id = ? `
  933. pars = append(pars, videoInfo.ActivityVoiceId)
  934. list, err := cygx.GetArticleCommentListSearch(condition, pars)
  935. if err != nil {
  936. br.Msg = "获取失败"
  937. br.ErrMsg = "获取失败,Err:" + err.Error()
  938. return
  939. }
  940. resp := new(cygx.ArticleCommentListResp)
  941. resp.List = list
  942. br.Ret = 200
  943. br.Success = true
  944. br.Msg = "获取成功"
  945. br.Data = resp
  946. }