tactics.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. package controllers
  2. import (
  3. "fmt"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "hongze/hongze_cygx/models"
  6. "hongze/hongze_cygx/services"
  7. "hongze/hongze_cygx/utils"
  8. "html"
  9. "regexp"
  10. "strconv"
  11. "strings"
  12. "time"
  13. )
  14. //策略
  15. type TacticsController struct {
  16. BaseAuthController
  17. }
  18. type TacticsCommonController struct {
  19. BaseCommonController
  20. }
  21. // @Title 策略、行业列表接口
  22. // @Description 获取策略、行业 通用列表接口
  23. // @Param PageSize query int true "每页数据条数"
  24. // @Param CurrentIndex query int true "当前页页码,从1开始"
  25. // @Param CategoryId query int true "分类ID"
  26. // @Success 200 {object} models.TacticsListResp
  27. // @router /list [get]
  28. func (this *TacticsController) List() {
  29. br := new(models.BaseResponse).Init()
  30. defer func() {
  31. this.Data["json"] = br
  32. this.ServeJSON()
  33. }()
  34. user := this.User
  35. if user == nil {
  36. br.Msg = "请重新登录"
  37. br.Ret = 408
  38. return
  39. }
  40. uid := user.UserId
  41. pageSize, _ := this.GetInt("PageSize")
  42. currentIndex, _ := this.GetInt("CurrentIndex")
  43. categoryId, _ := this.GetInt("CategoryId")
  44. var startSize int
  45. if pageSize <= 0 {
  46. pageSize = utils.PageSize20
  47. }
  48. if currentIndex <= 0 {
  49. currentIndex = 1
  50. }
  51. startSize = paging.StartIndex(currentIndex, pageSize)
  52. var condition string
  53. var listTacticsSrt string
  54. var pars []interface{}
  55. var total int
  56. resp := new(models.TacticsListResp)
  57. page := paging.GetPaging(currentIndex, pageSize, total)
  58. //获取该产业下所对应的行业图片
  59. detail, errCategory := models.GetdetailByCategoryIdOne(categoryId)
  60. if errCategory != nil {
  61. br.Msg = "获取信息失败"
  62. br.ErrMsg = "获取信息失败,Err:" + errCategory.Error() + "categoryID 不存在:" + strconv.Itoa(categoryId)
  63. return
  64. }
  65. //对应行业的图片
  66. detailChartPermissionUrl, err := models.GetConfigByCode("category_chart_permissionimg_url")
  67. if err != nil {
  68. br.Msg = "获取数据失败"
  69. br.ErrMsg = "行业配置信息失败,Err:" + err.Error()
  70. return
  71. }
  72. chartPermissionUrlList := strings.Split(detailChartPermissionUrl.ConfigValue, "{|}")
  73. mapChartPermission := make(map[string]string)
  74. var permissionName string
  75. var imgUrlChartPermission string
  76. for _, v := range chartPermissionUrlList {
  77. vslice := strings.Split(v, "_")
  78. permissionName = vslice[0]
  79. imgUrlChartPermission = vslice[len(vslice)-1]
  80. mapChartPermission[permissionName] = imgUrlChartPermission
  81. }
  82. //对应分类的所图片
  83. detailCategoryUrl, err := models.GetConfigByCode("category_map_img_url")
  84. if err != nil {
  85. br.Msg = "获取数据失败"
  86. br.ErrMsg = "行业配置信息失败,Err:" + err.Error()
  87. return
  88. }
  89. categoryUrlList := strings.Split(detailCategoryUrl.ConfigValue, "{|}")
  90. mapCategoryUrl := make(map[string]string)
  91. var categoryIdStr string
  92. var imgUrlChart string
  93. for _, v := range categoryUrlList {
  94. vslice := strings.Split(v, "_")
  95. categoryIdStr = vslice[0]
  96. imgUrlChart = vslice[len(vslice)-1]
  97. mapCategoryUrl[categoryIdStr] = imgUrlChart
  98. }
  99. if categoryId < 0 {
  100. listTactics, err := models.GetReportMappingStrategyAll()
  101. if err != nil && err.Error() != utils.ErrNoRow() {
  102. br.Msg = "获取信息失败"
  103. br.ErrMsg = "获取分类权限信息失败,Err:" + err.Error()
  104. return
  105. }
  106. for _, v := range listTactics {
  107. listTacticsSrt = listTacticsSrt + strconv.Itoa(v.CategoryId) + `,`
  108. }
  109. listTacticsSrt = strings.TrimRight(listTacticsSrt, ",")
  110. condition = ` AND category_id IN(` + listTacticsSrt + `)`
  111. } else {
  112. categoryIdSet, errCategory := models.GetdetailByCategoryIdSet(categoryId)
  113. if errCategory != nil {
  114. br.Msg = "获取信息失败"
  115. br.ErrMsg = "获取信息失败,Err:" + errCategory.Error() + "categoryID 不存在:" + strconv.Itoa(categoryId)
  116. return
  117. }
  118. if categoryIdSet != "" {
  119. condition = ` AND category_id IN(` + categoryIdSet + `)`
  120. } else {
  121. condition = ` AND category_id IN(` + strconv.Itoa(categoryId) + `)`
  122. }
  123. }
  124. total, err = models.GetHomeCount(condition, pars)
  125. if err != nil {
  126. br.Msg = "获取信息失败"
  127. br.Msg = "获取帖子总数失败,Err:" + err.Error()
  128. return
  129. }
  130. page = paging.GetPaging(currentIndex, pageSize, total)
  131. list, err := models.GetReportTacticsList(condition, pars, uid, startSize, pageSize)
  132. if err != nil {
  133. br.Msg = "获取信息失败"
  134. br.Msg = "获取帖子数据失败,Err:" + err.Error()
  135. return
  136. }
  137. for k, 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. list[k].ImgUrlPc = mapCategoryUrl[v.CategoryId]
  142. }
  143. if categoryId > 0 {
  144. detail, errCategory := models.GetdetailByCategoryId(categoryId)
  145. if errCategory != nil {
  146. br.Msg = "获取信息失败"
  147. br.ErrMsg = "获取信息失败,Err:" + errCategory.Error() + "categoryID 不存在:" + strconv.Itoa(categoryId)
  148. return
  149. }
  150. resp.MatchTypeName = detail.MatchTypeName
  151. }
  152. lenList := len(list)
  153. for i := 0; i < lenList; i++ {
  154. item := list[i]
  155. list[i].Body, _ = services.GetReportContentTextSub(item.Body)
  156. list[i].Abstract = html.UnescapeString(item.Abstract)
  157. //list[i].Abstract, _ = services.GetReportContentTextSub(item.Abstract)
  158. list[i].Annotation = strings.Replace(item.Annotation, "<br>", "", -1)
  159. //行业比较研究、资金流向,显示报告的摘要
  160. if resp.MatchTypeName == "行业比较研究" || resp.MatchTypeName == "资金流向" {
  161. list[i].Annotation = list[i].Abstract
  162. }
  163. //if item.ArticleId == 6881 {
  164. // fmt.Println(list[i].Annotation)
  165. //}
  166. list[i].Abstract, _ = services.GetReportContentTextSub(item.Abstract)
  167. }
  168. resp.CategoryImgUrlPc = mapChartPermission[detail.ChartPermissionName]
  169. resp.List = list
  170. resp.Paging = page
  171. br.Ret = 200
  172. br.Success = true
  173. br.Msg = "获取成功"
  174. br.Data = resp
  175. }
  176. // @Title 获取报告详情
  177. // @Description 获取报告详情接口
  178. // @Param ArticleId query int true "报告ID"
  179. // @Success 200 {object} models.ArticleDetailResp
  180. // @router /detail [get]
  181. func (this *TacticsController) Detail() {
  182. br := new(models.BaseResponse).Init()
  183. defer func() {
  184. this.Data["json"] = br
  185. this.ServeJSON()
  186. }()
  187. user := this.User
  188. if user == nil {
  189. br.Msg = "请登录"
  190. br.ErrMsg = "请登录,用户信息为空"
  191. br.Ret = 408
  192. return
  193. }
  194. uid := user.UserId
  195. articleId, err := this.GetInt("ArticleId")
  196. if articleId <= 0 {
  197. br.Msg = "参数错误"
  198. br.ErrMsg = "参数错误"
  199. return
  200. }
  201. detail := new(models.ArticleDetail)
  202. hasPermission := 0
  203. hasFree := 0
  204. //判断是否已经申请过
  205. applyCount, err := models.GetApplyRecordCount(uid)
  206. if err != nil && err.Error() != utils.ErrNoRow() {
  207. br.Msg = "获取信息失败"
  208. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  209. return
  210. }
  211. fmt.Println(user.CompanyId)
  212. //`description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,4:潜在客户,未提交过申请,5:潜在客户,已提交过申请"`
  213. if user.CompanyId > 1 {
  214. companyPermission, err := models.GetCompanyPermission(user.CompanyId)
  215. if err != nil {
  216. br.Msg = "获取信息失败"
  217. br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  218. return
  219. }
  220. detail, err = models.GetArticleDetailById(articleId)
  221. if err != nil {
  222. br.Msg = "获取信息失败"
  223. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  224. return
  225. }
  226. fmt.Println(detail.Department)
  227. detail.Body = html.UnescapeString(detail.Body)
  228. //detail.Abstract = html.UnescapeString(detail.Abstract)
  229. detail.Abstract, _ = services.GetReportContentTextSub(detail.Abstract)
  230. if companyPermission == "" {
  231. if applyCount > 0 {
  232. hasPermission = 5
  233. } else {
  234. hasPermission = 2
  235. }
  236. hasFree = 2
  237. goto Loop
  238. } else {
  239. hasFree = 1
  240. var articlePermissionPermissionName string
  241. if detail.CategoryId > 0 {
  242. articlePermission, err := models.GetArticlePermission(detail.CategoryId)
  243. if err != nil {
  244. br.Msg = "获取信息失败"
  245. br.ErrMsg = "获取报告权限失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  246. return
  247. }
  248. if articlePermission == nil {
  249. br.Msg = "获取信息失败"
  250. br.ErrMsg = "报告权限不存在,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  251. return
  252. }
  253. articlePermissionPermissionName = articlePermission.PermissionName
  254. } else {
  255. articlePermissionPermissionName = detail.CategoryName
  256. }
  257. if strings.Contains(companyPermission, articlePermissionPermissionName) {
  258. hasPermission = 1
  259. historyRecord := new(models.CygxArticleHistoryRecord)
  260. historyRecord.UserId = uid
  261. historyRecord.ArticleId = articleId
  262. historyRecord.CreateTime = time.Now()
  263. historyRecord.Mobile = user.Mobile
  264. historyRecord.Email = user.Email
  265. historyRecord.CompanyId = user.CompanyId
  266. historyRecord.CompanyName = user.CompanyName
  267. recordCount, _ := models.GetNoAddStoptimeArticleCount(uid, articleId)
  268. if recordCount == 0 {
  269. go models.AddCygxArticleHistoryRecord(historyRecord)
  270. } else {
  271. detailNew, err := models.GetNewArticleHistoryRecord(uid, articleId)
  272. if err != nil {
  273. br.Msg = "获取信息失败"
  274. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  275. return
  276. }
  277. if detailNew.StopTime > 0 {
  278. go models.AddCygxArticleHistoryRecord(historyRecord)
  279. }
  280. }
  281. } else { //无该行业权限
  282. hasPermission = 3
  283. }
  284. }
  285. collectCount, err := models.GetArticleCollectCount(uid, articleId)
  286. if err != nil && err.Error() != utils.ErrNoRow() {
  287. br.Msg = "获取信息失败"
  288. br.ErrMsg = "判断是否已收藏失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  289. return
  290. }
  291. if collectCount > 0 {
  292. detail.IsCollect = true
  293. }
  294. interviewApplyItem, err := models.GetArticleInterviewApply(uid, articleId)
  295. if err != nil && err.Error() != utils.ErrNoRow() {
  296. br.Msg = "获取信息失败"
  297. br.ErrMsg = "判断是否已申请访谈失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  298. return
  299. }
  300. if interviewApplyItem != nil && interviewApplyItem.InterviewApplyId > 0 {
  301. detail.IsInterviewApply = true
  302. detail.InterviewApplyStatus = interviewApplyItem.Status
  303. }
  304. //获取销售手机号
  305. sellerItem, err := models.GetSellerByCompanyId(user.CompanyId)
  306. if err != nil {
  307. br.Msg = "获取信息失败"
  308. br.ErrMsg = "获取销售数据失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  309. return
  310. }
  311. if sellerItem != nil {
  312. detail.SellerMobile = sellerItem.Mobile
  313. detail.SellerName = sellerItem.RealName
  314. }
  315. sellerList, err := models.GetSellerList(articleId)
  316. if err != nil {
  317. br.Msg = "获取信息失败"
  318. br.ErrMsg = "获取销售数据失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  319. return
  320. }
  321. if detail.ArticleId > 1000000 {
  322. var hrefRegexp = regexp.MustCompile("[0-9]\\d*")
  323. match := hrefRegexp.FindAllString(detail.SellerAndMobile, -1)
  324. if match != nil {
  325. for _, v := range match {
  326. sellerAndMobile := &models.SellerRep{
  327. SellerMobile: v,
  328. SellerName: strings.Replace(detail.SellerAndMobile, v, "", -1),
  329. }
  330. sellerList = append(sellerList, sellerAndMobile)
  331. }
  332. }
  333. }
  334. detail.SellerList = sellerList
  335. } else { //潜在客户
  336. if applyCount > 0 {
  337. hasPermission = 5
  338. } else {
  339. hasPermission = 4
  340. }
  341. }
  342. Loop:
  343. if hasPermission != 1 {
  344. detail.Body = ""
  345. detail.BodyText = ""
  346. }
  347. resp := new(models.ArticleDetailResp)
  348. resp.HasPermission = hasPermission
  349. resp.HasFree = hasFree
  350. resp.Detail = detail
  351. br.Ret = 200
  352. br.Success = true
  353. br.Msg = "获取成功"
  354. br.Data = resp
  355. }