tactics.go 15 KB

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