tactics.go 13 KB

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