tactics.go 8.1 KB

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