tactics.go 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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. "strconv"
  10. "strings"
  11. "time"
  12. )
  13. //策略
  14. type TacticsController struct {
  15. BaseAuthController
  16. }
  17. type TacticsCommonController struct {
  18. BaseCommonController
  19. }
  20. // @Title 策略、行业、产业列表接口
  21. // @Description 获取策略、行业、产业通用列表接口
  22. // @Param PageSize query int true "每页数据条数"
  23. // @Param CurrentIndex query int true "当前页页码,从1开始"
  24. // @Param CategoryId query int true "分类ID"
  25. // @Success 200 {object} models.TacticsListResp
  26. // @router /list [get]
  27. func (this *TacticsController) List() {
  28. br := new(models.BaseResponse).Init()
  29. defer func() {
  30. this.Data["json"] = br
  31. this.ServeJSON()
  32. }()
  33. user := this.User
  34. if user == nil {
  35. br.Msg = "请重新登录"
  36. br.Ret = 408
  37. return
  38. }
  39. uid := user.UserId
  40. pageSize, _ := this.GetInt("PageSize")
  41. currentIndex, _ := this.GetInt("CurrentIndex")
  42. categoryId, _ := this.GetInt("CategoryId")
  43. var startSize int
  44. if pageSize <= 0 {
  45. pageSize = utils.PageSize20
  46. }
  47. if currentIndex <= 0 {
  48. currentIndex = 1
  49. }
  50. startSize = paging.StartIndex(currentIndex, pageSize)
  51. var condition string
  52. var listTacticsSrt string
  53. var pars []interface{}
  54. var total int
  55. resp := new(models.TacticsListResp)
  56. page := paging.GetPaging(currentIndex, pageSize, total)
  57. if categoryId < 1 {
  58. listTactics, err := models.GetReportMappingStrategyAll()
  59. if err != nil && err.Error() != utils.ErrNoRow() {
  60. br.Msg = "获取信息失败"
  61. br.ErrMsg = "获取分类权限信息失败,Err:" + err.Error()
  62. return
  63. }
  64. for _, v := range listTactics {
  65. listTacticsSrt = listTacticsSrt + strconv.Itoa(v.CategoryId) + `,`
  66. }
  67. listTacticsSrt = strings.TrimRight(listTacticsSrt, ",")
  68. condition = ` AND category_id IN(` + listTacticsSrt + `)`
  69. } else {
  70. condition = ` AND category_id IN(` + strconv.Itoa(categoryId) + `)`
  71. }
  72. total, err := models.GetHomeCount(condition, pars)
  73. if err != nil {
  74. br.Msg = "获取信息失败"
  75. br.Msg = "获取帖子总数失败,Err:" + err.Error()
  76. return
  77. }
  78. uid = 46085
  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 {
  95. list[k].IsRed = true
  96. }
  97. }
  98. resp.List = list
  99. resp.Paging = page
  100. br.Ret = 200
  101. br.Success = true
  102. br.Msg = "获取成功"
  103. br.Data = resp
  104. }
  105. // @Title 获取报告详情
  106. // @Description 获取报告详情接口
  107. // @Param ArticleId query int true "报告ID"
  108. // @Success 200 {object} models.ArticleDetailResp
  109. // @router /detail [get]
  110. func (this *TacticsController) Detail() {
  111. br := new(models.BaseResponse).Init()
  112. defer func() {
  113. this.Data["json"] = br
  114. this.ServeJSON()
  115. }()
  116. user := this.User
  117. if user == nil {
  118. br.Msg = "请登录"
  119. br.ErrMsg = "请登录,用户信息为空"
  120. br.Ret = 408
  121. return
  122. }
  123. uid := user.UserId
  124. articleId, err := this.GetInt("ArticleId")
  125. if articleId <= 0 {
  126. br.Msg = "参数错误"
  127. br.ErrMsg = "参数错误"
  128. return
  129. }
  130. detail := new(models.ArticleDetail)
  131. hasPermission := 0
  132. hasFree := 0
  133. //判断是否已经申请过
  134. applyCount, err := models.GetApplyRecordCount(uid)
  135. if err != nil && err.Error() != utils.ErrNoRow() {
  136. br.Msg = "获取信息失败"
  137. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  138. return
  139. }
  140. fmt.Println(user.CompanyId)
  141. //`description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,4:潜在客户,未提交过申请,5:潜在客户,已提交过申请"`
  142. if user.CompanyId > 1 {
  143. companyPermission, err := models.GetCompanyPermission(user.CompanyId)
  144. if err != nil {
  145. br.Msg = "获取信息失败"
  146. br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  147. return
  148. }
  149. detail, err = models.GetArticleDetailById(articleId)
  150. if err != nil {
  151. br.Msg = "获取信息失败"
  152. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  153. return
  154. }
  155. fmt.Println(detail.Department)
  156. detail.Body = html.UnescapeString(detail.Body)
  157. //detail.Abstract = html.UnescapeString(detail.Abstract)
  158. detail.Abstract, _ = services.GetReportContentTextSub(detail.Abstract)
  159. if companyPermission == "" {
  160. if applyCount > 0 {
  161. hasPermission = 5
  162. } else {
  163. hasPermission = 2
  164. }
  165. hasFree = 2
  166. goto Loop
  167. } else {
  168. hasFree = 1
  169. articlePermission, err := models.GetReportPermission(detail.SubCategoryName)
  170. if err != nil {
  171. br.Msg = "获取信息失败"
  172. br.ErrMsg = "获取报告权限失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  173. return
  174. }
  175. if articlePermission == nil {
  176. br.Msg = "获取信息失败"
  177. br.ErrMsg = "报告权限不存在,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  178. return
  179. }
  180. for _, p := range articlePermission {
  181. fmt.Println(p)
  182. if strings.Contains(companyPermission, p.PermissionName) {
  183. hasPermission = 1
  184. historyRecord := new(models.CygxArticleHistoryRecord)
  185. historyRecord.UserId = uid
  186. historyRecord.ArticleId = articleId
  187. historyRecord.CreateTime = time.Now()
  188. historyRecord.Mobile = user.Mobile
  189. historyRecord.Email = user.Email
  190. historyRecord.CompanyId = user.CompanyId
  191. historyRecord.CompanyName = user.CompanyName
  192. go models.AddCygxArticleHistoryRecord(historyRecord)
  193. break
  194. } else { //无该行业权限
  195. hasPermission = 3
  196. }
  197. }
  198. }
  199. collectCount, err := models.GetArticleCollectCount(uid, articleId)
  200. if err != nil && err.Error() != utils.ErrNoRow() {
  201. br.Msg = "获取信息失败"
  202. br.ErrMsg = "判断是否已收藏失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  203. return
  204. }
  205. if collectCount > 0 {
  206. detail.IsCollect = true
  207. }
  208. interviewApplyItem, err := models.GetArticleInterviewApply(uid, articleId)
  209. if err != nil && err.Error() != utils.ErrNoRow() {
  210. br.Msg = "获取信息失败"
  211. br.ErrMsg = "判断是否已申请访谈失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  212. return
  213. }
  214. if interviewApplyItem != nil && interviewApplyItem.InterviewApplyId > 0 {
  215. detail.IsInterviewApply = true
  216. detail.InterviewApplyStatus = interviewApplyItem.Status
  217. }
  218. //获取销售手机号
  219. sellerItem, err := models.GetSellerByCompanyId(user.CompanyId)
  220. if err != nil {
  221. br.Msg = "获取信息失败"
  222. br.ErrMsg = "获取销售数据失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  223. return
  224. }
  225. if sellerItem != nil {
  226. detail.SellerMobile = sellerItem.Mobile
  227. detail.SellerName = sellerItem.RealName
  228. }
  229. sellerList, err := models.GetSellerList(articleId)
  230. if err != nil {
  231. br.Msg = "获取信息失败"
  232. br.ErrMsg = "获取销售数据失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  233. return
  234. }
  235. detail.SellerList = sellerList
  236. } else { //潜在客户
  237. if applyCount > 0 {
  238. hasPermission = 5
  239. } else {
  240. hasPermission = 4
  241. }
  242. }
  243. Loop:
  244. if hasPermission != 1 {
  245. detail.Body = ""
  246. detail.BodyText = ""
  247. }
  248. resp := new(models.ArticleDetailResp)
  249. resp.HasPermission = hasPermission
  250. resp.HasFree = hasFree
  251. resp.Detail = detail
  252. br.Ret = 200
  253. br.Success = true
  254. br.Msg = "获取成功"
  255. br.Data = resp
  256. }