tactics.go 13 KB

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