tactics.go 8.7 KB

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