article.go 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "hongze/hongze_cygx/models"
  5. "hongze/hongze_cygx/utils"
  6. "strconv"
  7. "strings"
  8. "time"
  9. )
  10. type ArticleController struct {
  11. BaseAuthController
  12. }
  13. type ArticleCommonController struct {
  14. BaseCommonController
  15. }
  16. // @Title 获取报告详情
  17. // @Description 获取报告详情接口
  18. // @Param ArticleId query int true "报告ID"
  19. // @Success 200 {object} models.ArticleDetailResp
  20. // @router /detail [get]
  21. func (this *ArticleController) Detail() {
  22. br := new(models.BaseResponse).Init()
  23. defer func() {
  24. this.Data["json"] = br
  25. this.ServeJSON()
  26. }()
  27. user := this.User
  28. if user == nil {
  29. br.Msg = "请登录"
  30. br.ErrMsg = "请登录,用户信息为空"
  31. br.Ret = 408
  32. return
  33. }
  34. uid := user.UserId
  35. articleId, err := this.GetInt("ArticleId")
  36. if articleId <= 0 {
  37. br.Msg = "参数错误"
  38. br.ErrMsg = "参数错误"
  39. return
  40. }
  41. detail := new(models.ArticleDetail)
  42. hasPermission := 0
  43. hasFree := 0
  44. //判断是否已经申请过
  45. applyCount, err := models.GetApplyRecordCount(uid)
  46. if err != nil && err.Error() != utils.ErrNoRow() {
  47. br.Msg = "获取信息失败"
  48. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  49. return
  50. }
  51. //`description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,已提交过申请,4:无该行业权限,未提交过申请,5:潜在客户,未提交过申请,6:潜在客户,已提交过申请"`
  52. if user.CompanyId > 1 {
  53. companyPermission, err := models.GetCompanyPermission(user.CompanyId)
  54. if err != nil {
  55. br.Msg = "获取信息失败"
  56. br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  57. return
  58. }
  59. if companyPermission == "" {
  60. hasPermission = 2
  61. hasFree = 2
  62. goto Loop
  63. } else {
  64. hasFree = 1
  65. articlePermission, err := models.GetArticlePermission(detail.SubCategoryName)
  66. if err != nil {
  67. br.Msg = "获取信息失败"
  68. br.ErrMsg = "获取报告权限失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  69. return
  70. }
  71. if articlePermission == nil {
  72. br.Msg = "获取信息失败"
  73. br.ErrMsg = "报告权限不存在,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  74. return
  75. }
  76. if strings.Contains(companyPermission, articlePermission.PermissionName) {
  77. hasPermission = 1
  78. //新增浏览记录
  79. record := new(models.CygxArticleViewRecord)
  80. record.UserId = uid
  81. record.ArticleId = articleId
  82. record.CreateTime = time.Now()
  83. record.Mobile = user.Mobile
  84. record.Email = user.Email
  85. record.CompanyId = user.CompanyId
  86. record.CompanyName = user.CompanyName
  87. go models.AddCygxArticleViewRecord(record)
  88. } else { //无该行业权限
  89. if applyCount > 0 {
  90. hasPermission = 3
  91. } else {
  92. hasPermission = 4
  93. }
  94. }
  95. }
  96. detail, err = models.GetArticleDetailById(articleId)
  97. if err != nil {
  98. br.Msg = "获取信息失败"
  99. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  100. return
  101. }
  102. collectCount, err := models.GetArticleCollectCount(uid, articleId)
  103. if err != nil && err.Error() != utils.ErrNoRow() {
  104. br.Msg = "获取信息失败"
  105. br.ErrMsg = "判断是否已收藏失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  106. return
  107. }
  108. if collectCount > 0 {
  109. detail.IsCollect = true
  110. }
  111. interviewApplyItem, err := models.GetArticleInterviewApply(uid, articleId)
  112. if err != nil && err.Error() != utils.ErrNoRow() {
  113. br.Msg = "获取信息失败"
  114. br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  115. return
  116. }
  117. if interviewApplyItem != nil && interviewApplyItem.InterviewApplyId > 0 {
  118. detail.IsInterviewApply = true
  119. detail.InterviewApplyStatus = interviewApplyItem.Status
  120. }
  121. //获取销售手机号
  122. sellerItem, err := models.GetSellerByCompanyId(user.CompanyId)
  123. if err != nil {
  124. br.Msg = "获取信息失败"
  125. br.ErrMsg = "获取销售数据失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  126. return
  127. }
  128. if sellerItem != nil {
  129. detail.SellerMobile = sellerItem.Mobile
  130. }
  131. } else { //潜在客户
  132. if applyCount > 0 {
  133. hasPermission = 6
  134. } else {
  135. hasPermission = 5
  136. }
  137. }
  138. Loop:
  139. resp := new(models.ArticleDetailResp)
  140. resp.HasPermission = hasPermission
  141. resp.HasFree = hasFree
  142. resp.Detail = detail
  143. br.Ret = 200
  144. br.Success = true
  145. br.Msg = "获取成功"
  146. br.Data = resp
  147. }
  148. // @Title 收藏
  149. // @Description 收藏
  150. // @Param request body models.ArticleCollectReq true "type json string"
  151. // @Success 200 {object} models.FontsCollectResp
  152. // @router /collect [post]
  153. func (this *ArticleController) ArticleCollect() {
  154. br := new(models.BaseResponse).Init()
  155. defer func() {
  156. this.Data["json"] = br
  157. this.ServeJSON()
  158. }()
  159. user := this.User
  160. if user == nil {
  161. br.Msg = "请重新登录"
  162. br.Ret = 408
  163. return
  164. }
  165. uid := user.UserId
  166. var req models.ArticleCollectReq
  167. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  168. if err != nil {
  169. br.Msg = "参数解析异常!"
  170. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  171. return
  172. }
  173. count, err := models.GetArticleCollectCount(uid, req.ArticleId)
  174. if err != nil {
  175. br.Msg = "获取数据失败!"
  176. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  177. return
  178. }
  179. resp := new(models.ArticleCollectResp)
  180. if count <= 0 {
  181. item := new(models.CygxArticleCollect)
  182. item.ArticleId = req.ArticleId
  183. item.UserId = uid
  184. item.CreateTime = time.Now()
  185. _, err = models.AddCygxArticleCollect(item)
  186. if err != nil {
  187. br.Msg = "收藏失败"
  188. br.ErrMsg = "收藏失败,Err:" + err.Error()
  189. return
  190. }
  191. br.Msg = "收藏成功"
  192. resp.Status = 1
  193. } else {
  194. err = models.RemoveArticleCollect(uid, req.ArticleId)
  195. if err != nil {
  196. br.Msg = "取消收藏失败"
  197. br.ErrMsg = "取消收藏失败,Err:" + err.Error()
  198. return
  199. }
  200. br.Msg = "已取消收藏"
  201. resp.Status = 2
  202. }
  203. collectTotal, err := models.GetArticleCollectUsersCount(req.ArticleId)
  204. if err != nil {
  205. br.Msg = "获取数据失败"
  206. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  207. return
  208. }
  209. resp.CollectCount = collectTotal
  210. br.Ret = 200
  211. br.Success = true
  212. br.Data = resp
  213. }
  214. // @Title 访谈申请
  215. // @Description 访谈申请
  216. // @Param request body models.ArticleInterviewApplyReq true "type json string"
  217. // @Success 200 {object} models.FontsCollectResp
  218. // @router /interview/apply [post]
  219. func (this *ArticleController) InterviewApply() {
  220. br := new(models.BaseResponse).Init()
  221. defer func() {
  222. this.Data["json"] = br
  223. this.ServeJSON()
  224. }()
  225. user := this.User
  226. if user == nil {
  227. br.Msg = "请重新登录"
  228. br.Ret = 408
  229. return
  230. }
  231. uid := user.UserId
  232. var req models.ArticleInterviewApplyReq
  233. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  234. if err != nil {
  235. br.Msg = "参数解析异常!"
  236. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  237. return
  238. }
  239. article, err := models.GetArticleDetailById(req.ArticleId)
  240. if err != nil {
  241. br.Msg = "获取纪要失败!"
  242. br.ErrMsg = "获取纪要失败,Err:" + err.Error()
  243. return
  244. }
  245. count, err := models.GetArticleInterviewApplyCount(uid, req.ArticleId)
  246. if err != nil {
  247. br.Msg = "获取数据失败!"
  248. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  249. return
  250. }
  251. resp := new(models.ArticleInterviewApplyResp)
  252. if count <= 0 {
  253. item := new(models.CygxInterviewApply)
  254. item.ArticleId = req.ArticleId
  255. item.UserId = uid
  256. item.CompanyId = this.User.CompanyId
  257. item.Status = "待邀请"
  258. item.Sort = 1
  259. item.ArticleTitle = article.Title
  260. item.InterviewTime = time.Now()
  261. item.CreateTime = time.Now()
  262. item.ModifyTime = time.Now()
  263. item.ArticleIdMd5 = article.ArticleIdMd5
  264. _, err = models.AddCygxInterviewApply(item)
  265. if err != nil {
  266. br.Msg = "申请失败"
  267. br.ErrMsg = "申请失败,Err:" + err.Error()
  268. return
  269. }
  270. br.Msg = "申请成功"
  271. resp.Status = 1
  272. } else {
  273. err = models.RemoveArticleInterviewApply(uid, req.ArticleId)
  274. if err != nil {
  275. br.Msg = "取消申请失败"
  276. br.ErrMsg = "取消申请失败,Err:" + err.Error()
  277. return
  278. }
  279. br.Msg = "已取消申请"
  280. resp.Status = 2
  281. }
  282. br.Ret = 200
  283. br.Success = true
  284. br.Data = resp
  285. }
  286. // @Title 获取报告详情
  287. // @Description 获取报告详情接口
  288. // @Param ArticleIdMd5 query int true "报告ID"
  289. // @Success 200 {object} models.ArticleDetailResp
  290. // @router /look/detail [get]
  291. func (this *ArticleCommonController) Detail() {
  292. br := new(models.BaseResponse).Init()
  293. defer func() {
  294. this.Data["json"] = br
  295. this.ServeJSON()
  296. }()
  297. articleIdMd5 := this.GetString("ArticleIdMd5")
  298. if articleIdMd5 == "" {
  299. br.Msg = "参数错误"
  300. br.ErrMsg = "参数错误"
  301. return
  302. }
  303. resp := new(models.ArticleDetailResp)
  304. detail, err := models.GetArticleDetailByIdMd5(articleIdMd5)
  305. if err != nil && err.Error() != utils.ErrNoRow() {
  306. br.Msg = "获取信息失败"
  307. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  308. return
  309. }
  310. if detail == nil {
  311. resp.HasPermission = 2
  312. } else {
  313. resp.HasPermission = 1
  314. }
  315. resp.Detail = detail
  316. br.Ret = 200
  317. br.Success = true
  318. br.Msg = "获取成功"
  319. br.Data = resp
  320. }