report_selection.go 15 KB

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