report_selection.go 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  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. "strings"
  10. "time"
  11. )
  12. // 报告
  13. type ReportSelectionController struct {
  14. BaseAuthController
  15. }
  16. // @Title 获取报告精选详情
  17. // @Description 获取报告精选详情接口
  18. // @Param ArticleId query int true "报告ID"
  19. // @Param IsBestNew query bool false "是否获取最新的一篇报告"
  20. // @Success 200 {object} models.ReportSelectionLetailResp
  21. // @router /detail [get]
  22. func (this *ReportSelectionController) Detail() {
  23. br := new(models.BaseResponse).Init()
  24. defer func() {
  25. this.Data["json"] = br
  26. this.ServeJSON()
  27. }()
  28. user := this.User
  29. if user == nil {
  30. br.Msg = "请重新登录"
  31. br.Ret = 408
  32. return
  33. }
  34. //uid := user.UserId
  35. articleId, _ := this.GetInt("ArticleId")
  36. activityId, _ := this.GetInt("ActivityId")
  37. isBestNew, _ := this.GetBool("IsBestNew")
  38. if activityId > 0 && articleId == 0 {
  39. articleId = activityId
  40. }
  41. if articleId == 0 || isBestNew {
  42. isBestNew = true
  43. if isBestNew {
  44. tbdb := "cygx_report_selection"
  45. condition := ` AND publish_status = 1 `
  46. var pars []interface{}
  47. list, err := models.GetReportSelectionListPublic(condition, "1", tbdb, pars, 0, 1)
  48. if err != nil {
  49. br.Msg = "获取失败"
  50. br.ErrMsg = "获取失败,Err:" + err.Error()
  51. return
  52. }
  53. for _, v := range list {
  54. articleId = v.ArticleId
  55. }
  56. }
  57. }
  58. if articleId < 1 {
  59. br.Msg = "获取信息失败"
  60. br.ErrMsg = "报告ID错误" + strconv.Itoa(articleId)
  61. return
  62. }
  63. resp := new(models.ReportSelectionLetailResp)
  64. //判断用户权限
  65. hasPermission, err := services.GetUserhasPermission(user)
  66. if err != nil {
  67. br.Msg = "获取信息失败"
  68. br.ErrMsg = "获取用户权限信息失败,Err:" + err.Error()
  69. }
  70. detail, err := models.GetCygxReportSelectionInfoById(articleId)
  71. if err != nil {
  72. br.Msg = "获取信息失败"
  73. br.ErrMsg = "报告不存在,Err:" + err.Error() + "articleId:" + strconv.Itoa(articleId)
  74. return
  75. }
  76. //未设置全部可见的只能给弘则内部查看
  77. if detail.VisibleRange == 1 || user.CompanyId == utils.HZ_COMPANY_ID {
  78. resp.IsShow = true
  79. }
  80. resp.HasPermission = hasPermission
  81. if hasPermission != 1 || !resp.IsShow {
  82. resp.Detail = detail
  83. br.Ret = 200
  84. br.Success = true
  85. br.Msg = "获取成功"
  86. br.Data = resp
  87. return
  88. }
  89. if detail.ReportLink != "" {
  90. articleIdLink, _ := services.GetReportLinkToArticleid(detail.ReportLink)
  91. detail.CeLueArticleId = articleIdLink
  92. }
  93. articleStockMap, _ := services.GetArticleStockMap()
  94. detail.PublishDate = utils.StrTimeToTime(detail.PublishDate).Format("2006-01-02")
  95. existMap := make(map[int]int)
  96. var items []*models.ReportSelectionChartPermission
  97. var itemsSubject []*models.ReportSelectionChartLogPermission
  98. listLog, err := models.GetReportSelectionlogListAll(articleId)
  99. if err != nil {
  100. br.Msg = "获取失败"
  101. br.ErrMsg = "获取子类信息失败,Err:" + err.Error()
  102. return
  103. }
  104. detail.VideoPlaySeconds = utils.Mp3Time(detail.VideoPlaySeconds)
  105. //获取行业核心逻辑汇总
  106. listChartLog, err := models.GetCygxReportSelectionChartLogRepList(articleId)
  107. if err != nil {
  108. br.Msg = "获取失败"
  109. br.ErrMsg = "获取失败,Err:" + err.Error()
  110. return
  111. }
  112. mapChartLog := make(map[string]string)
  113. for _, v := range listChartLog {
  114. mapChartLog[v.ChartPermissionName] = v.BodyChartSummary
  115. }
  116. for _, v := range listLog {
  117. item := new(models.ReportSelectionChartPermission)
  118. itemSubject := new(models.ReportSelectionChartLogPermission)
  119. itemSubject.PermissionName = v.PermissionName
  120. if existMap[v.ChartPermissionId] == 0 {
  121. //item.PermissionName = v.PermissionName + "领域深度报告和调研"
  122. item.PermissionName = v.PermissionName
  123. item.IcoLink = v.IcoLink
  124. listSonLog, err := models.GetReportSelectionlogSonListAll(articleId, v.ChartPermissionId)
  125. if err != nil && err.Error() != utils.ErrNoRow() {
  126. br.Msg = "获取信息失败"
  127. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  128. return
  129. }
  130. for k2, v2 := range listSonLog {
  131. if v2.IndustrialManagementId != "" {
  132. listIndustrial, err := models.GetIndustrialByIds(v2.IndustrialManagementId)
  133. if err != nil && err.Error() != utils.ErrNoRow() {
  134. br.Msg = "获取信息失败"
  135. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  136. return
  137. }
  138. listSonLog[k2].OverviewArticleId = articleStockMap[v2.SubjectName]
  139. listSonLog[k2].List = listIndustrial
  140. listSonLog[k2].IsShowApplyButton = true
  141. if v2.Label != "" {
  142. v2.CompanyLabel = strings.Split(v2.Label, "{|}")
  143. }
  144. }
  145. itemSubject.ListSubject = append(itemSubject.ListSubject, &models.ReportSelectionChartLogSubjectName{SubjectName: v2.SubjectName, IsNew: v2.IsNew, IndustrialSubjectId: v2.IndustrialSubjectId})
  146. }
  147. item.BodyChartSummary = mapChartLog[v.PermissionName]
  148. item.List = listSonLog
  149. items = append(items, item)
  150. itemsSubject = append(itemsSubject, itemSubject)
  151. //itemLogs = make([]*models.CygxReportSelectionLogDetail, 0)
  152. }
  153. existMap[v.ChartPermissionId] = v.ChartPermissionId
  154. }
  155. //historyRecord := new(models.CygxReportHistoryRecord)
  156. //historyRecord.UserId = uid
  157. //historyRecord.ArticleId = articleId
  158. //historyRecord.CreateTime = time.Now()
  159. //historyRecord.Mobile = user.Mobile
  160. //historyRecord.Email = user.Email
  161. //historyRecord.CompanyId = user.CompanyId
  162. //historyRecord.CompanyName = user.CompanyName
  163. //historyRecord.ReportType = "bgjx"
  164. //sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  165. //if err != nil && err.Error() != utils.ErrNoRow() {
  166. // br.Msg = "获取信息失败"
  167. // br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  168. // return
  169. //}
  170. //historyRecord.RealName = user.RealName
  171. //if sellerItem != nil {
  172. // historyRecord.SellerName = sellerItem.RealName
  173. //}
  174. //
  175. //go models.AddCygxReportHistoryRecord(historyRecord)
  176. resp.List = items
  177. resp.ListPermissionSubject = itemsSubject
  178. resp.Detail = detail
  179. br.Ret = 200
  180. br.Success = true
  181. br.Msg = "获取成功"
  182. br.Data = resp
  183. }
  184. // @Title 标的点击记录
  185. // @Description 标的点击记录接口
  186. // @Param request body models.AddCygxReportSelectionSubjectHistoryReq true "type json string"
  187. // @router /click/history [post]
  188. func (this *ReportSelectionController) ClickHistory() {
  189. br := new(models.BaseResponse).Init()
  190. defer func() {
  191. this.Data["json"] = br
  192. this.ServeJSON()
  193. }()
  194. user := this.User
  195. if user == nil {
  196. br.Msg = "请重新登录"
  197. br.Ret = 408
  198. return
  199. }
  200. var req models.AddCygxReportSelectionSubjectHistoryReq
  201. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  202. if err != nil {
  203. br.Msg = "参数解析异常!"
  204. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  205. return
  206. }
  207. if req.ArticleId <= 0 {
  208. br.Msg = "文章不存在"
  209. br.ErrMsg = "文章不存在,文章ID错误"
  210. return
  211. }
  212. if req.IndustrialSubjectId <= 0 {
  213. br.Msg = "标的ID不存在"
  214. br.ErrMsg = "标的ID不存在,标的ID错误"
  215. return
  216. }
  217. item := models.CygxReportSelectionSubjectHistory{
  218. UserId: user.UserId,
  219. ArticleId: req.ArticleId,
  220. CreateTime: time.Now(),
  221. ModifyTime: time.Now(),
  222. Mobile: user.Mobile,
  223. Email: user.Email,
  224. CompanyId: user.CompanyId,
  225. CompanyName: user.CompanyName,
  226. IndustrialSubjectId: req.IndustrialSubjectId,
  227. }
  228. err = models.AddCygxReportSelectionSubjectHistory(&item)
  229. if err != nil {
  230. br.Msg = "记录失败"
  231. br.ErrMsg = "记录失败,Err:" + err.Error()
  232. return
  233. }
  234. br.Ret = 200
  235. br.Success = true
  236. br.Msg = "记录成功"
  237. }
  238. // @Title 上传文章阅读时间
  239. // @Description 上传文章阅读时间接口
  240. // @Param request body models.AddStopTimeRep true "type json string"
  241. // @Success 200 {object} models.ArticleDetailResp
  242. // @router /addStopTime [post]
  243. func (this *ReportSelectionController) AddStopTime() {
  244. br := new(models.BaseResponse).Init()
  245. defer func() {
  246. this.Data["json"] = br
  247. this.ServeJSON()
  248. }()
  249. user := this.User
  250. if user == nil {
  251. br.Msg = "请登录"
  252. br.ErrMsg = "请登录,用户信息为空"
  253. br.Ret = 408
  254. return
  255. }
  256. var req models.AddReportSelectionStopTimeRep
  257. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  258. if err != nil {
  259. br.Msg = "参数解析异常!"
  260. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  261. return
  262. }
  263. uid := user.UserId
  264. articleId := req.ArticleId
  265. stopTime := req.StopTime
  266. outType := req.OutType
  267. source := req.Source
  268. var reportType string
  269. if source == 1 {
  270. reportType = "bgjx"
  271. } else if source == 2 {
  272. reportType = "bzyjhz"
  273. } else if source == 3 {
  274. reportType = "szjyhz"
  275. }
  276. hasPermission, err := services.GetUserhasPermission(user)
  277. if err != nil {
  278. br.Msg = "获取信息失败"
  279. br.ErrMsg = "获取用户权限信息失败,Err:" + err.Error()
  280. }
  281. if hasPermission == 1 {
  282. historyRecord := new(models.CygxReportHistoryRecord)
  283. historyRecord.UserId = uid
  284. historyRecord.ArticleId = articleId
  285. historyRecord.CreateTime = time.Now().Add(-time.Second * time.Duration(stopTime))
  286. historyRecord.Mobile = user.Mobile
  287. historyRecord.Email = user.Email
  288. historyRecord.CompanyId = user.CompanyId
  289. historyRecord.CompanyName = user.CompanyName
  290. historyRecord.StopTime = stopTime
  291. historyRecord.OutType = outType
  292. historyRecord.ReportType = reportType
  293. historyRecord.RegisterPlatform = utils.REGISTER_PLATFORM
  294. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  295. if err != nil && err.Error() != utils.ErrNoRow() {
  296. br.Msg = "获取信息失败"
  297. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  298. return
  299. }
  300. historyRecord.RealName = user.RealName
  301. if sellerItem != nil {
  302. historyRecord.SellerName = sellerItem.RealName
  303. }
  304. go services.AddCygxReportHistoryRecord(historyRecord)
  305. }
  306. br.Ret = 200
  307. br.Success = true
  308. br.Msg = "操作成功"
  309. }
  310. // @Title 获取报告精选列表
  311. // @Description 获取报告精选列表接口
  312. // @Param PageSize query int true "每页数据条数"
  313. // @Param CurrentIndex query int true "当前页页码,从1开始"
  314. // @Success 200 {object} models.ReportSelectionLetailResp
  315. // @router /list [get]
  316. func (this *ReportSelectionController) List() {
  317. br := new(models.BaseResponse).Init()
  318. defer func() {
  319. this.Data["json"] = br
  320. this.ServeJSON()
  321. }()
  322. user := this.User
  323. if user == nil {
  324. br.Msg = "请重新登录"
  325. br.Ret = 408
  326. return
  327. }
  328. resp := new(models.CygxReportSelectionListPublicRep)
  329. pageSize, _ := this.GetInt("PageSize")
  330. currentIndex, _ := this.GetInt("CurrentIndex")
  331. var startSize int
  332. if pageSize <= 0 {
  333. pageSize = utils.PageSize20
  334. }
  335. if currentIndex <= 0 {
  336. currentIndex = 1
  337. }
  338. startSize = utils.StartIndex(currentIndex, pageSize)
  339. var condition string
  340. var pars []interface{}
  341. condition += ` AND art.publish_status = 1 AND article_id >= 16 `
  342. total, err := models.GetCygxReportSelectionCount(condition, pars)
  343. if err != nil {
  344. br.Msg = "获取失败"
  345. br.ErrMsg = "获取失败,Err:" + err.Error()
  346. return
  347. }
  348. condition += " ORDER BY art.publish_date DESC "
  349. list, err := models.GetReportSelectionList(condition, pars, startSize, pageSize)
  350. if err != nil {
  351. br.Msg = "获取失败"
  352. br.ErrMsg = "获取失败,Err:" + err.Error()
  353. return
  354. }
  355. var articleIdArr []int
  356. for _, v := range list {
  357. v.PublishDate = utils.TimeRemoveHms2(v.PublishDate)
  358. articleIdArr = append(articleIdArr, v.ArticleId)
  359. }
  360. lenarticleIdArr := len(articleIdArr)
  361. maplabel := make(map[int]string)
  362. if lenarticleIdArr > 0 {
  363. condition = ""
  364. pars = make([]interface{}, 0)
  365. condition = ` AND is_new = 1 AND article_id IN (` + utils.GetOrmInReplace(lenarticleIdArr) + `)`
  366. pars = append(pars, articleIdArr)
  367. listLog, err := models.GetCygxReportSelectionLog(condition, pars, 0, 9999)
  368. if err != nil {
  369. br.Msg = "获取失败"
  370. br.ErrMsg = "获取失败,GetCygxReportSelectionLogErr:" + err.Error()
  371. return
  372. }
  373. for _, v := range listLog {
  374. maplabel[v.ArticleId] += v.SubjectName + ","
  375. }
  376. }
  377. for _, v := range list {
  378. v.SubjectName = strings.TrimRight(maplabel[v.ArticleId], ",")
  379. }
  380. page := paging.GetPaging(currentIndex, pageSize, total)
  381. resp.List = list
  382. resp.Paging = page
  383. br.Ret = 200
  384. br.Success = true
  385. br.Msg = "获取成功"
  386. br.Data = resp
  387. }
  388. // @Title 报告精选申请路演
  389. // @Description 报告精选申请路演
  390. // @Param request body cygx.CygxBannerIdReq true "type json string"
  391. // @Success 200 Ret=200 提交成功
  392. // @router /report_selection_log/apply [post]
  393. func (this *ReportSelectionController) ReportSelectionLogApply() {
  394. br := new(models.BaseResponse).Init()
  395. defer func() {
  396. this.Data["json"] = br
  397. this.ServeJSON()
  398. }()
  399. user := this.User
  400. if user == nil {
  401. br.Msg = "请登录"
  402. br.ErrMsg = "请登录,用户信息为空"
  403. br.Ret = 408
  404. return
  405. }
  406. var req models.CygxReportSelectionLogApplyReq
  407. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  408. if err != nil {
  409. br.Msg = "参数解析异常!"
  410. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  411. return
  412. }
  413. articleId := req.ArticleId
  414. subjectName := req.SubjectName
  415. var condition string
  416. var pars []interface{}
  417. condition += ` AND article_id = ? AND subject_name = ? AND user_id = ? `
  418. pars = append(pars, articleId, subjectName, user.UserId)
  419. totalApply, err := models.GetCygxReportSelectionLogApplyCount(condition, pars)
  420. if err != nil {
  421. br.Msg = "申请失败!"
  422. br.ErrMsg = "申请失败,Err:" + err.Error()
  423. return
  424. }
  425. if totalApply > 0 {
  426. br.Msg = "您已提交过此公司的路演申请,请等待销售与您联系!"
  427. return
  428. }
  429. logDetail, err := models.GetCygxReportSelectionLogDetail(articleId, subjectName)
  430. if err != nil {
  431. br.Msg = "申请失败!"
  432. br.ErrMsg = "申请失败,Err:" + err.Error()
  433. return
  434. }
  435. item := new(models.CygxReportSelectionLogApply)
  436. item.UserId = user.UserId
  437. item.CreateTime = time.Now()
  438. item.ModifyTime = time.Now()
  439. item.Mobile = user.Mobile
  440. item.Email = user.Email
  441. item.CompanyId = user.CompanyId
  442. item.CompanyName = user.CompanyName
  443. item.ArticleId = logDetail.ArticleId
  444. item.SubjectName = logDetail.SubjectName
  445. item.IndustrialSubjectId = logDetail.IndustrialSubjectId
  446. item.RegisterPlatform = utils.REGISTER_PLATFORM
  447. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  448. if err != nil && err.Error() != utils.ErrNoRow() {
  449. return
  450. }
  451. item.RealName = user.RealName
  452. if sellerItem != nil {
  453. item.SellerName = sellerItem.RealName
  454. }
  455. _, err = models.AddCygxReportSelectionLogApply(item)
  456. if err != nil {
  457. br.Msg = "申请失败"
  458. br.ErrMsg = "申请失败,Err:" + err.Error()
  459. return
  460. }
  461. go services.SendCygxReportSelectionLogApplyTemplateMsg(user, logDetail.SubjectName)
  462. br.Ret = 200
  463. br.Success = true
  464. br.Msg = "记录成功"
  465. }