tactics.go 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "hongze/hongze_cygx/models"
  7. "hongze/hongze_cygx/services"
  8. "hongze/hongze_cygx/utils"
  9. "html"
  10. "regexp"
  11. "strconv"
  12. "strings"
  13. "time"
  14. )
  15. // 策略
  16. type TacticsController struct {
  17. BaseAuthController
  18. }
  19. type TacticsCommonController struct {
  20. BaseCommonController
  21. }
  22. // @Title 策略、行业列表接口
  23. // @Description 获取策略、行业 通用列表接口
  24. // @Param PageSize query int true "每页数据条数"
  25. // @Param CurrentIndex query int true "当前页页码,从1开始"
  26. // @Param CategoryId query int true "分类ID"
  27. // @Success 200 {object} models.TacticsListResp
  28. // @router /list [get]
  29. func (this *TacticsController) List() {
  30. br := new(models.BaseResponse).Init()
  31. defer func() {
  32. this.Data["json"] = br
  33. this.ServeJSON()
  34. }()
  35. user := this.User
  36. if user == nil {
  37. br.Msg = "请重新登录"
  38. br.Ret = 408
  39. return
  40. }
  41. //uid := user.UserId
  42. pageSize, _ := this.GetInt("PageSize")
  43. currentIndex, _ := this.GetInt("CurrentIndex")
  44. categoryId, _ := this.GetInt("CategoryId")
  45. var startSize int
  46. if pageSize <= 0 {
  47. pageSize = utils.PageSize20
  48. }
  49. if currentIndex <= 0 {
  50. currentIndex = 1
  51. }
  52. startSize = paging.StartIndex(currentIndex, pageSize)
  53. //var condition string
  54. //var listTacticsSrt string
  55. //var pars []interface{}
  56. //var total int
  57. resp := new(models.TacticsListResp)
  58. list := make([]*models.ReportArticle, 0)
  59. var total int
  60. var err error
  61. if categoryId == utils.ACTEGORY_ID_AI_QY {
  62. list, total, err = services.GetAiQianYanArtilceList(startSize, pageSize)
  63. } else {
  64. list, total, err = models.GetReportAndproductIndustrylList(categoryId, startSize, pageSize)
  65. }
  66. if err != nil {
  67. br.Msg = "获取信息失败"
  68. br.Msg = "获取帖子数据失败,Err:" + err.Error()
  69. return
  70. }
  71. var articleIds []int
  72. var productInteriorIs []int
  73. page := paging.GetPaging(currentIndex, pageSize, total)
  74. for _, v := range list {
  75. if v.Resource == 1 {
  76. articleIds = append(articleIds, v.ArticleId)
  77. } else {
  78. productInteriorIs = append(productInteriorIs, v.ArticleId)
  79. }
  80. }
  81. ArticleHistoryMap := services.GetArticleHistoryByUser(articleIds, user)
  82. ProductInteriorHistoryMap := services.GetCygxProductInteriorHistoryListMap(productInteriorIs, user)
  83. productInteriorMapPv := services.GetCygxProductInteriorHistoryListPvMap(productInteriorIs) //产品内测Pv
  84. for k, v := range list {
  85. if v.Resource == 1 {
  86. if ArticleHistoryMap[v.ArticleId] == 0 && user.CreatedTime.Before(utils.StrTimeToTime(v.PublishDate)) && utils.StrTimeToTime(utils.OnlineTime).Before(utils.StrTimeToTime(v.PublishDate)) {
  87. list[k].IsRed = true
  88. }
  89. } else {
  90. if ProductInteriorHistoryMap[v.ArticleId] == 0 && user.CreatedTime.Before(utils.StrTimeToTime(v.PublishDate)) && utils.StrTimeToTime(utils.OnlineTime).Before(utils.StrTimeToTime(v.PublishDate)) {
  91. list[k].IsRed = true
  92. }
  93. }
  94. list[k].Abstract, _ = services.GetReportContentTextSub(v.Abstract)
  95. }
  96. if categoryId > 0 {
  97. detail, errCategory := models.GetCygxReportMappingCygxByCategoryId(categoryId)
  98. if errCategory != nil {
  99. br.Msg = "获取信息失败"
  100. br.ErrMsg = "获取信息失败,Err:" + errCategory.Error() + "categoryID 不存在:" + strconv.Itoa(categoryId)
  101. return
  102. }
  103. resp.MatchTypeName = detail.MatchTypeName
  104. if detail.MatchTypeName == "热点问答" || detail.ChartPermissionName == utils.ZHOU_QI_NAME || detail.ChartPermissionName == utils.GU_SHOU_NAME {
  105. resp.IsShowAbstract = true
  106. }
  107. }
  108. articleMapPv := services.GetArticleHistoryByArticleId(articleIds) //文章Pv
  109. articleCollectMap, _ := services.GetCygxArticleCollectMap(user.UserId) //用户收藏的文章
  110. articleCollectNumMap, _ := services.GetCygxArticleCollectNumMapByArtcileIds(articleIds) //文章收藏的数量
  111. for _, v := range list {
  112. if v.Resource == 1 {
  113. v.Pv = articleMapPv[v.ArticleId]
  114. v.IsCollect = articleCollectMap[v.ArticleId]
  115. v.CollectNum = articleCollectNumMap[v.ArticleId]
  116. }
  117. if v.Resource == 2 {
  118. v.PublishDate = utils.TimeRemoveHms2(v.PublishDate)
  119. v.Pv = productInteriorMapPv[v.ArticleId]
  120. }
  121. if v.ReportId > 0 {
  122. v.Resource = 3
  123. }
  124. v.IsShowAbstract = resp.IsShowAbstract
  125. }
  126. resp.List = list
  127. resp.Paging = page
  128. br.Ret = 200
  129. br.Success = true
  130. br.Msg = "获取成功"
  131. br.Data = resp
  132. }
  133. // @Title 获取报告详情
  134. // @Description 获取报告详情接口
  135. // @Param ArticleId query int true "报告ID"
  136. // @Success 200 {object} models.ArticleDetailResp
  137. // @router /detail [get]
  138. func (this *TacticsController) Detail() {
  139. br := new(models.BaseResponse).Init()
  140. defer func() {
  141. this.Data["json"] = br
  142. this.ServeJSON()
  143. }()
  144. user := this.User
  145. if user == nil {
  146. br.Msg = "请登录"
  147. br.ErrMsg = "请登录,用户信息为空"
  148. br.Ret = 408
  149. return
  150. }
  151. uid := user.UserId
  152. articleId, err := this.GetInt("ArticleId")
  153. if articleId <= 0 {
  154. br.Msg = "参数错误"
  155. br.ErrMsg = "参数错误"
  156. return
  157. }
  158. detail := new(models.ArticleDetail)
  159. hasPermission := 0
  160. hasFree := 0
  161. //判断是否已经申请过
  162. applyCount, err := models.GetApplyRecordCount(uid)
  163. if err != nil && err.Error() != utils.ErrNoRow() {
  164. br.Msg = "获取信息失败"
  165. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  166. return
  167. }
  168. fmt.Println(user.CompanyId)
  169. //`description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,4:潜在客户,未提交过申请,5:潜在客户,已提交过申请"`
  170. if user.CompanyId > 1 {
  171. companyPermission, err := models.GetCompanyPermission(user.CompanyId)
  172. if err != nil {
  173. br.Msg = "获取信息失败"
  174. br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  175. return
  176. }
  177. detail, err = models.GetArticleDetailById(articleId)
  178. if err != nil {
  179. br.Msg = "获取信息失败"
  180. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  181. return
  182. }
  183. fmt.Println(detail.Department)
  184. detail.Body = html.UnescapeString(detail.Body)
  185. //detail.Abstract = html.UnescapeString(detail.Abstract)
  186. detail.Abstract, _ = services.GetReportContentTextSub(detail.Abstract)
  187. if companyPermission == "" {
  188. if applyCount > 0 {
  189. hasPermission = 5
  190. } else {
  191. hasPermission = 2
  192. }
  193. hasFree = 2
  194. goto Loop
  195. } else {
  196. hasFree = 1
  197. var articlePermissionPermissionName string
  198. if detail.CategoryId > 0 {
  199. articlePermission, err := models.GetArticlePermission(detail.CategoryId)
  200. if err != nil {
  201. br.Msg = "获取信息失败"
  202. br.ErrMsg = "获取报告权限失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  203. return
  204. }
  205. if articlePermission == nil {
  206. br.Msg = "获取信息失败"
  207. br.ErrMsg = "报告权限不存在,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  208. return
  209. }
  210. articlePermissionPermissionName = articlePermission.PermissionName
  211. } else {
  212. articlePermissionPermissionName = detail.CategoryName
  213. }
  214. if strings.Contains(companyPermission, articlePermissionPermissionName) {
  215. hasPermission = 1
  216. historyRecord := new(models.CygxArticleHistoryRecord)
  217. historyRecord.UserId = uid
  218. historyRecord.ArticleId = articleId
  219. historyRecord.CreateTime = time.Now()
  220. historyRecord.Mobile = user.Mobile
  221. historyRecord.Email = user.Email
  222. historyRecord.CompanyId = user.CompanyId
  223. historyRecord.CompanyName = user.CompanyName
  224. recordCount, _ := models.GetNoAddStoptimeArticleCount(uid, articleId)
  225. if recordCount == 0 {
  226. go models.AddCygxArticleHistoryRecord(historyRecord)
  227. } else {
  228. detailNew, err := models.GetNewArticleHistoryRecord(uid, articleId)
  229. if err != nil {
  230. br.Msg = "获取信息失败"
  231. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  232. return
  233. }
  234. if detailNew.StopTime > 0 {
  235. go models.AddCygxArticleHistoryRecord(historyRecord)
  236. }
  237. }
  238. } else { //无该行业权限
  239. hasPermission = 3
  240. }
  241. }
  242. collectCount, err := models.GetArticleCollectCount(uid, articleId)
  243. if err != nil && err.Error() != utils.ErrNoRow() {
  244. br.Msg = "获取信息失败"
  245. br.ErrMsg = "判断是否已收藏失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  246. return
  247. }
  248. if collectCount > 0 {
  249. detail.IsCollect = true
  250. }
  251. interviewApplyItem, err := models.GetArticleInterviewApply(uid, articleId)
  252. if err != nil && err.Error() != utils.ErrNoRow() {
  253. br.Msg = "获取信息失败"
  254. br.ErrMsg = "判断是否已申请访谈失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  255. return
  256. }
  257. if interviewApplyItem != nil && interviewApplyItem.InterviewApplyId > 0 {
  258. detail.IsInterviewApply = true
  259. detail.InterviewApplyStatus = interviewApplyItem.Status
  260. }
  261. //获取销售手机号
  262. sellerItem, err := models.GetSellerByCompanyId(user.CompanyId)
  263. if err != nil {
  264. br.Msg = "获取信息失败"
  265. br.ErrMsg = "获取销售数据失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  266. return
  267. }
  268. if sellerItem != nil {
  269. detail.SellerMobile = sellerItem.Mobile
  270. detail.SellerName = sellerItem.RealName
  271. }
  272. sellerList, err := models.GetSellerList(articleId)
  273. if err != nil {
  274. br.Msg = "获取信息失败"
  275. br.ErrMsg = "获取销售数据失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  276. return
  277. }
  278. if detail.ArticleId > 1000000 {
  279. var hrefRegexp = regexp.MustCompile("[0-9]\\d*")
  280. match := hrefRegexp.FindAllString(detail.SellerAndMobile, -1)
  281. if match != nil {
  282. for _, v := range match {
  283. sellerAndMobile := &models.SellerRep{
  284. SellerMobile: v,
  285. SellerName: strings.Replace(detail.SellerAndMobile, v, "", -1),
  286. }
  287. sellerList = append(sellerList, sellerAndMobile)
  288. }
  289. }
  290. }
  291. detail.SellerList = sellerList
  292. } else { //潜在客户
  293. if applyCount > 0 {
  294. hasPermission = 5
  295. } else {
  296. hasPermission = 4
  297. }
  298. }
  299. Loop:
  300. if hasPermission != 1 {
  301. detail.Body = ""
  302. detail.BodyText = ""
  303. }
  304. resp := new(models.ArticleDetailResp)
  305. resp.HasPermission = hasPermission
  306. resp.HasFree = hasFree
  307. resp.Detail = detail
  308. br.Ret = 200
  309. br.Success = true
  310. br.Msg = "获取成功"
  311. br.Data = resp
  312. }
  313. // @Title 时间线列表
  314. // @Description 时间线列表接口
  315. // @Param PageSize query int true "每页数据条数"
  316. // @Param CurrentIndex query int true "当前页页码,从1开始"
  317. // @Success 200 {object} models.GetCygxTacticsTimeLineResp
  318. // @router /tacticsTimeLine/list [get]
  319. func (this *TacticsController) TacticsTimeLineList() {
  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.ErrMsg = "请登录,用户信息为空"
  329. br.Ret = 408
  330. return
  331. }
  332. resp := new(models.GetCygxTacticsTimeLineResp)
  333. pageSize, _ := this.GetInt("PageSize")
  334. currentIndex, _ := this.GetInt("CurrentIndex")
  335. var startSize int
  336. if pageSize <= 0 {
  337. pageSize = utils.PageSize20
  338. }
  339. if currentIndex <= 0 {
  340. currentIndex = 1
  341. }
  342. startSize = utils.StartIndex(currentIndex, pageSize)
  343. var condition string
  344. var pars []interface{}
  345. condition += ` AND art.status = 1 `
  346. total, err := models.GetCygxTacticsTimeLineCount(condition, pars)
  347. if err != nil {
  348. br.Msg = "获取失败"
  349. br.ErrMsg = "获取失败,Err:" + err.Error()
  350. return
  351. }
  352. condition += " ORDER BY art.publish_time DESC , art.time_line_id DESC "
  353. list, err := models.GetCygxTacticsTimeLineList(condition, pars, startSize, pageSize)
  354. if err != nil {
  355. br.Msg = "获取失败"
  356. br.ErrMsg = "获取失败,Err:" + err.Error()
  357. return
  358. }
  359. for _, v := range list {
  360. v.PublishTime = utils.TimeRemoveHms2(v.PublishTime)
  361. v.Resource = 1
  362. v.Content = services.AnnotationHtml(v.Content)
  363. }
  364. if len(list) == 0 {
  365. list = make([]*models.CygxTacticsTimeLineResp, 0)
  366. }
  367. cf, err := models.GetConfigByCode(utils.CYGX_TACTICS_TIME_LINE_STATUS)
  368. if err != nil {
  369. br.Msg = "获取失败"
  370. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  371. return
  372. }
  373. //如果不是弘则用户,并且设置了内部可见,那么数据就隐藏
  374. if user.CompanyId != utils.HZ_COMPANY_ID && cf.ConfigValue != "1" {
  375. list = make([]*models.CygxTacticsTimeLineResp, 0)
  376. }
  377. page := paging.GetPaging(currentIndex, pageSize, total)
  378. resp.List = list
  379. resp.Paging = page
  380. br.Ret = 200
  381. br.Success = true
  382. br.Msg = "获取成功"
  383. br.Data = resp
  384. }
  385. // @Title 时间线列表
  386. // @Description 时间线列表接口
  387. // @Param request body models.TacticsTimeLineTimeLineIdReq true "type json string"
  388. // @Success Ret=200 新增成功
  389. // @router /tacticsTimeLine/history [post]
  390. func (this *TacticsController) History() {
  391. br := new(models.BaseResponse).Init()
  392. defer func() {
  393. this.Data["json"] = br
  394. this.ServeJSON()
  395. }()
  396. user := this.User
  397. if user == nil {
  398. br.Msg = "请登录"
  399. br.ErrMsg = "请登录,用户信息为空"
  400. br.Ret = 408
  401. return
  402. }
  403. var req models.TacticsTimeLineTimeLineIdReq
  404. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  405. if err != nil {
  406. br.Msg = "参数解析异常!"
  407. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  408. return
  409. }
  410. timeLineId := req.TimeLineId
  411. if timeLineId == 0 {
  412. br.Msg = "时间线ID错误"
  413. return
  414. }
  415. var sellerName string
  416. sellerName, err = models.GetCompanySellerName(user.CompanyId)
  417. if err != nil {
  418. br.Msg = "报名失败!"
  419. br.ErrMsg = "获取对应销售失败,Err:" + err.Error()
  420. return
  421. }
  422. item := models.CygxTacticsTimeLineHistory{
  423. TimeLineId: timeLineId,
  424. UserId: user.UserId,
  425. Mobile: user.Mobile,
  426. Email: user.Email,
  427. CompanyId: user.CompanyId,
  428. CompanyName: user.CompanyName,
  429. RealName: user.RealName,
  430. SellerName: sellerName,
  431. CreateTime: time.Now(),
  432. ModifyTime: time.Now(),
  433. }
  434. err = models.AddCygxTacticsTimeLineHistory(&item)
  435. br.Ret = 200
  436. br.Success = true
  437. br.Msg = "获取成功"
  438. }