tactics.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  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. //page := paging.GetPaging(currentIndex, pageSize, total)
  59. //获取该产业下所对应的行业图片
  60. //detail, errCategory := models.GetdetailByCategoryIdOneByHangye(categoryId)
  61. //if errCategory != nil {
  62. // br.Msg = "获取信息失败"
  63. // br.ErrMsg = "获取信息失败,Err:" + errCategory.Error() + "categoryID 不存在:" + strconv.Itoa(categoryId)
  64. // return
  65. //}
  66. //对应行业的图片
  67. //detailChartPermissionUrl, err := models.GetConfigByCode("category_chart_permissionimg_url")
  68. //if err != nil {
  69. // br.Msg = "获取数据失败"
  70. // br.ErrMsg = "行业配置信息失败,Err:" + err.Error()
  71. // return
  72. //}
  73. //chartPermissionUrlList := strings.Split(detailChartPermissionUrl.ConfigValue, "{|}")
  74. //mapChartPermission := make(map[string]string)
  75. //var permissionName string
  76. //var imgUrlChartPermission string
  77. //for _, v := range chartPermissionUrlList {
  78. // vslice := strings.Split(v, "_")
  79. // permissionName = vslice[0]
  80. // imgUrlChartPermission = vslice[len(vslice)-1]
  81. // mapChartPermission[permissionName] = imgUrlChartPermission
  82. //}
  83. //对应分类的所图片
  84. //detailCategoryUrl, err := models.GetConfigByCode("category_map_img_url")
  85. //if err != nil {
  86. // br.Msg = "获取数据失败"
  87. // br.ErrMsg = "行业配置信息失败,Err:" + err.Error()
  88. // return
  89. //}
  90. //categoryUrlList := strings.Split(detailCategoryUrl.ConfigValue, "{|}")
  91. //mapCategoryUrl := make(map[string]string)
  92. //var categoryIdStr string
  93. //var imgUrlChart string
  94. //for _, v := range categoryUrlList {
  95. // vslice := strings.Split(v, "_")
  96. // categoryIdStr = vslice[0]
  97. // imgUrlChart = vslice[len(vslice)-1]
  98. // mapCategoryUrl[categoryIdStr] = imgUrlChart
  99. //}
  100. //if categoryId < 0 {
  101. // listTactics, err := models.GetReportMappingStrategyAll()
  102. // if err != nil && err.Error() != utils.ErrNoRow() {
  103. // br.Msg = "获取信息失败"
  104. // br.ErrMsg = "获取分类权限信息失败,Err:" + err.Error()
  105. // return
  106. // }
  107. // for _, v := range listTactics {
  108. // listTacticsSrt = listTacticsSrt + strconv.Itoa(v.CategoryId) + `,`
  109. // }
  110. // listTacticsSrt = strings.TrimRight(listTacticsSrt, ",")
  111. // condition = ` AND category_id IN(` + listTacticsSrt + `)`
  112. //} else {
  113. // if detail.CeLueFieldId != "" {
  114. // condition = ` AND ce_lue_field_id IN(` + detail.CeLueFieldId + `)`
  115. // } else if detail.PolymerizationId != "" {
  116. // condition = ` AND category_id IN(` + detail.PolymerizationId + `)`
  117. // } else {
  118. // condition = ` AND category_id IN(` + strconv.Itoa(categoryId) + `)`
  119. // }
  120. //}
  121. //total, err = models.GetHomeCount(condition, pars)
  122. //if err != nil {
  123. // br.Msg = "获取信息失败"
  124. // br.Msg = "获取帖子总数失败,Err:" + err.Error()
  125. // return
  126. //}
  127. //list, err := models.GetReportTacticsList(condition, pars, uid, startSize, pageSize)
  128. list, total, err := models.GetReportAndproductIndustrylList(categoryId, startSize, pageSize)
  129. if err != nil {
  130. br.Msg = "获取信息失败"
  131. br.Msg = "获取帖子数据失败,Err:" + err.Error()
  132. return
  133. }
  134. var articleIds []int
  135. var productInteriorIs []int
  136. page := paging.GetPaging(currentIndex, pageSize, total)
  137. for _, v := range list {
  138. //if v.Readnum == 0 && user.CreatedTime.Before(utils.StrTimeToTime(v.PublishDate)) && utils.StrTimeToTime(utils.OnlineTime).Before(utils.StrTimeToTime(v.PublishDate)) {
  139. // list[k].IsRed = true
  140. //}
  141. if v.Resource == 1 {
  142. articleIds = append(articleIds, v.ArticleId)
  143. } else {
  144. productInteriorIs = append(productInteriorIs, v.ArticleId)
  145. }
  146. //list[k].ImgUrlPc = mapCategoryUrl[v.CategoryId]
  147. }
  148. ArticleHistoryMap := services.GetArticleHistoryByUser(articleIds, user)
  149. ProductInteriorHistoryMap := services.GetCygxProductInteriorHistoryListMap(articleIds, user)
  150. for k, v := range list {
  151. if v.Resource == 1 {
  152. if ArticleHistoryMap[v.ArticleId] == 0 && user.CreatedTime.Before(utils.StrTimeToTime(v.PublishDate)) && utils.StrTimeToTime(utils.OnlineTime).Before(utils.StrTimeToTime(v.PublishDate)) {
  153. list[k].IsRed = true
  154. }
  155. } else {
  156. if ProductInteriorHistoryMap[v.ArticleId] == 0 && user.CreatedTime.Before(utils.StrTimeToTime(v.PublishDate)) && utils.StrTimeToTime(utils.OnlineTime).Before(utils.StrTimeToTime(v.PublishDate)) {
  157. list[k].IsRed = true
  158. }
  159. }
  160. }
  161. if categoryId > 0 {
  162. detail, errCategory := models.GetCygxReportMappingCygxByCategoryId(categoryId)
  163. if errCategory != nil {
  164. br.Msg = "获取信息失败"
  165. br.ErrMsg = "获取信息失败,Err:" + errCategory.Error() + "categoryID 不存在:" + strconv.Itoa(categoryId)
  166. return
  167. }
  168. resp.MatchTypeName = detail.MatchTypeName
  169. }
  170. //lenList := len(list)
  171. //for i := 0; i < lenList; i++ {
  172. // item := list[i]
  173. // list[i].Body, _ = services.GetReportContentTextSub(item.Body)
  174. // list[i].Abstract = html.UnescapeString(item.Abstract)
  175. // //list[i].Abstract, _ = services.GetReportContentTextSub(item.Abstract)
  176. // list[i].Annotation = strings.Replace(item.Annotation, "<br>", "", -1)
  177. // //行业比较研究、资金流向,显示报告的摘要
  178. // if resp.MatchTypeName == "行业比较研究" || resp.MatchTypeName == "资金流向" {
  179. // list[i].Annotation = list[i].Abstract
  180. // }
  181. // //if item.ArticleId == 6881 {
  182. // // fmt.Println(list[i].Annotation)
  183. // //}
  184. // list[i].Abstract, _ = services.GetReportContentTextSub(item.Abstract)
  185. //}
  186. //
  187. //resp.CategoryImgUrlPc = mapChartPermission[detail.ChartPermissionName]
  188. resp.List = list
  189. resp.Paging = page
  190. br.Ret = 200
  191. br.Success = true
  192. br.Msg = "获取成功"
  193. br.Data = resp
  194. }
  195. // @Title 获取报告详情
  196. // @Description 获取报告详情接口
  197. // @Param ArticleId query int true "报告ID"
  198. // @Success 200 {object} models.ArticleDetailResp
  199. // @router /detail [get]
  200. func (this *TacticsController) Detail() {
  201. br := new(models.BaseResponse).Init()
  202. defer func() {
  203. this.Data["json"] = br
  204. this.ServeJSON()
  205. }()
  206. user := this.User
  207. if user == nil {
  208. br.Msg = "请登录"
  209. br.ErrMsg = "请登录,用户信息为空"
  210. br.Ret = 408
  211. return
  212. }
  213. uid := user.UserId
  214. articleId, err := this.GetInt("ArticleId")
  215. if articleId <= 0 {
  216. br.Msg = "参数错误"
  217. br.ErrMsg = "参数错误"
  218. return
  219. }
  220. detail := new(models.ArticleDetail)
  221. hasPermission := 0
  222. hasFree := 0
  223. //判断是否已经申请过
  224. applyCount, err := models.GetApplyRecordCount(uid)
  225. if err != nil && err.Error() != utils.ErrNoRow() {
  226. br.Msg = "获取信息失败"
  227. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  228. return
  229. }
  230. fmt.Println(user.CompanyId)
  231. //`description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,4:潜在客户,未提交过申请,5:潜在客户,已提交过申请"`
  232. if user.CompanyId > 1 {
  233. companyPermission, err := models.GetCompanyPermission(user.CompanyId)
  234. if err != nil {
  235. br.Msg = "获取信息失败"
  236. br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  237. return
  238. }
  239. detail, err = models.GetArticleDetailById(articleId)
  240. if err != nil {
  241. br.Msg = "获取信息失败"
  242. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  243. return
  244. }
  245. fmt.Println(detail.Department)
  246. detail.Body = html.UnescapeString(detail.Body)
  247. //detail.Abstract = html.UnescapeString(detail.Abstract)
  248. detail.Abstract, _ = services.GetReportContentTextSub(detail.Abstract)
  249. if companyPermission == "" {
  250. if applyCount > 0 {
  251. hasPermission = 5
  252. } else {
  253. hasPermission = 2
  254. }
  255. hasFree = 2
  256. goto Loop
  257. } else {
  258. hasFree = 1
  259. var articlePermissionPermissionName string
  260. if detail.CategoryId > 0 {
  261. articlePermission, err := models.GetArticlePermission(detail.CategoryId)
  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 articlePermission == nil {
  268. br.Msg = "获取信息失败"
  269. br.ErrMsg = "报告权限不存在,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  270. return
  271. }
  272. articlePermissionPermissionName = articlePermission.PermissionName
  273. } else {
  274. articlePermissionPermissionName = detail.CategoryName
  275. }
  276. if strings.Contains(companyPermission, articlePermissionPermissionName) {
  277. hasPermission = 1
  278. historyRecord := new(models.CygxArticleHistoryRecord)
  279. historyRecord.UserId = uid
  280. historyRecord.ArticleId = articleId
  281. historyRecord.CreateTime = time.Now()
  282. historyRecord.Mobile = user.Mobile
  283. historyRecord.Email = user.Email
  284. historyRecord.CompanyId = user.CompanyId
  285. historyRecord.CompanyName = user.CompanyName
  286. recordCount, _ := models.GetNoAddStoptimeArticleCount(uid, articleId)
  287. if recordCount == 0 {
  288. go models.AddCygxArticleHistoryRecord(historyRecord)
  289. } else {
  290. detailNew, err := models.GetNewArticleHistoryRecord(uid, articleId)
  291. if err != nil {
  292. br.Msg = "获取信息失败"
  293. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  294. return
  295. }
  296. if detailNew.StopTime > 0 {
  297. go models.AddCygxArticleHistoryRecord(historyRecord)
  298. }
  299. }
  300. } else { //无该行业权限
  301. hasPermission = 3
  302. }
  303. }
  304. collectCount, err := models.GetArticleCollectCount(uid, articleId)
  305. if err != nil && err.Error() != utils.ErrNoRow() {
  306. br.Msg = "获取信息失败"
  307. br.ErrMsg = "判断是否已收藏失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  308. return
  309. }
  310. if collectCount > 0 {
  311. detail.IsCollect = true
  312. }
  313. interviewApplyItem, err := models.GetArticleInterviewApply(uid, articleId)
  314. if err != nil && err.Error() != utils.ErrNoRow() {
  315. br.Msg = "获取信息失败"
  316. br.ErrMsg = "判断是否已申请访谈失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  317. return
  318. }
  319. if interviewApplyItem != nil && interviewApplyItem.InterviewApplyId > 0 {
  320. detail.IsInterviewApply = true
  321. detail.InterviewApplyStatus = interviewApplyItem.Status
  322. }
  323. //获取销售手机号
  324. sellerItem, err := models.GetSellerByCompanyId(user.CompanyId)
  325. if err != nil {
  326. br.Msg = "获取信息失败"
  327. br.ErrMsg = "获取销售数据失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  328. return
  329. }
  330. if sellerItem != nil {
  331. detail.SellerMobile = sellerItem.Mobile
  332. detail.SellerName = sellerItem.RealName
  333. }
  334. sellerList, err := models.GetSellerList(articleId)
  335. if err != nil {
  336. br.Msg = "获取信息失败"
  337. br.ErrMsg = "获取销售数据失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  338. return
  339. }
  340. if detail.ArticleId > 1000000 {
  341. var hrefRegexp = regexp.MustCompile("[0-9]\\d*")
  342. match := hrefRegexp.FindAllString(detail.SellerAndMobile, -1)
  343. if match != nil {
  344. for _, v := range match {
  345. sellerAndMobile := &models.SellerRep{
  346. SellerMobile: v,
  347. SellerName: strings.Replace(detail.SellerAndMobile, v, "", -1),
  348. }
  349. sellerList = append(sellerList, sellerAndMobile)
  350. }
  351. }
  352. }
  353. detail.SellerList = sellerList
  354. } else { //潜在客户
  355. if applyCount > 0 {
  356. hasPermission = 5
  357. } else {
  358. hasPermission = 4
  359. }
  360. }
  361. Loop:
  362. if hasPermission != 1 {
  363. detail.Body = ""
  364. detail.BodyText = ""
  365. }
  366. resp := new(models.ArticleDetailResp)
  367. resp.HasPermission = hasPermission
  368. resp.HasFree = hasFree
  369. resp.Detail = detail
  370. br.Ret = 200
  371. br.Success = true
  372. br.Msg = "获取成功"
  373. br.Data = resp
  374. }
  375. // @Title 时间线列表
  376. // @Description 时间线列表接口
  377. // @Param PageSize query int true "每页数据条数"
  378. // @Param CurrentIndex query int true "当前页页码,从1开始"
  379. // @Success 200 {object} models.GetCygxTacticsTimeLineResp
  380. // @router /tacticsTimeLine/list [get]
  381. func (this *TacticsController) TacticsTimeLineList() {
  382. br := new(models.BaseResponse).Init()
  383. defer func() {
  384. this.Data["json"] = br
  385. this.ServeJSON()
  386. }()
  387. user := this.User
  388. if user == nil {
  389. br.Msg = "请登录"
  390. br.ErrMsg = "请登录,用户信息为空"
  391. br.Ret = 408
  392. return
  393. }
  394. resp := new(models.GetCygxTacticsTimeLineResp)
  395. pageSize, _ := this.GetInt("PageSize")
  396. currentIndex, _ := this.GetInt("CurrentIndex")
  397. var startSize int
  398. if pageSize <= 0 {
  399. pageSize = utils.PageSize20
  400. }
  401. if currentIndex <= 0 {
  402. currentIndex = 1
  403. }
  404. startSize = utils.StartIndex(currentIndex, pageSize)
  405. var condition string
  406. var pars []interface{}
  407. condition += ` AND art.status = 1 `
  408. total, err := models.GetCygxTacticsTimeLineCount(condition, pars)
  409. if err != nil {
  410. br.Msg = "获取失败"
  411. br.ErrMsg = "获取失败,Err:" + err.Error()
  412. return
  413. }
  414. condition += " ORDER BY art.publish_time DESC , art.time_line_id DESC "
  415. list, err := models.GetCygxTacticsTimeLineList(condition, pars, startSize, pageSize)
  416. if err != nil {
  417. br.Msg = "获取失败"
  418. br.ErrMsg = "获取失败,Err:" + err.Error()
  419. return
  420. }
  421. for _, v := range list {
  422. v.PublishTime = utils.TimeRemoveHms2(v.PublishTime)
  423. }
  424. if len(list) == 0 {
  425. list = make([]*models.CygxTacticsTimeLineResp, 0)
  426. }
  427. cf, err := models.GetConfigByCode(utils.CYGX_TACTICS_TIME_LINE_STATUS)
  428. if err != nil {
  429. br.Msg = "获取失败"
  430. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  431. return
  432. }
  433. //如果不是弘则用户,并且设置了内部可见,那么数据就隐藏
  434. if user.CompanyId != utils.HZ_COMPANY_ID && cf.ConfigValue != "1" {
  435. list = make([]*models.CygxTacticsTimeLineResp, 0)
  436. }
  437. page := paging.GetPaging(currentIndex, pageSize, total)
  438. resp.List = list
  439. resp.Paging = page
  440. br.Ret = 200
  441. br.Success = true
  442. br.Msg = "获取成功"
  443. br.Data = resp
  444. }
  445. // @Title 时间线列表
  446. // @Description 时间线列表接口
  447. // @Param request body models.TacticsTimeLineTimeLineIdReq true "type json string"
  448. // @Success Ret=200 新增成功
  449. // @router /tacticsTimeLine/history [post]
  450. func (this *TacticsController) History() {
  451. br := new(models.BaseResponse).Init()
  452. defer func() {
  453. this.Data["json"] = br
  454. this.ServeJSON()
  455. }()
  456. user := this.User
  457. if user == nil {
  458. br.Msg = "请登录"
  459. br.ErrMsg = "请登录,用户信息为空"
  460. br.Ret = 408
  461. return
  462. }
  463. var req models.TacticsTimeLineTimeLineIdReq
  464. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  465. if err != nil {
  466. br.Msg = "参数解析异常!"
  467. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  468. return
  469. }
  470. timeLineId := req.TimeLineId
  471. if timeLineId == 0 {
  472. br.Msg = "时间线ID错误"
  473. return
  474. }
  475. var sellerName string
  476. sellerName, err = models.GetCompanySellerName(user.CompanyId)
  477. if err != nil {
  478. br.Msg = "报名失败!"
  479. br.ErrMsg = "获取对应销售失败,Err:" + err.Error()
  480. return
  481. }
  482. item := models.CygxTacticsTimeLineHistory{
  483. TimeLineId: timeLineId,
  484. UserId: user.UserId,
  485. Mobile: user.Mobile,
  486. Email: user.Email,
  487. CompanyId: user.CompanyId,
  488. CompanyName: user.CompanyName,
  489. RealName: user.RealName,
  490. SellerName: sellerName,
  491. CreateTime: time.Now(),
  492. ModifyTime: time.Now(),
  493. }
  494. err = models.AddCygxTacticsTimeLineHistory(&item)
  495. br.Ret = 200
  496. br.Success = true
  497. br.Msg = "获取成功"
  498. }