tactics.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  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. for _, v := range list {
  171. if v.Resource == 2 {
  172. v.PublishDate = utils.TimeRemoveHms2(v.PublishDate)
  173. }
  174. }
  175. //lenList := len(list)
  176. //for i := 0; i < lenList; i++ {
  177. // item := list[i]
  178. // list[i].Body, _ = services.GetReportContentTextSub(item.Body)
  179. // list[i].Abstract = html.UnescapeString(item.Abstract)
  180. // //list[i].Abstract, _ = services.GetReportContentTextSub(item.Abstract)
  181. // list[i].Annotation = strings.Replace(item.Annotation, "<br>", "", -1)
  182. // //行业比较研究、资金流向,显示报告的摘要
  183. // if resp.MatchTypeName == "行业比较研究" || resp.MatchTypeName == "资金流向" {
  184. // list[i].Annotation = list[i].Abstract
  185. // }
  186. // //if item.ArticleId == 6881 {
  187. // // fmt.Println(list[i].Annotation)
  188. // //}
  189. // list[i].Abstract, _ = services.GetReportContentTextSub(item.Abstract)
  190. //}
  191. //
  192. //resp.CategoryImgUrlPc = mapChartPermission[detail.ChartPermissionName]
  193. resp.List = list
  194. resp.Paging = page
  195. br.Ret = 200
  196. br.Success = true
  197. br.Msg = "获取成功"
  198. br.Data = resp
  199. }
  200. // @Title 获取报告详情
  201. // @Description 获取报告详情接口
  202. // @Param ArticleId query int true "报告ID"
  203. // @Success 200 {object} models.ArticleDetailResp
  204. // @router /detail [get]
  205. func (this *TacticsController) Detail() {
  206. br := new(models.BaseResponse).Init()
  207. defer func() {
  208. this.Data["json"] = br
  209. this.ServeJSON()
  210. }()
  211. user := this.User
  212. if user == nil {
  213. br.Msg = "请登录"
  214. br.ErrMsg = "请登录,用户信息为空"
  215. br.Ret = 408
  216. return
  217. }
  218. uid := user.UserId
  219. articleId, err := this.GetInt("ArticleId")
  220. if articleId <= 0 {
  221. br.Msg = "参数错误"
  222. br.ErrMsg = "参数错误"
  223. return
  224. }
  225. detail := new(models.ArticleDetail)
  226. hasPermission := 0
  227. hasFree := 0
  228. //判断是否已经申请过
  229. applyCount, err := models.GetApplyRecordCount(uid)
  230. if err != nil && err.Error() != utils.ErrNoRow() {
  231. br.Msg = "获取信息失败"
  232. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  233. return
  234. }
  235. fmt.Println(user.CompanyId)
  236. //`description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,4:潜在客户,未提交过申请,5:潜在客户,已提交过申请"`
  237. if user.CompanyId > 1 {
  238. companyPermission, err := models.GetCompanyPermission(user.CompanyId)
  239. if err != nil {
  240. br.Msg = "获取信息失败"
  241. br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  242. return
  243. }
  244. detail, err = models.GetArticleDetailById(articleId)
  245. if err != nil {
  246. br.Msg = "获取信息失败"
  247. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  248. return
  249. }
  250. fmt.Println(detail.Department)
  251. detail.Body = html.UnescapeString(detail.Body)
  252. //detail.Abstract = html.UnescapeString(detail.Abstract)
  253. detail.Abstract, _ = services.GetReportContentTextSub(detail.Abstract)
  254. if companyPermission == "" {
  255. if applyCount > 0 {
  256. hasPermission = 5
  257. } else {
  258. hasPermission = 2
  259. }
  260. hasFree = 2
  261. goto Loop
  262. } else {
  263. hasFree = 1
  264. var articlePermissionPermissionName string
  265. if detail.CategoryId > 0 {
  266. articlePermission, err := models.GetArticlePermission(detail.CategoryId)
  267. if err != nil {
  268. br.Msg = "获取信息失败"
  269. br.ErrMsg = "获取报告权限失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  270. return
  271. }
  272. if articlePermission == nil {
  273. br.Msg = "获取信息失败"
  274. br.ErrMsg = "报告权限不存在,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  275. return
  276. }
  277. articlePermissionPermissionName = articlePermission.PermissionName
  278. } else {
  279. articlePermissionPermissionName = detail.CategoryName
  280. }
  281. if strings.Contains(companyPermission, articlePermissionPermissionName) {
  282. hasPermission = 1
  283. historyRecord := new(models.CygxArticleHistoryRecord)
  284. historyRecord.UserId = uid
  285. historyRecord.ArticleId = articleId
  286. historyRecord.CreateTime = time.Now()
  287. historyRecord.Mobile = user.Mobile
  288. historyRecord.Email = user.Email
  289. historyRecord.CompanyId = user.CompanyId
  290. historyRecord.CompanyName = user.CompanyName
  291. recordCount, _ := models.GetNoAddStoptimeArticleCount(uid, articleId)
  292. if recordCount == 0 {
  293. go models.AddCygxArticleHistoryRecord(historyRecord)
  294. } else {
  295. detailNew, err := models.GetNewArticleHistoryRecord(uid, articleId)
  296. if err != nil {
  297. br.Msg = "获取信息失败"
  298. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  299. return
  300. }
  301. if detailNew.StopTime > 0 {
  302. go models.AddCygxArticleHistoryRecord(historyRecord)
  303. }
  304. }
  305. } else { //无该行业权限
  306. hasPermission = 3
  307. }
  308. }
  309. collectCount, err := models.GetArticleCollectCount(uid, articleId)
  310. if err != nil && err.Error() != utils.ErrNoRow() {
  311. br.Msg = "获取信息失败"
  312. br.ErrMsg = "判断是否已收藏失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  313. return
  314. }
  315. if collectCount > 0 {
  316. detail.IsCollect = true
  317. }
  318. interviewApplyItem, err := models.GetArticleInterviewApply(uid, articleId)
  319. if err != nil && err.Error() != utils.ErrNoRow() {
  320. br.Msg = "获取信息失败"
  321. br.ErrMsg = "判断是否已申请访谈失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  322. return
  323. }
  324. if interviewApplyItem != nil && interviewApplyItem.InterviewApplyId > 0 {
  325. detail.IsInterviewApply = true
  326. detail.InterviewApplyStatus = interviewApplyItem.Status
  327. }
  328. //获取销售手机号
  329. sellerItem, err := models.GetSellerByCompanyId(user.CompanyId)
  330. if err != nil {
  331. br.Msg = "获取信息失败"
  332. br.ErrMsg = "获取销售数据失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  333. return
  334. }
  335. if sellerItem != nil {
  336. detail.SellerMobile = sellerItem.Mobile
  337. detail.SellerName = sellerItem.RealName
  338. }
  339. sellerList, err := models.GetSellerList(articleId)
  340. if err != nil {
  341. br.Msg = "获取信息失败"
  342. br.ErrMsg = "获取销售数据失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  343. return
  344. }
  345. if detail.ArticleId > 1000000 {
  346. var hrefRegexp = regexp.MustCompile("[0-9]\\d*")
  347. match := hrefRegexp.FindAllString(detail.SellerAndMobile, -1)
  348. if match != nil {
  349. for _, v := range match {
  350. sellerAndMobile := &models.SellerRep{
  351. SellerMobile: v,
  352. SellerName: strings.Replace(detail.SellerAndMobile, v, "", -1),
  353. }
  354. sellerList = append(sellerList, sellerAndMobile)
  355. }
  356. }
  357. }
  358. detail.SellerList = sellerList
  359. } else { //潜在客户
  360. if applyCount > 0 {
  361. hasPermission = 5
  362. } else {
  363. hasPermission = 4
  364. }
  365. }
  366. Loop:
  367. if hasPermission != 1 {
  368. detail.Body = ""
  369. detail.BodyText = ""
  370. }
  371. resp := new(models.ArticleDetailResp)
  372. resp.HasPermission = hasPermission
  373. resp.HasFree = hasFree
  374. resp.Detail = detail
  375. br.Ret = 200
  376. br.Success = true
  377. br.Msg = "获取成功"
  378. br.Data = resp
  379. }
  380. // @Title 时间线列表
  381. // @Description 时间线列表接口
  382. // @Param PageSize query int true "每页数据条数"
  383. // @Param CurrentIndex query int true "当前页页码,从1开始"
  384. // @Success 200 {object} models.GetCygxTacticsTimeLineResp
  385. // @router /tacticsTimeLine/list [get]
  386. func (this *TacticsController) TacticsTimeLineList() {
  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. resp := new(models.GetCygxTacticsTimeLineResp)
  400. pageSize, _ := this.GetInt("PageSize")
  401. currentIndex, _ := this.GetInt("CurrentIndex")
  402. var startSize int
  403. if pageSize <= 0 {
  404. pageSize = utils.PageSize20
  405. }
  406. if currentIndex <= 0 {
  407. currentIndex = 1
  408. }
  409. startSize = utils.StartIndex(currentIndex, pageSize)
  410. var condition string
  411. var pars []interface{}
  412. condition += ` AND art.status = 1 `
  413. total, err := models.GetCygxTacticsTimeLineCount(condition, pars)
  414. if err != nil {
  415. br.Msg = "获取失败"
  416. br.ErrMsg = "获取失败,Err:" + err.Error()
  417. return
  418. }
  419. condition += " ORDER BY art.publish_time DESC , art.time_line_id DESC "
  420. list, err := models.GetCygxTacticsTimeLineList(condition, pars, startSize, pageSize)
  421. if err != nil {
  422. br.Msg = "获取失败"
  423. br.ErrMsg = "获取失败,Err:" + err.Error()
  424. return
  425. }
  426. for _, v := range list {
  427. v.PublishTime = utils.TimeRemoveHms2(v.PublishTime)
  428. }
  429. if len(list) == 0 {
  430. list = make([]*models.CygxTacticsTimeLineResp, 0)
  431. }
  432. cf, err := models.GetConfigByCode(utils.CYGX_TACTICS_TIME_LINE_STATUS)
  433. if err != nil {
  434. br.Msg = "获取失败"
  435. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  436. return
  437. }
  438. //如果不是弘则用户,并且设置了内部可见,那么数据就隐藏
  439. if user.CompanyId != utils.HZ_COMPANY_ID && cf.ConfigValue != "1" {
  440. list = make([]*models.CygxTacticsTimeLineResp, 0)
  441. }
  442. page := paging.GetPaging(currentIndex, pageSize, total)
  443. resp.List = list
  444. resp.Paging = page
  445. br.Ret = 200
  446. br.Success = true
  447. br.Msg = "获取成功"
  448. br.Data = resp
  449. }
  450. // @Title 时间线列表
  451. // @Description 时间线列表接口
  452. // @Param request body models.TacticsTimeLineTimeLineIdReq true "type json string"
  453. // @Success Ret=200 新增成功
  454. // @router /tacticsTimeLine/history [post]
  455. func (this *TacticsController) History() {
  456. br := new(models.BaseResponse).Init()
  457. defer func() {
  458. this.Data["json"] = br
  459. this.ServeJSON()
  460. }()
  461. user := this.User
  462. if user == nil {
  463. br.Msg = "请登录"
  464. br.ErrMsg = "请登录,用户信息为空"
  465. br.Ret = 408
  466. return
  467. }
  468. var req models.TacticsTimeLineTimeLineIdReq
  469. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  470. if err != nil {
  471. br.Msg = "参数解析异常!"
  472. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  473. return
  474. }
  475. timeLineId := req.TimeLineId
  476. if timeLineId == 0 {
  477. br.Msg = "时间线ID错误"
  478. return
  479. }
  480. var sellerName string
  481. sellerName, err = models.GetCompanySellerName(user.CompanyId)
  482. if err != nil {
  483. br.Msg = "报名失败!"
  484. br.ErrMsg = "获取对应销售失败,Err:" + err.Error()
  485. return
  486. }
  487. item := models.CygxTacticsTimeLineHistory{
  488. TimeLineId: timeLineId,
  489. UserId: user.UserId,
  490. Mobile: user.Mobile,
  491. Email: user.Email,
  492. CompanyId: user.CompanyId,
  493. CompanyName: user.CompanyName,
  494. RealName: user.RealName,
  495. SellerName: sellerName,
  496. CreateTime: time.Now(),
  497. ModifyTime: time.Now(),
  498. }
  499. err = models.AddCygxTacticsTimeLineHistory(&item)
  500. br.Ret = 200
  501. br.Success = true
  502. br.Msg = "获取成功"
  503. }