tactics.go 10 KB

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