tactics.go 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  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. if v.Abstract != "" {
  125. v.IsShowAbstract = true
  126. }
  127. }
  128. resp.List = list
  129. resp.Paging = page
  130. br.Ret = 200
  131. br.Success = true
  132. br.Msg = "获取成功"
  133. br.Data = resp
  134. }
  135. // @Title 获取报告详情
  136. // @Description 获取报告详情接口
  137. // @Param ArticleId query int true "报告ID"
  138. // @Success 200 {object} models.ArticleDetailResp
  139. // @router /detail [get]
  140. func (this *TacticsController) Detail() {
  141. br := new(models.BaseResponse).Init()
  142. defer func() {
  143. this.Data["json"] = br
  144. this.ServeJSON()
  145. }()
  146. user := this.User
  147. if user == nil {
  148. br.Msg = "请登录"
  149. br.ErrMsg = "请登录,用户信息为空"
  150. br.Ret = 408
  151. return
  152. }
  153. uid := user.UserId
  154. articleId, err := this.GetInt("ArticleId")
  155. if articleId <= 0 {
  156. br.Msg = "参数错误"
  157. br.ErrMsg = "参数错误"
  158. return
  159. }
  160. detail := new(models.ArticleDetail)
  161. hasPermission := 0
  162. hasFree := 0
  163. //判断是否已经申请过
  164. applyCount, err := models.GetApplyRecordCount(uid)
  165. if err != nil && err.Error() != utils.ErrNoRow() {
  166. br.Msg = "获取信息失败"
  167. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  168. return
  169. }
  170. fmt.Println(user.CompanyId)
  171. //`description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,4:潜在客户,未提交过申请,5:潜在客户,已提交过申请"`
  172. if user.CompanyId > 1 {
  173. companyPermission, err := models.GetCompanyPermission(user.CompanyId)
  174. if err != nil {
  175. br.Msg = "获取信息失败"
  176. br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  177. return
  178. }
  179. detail, err = models.GetArticleDetailById(articleId)
  180. if err != nil {
  181. br.Msg = "获取信息失败"
  182. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  183. return
  184. }
  185. fmt.Println(detail.Department)
  186. detail.Body = html.UnescapeString(detail.Body)
  187. //detail.Abstract = html.UnescapeString(detail.Abstract)
  188. detail.Abstract, _ = services.GetReportContentTextSub(detail.Abstract)
  189. if companyPermission == "" {
  190. if applyCount > 0 {
  191. hasPermission = 5
  192. } else {
  193. hasPermission = 2
  194. }
  195. hasFree = 2
  196. goto Loop
  197. } else {
  198. hasFree = 1
  199. var articlePermissionPermissionName string
  200. if detail.CategoryId > 0 {
  201. articlePermission, err := models.GetArticlePermission(detail.CategoryId)
  202. if err != nil {
  203. br.Msg = "获取信息失败"
  204. br.ErrMsg = "获取报告权限失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  205. return
  206. }
  207. if articlePermission == nil {
  208. br.Msg = "获取信息失败"
  209. br.ErrMsg = "报告权限不存在,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  210. return
  211. }
  212. articlePermissionPermissionName = articlePermission.PermissionName
  213. } else {
  214. articlePermissionPermissionName = detail.CategoryName
  215. }
  216. if strings.Contains(companyPermission, articlePermissionPermissionName) {
  217. hasPermission = 1
  218. historyRecord := new(models.CygxArticleHistoryRecord)
  219. historyRecord.UserId = uid
  220. historyRecord.ArticleId = articleId
  221. historyRecord.CreateTime = time.Now()
  222. historyRecord.Mobile = user.Mobile
  223. historyRecord.Email = user.Email
  224. historyRecord.CompanyId = user.CompanyId
  225. historyRecord.CompanyName = user.CompanyName
  226. recordCount, _ := models.GetNoAddStoptimeArticleCount(uid, articleId)
  227. if recordCount == 0 {
  228. go models.AddCygxArticleHistoryRecord(historyRecord)
  229. } else {
  230. detailNew, err := models.GetNewArticleHistoryRecord(uid, articleId)
  231. if err != nil {
  232. br.Msg = "获取信息失败"
  233. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  234. return
  235. }
  236. if detailNew.StopTime > 0 {
  237. go models.AddCygxArticleHistoryRecord(historyRecord)
  238. }
  239. }
  240. } else { //无该行业权限
  241. hasPermission = 3
  242. }
  243. }
  244. collectCount, err := models.GetArticleCollectCount(uid, articleId)
  245. if err != nil && err.Error() != utils.ErrNoRow() {
  246. br.Msg = "获取信息失败"
  247. br.ErrMsg = "判断是否已收藏失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  248. return
  249. }
  250. if collectCount > 0 {
  251. detail.IsCollect = true
  252. }
  253. interviewApplyItem, err := models.GetArticleInterviewApply(uid, articleId)
  254. if err != nil && err.Error() != utils.ErrNoRow() {
  255. br.Msg = "获取信息失败"
  256. br.ErrMsg = "判断是否已申请访谈失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  257. return
  258. }
  259. if interviewApplyItem != nil && interviewApplyItem.InterviewApplyId > 0 {
  260. detail.IsInterviewApply = true
  261. detail.InterviewApplyStatus = interviewApplyItem.Status
  262. }
  263. //获取销售手机号
  264. sellerItem, err := models.GetSellerByCompanyId(user.CompanyId)
  265. if err != nil {
  266. br.Msg = "获取信息失败"
  267. br.ErrMsg = "获取销售数据失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  268. return
  269. }
  270. if sellerItem != nil {
  271. detail.SellerMobile = sellerItem.Mobile
  272. detail.SellerName = sellerItem.RealName
  273. }
  274. sellerList, err := models.GetSellerList(articleId)
  275. if err != nil {
  276. br.Msg = "获取信息失败"
  277. br.ErrMsg = "获取销售数据失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  278. return
  279. }
  280. if detail.ArticleId > 1000000 {
  281. var hrefRegexp = regexp.MustCompile("[0-9]\\d*")
  282. match := hrefRegexp.FindAllString(detail.SellerAndMobile, -1)
  283. if match != nil {
  284. for _, v := range match {
  285. sellerAndMobile := &models.SellerRep{
  286. SellerMobile: v,
  287. SellerName: strings.Replace(detail.SellerAndMobile, v, "", -1),
  288. }
  289. sellerList = append(sellerList, sellerAndMobile)
  290. }
  291. }
  292. }
  293. detail.SellerList = sellerList
  294. } else { //潜在客户
  295. if applyCount > 0 {
  296. hasPermission = 5
  297. } else {
  298. hasPermission = 4
  299. }
  300. }
  301. Loop:
  302. if hasPermission != 1 {
  303. detail.Body = ""
  304. detail.BodyText = ""
  305. }
  306. resp := new(models.ArticleDetailResp)
  307. resp.HasPermission = hasPermission
  308. resp.HasFree = hasFree
  309. resp.Detail = detail
  310. br.Ret = 200
  311. br.Success = true
  312. br.Msg = "获取成功"
  313. br.Data = resp
  314. }
  315. // @Title 时间线列表
  316. // @Description 时间线列表接口
  317. // @Param PageSize query int true "每页数据条数"
  318. // @Param CurrentIndex query int true "当前页页码,从1开始"
  319. // @Success 200 {object} models.GetCygxTacticsTimeLineResp
  320. // @router /tacticsTimeLine/list [get]
  321. func (this *TacticsController) TacticsTimeLineList() {
  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.ErrMsg = "请登录,用户信息为空"
  331. br.Ret = 408
  332. return
  333. }
  334. resp := new(models.GetCygxTacticsTimeLineResp)
  335. pageSize, _ := this.GetInt("PageSize")
  336. currentIndex, _ := this.GetInt("CurrentIndex")
  337. var startSize int
  338. if pageSize <= 0 {
  339. pageSize = utils.PageSize20
  340. }
  341. if currentIndex <= 0 {
  342. currentIndex = 1
  343. }
  344. startSize = utils.StartIndex(currentIndex, pageSize)
  345. var condition string
  346. var pars []interface{}
  347. condition += ` AND art.status = 1 `
  348. total, err := models.GetCygxTacticsTimeLineCount(condition, pars)
  349. if err != nil {
  350. br.Msg = "获取失败"
  351. br.ErrMsg = "获取失败,Err:" + err.Error()
  352. return
  353. }
  354. condition += " ORDER BY art.publish_time DESC , art.time_line_id DESC "
  355. list, err := models.GetCygxTacticsTimeLineList(condition, pars, startSize, pageSize)
  356. if err != nil {
  357. br.Msg = "获取失败"
  358. br.ErrMsg = "获取失败,Err:" + err.Error()
  359. return
  360. }
  361. for _, v := range list {
  362. v.PublishTime = utils.TimeRemoveHms2(v.PublishTime)
  363. v.Resource = 1
  364. v.Content = services.AnnotationHtml(v.Content)
  365. }
  366. if len(list) == 0 {
  367. list = make([]*models.CygxTacticsTimeLineResp, 0)
  368. }
  369. cf, err := models.GetConfigByCode(utils.CYGX_TACTICS_TIME_LINE_STATUS)
  370. if err != nil {
  371. br.Msg = "获取失败"
  372. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  373. return
  374. }
  375. //如果不是弘则用户,并且设置了内部可见,那么数据就隐藏
  376. if user.CompanyId != utils.HZ_COMPANY_ID && cf.ConfigValue != "1" {
  377. list = make([]*models.CygxTacticsTimeLineResp, 0)
  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 models.TacticsTimeLineTimeLineIdReq true "type json string"
  390. // @Success Ret=200 新增成功
  391. // @router /tacticsTimeLine/history [post]
  392. func (this *TacticsController) History() {
  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.TacticsTimeLineTimeLineIdReq
  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. timeLineId := req.TimeLineId
  413. if timeLineId == 0 {
  414. br.Msg = "时间线ID错误"
  415. return
  416. }
  417. var sellerName string
  418. sellerName, err = models.GetCompanySellerName(user.CompanyId)
  419. if err != nil {
  420. br.Msg = "报名失败!"
  421. br.ErrMsg = "获取对应销售失败,Err:" + err.Error()
  422. return
  423. }
  424. item := models.CygxTacticsTimeLineHistory{
  425. TimeLineId: timeLineId,
  426. UserId: user.UserId,
  427. Mobile: user.Mobile,
  428. Email: user.Email,
  429. CompanyId: user.CompanyId,
  430. CompanyName: user.CompanyName,
  431. RealName: user.RealName,
  432. SellerName: sellerName,
  433. CreateTime: time.Now(),
  434. ModifyTime: time.Now(),
  435. }
  436. err = models.AddCygxTacticsTimeLineHistory(&item)
  437. br.Ret = 200
  438. br.Success = true
  439. br.Msg = "获取成功"
  440. }