tactics.go 13 KB

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