report_selection.go 14 KB

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