tactics.go 13 KB

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