tactics.go 9.3 KB

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