report_selection.go 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  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. //后台如果勾了隐藏那么这里就不展示 V11.3 2023-08-17
  139. if listSonLog[k2].IsShowOverviewArticle == 1 {
  140. listSonLog[k2].OverviewArticleId = articleStockMap[v2.SubjectName]
  141. }
  142. listSonLog[k2].List = listIndustrial
  143. listSonLog[k2].IsShowApplyButton = true
  144. if v2.Label != "" {
  145. v2.CompanyLabel = strings.Split(v2.Label, "{|}")
  146. }
  147. }
  148. itemSubject.ListSubject = append(itemSubject.ListSubject, &models.ReportSelectionChartLogSubjectName{SubjectName: v2.SubjectName, IsNew: v2.IsNew, IndustrialSubjectId: v2.IndustrialSubjectId})
  149. }
  150. item.BodyChartSummary = mapChartLog[v.PermissionName]
  151. item.List = listSonLog
  152. items = append(items, item)
  153. itemsSubject = append(itemsSubject, itemSubject)
  154. //itemLogs = make([]*models.CygxReportSelectionLogDetail, 0)
  155. }
  156. existMap[v.ChartPermissionId] = v.ChartPermissionId
  157. }
  158. //historyRecord := new(models.CygxReportHistoryRecord)
  159. //historyRecord.UserId = uid
  160. //historyRecord.ArticleId = articleId
  161. //historyRecord.CreateTime = time.Now()
  162. //historyRecord.Mobile = user.Mobile
  163. //historyRecord.Email = user.Email
  164. //historyRecord.CompanyId = user.CompanyId
  165. //historyRecord.CompanyName = user.CompanyName
  166. //historyRecord.ReportType = "bgjx"
  167. //sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  168. //if err != nil && err.Error() != utils.ErrNoRow() {
  169. // br.Msg = "获取信息失败"
  170. // br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  171. // return
  172. //}
  173. //historyRecord.RealName = user.RealName
  174. //if sellerItem != nil {
  175. // historyRecord.SellerName = sellerItem.RealName
  176. //}
  177. //
  178. //go models.AddCygxReportHistoryRecord(historyRecord)
  179. resp.List = items
  180. resp.ListPermissionSubject = itemsSubject
  181. resp.Detail = detail
  182. br.Ret = 200
  183. br.Success = true
  184. br.Msg = "获取成功"
  185. br.Data = resp
  186. }
  187. // @Title 标的点击记录
  188. // @Description 标的点击记录接口
  189. // @Param request body models.AddCygxReportSelectionSubjectHistoryReq true "type json string"
  190. // @router /click/history [post]
  191. func (this *ReportSelectionController) ClickHistory() {
  192. br := new(models.BaseResponse).Init()
  193. defer func() {
  194. this.Data["json"] = br
  195. this.ServeJSON()
  196. }()
  197. user := this.User
  198. if user == nil {
  199. br.Msg = "请重新登录"
  200. br.Ret = 408
  201. return
  202. }
  203. var req models.AddCygxReportSelectionSubjectHistoryReq
  204. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  205. if err != nil {
  206. br.Msg = "参数解析异常!"
  207. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  208. return
  209. }
  210. if req.ArticleId <= 0 {
  211. br.Msg = "文章不存在"
  212. br.ErrMsg = "文章不存在,文章ID错误"
  213. return
  214. }
  215. if req.IndustrialSubjectId <= 0 {
  216. br.Msg = "标的ID不存在"
  217. br.ErrMsg = "标的ID不存在,标的ID错误"
  218. return
  219. }
  220. item := models.CygxReportSelectionSubjectHistory{
  221. UserId: user.UserId,
  222. ArticleId: req.ArticleId,
  223. CreateTime: time.Now(),
  224. ModifyTime: time.Now(),
  225. Mobile: user.Mobile,
  226. Email: user.Email,
  227. CompanyId: user.CompanyId,
  228. CompanyName: user.CompanyName,
  229. IndustrialSubjectId: req.IndustrialSubjectId,
  230. }
  231. err = models.AddCygxReportSelectionSubjectHistory(&item)
  232. if err != nil {
  233. br.Msg = "记录失败"
  234. br.ErrMsg = "记录失败,Err:" + err.Error()
  235. return
  236. }
  237. br.Ret = 200
  238. br.Success = true
  239. br.Msg = "记录成功"
  240. }
  241. // @Title 上传文章阅读时间
  242. // @Description 上传文章阅读时间接口
  243. // @Param request body models.AddStopTimeRep true "type json string"
  244. // @Success 200 {object} models.ArticleDetailResp
  245. // @router /addStopTime [post]
  246. func (this *ReportSelectionController) AddStopTime() {
  247. br := new(models.BaseResponse).Init()
  248. defer func() {
  249. this.Data["json"] = br
  250. this.ServeJSON()
  251. }()
  252. user := this.User
  253. if user == nil {
  254. br.Msg = "请登录"
  255. br.ErrMsg = "请登录,用户信息为空"
  256. br.Ret = 408
  257. return
  258. }
  259. var req models.AddReportSelectionStopTimeRep
  260. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  261. if err != nil {
  262. br.Msg = "参数解析异常!"
  263. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  264. return
  265. }
  266. uid := user.UserId
  267. articleId := req.ArticleId
  268. stopTime := req.StopTime
  269. outType := req.OutType
  270. source := req.Source
  271. var reportType string
  272. if source == 1 {
  273. reportType = "bgjx"
  274. } else if source == 2 {
  275. reportType = "bzyjhz"
  276. } else if source == 3 {
  277. reportType = "szjyhz"
  278. }
  279. hasPermission, err := services.GetUserhasPermission(user)
  280. if err != nil {
  281. br.Msg = "获取信息失败"
  282. br.ErrMsg = "获取用户权限信息失败,Err:" + err.Error()
  283. }
  284. if hasPermission == 1 {
  285. historyRecord := new(models.CygxReportHistoryRecord)
  286. historyRecord.UserId = uid
  287. historyRecord.ArticleId = articleId
  288. historyRecord.CreateTime = time.Now().Add(-time.Second * time.Duration(stopTime))
  289. historyRecord.Mobile = user.Mobile
  290. historyRecord.Email = user.Email
  291. historyRecord.CompanyId = user.CompanyId
  292. historyRecord.CompanyName = user.CompanyName
  293. historyRecord.StopTime = stopTime
  294. historyRecord.OutType = outType
  295. historyRecord.ReportType = reportType
  296. historyRecord.RegisterPlatform = utils.REGISTER_PLATFORM
  297. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  298. if err != nil && err.Error() != utils.ErrNoRow() {
  299. br.Msg = "获取信息失败"
  300. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  301. return
  302. }
  303. historyRecord.RealName = user.RealName
  304. if sellerItem != nil {
  305. historyRecord.SellerName = sellerItem.RealName
  306. }
  307. go services.AddCygxReportHistoryRecord(historyRecord)
  308. }
  309. br.Ret = 200
  310. br.Success = true
  311. br.Msg = "操作成功"
  312. }
  313. // @Title 获取报告精选列表
  314. // @Description 获取报告精选列表接口
  315. // @Param PageSize query int true "每页数据条数"
  316. // @Param CurrentIndex query int true "当前页页码,从1开始"
  317. // @Success 200 {object} models.ReportSelectionLetailResp
  318. // @router /list [get]
  319. func (this *ReportSelectionController) List() {
  320. br := new(models.BaseResponse).Init()
  321. defer func() {
  322. this.Data["json"] = br
  323. this.ServeJSON()
  324. }()
  325. user := this.User
  326. if user == nil {
  327. br.Msg = "请重新登录"
  328. br.Ret = 408
  329. return
  330. }
  331. resp := new(models.CygxReportSelectionListPublicRep)
  332. pageSize, _ := this.GetInt("PageSize")
  333. currentIndex, _ := this.GetInt("CurrentIndex")
  334. var startSize int
  335. if pageSize <= 0 {
  336. pageSize = utils.PageSize20
  337. }
  338. if currentIndex <= 0 {
  339. currentIndex = 1
  340. }
  341. startSize = utils.StartIndex(currentIndex, pageSize)
  342. var condition string
  343. var pars []interface{}
  344. condition += ` AND art.publish_status = 1 AND article_id >= 16 `
  345. total, err := models.GetCygxReportSelectionCount(condition, pars)
  346. if err != nil {
  347. br.Msg = "获取失败"
  348. br.ErrMsg = "获取失败,Err:" + err.Error()
  349. return
  350. }
  351. condition += " ORDER BY art.publish_date DESC "
  352. list, err := models.GetReportSelectionList(condition, pars, startSize, pageSize)
  353. if err != nil {
  354. br.Msg = "获取失败"
  355. br.ErrMsg = "获取失败,Err:" + err.Error()
  356. return
  357. }
  358. var articleIdArr []int
  359. for _, v := range list {
  360. v.PublishDate = utils.TimeRemoveHms2(v.PublishDate)
  361. articleIdArr = append(articleIdArr, v.ArticleId)
  362. }
  363. lenarticleIdArr := len(articleIdArr)
  364. maplabel := make(map[int]string)
  365. if lenarticleIdArr > 0 {
  366. condition = ""
  367. pars = make([]interface{}, 0)
  368. condition = ` AND is_new = 1 AND article_id IN (` + utils.GetOrmInReplace(lenarticleIdArr) + `)`
  369. pars = append(pars, articleIdArr)
  370. listLog, err := models.GetCygxReportSelectionLog(condition, pars, 0, 9999)
  371. if err != nil {
  372. br.Msg = "获取失败"
  373. br.ErrMsg = "获取失败,GetCygxReportSelectionLogErr:" + err.Error()
  374. return
  375. }
  376. for _, v := range listLog {
  377. maplabel[v.ArticleId] += v.SubjectName + ","
  378. }
  379. }
  380. for _, v := range list {
  381. v.SubjectName = strings.TrimRight(maplabel[v.ArticleId], ",")
  382. }
  383. page := paging.GetPaging(currentIndex, pageSize, total)
  384. resp.List = list
  385. resp.Paging = page
  386. br.Ret = 200
  387. br.Success = true
  388. br.Msg = "获取成功"
  389. br.Data = resp
  390. }
  391. // @Title 报告精选申请路演
  392. // @Description 报告精选申请路演
  393. // @Param request body cygx.CygxBannerIdReq true "type json string"
  394. // @Success 200 Ret=200 提交成功
  395. // @router /report_selection_log/apply [post]
  396. func (this *ReportSelectionController) ReportSelectionLogApply() {
  397. br := new(models.BaseResponse).Init()
  398. defer func() {
  399. this.Data["json"] = br
  400. this.ServeJSON()
  401. }()
  402. user := this.User
  403. if user == nil {
  404. br.Msg = "请登录"
  405. br.ErrMsg = "请登录,用户信息为空"
  406. br.Ret = 408
  407. return
  408. }
  409. var req models.CygxReportSelectionLogApplyReq
  410. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  411. if err != nil {
  412. br.Msg = "参数解析异常!"
  413. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  414. return
  415. }
  416. articleId := req.ArticleId
  417. subjectName := req.SubjectName
  418. var condition string
  419. var pars []interface{}
  420. condition += ` AND article_id = ? AND subject_name = ? AND user_id = ? `
  421. pars = append(pars, articleId, subjectName, user.UserId)
  422. totalApply, err := models.GetCygxReportSelectionLogApplyCount(condition, pars)
  423. if err != nil {
  424. br.Msg = "申请失败!"
  425. br.ErrMsg = "申请失败,Err:" + err.Error()
  426. return
  427. }
  428. if totalApply > 0 {
  429. br.Msg = "您已提交过此公司的路演申请,请等待销售与您联系!"
  430. return
  431. }
  432. logDetail, err := models.GetCygxReportSelectionLogDetail(articleId, subjectName)
  433. if err != nil {
  434. br.Msg = "申请失败!"
  435. br.ErrMsg = "申请失败,Err:" + err.Error()
  436. return
  437. }
  438. item := new(models.CygxReportSelectionLogApply)
  439. item.UserId = user.UserId
  440. item.CreateTime = time.Now()
  441. item.ModifyTime = time.Now()
  442. item.Mobile = user.Mobile
  443. item.Email = user.Email
  444. item.CompanyId = user.CompanyId
  445. item.CompanyName = user.CompanyName
  446. item.ArticleId = logDetail.ArticleId
  447. item.SubjectName = logDetail.SubjectName
  448. item.IndustrialSubjectId = logDetail.IndustrialSubjectId
  449. item.RegisterPlatform = utils.REGISTER_PLATFORM
  450. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  451. if err != nil && err.Error() != utils.ErrNoRow() {
  452. return
  453. }
  454. item.RealName = user.RealName
  455. if sellerItem != nil {
  456. item.SellerName = sellerItem.RealName
  457. }
  458. _, err = models.AddCygxReportSelectionLogApply(item)
  459. if err != nil {
  460. br.Msg = "申请失败"
  461. br.ErrMsg = "申请失败,Err:" + err.Error()
  462. return
  463. }
  464. go services.SendCygxReportSelectionLogApplyTemplateMsg(user, logDetail.SubjectName)
  465. br.Ret = 200
  466. br.Success = true
  467. br.Msg = "记录成功"
  468. }