tactics.go 9.2 KB

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