article.go 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111
  1. package controllers
  2. import (
  3. "bufio"
  4. "github.com/pdfcpu/pdfcpu/pkg/api"
  5. "github.com/pdfcpu/pdfcpu/pkg/pdfcpu"
  6. "io"
  7. //"bufio"
  8. "encoding/json"
  9. "fmt"
  10. "github.com/medivhzhan/weapp/v2"
  11. "os"
  12. //"github.com/pdfcpu/pdfcpu/pkg/api"
  13. //"github.com/pdfcpu/pdfcpu/pkg/pdfcpu"
  14. "hongze/hongze_mfyx/models"
  15. "hongze/hongze_mfyx/services"
  16. "hongze/hongze_mfyx/utils"
  17. "html"
  18. nhttp "net/http"
  19. "strconv"
  20. "strings"
  21. "time"
  22. )
  23. type ArticleController struct {
  24. BaseAuthController
  25. }
  26. type ArticleCommonController struct {
  27. BaseCommonController
  28. }
  29. type ArticleControllerMobile struct {
  30. BaseAuthMobileController
  31. }
  32. // @Title 获取报告详情
  33. // @Description 获取报告详情接口
  34. // @Param ArticleId query int true "报告ID"
  35. // @Param IsSendWx query int false "是否是通过微信模版进来的 1是,其它否"
  36. // @Param InviteShareCode query string false "销售账号邀请码"
  37. // @Success 200 {object} models.ArticleDetailResp
  38. // @router /detail [get]
  39. func (this *ArticleController) Detail() {
  40. br := new(models.BaseResponse).Init()
  41. defer func() {
  42. this.Data["json"] = br
  43. this.ServeJSON()
  44. }()
  45. user := this.User
  46. if user == nil {
  47. br.Msg = "请登录"
  48. br.ErrMsg = "请登录,用户信息为空"
  49. br.Ret = 408
  50. return
  51. }
  52. uid := user.UserId
  53. articleId, err := this.GetInt("ArticleId")
  54. isSendWx, _ := this.GetInt("IsSendWx")
  55. if articleId <= 0 {
  56. br.Msg = "文章不存在"
  57. br.ErrMsg = "文章不存在,文章ID错误"
  58. return
  59. }
  60. inviteShareCode := this.GetString("InviteShareCode")
  61. detail := new(models.ArticleDetail)
  62. //detailInit := new(models.ArticleDetail) // 初始化的文章信息,用来处理body 内容回显
  63. hasPermission := 0
  64. var haveResearch bool
  65. //判断是否已经申请过
  66. applyCount, err := models.GetApplyRecordCount(uid)
  67. if err != nil && err.Error() != utils.ErrNoRow() {
  68. br.Msg = "获取信息失败"
  69. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  70. return
  71. }
  72. resp := new(models.ArticleDetailResp)
  73. detail, err = models.GetArticleDetailById(articleId)
  74. if err != nil {
  75. br.Msg = "获取信息失败"
  76. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  77. return
  78. }
  79. //记录分享来源
  80. if inviteShareCode != "" {
  81. go services.AddCygxUserAdminShareHistory(user, utils.CYGX_OBJ_ARTICLE, detail.Title, inviteShareCode, articleId)
  82. }
  83. detail.PublishDate = utils.TimeRemoveHms2(detail.PublishDate)
  84. detail.Body = html.UnescapeString(detail.Body)
  85. detail.Body = strings.Replace(detail.Body, "<p data-f-id=\"pbf\" style=\"text-align: center; font-size: 14px; margin-top: 30px; opacity: 0.65; font-family: sans-serif;\">Powered by <a href=\"https://www.froala.com/wysiwyg-editor?pb=1\" title=\"Froala Editor\">Froala Editor</a></p>", "", -1)
  86. detail.Body = strings.Replace(detail.Body, "pre", "div", -1)
  87. detail.Abstract = html.UnescapeString(detail.Abstract)
  88. //detail.Abstract, _ = services.GetReportContentTextSubNew(detail.Abstract)
  89. //作者头像
  90. if detail.DepartmentId > 0 {
  91. departmentDetail, err := models.GetArticleDepartmentDateilById(detail.DepartmentId)
  92. if err == nil {
  93. detail.DepartmentImgUrl = departmentDetail.ImgUrl
  94. }
  95. }
  96. lyjhTypeMap, _ := services.GetLyjhTypeMap()
  97. if _, ok := lyjhTypeMap[detail.CategoryId]; ok {
  98. detail.IsRoadShow = true
  99. }
  100. // 判断是否属于研选类型的报告
  101. if strings.Contains(detail.CategoryName, utils.CHART_PERMISSION_NAME_YANXUAN) {
  102. detail.IsResearch = true
  103. }
  104. // 高毅资产的联系人,有权限的行业也不能查看报告详情页。提示无权限页面
  105. if detail.ArticleTypeId == 0 && user.CompanyId == utils.GAO_YI_ZI_CHAN_COMPANY_ID {
  106. _, sellerName, sellerMobile, popupMsg, err := services.GetUserHasPermissionArticle(user)
  107. if err != nil {
  108. br.Msg = "获取信息失败"
  109. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  110. return
  111. }
  112. resp.PopupMsg = popupMsg
  113. resp.HasPermission = 3
  114. resp.SellerName = sellerName
  115. resp.SellerMobile = sellerMobile
  116. detail.Body = ""
  117. detail.Abstract = ""
  118. detail.BodyText = ""
  119. detail.SellerName = sellerName
  120. detail.SellerMobile = sellerMobile
  121. resp.Detail = detail
  122. br.Ret = 200
  123. br.Success = true
  124. br.Msg = "获取成功"
  125. br.Data = resp
  126. return
  127. }
  128. articleCollectMap, _ := services.GetCygxArticleCollectMap(user.UserId)
  129. detail.IsCollect = articleCollectMap[detail.ArticleId]
  130. //detailInit = detail
  131. if isSendWx == 1 {
  132. var condition string
  133. var pars []interface{}
  134. pars = make([]interface{}, 0)
  135. condition = ` AND article_id = ? `
  136. reportMappingMap, _ := services.GetReportMappingMap()
  137. if reportMappingMap[detail.CategoryId] {
  138. chooseCategoryMap, _ := services.GetChooseCategoryMap(user)
  139. detail.IsShowFollowButton = true
  140. detail.IsFollowButton = chooseCategoryMap[detail.CategoryId]
  141. } else {
  142. pars = append(pars, articleId)
  143. industrialList, err := models.GetIndustrialArticleGroupManagementList(condition, pars)
  144. if err != nil && err.Error() != utils.ErrNoRow() {
  145. br.Msg = "获取信息失败"
  146. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  147. return
  148. }
  149. if len(industrialList) > 0 {
  150. industryUserFollowMap, err := services.GetIndustryUserFollowMap(user)
  151. if err != nil {
  152. br.Msg = "获取信息失败"
  153. br.ErrMsg = "GetActivitySignupResp,Err:" + err.Error()
  154. return
  155. }
  156. for _, v := range industrialList {
  157. if industryUserFollowMap[v.IndustrialManagementId] {
  158. detail.IsFollowButton = true
  159. }
  160. }
  161. detail.IsShowFollowButton = true
  162. }
  163. }
  164. }
  165. //是否属于专项调研报告
  166. if detail.SubCategoryName == "专项调研" {
  167. detail.IsSpecialArticle = true
  168. havePower, err := services.GetSpecialArticleDetailUserPower(user, detail)
  169. if err != nil {
  170. br.Msg = "获取信息失败"
  171. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  172. return
  173. }
  174. resp.IsSpecialArticle = true
  175. if !havePower {
  176. hasPermission, sellerName, sellerMobile, popupMsg, err := services.GetUserHasPermissionArticle(user)
  177. if err != nil {
  178. br.Msg = "获取信息失败"
  179. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  180. return
  181. }
  182. resp.PopupMsg = popupMsg
  183. resp.HasPermission = hasPermission
  184. resp.SellerName = sellerName
  185. resp.SellerMobile = sellerMobile
  186. detail.Body = ""
  187. detail.Abstract = ""
  188. detail.BodyText = ""
  189. detail.SellerName = sellerName
  190. detail.SellerMobile = sellerMobile
  191. resp.Detail = detail
  192. br.Ret = 200
  193. br.Success = true
  194. br.Msg = "获取成功"
  195. br.Data = resp
  196. return
  197. }
  198. }
  199. //`description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,4:潜在客户,未提交过申请,5:潜在客户,已提交过申请"`
  200. if user.CompanyId > 1 {
  201. companyPermission, err := models.GetCompanyPermission(user.CompanyId)
  202. if err != nil {
  203. br.Msg = "获取信息失败"
  204. br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  205. return
  206. }
  207. //判断用户是否开通了个人研选权限,如果有权限后缀拼接权限名称
  208. mfyxUserPermissionTotal := services.GetMfyxUserPermissionTotal(uid)
  209. if mfyxUserPermissionTotal == 1 {
  210. companyPermission += "," + utils.CHART_PERMISSION_NAME_MF_YANXUAN
  211. companyPermission += "," + utils.MAI_FANG_YAN_XUAN_NAME
  212. }
  213. //如果有研选订阅的权限,那么就拼接一个 买方研选的权限做校验
  214. if strings.Contains(companyPermission, utils.CHART_PERMISSION_NAME_MF_YANXUAN) {
  215. companyPermission += "," + utils.MAI_FANG_YAN_XUAN_NAME
  216. }
  217. if companyPermission == "" {
  218. if applyCount > 0 {
  219. hasPermission = 5
  220. } else {
  221. hasPermission = 2
  222. }
  223. goto Loop
  224. } else {
  225. var articlePermissionName string
  226. if detail.CategoryId > 0 {
  227. articlePermission, err := models.GetArticlePermission(detail.CategoryId)
  228. if err != nil {
  229. br.Msg = "获取信息失败"
  230. br.ErrMsg = "获取报告权限失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  231. return
  232. }
  233. if articlePermission == nil {
  234. br.Msg = "获取信息失败"
  235. br.ErrMsg = "报告权限不存在,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  236. return
  237. }
  238. articlePermissionName = articlePermission.PermissionName
  239. } else {
  240. articlePermissionName = detail.CategoryName
  241. }
  242. var hasPersion bool
  243. slice := strings.Split(articlePermissionName, ",")
  244. for _, v := range slice {
  245. if strings.Contains(companyPermission, v) {
  246. hasPersion = true
  247. }
  248. }
  249. if strings.Contains(detail.CategoryName, "研选") {
  250. detail.IsResearch = true
  251. }
  252. userType, _, err := services.GetUserType(user.CompanyId)
  253. if err != nil {
  254. br.Msg = "获取信息失败"
  255. br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
  256. return
  257. }
  258. //永续客户,无法查看研选权限,但是下面的联系人,单独开通研选后,也可以查看研选内容
  259. if userType == 1 && strings.Contains(detail.CategoryName, "研选") && mfyxUserPermissionTotal == 0 {
  260. hasPersion = false
  261. }
  262. //if detail.IsReport == 1 {
  263. //detailCategory, err := models.GetdetailByCategoryIdSando(detail.CategoryId)
  264. //if err != nil && err.Error() != utils.ErrNoRow() {
  265. // br.Msg = "获取信息失败"
  266. // br.ErrMsg = "获取信息失败,Err:" + err.Error() + "categoryID 不存在:" + strconv.Itoa(detail.CategoryId)
  267. // return
  268. //}
  269. //permissionStr, err := models.GetCompanyPermissionByUser(user.CompanyId)
  270. //if err != nil {
  271. // br.Msg = "获取信息失败"
  272. // br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  273. // return
  274. //}
  275. //if detailCategory != nil {
  276. // if detailCategory.PermissionType == 1 {
  277. // if !strings.Contains(permissionStr, detailCategory.ChartPermissionName+"(主观)") {
  278. // hasPersion = false
  279. // }
  280. // } else if detailCategory.PermissionType == 2 {
  281. // if !strings.Contains(permissionStr, detailCategory.ChartPermissionName+"(客观)") {
  282. // hasPersion = false
  283. // }
  284. // }
  285. //}
  286. //}
  287. //大行业通过权限校验,再校验主客观权限。只有医药、消费、科技、智造,才会校验主客观权限
  288. if hasPersion && utils.InArrayByStr([]string{utils.YI_YAO_NAME, utils.XIAO_FEI_NAME, utils.KE_JI_NAME, utils.ZHI_ZAO_NAME}, articlePermissionName) {
  289. hasPersion = services.CheckArticlePermissionType(articleId, user)
  290. }
  291. if hasPersion {
  292. hasPermission = 1
  293. go services.ArticleHistory(articleId, user)
  294. //30分钟之内阅读同一篇文章不错二次推送
  295. key := "CYGX_ARTICLE_READ" + strconv.Itoa(articleId) + "_" + strconv.Itoa(uid)
  296. if !utils.Rc.IsExist(key) {
  297. go services.ArticleUserRemind(user, detail, 1)
  298. utils.Rc.Put(key, 1, 30*time.Second)
  299. }
  300. } else { //无该行业权限
  301. companyDetail, err := models.GetCompanyDetailById(user.CompanyId)
  302. if err == nil && companyDetail.ProductId == 1 {
  303. hasPermission = 2
  304. } else {
  305. hasPermission = 3
  306. }
  307. }
  308. }
  309. interviewApplyItem, err := models.GetArticleInterviewApply(uid, articleId)
  310. if err != nil && err.Error() != utils.ErrNoRow() {
  311. br.Msg = "获取信息失败"
  312. br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  313. return
  314. }
  315. if interviewApplyItem != nil && interviewApplyItem.InterviewApplyId > 0 {
  316. detail.IsInterviewApply = true
  317. detail.InterviewApplyStatus = interviewApplyItem.Status
  318. }
  319. //获取销售手机号
  320. sellerItem, err := models.GetSellerByCompanyId(user.CompanyId)
  321. if err != nil && err.Error() != utils.ErrNoRow() {
  322. br.Msg = "获取信息失败"
  323. br.ErrMsg = "获取销售数据失败2,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  324. return
  325. }
  326. if sellerItem != nil {
  327. detail.SellerMobile = sellerItem.Mobile
  328. detail.SellerName = sellerItem.RealName
  329. }
  330. sellerList, err := models.GetSellerList(articleId)
  331. if err != nil {
  332. br.Msg = "获取信息失败"
  333. br.ErrMsg = "获取销售数据失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  334. return
  335. }
  336. if detail.ArticleId >= utils.SummaryArticleId && strings.Contains(detail.SellerAndMobile, "-") {
  337. strnum := strings.Index(detail.SellerAndMobile, "-")
  338. detail.SellerAndMobile = detail.SellerAndMobile[0:strnum]
  339. if strnum > 0 {
  340. nickName := detail.SellerAndMobile[0:strnum]
  341. sellerAndMobile := &models.SellerRep{
  342. SellerMobile: "",
  343. SellerName: nickName,
  344. }
  345. sellerList = append(sellerList, sellerAndMobile)
  346. }
  347. }
  348. detail.SellerList = sellerList
  349. } else { //潜在客户
  350. if applyCount > 0 {
  351. hasPermission = 5
  352. } else {
  353. hasPermission = 4
  354. }
  355. }
  356. Loop:
  357. if hasPermission != 1 && user.UserId > 0 {
  358. detail.Body = ""
  359. detail.BodyText = ""
  360. } else {
  361. articleFollowdetail, err := models.GetArticleFollowDetail(articleId, uid)
  362. if err != nil {
  363. br.Msg = "获取信息失败"
  364. br.ErrMsg = "获取关注信息失败,Err:" + err.Error()
  365. return
  366. }
  367. detail.FollowNum = articleFollowdetail.DNum
  368. detail.CollectionNum = articleFollowdetail.AcNum
  369. if articleFollowdetail.MdNum > 0 {
  370. detail.IsFollow = true
  371. }
  372. if detail.IsSummary == 1 {
  373. detail.IsBelongSummary = true
  374. }
  375. if detail.IsReport == 1 {
  376. detail.IsBelongReport = true
  377. }
  378. haveResearch = true
  379. }
  380. if hasPermission == 5 {
  381. companyPermissionNoStatus, err := models.GetCompanyPermissionByUserNoStatus(user.CompanyId)
  382. if err != nil {
  383. br.Msg = "获取信息失败"
  384. br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  385. return
  386. }
  387. if companyPermissionNoStatus != "" {
  388. sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  389. if err != nil && err.Error() != utils.ErrNoRow() {
  390. br.Msg = "获取信息失败"
  391. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  392. return
  393. }
  394. if sellerItemQy != nil {
  395. hasPermission = 3
  396. detail.SellerMobile = sellerItemQy.Mobile
  397. detail.SellerName = sellerItemQy.RealName
  398. }
  399. }
  400. }
  401. if hasPermission == 2 || hasPermission == 4 {
  402. //获取销售手机号
  403. sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  404. if err != nil && err.Error() != utils.ErrNoRow() {
  405. br.Msg = "获取信息失败"
  406. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  407. return
  408. }
  409. if sellerItemQy != nil {
  410. hasPermission = 3
  411. detail.SellerMobile = sellerItemQy.Mobile
  412. detail.SellerName = sellerItemQy.RealName
  413. }
  414. }
  415. if detail.ArticleId < utils.SummaryArticleId {
  416. if user.Mobile != "" {
  417. detail.HttpUrl = utils.StrategyPlatform + strconv.Itoa(articleId) + "?token="
  418. } else {
  419. detail.HttpUrl = utils.StrategyPlatform + strconv.Itoa(articleId)
  420. }
  421. detail.IsNeedJump = true
  422. }
  423. // 处理研选下面的路演精华 的报告链接是否跳转
  424. if hasPermission == 1 && detail.ArticleId > utils.SummaryArticleId && detail.ArticleTypeId > 0 {
  425. //detail.PublishDate = utils.TimeRemoveHms2(detail.PublishDate)
  426. if detail.ReportLink != "" {
  427. detail.ReportLink += "?token="
  428. }
  429. }
  430. if articleId < utils.SummaryArticleId {
  431. detail.Abstract, _ = services.GetReportContentTextSubNew(detail.Abstract)
  432. }
  433. if detail.ArticleTypeId == 14 {
  434. detail.IsApplyAppointmentExpert = true //判断文章类型是否属于专家访谈 查研观向11.0
  435. }
  436. resp.HasPermission = hasPermission
  437. resp.HaveResearch = haveResearch
  438. if user.UserId == 0 {
  439. resp.HasPermission = 1
  440. if detail.UpdateFrequency == "daily" {
  441. detail.Frequency = "日度"
  442. } else if detail.UpdateFrequency == "weekly" {
  443. detail.Frequency = "周度"
  444. } else if detail.UpdateFrequency == "monthly" {
  445. detail.Frequency = "月度"
  446. } else if detail.UpdateFrequency == "quarterly" {
  447. detail.Frequency = "季度"
  448. } else if detail.UpdateFrequency == "yearly" {
  449. detail.Frequency = "年度"
  450. }
  451. }
  452. resp.Detail = detail
  453. if user.Mobile != "" {
  454. resp.Mobile = user.Mobile
  455. } else {
  456. resp.Mobile = user.Email
  457. }
  458. br.Ret = 200
  459. br.Success = true
  460. br.Msg = "获取成功"
  461. br.Data = resp
  462. }
  463. // @Title 收藏
  464. // @Description 收藏
  465. // @Param request body models.ArticleCollectReq true "type json string"
  466. // @Success 200 {object} models.FontsCollectResp
  467. // @router /collect [post]
  468. func (this *ArticleController) ArticleCollect() {
  469. br := new(models.BaseResponse).Init()
  470. defer func() {
  471. this.Data["json"] = br
  472. this.ServeJSON()
  473. }()
  474. user := this.User
  475. if user == nil {
  476. br.Msg = "请重新登录"
  477. br.Ret = 408
  478. return
  479. }
  480. uid := user.UserId
  481. var req models.ArticleCollectReq
  482. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  483. if err != nil {
  484. br.Msg = "参数解析异常!"
  485. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  486. return
  487. }
  488. articleId := req.ArticleId
  489. detail, err := models.GetArticleDetailById(articleId)
  490. if err != nil {
  491. br.Msg = "获取信息失败"
  492. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  493. return
  494. }
  495. count, err := models.GetArticleCollectCount(uid, articleId)
  496. if err != nil {
  497. br.Msg = "获取数据失败!"
  498. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  499. return
  500. }
  501. resp := new(models.ArticleCollectResp)
  502. if count <= 0 {
  503. item := new(models.CygxArticleCollect)
  504. item.ArticleId = req.ArticleId
  505. item.UserId = uid
  506. item.CreateTime = time.Now()
  507. item.Mobile = user.Mobile
  508. item.Email = user.Email
  509. item.CompanyId = user.CompanyId
  510. item.CompanyName = user.CompanyName
  511. item.RealName = user.RealName
  512. _, err = models.AddCygxArticleCollect(item)
  513. if err != nil {
  514. br.Msg = "收藏失败"
  515. br.ErrMsg = "收藏失败,Err:" + err.Error()
  516. return
  517. }
  518. br.Msg = "收藏成功"
  519. resp.Status = 1
  520. // 文章收藏消息发送
  521. go services.ArticleUserRemind(user, detail, 2)
  522. go services.ArticleHistoryUserLabelLogAdd(articleId, user.UserId)
  523. } else {
  524. err = models.RemoveArticleCollect(uid, articleId)
  525. if err != nil {
  526. br.Msg = "取消收藏失败"
  527. br.ErrMsg = "取消收藏失败,Err:" + err.Error()
  528. return
  529. }
  530. br.Msg = "已取消收藏"
  531. resp.Status = 2
  532. }
  533. collectTotal, err := models.GetArticleCollectUsersCount(articleId)
  534. if err != nil {
  535. br.Msg = "获取数据失败"
  536. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  537. return
  538. }
  539. resp.CollectCount = collectTotal
  540. br.Ret = 200
  541. br.Success = true
  542. br.Data = resp
  543. }
  544. // @Title 访谈申请
  545. // @Description 访谈申请
  546. // @Param request body models.ArticleInterviewApplyReq true "type json string"
  547. // @Success 200 {object} models.FontsCollectResp
  548. // @router /interview/apply [post]
  549. func (this *ArticleController) InterviewApply() {
  550. br := new(models.BaseResponse).Init()
  551. defer func() {
  552. this.Data["json"] = br
  553. this.ServeJSON()
  554. }()
  555. user := this.User
  556. if user == nil {
  557. br.Msg = "请重新登录"
  558. br.Ret = 408
  559. return
  560. }
  561. uid := user.UserId
  562. var req models.ArticleInterviewApplyReq
  563. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  564. if err != nil {
  565. br.Msg = "参数解析异常!"
  566. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  567. return
  568. }
  569. article, err := models.GetArticleDetailById(req.ArticleId)
  570. if err != nil {
  571. br.Msg = "获取纪要失败!"
  572. br.ErrMsg = "获取纪要失败,Err:" + err.Error()
  573. return
  574. }
  575. count, err := models.GetArticleInterviewApplyCount(uid, req.ArticleId)
  576. if err != nil {
  577. br.Msg = "获取数据失败!"
  578. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  579. return
  580. }
  581. resp := new(models.ArticleInterviewApplyResp)
  582. if count <= 0 {
  583. item := new(models.CygxInterviewApply)
  584. item.ArticleId = req.ArticleId
  585. item.UserId = uid
  586. item.CompanyId = user.CompanyId
  587. item.Status = "待邀请"
  588. item.Sort = 1
  589. item.ArticleTitle = article.Title
  590. item.CreateTime = time.Now()
  591. item.ModifyTime = time.Now()
  592. item.ArticleIdMd5 = article.ArticleIdMd5
  593. _, err = models.AddCygxInterviewApply(item)
  594. if err != nil {
  595. br.Msg = "申请失败"
  596. br.ErrMsg = "申请失败,Err:" + err.Error()
  597. return
  598. }
  599. br.Msg = "申请成功"
  600. resp.Status = 1
  601. //发送模板消息
  602. if user.CompanyId > 1 {
  603. mobile := user.Mobile
  604. if mobile == "" {
  605. mobile = user.Email
  606. }
  607. sellerItem, _ := models.GetSellerByCompanyId(user.CompanyId)
  608. if sellerItem != nil && sellerItem.AdminId > 0 && user.Mobile != "" {
  609. openIpItem, _ := models.GetUserRecordByMobile(4, sellerItem.Mobile)
  610. if openIpItem != nil && openIpItem.OpenId != "" {
  611. go services.SendInterviewApplyTemplateMsg(user.RealName, sellerItem.CompanyName, mobile, article.Title, openIpItem)
  612. }
  613. }
  614. }
  615. } else {
  616. err = models.RemoveArticleInterviewApply(uid, req.ArticleId)
  617. if err != nil {
  618. br.Msg = "取消申请失败"
  619. br.ErrMsg = "取消申请失败,Err:" + err.Error()
  620. return
  621. }
  622. br.Msg = "已取消申请"
  623. resp.Status = 2
  624. if user.CompanyId > 1 {
  625. mobile := user.Mobile
  626. if mobile == "" {
  627. mobile = user.Email
  628. }
  629. sellerItem, _ := models.GetSellerByCompanyId(user.CompanyId)
  630. if sellerItem != nil && sellerItem.AdminId > 0 && user.Mobile != "" {
  631. openIpItem, _ := models.GetUserRecordByMobile(4, sellerItem.Mobile)
  632. if openIpItem != nil && openIpItem.OpenId != "" {
  633. go services.SendInterviewApplyCancelTemplateMsg(user.RealName, sellerItem.CompanyName, mobile, article.Title, openIpItem)
  634. }
  635. }
  636. }
  637. }
  638. br.Ret = 200
  639. br.Success = true
  640. br.Data = resp
  641. }
  642. // @Title 上传文章阅读时间
  643. // @Description 上传文章阅读时间接口
  644. // @Param request body models.AddStopTimeRep true "type json string"
  645. // @Success 200 {object} models.ArticleDetailResp
  646. // @router /addStopTime [post]
  647. func (this *ArticleController) AddStopTime() {
  648. br := new(models.BaseResponse).Init()
  649. defer func() {
  650. this.Data["json"] = br
  651. this.ServeJSON()
  652. }()
  653. user := this.User
  654. if user == nil {
  655. br.Msg = "请登录"
  656. br.ErrMsg = "请登录,用户信息为空"
  657. br.Ret = 408
  658. return
  659. }
  660. var req models.AddStopTimeRep
  661. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  662. if err != nil {
  663. br.Msg = "参数解析异常!"
  664. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  665. return
  666. }
  667. uid := user.UserId
  668. articleId := req.ArticleId
  669. stopTime := req.StopTime
  670. outType := req.OutType
  671. source := req.Source
  672. if articleId <= 0 {
  673. br.Msg = "参数错误"
  674. br.ErrMsg = "参数错误"
  675. return
  676. }
  677. if stopTime == 0 {
  678. stopTime = 1
  679. }
  680. if outType != 2 {
  681. outType = 1
  682. }
  683. if source != "PC" {
  684. source = "MOBILE"
  685. }
  686. detail := new(models.ArticleDetail)
  687. hasPermission := 0
  688. hasFree := 0
  689. //判断是否已经申请过
  690. applyCount, err := models.GetApplyRecordCount(uid)
  691. if err != nil && err.Error() != utils.ErrNoRow() {
  692. br.Msg = "获取信息失败"
  693. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  694. return
  695. }
  696. //`description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,4:潜在客户,未提交过申请,5:潜在客户,已提交过申请"`
  697. if user.CompanyId > 1 {
  698. companyPermission, err := models.GetCompanyPermission(user.CompanyId)
  699. if err != nil {
  700. br.Msg = "获取信息失败"
  701. br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  702. return
  703. }
  704. detail, err = models.GetArticleDetailById(articleId)
  705. if err != nil {
  706. br.Msg = "获取信息失败"
  707. br.ErrMsg = "获取文章信息失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  708. return
  709. }
  710. if companyPermission == "" {
  711. if applyCount > 0 {
  712. hasPermission = 5
  713. } else {
  714. hasPermission = 2
  715. }
  716. hasFree = 2
  717. goto Loop
  718. } else {
  719. hasFree = 1
  720. var articlePermissionPermissionName string
  721. if detail.CategoryId > 0 {
  722. articlePermission, err := models.GetArticlePermission(detail.CategoryId)
  723. if err != nil {
  724. br.Msg = "获取信息失败"
  725. br.ErrMsg = "获取报告权限失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  726. return
  727. }
  728. if articlePermission == nil {
  729. br.Msg = "获取信息失败"
  730. br.ErrMsg = "报告权限不存在,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  731. return
  732. }
  733. articlePermissionPermissionName = articlePermission.PermissionName
  734. } else {
  735. articlePermissionPermissionName = detail.CategoryName
  736. }
  737. var hasPersion bool
  738. slice := strings.Split(articlePermissionPermissionName, ",")
  739. //判断用户是否开通了个人研选权限,如果有权限后缀拼接权限名称
  740. mfyxUserPermissionTotal := services.GetMfyxUserPermissionTotal(uid)
  741. if mfyxUserPermissionTotal == 1 {
  742. companyPermission += "," + utils.CHART_PERMISSION_NAME_MF_YANXUAN
  743. companyPermission += "," + utils.MAI_FANG_YAN_XUAN_NAME
  744. }
  745. //如果有研选订阅的权限,那么就拼接一个 买方研选的权限做校验
  746. if strings.Contains(companyPermission, utils.CHART_PERMISSION_NAME_MF_YANXUAN) {
  747. companyPermission += "," + utils.MAI_FANG_YAN_XUAN_NAME
  748. }
  749. for _, v := range slice {
  750. if strings.Contains(companyPermission, v) {
  751. hasPersion = true
  752. }
  753. }
  754. if hasPersion {
  755. go services.ArticleHistoryStopTime(articleId, stopTime, outType, user)
  756. } else { //无该行业权限
  757. hasPermission = 3
  758. }
  759. }
  760. } else { //潜在客户
  761. if applyCount > 0 {
  762. hasPermission = 5
  763. } else {
  764. hasPermission = 4
  765. }
  766. }
  767. Loop:
  768. resp := new(models.ArticleDetailAddStopTimeRep)
  769. resp.HasPermission = hasPermission
  770. resp.HasFree = hasFree
  771. br.Ret = 200
  772. br.Success = true
  773. br.Msg = "操作成功"
  774. br.Data = resp
  775. }
  776. // @Title 文章带问
  777. // @Description 新增文章带问接口
  778. // @Param request body models.AddArticleAskRep true "type json string"
  779. // @Success Ret=200 新增成功
  780. // @router /askAdd [post]
  781. func (this *ArticleController) AskAdd() {
  782. br := new(models.BaseResponse).Init()
  783. defer func() {
  784. this.Data["json"] = br
  785. this.ServeJSON()
  786. }()
  787. user := this.User
  788. if user == nil {
  789. br.Msg = "请登录"
  790. br.ErrMsg = "请登录,SysUser Is Empty"
  791. br.Ret = 408
  792. return
  793. }
  794. var req models.AddArticleAskRep
  795. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  796. if err != nil {
  797. br.Msg = "参数解析异常!"
  798. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  799. return
  800. }
  801. if req.Content == "" {
  802. br.Msg = "建议内容不可为空"
  803. return
  804. }
  805. content := req.Content
  806. itemToken, err := services.WxGetToken()
  807. if err != nil {
  808. br.Msg = "GetWxAccessToken Err:" + err.Error()
  809. return
  810. }
  811. if itemToken.AccessToken == "" {
  812. br.Msg = "accessToken is empty"
  813. return
  814. }
  815. commerr, err := weapp.MSGSecCheck(itemToken.AccessToken, content)
  816. if err != nil {
  817. br.Msg = "内容校验失败!"
  818. br.ErrMsg = "内容校验失败,Err:" + err.Error()
  819. return
  820. }
  821. if commerr.ErrCode != 0 {
  822. br.Msg = "内容违规,请重新提交!"
  823. br.ErrMsg = "颜文字内容违规,Err:" + commerr.ErrMSG
  824. return
  825. }
  826. articleId := req.ArticleId
  827. count, _ := models.GetArticleCountById(articleId)
  828. if count == 0 {
  829. br.Msg = "操作失败"
  830. br.ErrMsg = "文章ID错误,不存在 articleId:" + strconv.Itoa(articleId)
  831. return
  832. }
  833. companyDetail, err := models.GetCompanyDetailById(user.CompanyId)
  834. if err != nil {
  835. br.Msg = "提交失败!"
  836. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  837. return
  838. }
  839. if companyDetail == nil {
  840. br.Msg = "提交失败!"
  841. br.ErrMsg = "客户不存在,uid:" + strconv.Itoa(user.UserId)
  842. return
  843. }
  844. item := new(models.CygxArticleAsk)
  845. item.UserId = user.UserId
  846. item.ArticleId = req.ArticleId
  847. item.CompanyId = user.CompanyId
  848. item.CompanyName = companyDetail.CompanyName
  849. item.CreateTime = time.Now()
  850. item.Mobile = user.Mobile
  851. item.Email = user.Email
  852. item.Content = content
  853. _, err = models.AddArticleAsk(item)
  854. if err != nil {
  855. br.Msg = "提交失败"
  856. br.ErrMsg = "提交失败,Err:" + err.Error()
  857. return
  858. }
  859. companyItem, err := models.GetSellerDetailAllByCompanyId(user.CompanyId)
  860. if err != nil {
  861. br.Msg = "获取信息失败"
  862. br.ErrMsg = "获取所属销售信息失败,Err:" + err.Error()
  863. return
  864. }
  865. var mobile string
  866. if utils.RunMode == "release" {
  867. //mobile = utils.WxMsgTemplateIdAskMsgMobileAll + "," + companyItem.Mobile
  868. mobile = utils.WxMsgTemplateIdAskMsgMobileAll
  869. } else {
  870. mobile = utils.WxMsgTemplateIdAskMsgMobile
  871. }
  872. openIdList, err := models.GetWxOpenIdByMobileList(mobile)
  873. if err != nil {
  874. br.Msg = "提交失败"
  875. br.ErrMsg = "提交失败,Err:" + err.Error()
  876. return
  877. }
  878. detail, err := models.GetArticleDetailById(articleId)
  879. if err != nil {
  880. br.Msg = "获取信息失败"
  881. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  882. return
  883. }
  884. companyName := user.CompanyName + "-" + user.RealName + "(" + companyItem.SellerName + ")"
  885. go services.SendWxMsgWithAsk(companyName, time.Now().Format(utils.FormatDateTime), content, detail.Title, openIdList, req.ArticleId)
  886. br.Ret = 200
  887. br.Success = true
  888. br.Msg = "提交成功"
  889. }
  890. // @Title 下载PDF打水印
  891. // @Description 下载PDF打水印接口
  892. // @Param ArticleId query int true "报告ID"
  893. // @Success 200 {object} models.ArticleDetailFileLink
  894. // @router /pdfwatermark [get]
  895. func (this *ArticleController) Pdfwatermark() {
  896. br := new(models.BaseResponse).Init()
  897. defer func() {
  898. this.Data["json"] = br
  899. this.ServeJSON()
  900. }()
  901. user := this.User
  902. if user == nil {
  903. br.Msg = "请登录"
  904. br.ErrMsg = "请登录,用户信息为空"
  905. br.Ret = 408
  906. return
  907. }
  908. uid := user.UserId
  909. articleId, err := this.GetInt("ArticleId")
  910. if articleId <= 0 {
  911. br.Msg = "文章不存在"
  912. br.ErrMsg = "文章不存在,文章ID错误"
  913. return
  914. }
  915. //缓存校验
  916. cacheKey := fmt.Sprint("xygx:apply_record:add:", uid, "ArticleId_", articleId)
  917. ttlTime := utils.Rc.GetRedisTTL(cacheKey)
  918. if ttlTime > 0 && user.CompanyId != 16 {
  919. br.Msg = "下载失败,下载过于频繁"
  920. br.ErrMsg = "下载失败,下载过于频繁:mobile" + user.Mobile
  921. return
  922. }
  923. resp := new(models.ArticleDetailFileLink)
  924. detail := new(models.ArticleDetail)
  925. detail, err = models.GetArticleDetailById(articleId)
  926. if err != nil {
  927. br.Msg = "获取信息失败"
  928. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  929. return
  930. }
  931. fileLink := detail.FileLink
  932. if fileLink == "" {
  933. br.Msg = "下载失败"
  934. br.ErrMsg = "下载失败,报告链接不存在"
  935. return
  936. }
  937. mobile := user.Mobile
  938. if mobile == "" {
  939. mobile = user.Email
  940. }
  941. sliceLink := strings.Split(fileLink, "/")
  942. uploadDir := "static/pdf/"
  943. //判断文件夹是否存在,不存在则创建
  944. if !utils.FileIsExist(uploadDir) {
  945. err = os.MkdirAll(uploadDir, 0755)
  946. if err != nil {
  947. br.Msg = "下载失败"
  948. br.ErrMsg = "存储目录创建失败,Err:" + err.Error()
  949. return
  950. }
  951. }
  952. var oldFile string
  953. var newFile string
  954. //获取PDF源文件名称
  955. pdfName := sliceLink[len(sliceLink)-1]
  956. pdfName = utils.MD5(pdfName) + ".pdf"
  957. oldFile = uploadDir + pdfName
  958. //判断PDF本地是否存在,不存在则保存到本地
  959. if !utils.FileIsExist(oldFile) {
  960. res, err := nhttp.Get(fileLink)
  961. if err != nil {
  962. br.Msg = "下载失败"
  963. br.ErrMsg = "获取源文件失败,Err:" + err.Error()
  964. return
  965. }
  966. defer res.Body.Close()
  967. // 获得get请求响应的reader对象
  968. reader := bufio.NewReaderSize(res.Body, 32*1024)
  969. file, err := os.Create(oldFile)
  970. if err != nil {
  971. br.Msg = "下载失败"
  972. br.ErrMsg = "保存源文件到本地失败,Err:" + err.Error()
  973. return
  974. }
  975. defer file.Close()
  976. //获得文件的writer对象
  977. writer := bufio.NewWriter(file)
  978. written, _ := io.Copy(writer, reader)
  979. fmt.Printf("Total length: %d", written)
  980. }
  981. newFile = uploadDir + "new_" + pdfName
  982. onTop := true
  983. wm, err := pdfcpu.ParseTextWatermarkDetails(mobile, " op:.4, pos:c ,points:16 ", onTop, 1)
  984. if err != nil {
  985. br.Msg = "下载失败"
  986. br.ErrMsg = "生成水印文件失败,Err:" + err.Error()
  987. return
  988. }
  989. err = api.AddWatermarksFile(oldFile, newFile, nil, wm, nil)
  990. if err != nil {
  991. //br.Msg = "下载失败"
  992. //br.ErrMsg = "生成水印PDF失败,Err:" + err.Error()
  993. resp.FileLink = fileLink
  994. br.Ret = 200
  995. br.Success = true
  996. br.Msg = "获取成功"
  997. br.Data = resp
  998. return
  999. }
  1000. randStr := utils.GetRandStringNoSpecialChar(28)
  1001. fileName := randStr + ".pdf"
  1002. savePath := uploadDir + time.Now().Format("200601/20060102/")
  1003. savePath += fileName
  1004. //上传到阿里云
  1005. err = services.UploadFileToAliyun(fileName, newFile, savePath)
  1006. if err != nil {
  1007. br.Msg = "下载失败"
  1008. br.ErrMsg = "文件上传失败,Err:" + err.Error()
  1009. return
  1010. }
  1011. fileHost := "https://hzstatic.hzinsights.com/"
  1012. resourceUrl := fileHost + savePath
  1013. defer func() {
  1014. os.Remove(newFile)
  1015. }()
  1016. utils.Rc.SetNX(cacheKey, user.Mobile, time.Minute*5)
  1017. resp.FileLink = resourceUrl
  1018. br.Ret = 200
  1019. br.Success = true
  1020. br.Msg = "获取成功"
  1021. br.Data = resp
  1022. }
  1023. // @Title 约访专家
  1024. // @Description 约访专家接口
  1025. // @Param request body models.CygxArticleIdReq true "type json string"
  1026. // @Success 200 {object}
  1027. // @router /applyAppointmentExpert [post]
  1028. func (this *ArticleController) ApplyAppointmentExpert() {
  1029. br := new(models.BaseResponse).Init()
  1030. defer func() {
  1031. this.Data["json"] = br
  1032. this.ServeJSON()
  1033. }()
  1034. user := this.User
  1035. if user == nil {
  1036. br.Msg = "请登录"
  1037. br.ErrMsg = "请登录,用户信息为空"
  1038. br.Ret = 408
  1039. return
  1040. }
  1041. fmt.Println(user)
  1042. var req models.CygxArticleIdReq
  1043. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1044. if err != nil {
  1045. br.Msg = "参数解析异常!"
  1046. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1047. return
  1048. }
  1049. articleId := req.ArticleId
  1050. var condition string
  1051. var pars []interface{}
  1052. condition += ` AND article_id =? AND user_id = ? `
  1053. pars = append(pars, articleId, user.UserId)
  1054. total, err := models.GetCygxArticleApplyAppointmentExpertCount(condition, pars)
  1055. if err != nil {
  1056. br.Msg = "约访专家失败"
  1057. br.ErrMsg = "约访专家失败,Err:" + err.Error()
  1058. return
  1059. }
  1060. if total > 0 {
  1061. br.Msg = "您已提交申请,请勿重复提交。"
  1062. return
  1063. }
  1064. err = services.AddArticleApplyAppointmentExpert(user, articleId)
  1065. if err != nil {
  1066. br.Msg = "约访专家失败"
  1067. br.ErrMsg = "约访专家失败,Err:" + err.Error()
  1068. return
  1069. }
  1070. services.SendArticleApplyAppointmentExpertTemplateMsg(user, articleId)
  1071. br.Ret = 200
  1072. br.Success = true
  1073. br.Msg = "操作成功"
  1074. }