tactics.go 14 KB

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