tactics.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  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. condition = ` AND category_id IN(` + strconv.Itoa(categoryId) + `)`
  113. }
  114. total, err = models.GetHomeCount(condition, pars)
  115. if err != nil {
  116. br.Msg = "获取信息失败"
  117. br.Msg = "获取帖子总数失败,Err:" + err.Error()
  118. return
  119. }
  120. page = paging.GetPaging(currentIndex, pageSize, total)
  121. list, err := models.GetReportTacticsList(condition, pars, uid, startSize, pageSize)
  122. if err != nil {
  123. br.Msg = "获取信息失败"
  124. br.Msg = "获取帖子数据失败,Err:" + err.Error()
  125. return
  126. }
  127. for k, v := range list {
  128. if v.Readnum == 0 && user.CreatedTime.Before(utils.StrTimeToTime(v.PublishDate)) && utils.StrTimeToTime(utils.OnlineTime).Before(utils.StrTimeToTime(v.PublishDate)) {
  129. list[k].IsRed = true
  130. }
  131. list[k].ImgUrlPc = mapCategoryUrl[v.CategoryId]
  132. }
  133. if categoryId > 0 {
  134. detail, errCategory := models.GetdetailByCategoryId(categoryId)
  135. if errCategory != nil {
  136. br.Msg = "获取信息失败"
  137. br.ErrMsg = "获取信息失败,Err:" + errCategory.Error() + "categoryID 不存在:" + strconv.Itoa(categoryId)
  138. return
  139. }
  140. resp.MatchTypeName = detail.MatchTypeName
  141. }
  142. lenList := len(list)
  143. for i := 0; i < lenList; i++ {
  144. item := list[i]
  145. list[i].Body, _ = services.GetReportContentTextSub(item.Body)
  146. list[i].Abstract = html.UnescapeString(item.Abstract)
  147. //list[i].Abstract, _ = services.GetReportContentTextSub(item.Abstract)
  148. list[i].Annotation = strings.Replace(item.Annotation, "<br>", "", -1)
  149. //行业比较研究、资金流向,显示报告的摘要
  150. if resp.MatchTypeName == "行业比较研究" || resp.MatchTypeName == "资金流向" {
  151. list[i].Annotation = list[i].Abstract
  152. }
  153. //if item.ArticleId == 6881 {
  154. // fmt.Println(list[i].Annotation)
  155. //}
  156. list[i].Abstract, _ = services.GetReportContentTextSub(item.Abstract)
  157. }
  158. resp.CategoryImgUrlPc = mapChartPermission[detail.ChartPermissionName]
  159. resp.List = list
  160. resp.Paging = page
  161. br.Ret = 200
  162. br.Success = true
  163. br.Msg = "获取成功"
  164. br.Data = resp
  165. }
  166. // @Title 获取报告详情
  167. // @Description 获取报告详情接口
  168. // @Param ArticleId query int true "报告ID"
  169. // @Success 200 {object} models.ArticleDetailResp
  170. // @router /detail [get]
  171. func (this *TacticsController) Detail() {
  172. br := new(models.BaseResponse).Init()
  173. defer func() {
  174. this.Data["json"] = br
  175. this.ServeJSON()
  176. }()
  177. user := this.User
  178. if user == nil {
  179. br.Msg = "请登录"
  180. br.ErrMsg = "请登录,用户信息为空"
  181. br.Ret = 408
  182. return
  183. }
  184. uid := user.UserId
  185. articleId, err := this.GetInt("ArticleId")
  186. if articleId <= 0 {
  187. br.Msg = "参数错误"
  188. br.ErrMsg = "参数错误"
  189. return
  190. }
  191. detail := new(models.ArticleDetail)
  192. hasPermission := 0
  193. hasFree := 0
  194. //判断是否已经申请过
  195. applyCount, err := models.GetApplyRecordCount(uid)
  196. if err != nil && err.Error() != utils.ErrNoRow() {
  197. br.Msg = "获取信息失败"
  198. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  199. return
  200. }
  201. fmt.Println(user.CompanyId)
  202. //`description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,4:潜在客户,未提交过申请,5:潜在客户,已提交过申请"`
  203. if user.CompanyId > 1 {
  204. companyPermission, err := models.GetCompanyPermission(user.CompanyId)
  205. if err != nil {
  206. br.Msg = "获取信息失败"
  207. br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  208. return
  209. }
  210. detail, err = models.GetArticleDetailById(articleId)
  211. if err != nil {
  212. br.Msg = "获取信息失败"
  213. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  214. return
  215. }
  216. fmt.Println(detail.Department)
  217. detail.Body = html.UnescapeString(detail.Body)
  218. //detail.Abstract = html.UnescapeString(detail.Abstract)
  219. detail.Abstract, _ = services.GetReportContentTextSub(detail.Abstract)
  220. if companyPermission == "" {
  221. if applyCount > 0 {
  222. hasPermission = 5
  223. } else {
  224. hasPermission = 2
  225. }
  226. hasFree = 2
  227. goto Loop
  228. } else {
  229. hasFree = 1
  230. var articlePermissionPermissionName string
  231. if detail.CategoryId > 0 {
  232. articlePermission, err := models.GetArticlePermission(detail.CategoryId)
  233. if err != nil {
  234. br.Msg = "获取信息失败"
  235. br.ErrMsg = "获取报告权限失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  236. return
  237. }
  238. if articlePermission == nil {
  239. br.Msg = "获取信息失败"
  240. br.ErrMsg = "报告权限不存在,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  241. return
  242. }
  243. articlePermissionPermissionName = articlePermission.PermissionName
  244. } else {
  245. articlePermissionPermissionName = detail.CategoryName
  246. }
  247. if strings.Contains(companyPermission, articlePermissionPermissionName) {
  248. hasPermission = 1
  249. historyRecord := new(models.CygxArticleHistoryRecord)
  250. historyRecord.UserId = uid
  251. historyRecord.ArticleId = articleId
  252. historyRecord.CreateTime = time.Now()
  253. historyRecord.Mobile = user.Mobile
  254. historyRecord.Email = user.Email
  255. historyRecord.CompanyId = user.CompanyId
  256. historyRecord.CompanyName = user.CompanyName
  257. recordCount, _ := models.GetNoAddStoptimeArticleCount(uid, articleId)
  258. if recordCount == 0 {
  259. go models.AddCygxArticleHistoryRecord(historyRecord)
  260. } else {
  261. detailNew, err := models.GetNewArticleHistoryRecord(uid, articleId)
  262. if err != nil {
  263. br.Msg = "获取信息失败"
  264. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  265. return
  266. }
  267. if detailNew.StopTime > 0 {
  268. go models.AddCygxArticleHistoryRecord(historyRecord)
  269. }
  270. }
  271. } else { //无该行业权限
  272. hasPermission = 3
  273. }
  274. }
  275. collectCount, err := models.GetArticleCollectCount(uid, articleId)
  276. if err != nil && err.Error() != utils.ErrNoRow() {
  277. br.Msg = "获取信息失败"
  278. br.ErrMsg = "判断是否已收藏失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  279. return
  280. }
  281. if collectCount > 0 {
  282. detail.IsCollect = true
  283. }
  284. interviewApplyItem, err := models.GetArticleInterviewApply(uid, articleId)
  285. if err != nil && err.Error() != utils.ErrNoRow() {
  286. br.Msg = "获取信息失败"
  287. br.ErrMsg = "判断是否已申请访谈失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  288. return
  289. }
  290. if interviewApplyItem != nil && interviewApplyItem.InterviewApplyId > 0 {
  291. detail.IsInterviewApply = true
  292. detail.InterviewApplyStatus = interviewApplyItem.Status
  293. }
  294. //获取销售手机号
  295. sellerItem, err := models.GetSellerByCompanyId(user.CompanyId)
  296. if err != nil {
  297. br.Msg = "获取信息失败"
  298. br.ErrMsg = "获取销售数据失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  299. return
  300. }
  301. if sellerItem != nil {
  302. detail.SellerMobile = sellerItem.Mobile
  303. detail.SellerName = sellerItem.RealName
  304. }
  305. sellerList, err := models.GetSellerList(articleId)
  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 detail.ArticleId > 1000000 {
  312. var hrefRegexp = regexp.MustCompile("[0-9]\\d*")
  313. match := hrefRegexp.FindAllString(detail.SellerAndMobile, -1)
  314. if match != nil {
  315. for _, v := range match {
  316. sellerAndMobile := &models.SellerRep{
  317. SellerMobile: v,
  318. SellerName: strings.Replace(detail.SellerAndMobile, v, "", -1),
  319. }
  320. sellerList = append(sellerList, sellerAndMobile)
  321. }
  322. }
  323. }
  324. detail.SellerList = sellerList
  325. } else { //潜在客户
  326. if applyCount > 0 {
  327. hasPermission = 5
  328. } else {
  329. hasPermission = 4
  330. }
  331. }
  332. Loop:
  333. if hasPermission != 1 {
  334. detail.Body = ""
  335. detail.BodyText = ""
  336. }
  337. resp := new(models.ArticleDetailResp)
  338. resp.HasPermission = hasPermission
  339. resp.HasFree = hasFree
  340. resp.Detail = detail
  341. br.Ret = 200
  342. br.Success = true
  343. br.Msg = "获取成功"
  344. br.Data = resp
  345. }