tactics.go 14 KB

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