tactics.go 7.5 KB

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