tactics.go 11 KB

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