tactics.go 12 KB

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