article.go 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642
  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_cygx/models"
  15. "hongze/hongze_cygx/services"
  16. "hongze/hongze_cygx/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. // @Success 200 {object} models.ArticleDetailResp
  37. // @router /detail [get]
  38. func (this *ArticleController) Detail() {
  39. br := new(models.BaseResponse).Init()
  40. defer func() {
  41. this.Data["json"] = br
  42. this.ServeJSON()
  43. }()
  44. user := this.User
  45. if user == nil {
  46. br.Msg = "请登录"
  47. br.ErrMsg = "请登录,用户信息为空"
  48. br.Ret = 408
  49. return
  50. }
  51. uid := user.UserId
  52. articleId, err := this.GetInt("ArticleId")
  53. isSendWx, _ := this.GetInt("IsSendWx")
  54. if articleId <= 0 {
  55. br.Msg = "文章不存在"
  56. br.ErrMsg = "文章不存在,文章ID错误"
  57. return
  58. }
  59. detail := new(models.ArticleDetail)
  60. hasPermission := 0
  61. var haveResearch bool
  62. //判断是否已经申请过
  63. applyCount, err := models.GetApplyRecordCount(uid)
  64. if err != nil && err.Error() != utils.ErrNoRow() {
  65. br.Msg = "获取信息失败"
  66. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  67. return
  68. }
  69. resp := new(models.ArticleDetailResp)
  70. detail, err = models.GetArticleDetailById(articleId)
  71. if err != nil {
  72. br.Msg = "获取信息失败"
  73. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  74. return
  75. }
  76. lyjhTypeMap, _ := services.GetLyjhTypeMap()
  77. if _, ok := lyjhTypeMap[detail.CategoryId]; ok {
  78. detail.IsRoadShow = true
  79. }
  80. // 判断是否属于研选类型的报告
  81. if strings.Contains(detail.CategoryName, utils.CHART_PERMISSION_NAME_YANXUAN) {
  82. detail.IsResearch = true
  83. }
  84. // 高毅资产的联系人,有权限的行业也不能查看报告详情页。提示无权限页面
  85. if detail.ArticleTypeId == 0 && user.CompanyId == utils.GAO_YI_ZI_CHAN_COMPANY_ID {
  86. _, sellerName, sellerMobile, popupMsg, err := services.GetUserHasPermissionArticle(user)
  87. if err != nil {
  88. br.Msg = "获取信息失败"
  89. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  90. return
  91. }
  92. resp.PopupMsg = popupMsg
  93. resp.HasPermission = 3
  94. resp.SellerName = sellerName
  95. resp.SellerMobile = sellerMobile
  96. detail.Body = ""
  97. detail.Abstract = ""
  98. detail.BodyText = ""
  99. detail.SellerName = sellerName
  100. detail.SellerMobile = sellerMobile
  101. resp.Detail = detail
  102. br.Ret = 200
  103. br.Success = true
  104. br.Msg = "获取成功"
  105. br.Data = resp
  106. return
  107. }
  108. articleCollectMap, _ := services.GetCygxArticleCollectMap(user.UserId)
  109. detail.IsCollect = articleCollectMap[detail.ArticleId]
  110. if isSendWx == 1 {
  111. var condition string
  112. var pars []interface{}
  113. pars = make([]interface{}, 0)
  114. condition = ` AND article_id = ? `
  115. reportMappingMap, _ := services.GetReportMappingMap()
  116. if reportMappingMap[detail.CategoryId] {
  117. chooseCategoryMap, _ := services.GetChooseCategoryMap(user)
  118. detail.IsShowFollowButton = true
  119. detail.IsFollowButton = chooseCategoryMap[detail.CategoryId]
  120. } else {
  121. pars = append(pars, articleId)
  122. industrialList, err := models.GetIndustrialArticleGroupManagementList(condition, pars)
  123. if err != nil && err.Error() != utils.ErrNoRow() {
  124. br.Msg = "获取信息失败"
  125. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  126. return
  127. }
  128. if len(industrialList) > 0 {
  129. industryUserFollowMap, err := services.GetIndustryUserFollowMap(user)
  130. if err != nil {
  131. br.Msg = "获取信息失败"
  132. br.ErrMsg = "GetActivitySignupResp,Err:" + err.Error()
  133. return
  134. }
  135. for _, v := range industrialList {
  136. if industryUserFollowMap[v.IndustrialManagementId] {
  137. detail.IsFollowButton = true
  138. }
  139. }
  140. detail.IsShowFollowButton = true
  141. }
  142. }
  143. }
  144. //是否属于专项调研报告
  145. if detail.SubCategoryName == "专项调研" {
  146. detail.IsSpecialArticle = true
  147. havePower, err := services.GetSpecialArticleDetailUserPower(user, detail)
  148. if err != nil {
  149. br.Msg = "获取信息失败"
  150. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  151. return
  152. }
  153. resp.IsSpecialArticle = true
  154. if !havePower {
  155. hasPermission, sellerName, sellerMobile, popupMsg, err := services.GetUserHasPermissionArticle(user)
  156. if err != nil {
  157. br.Msg = "获取信息失败"
  158. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  159. return
  160. }
  161. resp.PopupMsg = popupMsg
  162. resp.HasPermission = hasPermission
  163. resp.SellerName = sellerName
  164. resp.SellerMobile = sellerMobile
  165. detail.Body = ""
  166. detail.Abstract = ""
  167. detail.BodyText = ""
  168. detail.SellerName = sellerName
  169. detail.SellerMobile = sellerMobile
  170. resp.Detail = detail
  171. br.Ret = 200
  172. br.Success = true
  173. br.Msg = "获取成功"
  174. br.Data = resp
  175. return
  176. }
  177. }
  178. //`description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,4:潜在客户,未提交过申请,5:潜在客户,已提交过申请"`
  179. if user.CompanyId > 1 {
  180. companyPermission, err := models.GetCompanyPermission(user.CompanyId)
  181. if err != nil {
  182. br.Msg = "获取信息失败"
  183. br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  184. return
  185. }
  186. detail.PublishDate = utils.TimeRemoveHms2(detail.PublishDate)
  187. detail.Body = html.UnescapeString(detail.Body)
  188. 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)
  189. detail.Body = strings.Replace(detail.Body, "pre", "div", -1)
  190. //detail.Abstract = html.UnescapeString(detail.Abstract)
  191. detail.Abstract, _ = services.GetReportContentTextSubNew(detail.Abstract)
  192. if companyPermission == "" {
  193. if applyCount > 0 {
  194. hasPermission = 5
  195. } else {
  196. hasPermission = 2
  197. }
  198. goto Loop
  199. } else {
  200. var articlePermissionPermissionName string
  201. if detail.CategoryId > 0 {
  202. articlePermission, err := models.GetArticlePermission(detail.CategoryId)
  203. if err != nil {
  204. br.Msg = "获取信息失败"
  205. br.ErrMsg = "获取报告权限失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  206. return
  207. }
  208. if articlePermission == nil {
  209. br.Msg = "获取信息失败"
  210. br.ErrMsg = "报告权限不存在,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  211. return
  212. }
  213. articlePermissionPermissionName = articlePermission.PermissionName
  214. } else {
  215. articlePermissionPermissionName = detail.CategoryName
  216. }
  217. var hasPersion bool
  218. slice := strings.Split(articlePermissionPermissionName, ",")
  219. for _, v := range slice {
  220. if strings.Contains(companyPermission, v) {
  221. hasPersion = true
  222. }
  223. }
  224. if strings.Contains(detail.CategoryName, "研选") {
  225. detail.IsResearch = true
  226. }
  227. userType, _, err := services.GetUserType(user.CompanyId)
  228. if err != nil {
  229. br.Msg = "获取信息失败"
  230. br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
  231. return
  232. }
  233. if userType == 1 && strings.Contains(detail.CategoryName, "研选") {
  234. hasPersion = false
  235. }
  236. if detail.IsReport == 1 {
  237. detailCategory, err := models.GetdetailByCategoryIdSando(detail.CategoryId)
  238. if err != nil && err.Error() != utils.ErrNoRow() {
  239. br.Msg = "获取信息失败"
  240. br.ErrMsg = "获取信息失败,Err:" + err.Error() + "categoryID 不存在:" + strconv.Itoa(detail.CategoryId)
  241. return
  242. }
  243. permissionStr, err := models.GetCompanyPermissionByUser(user.CompanyId)
  244. if err != nil {
  245. br.Msg = "获取信息失败"
  246. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  247. return
  248. }
  249. if detailCategory != nil {
  250. if detailCategory.PermissionType == 1 {
  251. if !strings.Contains(permissionStr, detailCategory.ChartPermissionName+"(主观)") {
  252. hasPersion = false
  253. }
  254. } else if detailCategory.PermissionType == 2 {
  255. if !strings.Contains(permissionStr, detailCategory.ChartPermissionName+"(客观)") {
  256. hasPersion = false
  257. }
  258. }
  259. }
  260. }
  261. if hasPersion {
  262. hasPermission = 1
  263. go services.ArticleHistory(articleId, user)
  264. //30分钟之内阅读同一篇文章不错二次推送
  265. key := "CYGX_ARTICLE_READ" + strconv.Itoa(articleId) + "_" + strconv.Itoa(uid)
  266. if !utils.Rc.IsExist(key) {
  267. go services.ArticleUserRemind(user, detail, 1)
  268. utils.Rc.Put(key, 1, 30*time.Second)
  269. }
  270. } else { //无该行业权限
  271. companyDetail, err := models.GetCompanyDetailById(user.CompanyId)
  272. if err == nil && companyDetail.ProductId == 1 {
  273. hasPermission = 2
  274. } else {
  275. hasPermission = 3
  276. }
  277. }
  278. }
  279. interviewApplyItem, err := models.GetArticleInterviewApply(uid, articleId)
  280. if err != nil && err.Error() != utils.ErrNoRow() {
  281. br.Msg = "获取信息失败"
  282. br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  283. return
  284. }
  285. if interviewApplyItem != nil && interviewApplyItem.InterviewApplyId > 0 {
  286. detail.IsInterviewApply = true
  287. detail.InterviewApplyStatus = interviewApplyItem.Status
  288. }
  289. //获取销售手机号
  290. sellerItem, err := models.GetSellerByCompanyId(user.CompanyId)
  291. if err != nil && err.Error() != utils.ErrNoRow() {
  292. br.Msg = "获取信息失败"
  293. br.ErrMsg = "获取销售数据失败2,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  294. return
  295. }
  296. if sellerItem != nil {
  297. detail.SellerMobile = sellerItem.Mobile
  298. detail.SellerName = sellerItem.RealName
  299. }
  300. sellerList, err := models.GetSellerList(articleId)
  301. if err != nil {
  302. br.Msg = "获取信息失败"
  303. br.ErrMsg = "获取销售数据失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  304. return
  305. }
  306. if detail.ArticleId >= utils.SummaryArticleId && strings.Contains(detail.SellerAndMobile, "-") {
  307. strnum := strings.Index(detail.SellerAndMobile, "-")
  308. detail.SellerAndMobile = detail.SellerAndMobile[0:strnum]
  309. if strnum > 0 {
  310. nickName := detail.SellerAndMobile[0:strnum]
  311. sellerAndMobile := &models.SellerRep{
  312. SellerMobile: "",
  313. SellerName: nickName,
  314. }
  315. sellerList = append(sellerList, sellerAndMobile)
  316. }
  317. }
  318. detail.SellerList = sellerList
  319. //作者头像
  320. if detail.DepartmentId > 0 {
  321. departmentDetail, err := models.GetArticleDepartmentDateilById(detail.DepartmentId)
  322. if err == nil {
  323. detail.DepartmentImgUrl = departmentDetail.ImgUrl
  324. }
  325. }
  326. } else { //潜在客户
  327. if applyCount > 0 {
  328. hasPermission = 5
  329. } else {
  330. hasPermission = 4
  331. }
  332. }
  333. Loop:
  334. if hasPermission != 1 {
  335. detail.Body = ""
  336. detail.BodyText = ""
  337. } else {
  338. articleFollowdetail, err := models.GetArticleFollowDetail(articleId, uid)
  339. if err != nil {
  340. br.Msg = "获取信息失败"
  341. br.ErrMsg = "获取关注信息失败,Err:" + err.Error()
  342. return
  343. }
  344. detail.FollowNum = articleFollowdetail.DNum
  345. detail.CollectionNum = articleFollowdetail.AcNum
  346. if articleFollowdetail.MdNum > 0 {
  347. detail.IsFollow = true
  348. }
  349. if detail.IsSummary == 1 {
  350. detail.IsBelongSummary = true
  351. }
  352. if detail.IsReport == 1 {
  353. detail.IsBelongReport = true
  354. }
  355. haveResearch = true
  356. }
  357. if hasPermission == 5 {
  358. companyPermissionNoStatus, err := models.GetCompanyPermissionByUserNoStatus(user.CompanyId)
  359. if err != nil {
  360. br.Msg = "获取信息失败"
  361. br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  362. return
  363. }
  364. if companyPermissionNoStatus != "" {
  365. sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  366. if err != nil && err.Error() != utils.ErrNoRow() {
  367. br.Msg = "获取信息失败"
  368. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  369. return
  370. }
  371. if sellerItemQy != nil {
  372. hasPermission = 3
  373. detail.SellerMobile = sellerItemQy.Mobile
  374. detail.SellerName = sellerItemQy.RealName
  375. }
  376. }
  377. }
  378. if hasPermission == 2 || hasPermission == 4 {
  379. //获取销售手机号
  380. sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  381. if err != nil && err.Error() != utils.ErrNoRow() {
  382. br.Msg = "获取信息失败"
  383. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  384. return
  385. }
  386. if sellerItemQy != nil {
  387. hasPermission = 3
  388. detail.SellerMobile = sellerItemQy.Mobile
  389. detail.SellerName = sellerItemQy.RealName
  390. }
  391. }
  392. if detail.ArticleId < utils.SummaryArticleId {
  393. if user.Mobile != "" {
  394. chartUserTokenByMobile, _ := services.GetUserTokenByMobile(user.Mobile)
  395. detail.HttpUrl = utils.StrategyPlatform + strconv.Itoa(articleId) + "?token=" + chartUserTokenByMobile
  396. } else {
  397. detail.HttpUrl = utils.StrategyPlatform + strconv.Itoa(articleId)
  398. }
  399. detail.IsNeedJump = true
  400. }
  401. // 处理研选下面的路演精华 的报告链接是否跳转
  402. if hasPermission == 1 && detail.ArticleId > utils.SummaryArticleId && detail.ArticleTypeId > 0 {
  403. //detail.PublishDate = utils.TimeRemoveHms2(detail.PublishDate)
  404. if detail.ReportLink != "" {
  405. chartUserTokenByMobile, _ := services.GetUserTokenByMobile(user.Mobile)
  406. detail.ReportLink += "?token=" + chartUserTokenByMobile
  407. }
  408. }
  409. resp.HasPermission = hasPermission
  410. resp.HaveResearch = haveResearch
  411. resp.Detail = detail
  412. if user.Mobile != "" {
  413. resp.Mobile = user.Mobile
  414. } else {
  415. resp.Mobile = user.Email
  416. }
  417. br.Ret = 200
  418. br.Success = true
  419. br.Msg = "获取成功"
  420. br.Data = resp
  421. }
  422. // @Title 收藏
  423. // @Description 收藏
  424. // @Param request body models.ArticleCollectReq true "type json string"
  425. // @Success 200 {object} models.FontsCollectResp
  426. // @router /collect [post]
  427. func (this *ArticleController) ArticleCollect() {
  428. br := new(models.BaseResponse).Init()
  429. defer func() {
  430. this.Data["json"] = br
  431. this.ServeJSON()
  432. }()
  433. user := this.User
  434. if user == nil {
  435. br.Msg = "请重新登录"
  436. br.Ret = 408
  437. return
  438. }
  439. uid := user.UserId
  440. var req models.ArticleCollectReq
  441. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  442. if err != nil {
  443. br.Msg = "参数解析异常!"
  444. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  445. return
  446. }
  447. articleId := req.ArticleId
  448. detail, err := models.GetArticleDetailById(articleId)
  449. if err != nil {
  450. br.Msg = "获取信息失败"
  451. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  452. return
  453. }
  454. count, err := models.GetArticleCollectCount(uid, articleId)
  455. if err != nil {
  456. br.Msg = "获取数据失败!"
  457. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  458. return
  459. }
  460. resp := new(models.ArticleCollectResp)
  461. if count <= 0 {
  462. item := new(models.CygxArticleCollect)
  463. item.ArticleId = req.ArticleId
  464. item.UserId = uid
  465. item.CreateTime = time.Now()
  466. item.Mobile = user.Mobile
  467. item.Email = user.Email
  468. item.CompanyId = user.CompanyId
  469. item.CompanyName = user.CompanyName
  470. item.RealName = user.RealName
  471. _, err = models.AddCygxArticleCollect(item)
  472. if err != nil {
  473. br.Msg = "收藏失败"
  474. br.ErrMsg = "收藏失败,Err:" + err.Error()
  475. return
  476. }
  477. br.Msg = "收藏成功"
  478. resp.Status = 1
  479. // 文章收藏消息发送
  480. go services.ArticleUserRemind(user, detail, 2)
  481. go services.ArticleHistoryUserLabelLogAdd(articleId, user.UserId)
  482. } else {
  483. err = models.RemoveArticleCollect(uid, articleId)
  484. if err != nil {
  485. br.Msg = "取消收藏失败"
  486. br.ErrMsg = "取消收藏失败,Err:" + err.Error()
  487. return
  488. }
  489. br.Msg = "已取消收藏"
  490. resp.Status = 2
  491. }
  492. collectTotal, err := models.GetArticleCollectUsersCount(articleId)
  493. if err != nil {
  494. br.Msg = "获取数据失败"
  495. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  496. return
  497. }
  498. resp.CollectCount = collectTotal
  499. br.Ret = 200
  500. br.Success = true
  501. br.Data = resp
  502. }
  503. // @Title 访谈申请
  504. // @Description 访谈申请
  505. // @Param request body models.ArticleInterviewApplyReq true "type json string"
  506. // @Success 200 {object} models.FontsCollectResp
  507. // @router /interview/apply [post]
  508. func (this *ArticleController) InterviewApply() {
  509. br := new(models.BaseResponse).Init()
  510. defer func() {
  511. this.Data["json"] = br
  512. this.ServeJSON()
  513. }()
  514. user := this.User
  515. if user == nil {
  516. br.Msg = "请重新登录"
  517. br.Ret = 408
  518. return
  519. }
  520. uid := user.UserId
  521. var req models.ArticleInterviewApplyReq
  522. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  523. if err != nil {
  524. br.Msg = "参数解析异常!"
  525. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  526. return
  527. }
  528. article, err := models.GetArticleDetailById(req.ArticleId)
  529. if err != nil {
  530. br.Msg = "获取纪要失败!"
  531. br.ErrMsg = "获取纪要失败,Err:" + err.Error()
  532. return
  533. }
  534. count, err := models.GetArticleInterviewApplyCount(uid, req.ArticleId)
  535. if err != nil {
  536. br.Msg = "获取数据失败!"
  537. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  538. return
  539. }
  540. resp := new(models.ArticleInterviewApplyResp)
  541. if count <= 0 {
  542. item := new(models.CygxInterviewApply)
  543. item.ArticleId = req.ArticleId
  544. item.UserId = uid
  545. item.CompanyId = user.CompanyId
  546. item.Status = "待邀请"
  547. item.Sort = 1
  548. item.ArticleTitle = article.Title
  549. item.CreateTime = time.Now()
  550. item.ModifyTime = time.Now()
  551. item.ArticleIdMd5 = article.ArticleIdMd5
  552. _, err = models.AddCygxInterviewApply(item)
  553. if err != nil {
  554. br.Msg = "申请失败"
  555. br.ErrMsg = "申请失败,Err:" + err.Error()
  556. return
  557. }
  558. br.Msg = "申请成功"
  559. resp.Status = 1
  560. //发送模板消息
  561. if user.CompanyId > 1 {
  562. mobile := user.Mobile
  563. if mobile == "" {
  564. mobile = user.Email
  565. }
  566. sellerItem, _ := models.GetSellerByCompanyId(user.CompanyId)
  567. if sellerItem != nil && sellerItem.AdminId > 0 && user.Mobile != "" {
  568. openIpItem, _ := models.GetUserRecordByMobile(4, sellerItem.Mobile)
  569. if openIpItem != nil && openIpItem.OpenId != "" {
  570. go services.SendInterviewApplyTemplateMsg(user.RealName, sellerItem.CompanyName, mobile, article.Title, openIpItem)
  571. }
  572. }
  573. }
  574. } else {
  575. err = models.RemoveArticleInterviewApply(uid, req.ArticleId)
  576. if err != nil {
  577. br.Msg = "取消申请失败"
  578. br.ErrMsg = "取消申请失败,Err:" + err.Error()
  579. return
  580. }
  581. br.Msg = "已取消申请"
  582. resp.Status = 2
  583. if user.CompanyId > 1 {
  584. mobile := user.Mobile
  585. if mobile == "" {
  586. mobile = user.Email
  587. }
  588. sellerItem, _ := models.GetSellerByCompanyId(user.CompanyId)
  589. if sellerItem != nil && sellerItem.AdminId > 0 && user.Mobile != "" {
  590. openIpItem, _ := models.GetUserRecordByMobile(4, sellerItem.Mobile)
  591. if openIpItem != nil && openIpItem.OpenId != "" {
  592. go services.SendInterviewApplyCancelTemplateMsg(user.RealName, sellerItem.CompanyName, mobile, article.Title, openIpItem)
  593. }
  594. }
  595. }
  596. }
  597. br.Ret = 200
  598. br.Success = true
  599. br.Data = resp
  600. }
  601. // @Title 获取报告详情
  602. // @Description 获取报告详情接口
  603. // @Param ArticleIdMd5 query int true "报告ID"
  604. // @Success 200 {object} models.ArticleDetailResp
  605. // @router /look/detail [get]
  606. func (this *ArticleControllerMobile) DetailMd5() {
  607. br := new(models.BaseResponse).Init()
  608. defer func() {
  609. this.Data["json"] = br
  610. this.ServeJSON()
  611. }()
  612. user := this.User
  613. if user == nil {
  614. br.Msg = "请登录"
  615. br.ErrMsg = "请登录,用户信息为空"
  616. br.Ret = 408
  617. return
  618. }
  619. uid := user.UserId
  620. articleIdMd5 := this.GetString("ArticleIdMd5")
  621. if articleIdMd5 == "" {
  622. br.Msg = "参数错误"
  623. br.ErrMsg = "参数错误"
  624. return
  625. }
  626. resp := new(models.ArticleDetailResp)
  627. detail, err := models.GetArticleDetailByIdMd5(articleIdMd5)
  628. if err != nil {
  629. br.Msg = "获取信息失败"
  630. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  631. return
  632. }
  633. articleId := detail.ArticleId
  634. detail.Body = html.UnescapeString(detail.Body)
  635. hasPermission := 2
  636. //`description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,4:潜在客户,未提交过申请,5:潜在客户,已提交过申请"`
  637. if user.CompanyId > 1 {
  638. companyPermission, err := models.GetCompanyPermission(user.CompanyId)
  639. if err != nil {
  640. br.Msg = "获取信息失败"
  641. br.ErrMsg = "获取公司权限失败,Err:" + err.Error()
  642. return
  643. }
  644. detail.Body = html.UnescapeString(detail.Body)
  645. 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)
  646. detail.Body = strings.Replace(detail.Body, "pre", "div", -1)
  647. detail.Abstract, _ = services.GetReportContentTextSubNew(detail.Abstract)
  648. if companyPermission == "" {
  649. hasPermission = 2
  650. } else {
  651. var articlePermissionPermissionName string
  652. if detail.CategoryId > 0 {
  653. articlePermission, err := models.GetArticlePermission(detail.CategoryId)
  654. if err != nil {
  655. br.Msg = "获取信息失败"
  656. br.ErrMsg = "获取报告权限失败,Err:" + err.Error() + articleIdMd5
  657. return
  658. }
  659. if articlePermission == nil {
  660. br.Msg = "获取信息失败"
  661. br.ErrMsg = "报告权限不存在,Err:" + articleIdMd5
  662. return
  663. }
  664. articlePermissionPermissionName = articlePermission.PermissionName
  665. } else {
  666. articlePermissionPermissionName = detail.CategoryName
  667. }
  668. var hasPersion bool
  669. slice := strings.Split(articlePermissionPermissionName, ",")
  670. for _, v := range slice {
  671. if strings.Contains(companyPermission, v) {
  672. hasPersion = true
  673. }
  674. }
  675. userType, _, err := services.GetUserType(user.CompanyId)
  676. if err != nil {
  677. br.Msg = "获取信息失败"
  678. br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
  679. return
  680. }
  681. if userType == 1 && strings.Contains(detail.CategoryName, "研选") {
  682. hasPersion = false
  683. }
  684. if detail.IsReport == 1 {
  685. detailCategory, err := models.GetdetailByCategoryIdSando(detail.CategoryId)
  686. if err != nil && err.Error() != utils.ErrNoRow() {
  687. br.Msg = "获取信息失败"
  688. br.ErrMsg = "获取信息失败,Err:" + err.Error() + "categoryID 不存在:" + strconv.Itoa(detail.CategoryId)
  689. return
  690. }
  691. permissionStr, err := models.GetCompanyPermissionByUser(user.CompanyId)
  692. if err != nil {
  693. br.Msg = "获取信息失败"
  694. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  695. return
  696. }
  697. if detailCategory != nil {
  698. if detailCategory.PermissionType == 1 {
  699. if !strings.Contains(permissionStr, detailCategory.ChartPermissionName+"(主观)") {
  700. hasPersion = false
  701. }
  702. } else if detailCategory.PermissionType == 2 {
  703. if !strings.Contains(permissionStr, detailCategory.ChartPermissionName+"(客观)") {
  704. hasPersion = false
  705. }
  706. }
  707. }
  708. }
  709. if hasPersion {
  710. hasPermission = 1
  711. record := new(models.CygxArticleHistoryRecordNewpv)
  712. record.UserId = uid
  713. record.ArticleId = articleId
  714. record.CreateTime = time.Now()
  715. record.ModifyTime = time.Now()
  716. record.Mobile = user.Mobile
  717. record.Email = user.Email
  718. record.CompanyId = user.CompanyId
  719. record.CompanyName = user.CompanyName
  720. //新增浏览记录
  721. go models.AddCygxArticleViewRecordNewpv(record)
  722. //30分钟之内阅读同一篇文章不错二次推送
  723. key := "CYGX_ARTICLE_READ" + strconv.Itoa(articleId) + "_" + strconv.Itoa(uid)
  724. if !utils.Rc.IsExist(key) {
  725. go services.ArticleUserRemind(user, detail, 1)
  726. utils.Rc.Put(key, 1, 30*time.Second)
  727. }
  728. }
  729. if hasPermission == 1 {
  730. key := "CYGX_ARTICLE_" + strconv.Itoa(articleId) + "_" + strconv.Itoa(uid)
  731. if !utils.Rc.IsExist(key) {
  732. //新增浏览记录
  733. record := new(models.CygxArticleViewRecord)
  734. record.UserId = uid
  735. record.ArticleId = articleId
  736. record.CreateTime = time.Now()
  737. record.Mobile = user.Mobile
  738. record.Email = user.Email
  739. record.CompanyId = user.CompanyId
  740. record.CompanyName = user.CompanyName
  741. go models.AddCygxArticleViewRecord(record)
  742. utils.Rc.Put(key, 1, 5*time.Second)
  743. models.ModifyReportLastViewTime(uid)
  744. }
  745. }
  746. }
  747. //作者头像
  748. if detail.DepartmentId > 0 {
  749. departmentDetail, err := models.GetArticleDepartmentDateilById(detail.DepartmentId)
  750. if err == nil {
  751. detail.DepartmentImgUrl = departmentDetail.ImgUrl
  752. detail.NickName = departmentDetail.NickName
  753. }
  754. }
  755. }
  756. detail.SellerAndMobile = "" //业务需要强制处理为空
  757. resp.HasPermission = hasPermission
  758. if hasPermission == 1 {
  759. detail.Abstract, _ = services.GetReportContentTextSub(detail.Abstract)
  760. resp.Detail = detail
  761. } else {
  762. if user.Mobile != "" {
  763. resp.Mobile = user.Mobile
  764. } else {
  765. resp.Mobile = user.Email
  766. }
  767. }
  768. br.Ret = 200
  769. br.Success = true
  770. br.Msg = "获取成功"
  771. br.Data = resp
  772. }
  773. // @Title 上传文章阅读时间
  774. // @Description 上传文章阅读时间接口
  775. // @Param request body models.AddStopTimeRep true "type json string"
  776. // @Success 200 {object} models.ArticleDetailResp
  777. // @router /addStopTime [post]
  778. func (this *ArticleController) AddStopTime() {
  779. br := new(models.BaseResponse).Init()
  780. defer func() {
  781. this.Data["json"] = br
  782. this.ServeJSON()
  783. }()
  784. user := this.User
  785. if user == nil {
  786. br.Msg = "请登录"
  787. br.ErrMsg = "请登录,用户信息为空"
  788. br.Ret = 408
  789. return
  790. }
  791. var req models.AddStopTimeRep
  792. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  793. if err != nil {
  794. br.Msg = "参数解析异常!"
  795. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  796. return
  797. }
  798. uid := user.UserId
  799. articleId := req.ArticleId
  800. stopTime := req.StopTime
  801. outType := req.OutType
  802. source := req.Source
  803. if articleId <= 0 {
  804. br.Msg = "参数错误"
  805. br.ErrMsg = "参数错误"
  806. return
  807. }
  808. if stopTime == 0 {
  809. stopTime = 1
  810. }
  811. if outType != 2 {
  812. outType = 1
  813. }
  814. if source != "PC" {
  815. source = "MOBILE"
  816. }
  817. detail := new(models.ArticleDetail)
  818. hasPermission := 0
  819. hasFree := 0
  820. //判断是否已经申请过
  821. applyCount, err := models.GetApplyRecordCount(uid)
  822. if err != nil && err.Error() != utils.ErrNoRow() {
  823. br.Msg = "获取信息失败"
  824. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  825. return
  826. }
  827. //`description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,4:潜在客户,未提交过申请,5:潜在客户,已提交过申请"`
  828. if user.CompanyId > 1 {
  829. companyPermission, err := models.GetCompanyPermission(user.CompanyId)
  830. if err != nil {
  831. br.Msg = "获取信息失败"
  832. br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  833. return
  834. }
  835. detail, err = models.GetArticleDetailById(articleId)
  836. if err != nil {
  837. br.Msg = "获取信息失败"
  838. br.ErrMsg = "获取文章信息失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  839. return
  840. }
  841. if companyPermission == "" {
  842. if applyCount > 0 {
  843. hasPermission = 5
  844. } else {
  845. hasPermission = 2
  846. }
  847. hasFree = 2
  848. goto Loop
  849. } else {
  850. hasFree = 1
  851. var articlePermissionPermissionName string
  852. if detail.CategoryId > 0 {
  853. articlePermission, err := models.GetArticlePermission(detail.CategoryId)
  854. if err != nil {
  855. br.Msg = "获取信息失败"
  856. br.ErrMsg = "获取报告权限失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  857. return
  858. }
  859. if articlePermission == nil {
  860. br.Msg = "获取信息失败"
  861. br.ErrMsg = "报告权限不存在,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  862. return
  863. }
  864. articlePermissionPermissionName = articlePermission.PermissionName
  865. } else {
  866. articlePermissionPermissionName = detail.CategoryName
  867. }
  868. var hasPersion bool
  869. slice := strings.Split(articlePermissionPermissionName, ",")
  870. for _, v := range slice {
  871. if strings.Contains(companyPermission, v) {
  872. hasPersion = true
  873. }
  874. }
  875. if hasPersion {
  876. go services.ArticleHistoryStopTime(articleId, stopTime, outType, user)
  877. } else { //无该行业权限
  878. hasPermission = 3
  879. }
  880. }
  881. } else { //潜在客户
  882. if applyCount > 0 {
  883. hasPermission = 5
  884. } else {
  885. hasPermission = 4
  886. }
  887. }
  888. Loop:
  889. resp := new(models.ArticleDetailAddStopTimeRep)
  890. resp.HasPermission = hasPermission
  891. resp.HasFree = hasFree
  892. br.Ret = 200
  893. br.Success = true
  894. br.Msg = "操作成功"
  895. br.Data = resp
  896. }
  897. // @Title 文章带问
  898. // @Description 新增文章带问接口
  899. // @Param request body models.AddArticleAskRep true "type json string"
  900. // @Success Ret=200 新增成功
  901. // @router /askAdd [post]
  902. func (this *ArticleController) AskAdd() {
  903. br := new(models.BaseResponse).Init()
  904. defer func() {
  905. this.Data["json"] = br
  906. this.ServeJSON()
  907. }()
  908. user := this.User
  909. if user == nil {
  910. br.Msg = "请登录"
  911. br.ErrMsg = "请登录,SysUser Is Empty"
  912. br.Ret = 408
  913. return
  914. }
  915. var req models.AddArticleAskRep
  916. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  917. if err != nil {
  918. br.Msg = "参数解析异常!"
  919. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  920. return
  921. }
  922. if req.Content == "" {
  923. br.Msg = "建议内容不可为空"
  924. return
  925. }
  926. content := req.Content
  927. itemToken, err := services.WxGetToken()
  928. if err != nil {
  929. br.Msg = "GetWxAccessToken Err:" + err.Error()
  930. return
  931. }
  932. if itemToken.AccessToken == "" {
  933. br.Msg = "accessToken is empty"
  934. return
  935. }
  936. commerr, err := weapp.MSGSecCheck(itemToken.AccessToken, content)
  937. if err != nil {
  938. br.Msg = "内容校验失败!"
  939. br.ErrMsg = "内容校验失败,Err:" + err.Error()
  940. return
  941. }
  942. if commerr.ErrCode != 0 {
  943. br.Msg = "内容违规,请重新提交!"
  944. br.ErrMsg = "颜文字内容违规,Err:" + commerr.ErrMSG
  945. return
  946. }
  947. articleId := req.ArticleId
  948. count, _ := models.GetArticleCountById(articleId)
  949. if count == 0 {
  950. br.Msg = "操作失败"
  951. br.ErrMsg = "文章ID错误,不存在 articleId:" + strconv.Itoa(articleId)
  952. return
  953. }
  954. companyDetail, err := models.GetCompanyDetailById(user.CompanyId)
  955. if err != nil {
  956. br.Msg = "提交失败!"
  957. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  958. return
  959. }
  960. if companyDetail == nil {
  961. br.Msg = "提交失败!"
  962. br.ErrMsg = "客户不存在,uid:" + strconv.Itoa(user.UserId)
  963. return
  964. }
  965. item := new(models.CygxArticleAsk)
  966. item.UserId = user.UserId
  967. item.ArticleId = req.ArticleId
  968. item.CompanyId = user.CompanyId
  969. item.CompanyName = companyDetail.CompanyName
  970. item.CreateTime = time.Now()
  971. item.Mobile = user.Mobile
  972. item.Email = user.Email
  973. item.Content = content
  974. _, err = models.AddArticleAsk(item)
  975. if err != nil {
  976. br.Msg = "提交失败"
  977. br.ErrMsg = "提交失败,Err:" + err.Error()
  978. return
  979. }
  980. companyItem, err := models.GetSellerDetailAllByCompanyId(user.CompanyId)
  981. if err != nil {
  982. br.Msg = "获取信息失败"
  983. br.ErrMsg = "获取所属销售信息失败,Err:" + err.Error()
  984. return
  985. }
  986. var mobile string
  987. if utils.RunMode == "release" {
  988. //mobile = utils.WxMsgTemplateIdAskMsgMobileAll + "," + companyItem.Mobile
  989. mobile = utils.WxMsgTemplateIdAskMsgMobileAll
  990. } else {
  991. mobile = utils.WxMsgTemplateIdAskMsgMobile
  992. }
  993. openIdList, err := models.GetWxOpenIdByMobileList(mobile)
  994. if err != nil {
  995. br.Msg = "提交失败"
  996. br.ErrMsg = "提交失败,Err:" + err.Error()
  997. return
  998. }
  999. detail, err := models.GetArticleDetailById(articleId)
  1000. if err != nil {
  1001. br.Msg = "获取信息失败"
  1002. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  1003. return
  1004. }
  1005. companyName := user.CompanyName + "-" + user.RealName + "(" + companyItem.SellerName + ")"
  1006. go services.SendWxMsgWithAsk(companyName, time.Now().Format(utils.FormatDateTime), content, detail.Title, openIdList, req.ArticleId)
  1007. br.Ret = 200
  1008. br.Success = true
  1009. br.Msg = "提交成功"
  1010. }
  1011. // @Title 下载PDF打水印
  1012. // @Description 下载PDF打水印接口
  1013. // @Param ArticleId query int true "报告ID"
  1014. // @Success 200 {object} models.ArticleDetailFileLink
  1015. // @router /pdfwatermark [get]
  1016. func (this *ArticleController) Pdfwatermark() {
  1017. br := new(models.BaseResponse).Init()
  1018. defer func() {
  1019. this.Data["json"] = br
  1020. this.ServeJSON()
  1021. }()
  1022. user := this.User
  1023. if user == nil {
  1024. br.Msg = "请登录"
  1025. br.ErrMsg = "请登录,用户信息为空"
  1026. br.Ret = 408
  1027. return
  1028. }
  1029. uid := user.UserId
  1030. articleId, err := this.GetInt("ArticleId")
  1031. if articleId <= 0 {
  1032. br.Msg = "文章不存在"
  1033. br.ErrMsg = "文章不存在,文章ID错误"
  1034. return
  1035. }
  1036. //缓存校验
  1037. cacheKey := fmt.Sprint("xygx:apply_record:add:", uid, "ArticleId_", articleId)
  1038. ttlTime := utils.Rc.GetRedisTTL(cacheKey)
  1039. if ttlTime > 0 && user.CompanyId != 16 {
  1040. br.Msg = "下载失败,下载过于频繁"
  1041. br.ErrMsg = "下载失败,下载过于频繁:mobile" + user.Mobile
  1042. return
  1043. }
  1044. resp := new(models.ArticleDetailFileLink)
  1045. detail := new(models.ArticleDetail)
  1046. detail, err = models.GetArticleDetailById(articleId)
  1047. if err != nil {
  1048. br.Msg = "获取信息失败"
  1049. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  1050. return
  1051. }
  1052. fileLink := detail.FileLink
  1053. if fileLink == "" {
  1054. br.Msg = "下载失败"
  1055. br.ErrMsg = "下载失败,报告链接不存在"
  1056. return
  1057. }
  1058. mobile := user.Mobile
  1059. if mobile == "" {
  1060. mobile = user.Email
  1061. }
  1062. sliceLink := strings.Split(fileLink, "/")
  1063. uploadDir := "static/pdf/"
  1064. //判断文件夹是否存在,不存在则创建
  1065. if !utils.FileIsExist(uploadDir) {
  1066. err = os.MkdirAll(uploadDir, 0755)
  1067. if err != nil {
  1068. br.Msg = "下载失败"
  1069. br.ErrMsg = "存储目录创建失败,Err:" + err.Error()
  1070. return
  1071. }
  1072. }
  1073. var oldFile string
  1074. var newFile string
  1075. //获取PDF源文件名称
  1076. pdfName := sliceLink[len(sliceLink)-1]
  1077. pdfName = utils.MD5(pdfName) + ".pdf"
  1078. oldFile = uploadDir + pdfName
  1079. //判断PDF本地是否存在,不存在则保存到本地
  1080. if !utils.FileIsExist(oldFile) {
  1081. res, err := nhttp.Get(fileLink)
  1082. if err != nil {
  1083. br.Msg = "下载失败"
  1084. br.ErrMsg = "获取源文件失败,Err:" + err.Error()
  1085. return
  1086. }
  1087. defer res.Body.Close()
  1088. // 获得get请求响应的reader对象
  1089. reader := bufio.NewReaderSize(res.Body, 32*1024)
  1090. file, err := os.Create(oldFile)
  1091. if err != nil {
  1092. br.Msg = "下载失败"
  1093. br.ErrMsg = "保存源文件到本地失败,Err:" + err.Error()
  1094. return
  1095. }
  1096. defer file.Close()
  1097. //获得文件的writer对象
  1098. writer := bufio.NewWriter(file)
  1099. written, _ := io.Copy(writer, reader)
  1100. fmt.Printf("Total length: %d", written)
  1101. }
  1102. newFile = uploadDir + "new_" + pdfName
  1103. onTop := true
  1104. wm, err := pdfcpu.ParseTextWatermarkDetails(mobile, " op:.4, pos:c ,points:16 ", onTop, 1)
  1105. if err != nil {
  1106. br.Msg = "下载失败"
  1107. br.ErrMsg = "生成水印文件失败,Err:" + err.Error()
  1108. return
  1109. }
  1110. err = api.AddWatermarksFile(oldFile, newFile, nil, wm, nil)
  1111. if err != nil {
  1112. //br.Msg = "下载失败"
  1113. //br.ErrMsg = "生成水印PDF失败,Err:" + err.Error()
  1114. resp.FileLink = fileLink
  1115. br.Ret = 200
  1116. br.Success = true
  1117. br.Msg = "获取成功"
  1118. br.Data = resp
  1119. return
  1120. }
  1121. randStr := utils.GetRandStringNoSpecialChar(28)
  1122. fileName := randStr + ".pdf"
  1123. savePath := uploadDir + time.Now().Format("200601/20060102/")
  1124. savePath += fileName
  1125. //上传到阿里云
  1126. err = services.UploadFileToAliyun(fileName, newFile, savePath)
  1127. if err != nil {
  1128. br.Msg = "下载失败"
  1129. br.ErrMsg = "文件上传失败,Err:" + err.Error()
  1130. return
  1131. }
  1132. fileHost := "https://hzstatic.hzinsights.com/"
  1133. resourceUrl := fileHost + savePath
  1134. defer func() {
  1135. os.Remove(newFile)
  1136. }()
  1137. utils.Rc.SetNX(cacheKey, user.Mobile, time.Minute*5)
  1138. resp.FileLink = resourceUrl
  1139. br.Ret = 200
  1140. br.Success = true
  1141. br.Msg = "获取成功"
  1142. br.Data = resp
  1143. }
  1144. // @Title 获取报告详情(无需token)
  1145. // @Description 获取报告详情接口
  1146. // @Param ArticleId query int true "报告ID"
  1147. // @Param CompanyCode query string false "机构编号"
  1148. // @Param CompanyName query string false "机构名称"
  1149. // @Param Email query string false "邮箱"
  1150. // @Param Sign query string false "加密签名"
  1151. // @Success 200 {object} models.ArticleDetailHtgjResp
  1152. // @router /detailPublic [get]
  1153. func (this *ArticleCommonController) DetailPublic() {
  1154. br := new(models.BaseResponse).Init()
  1155. defer func() {
  1156. this.Data["json"] = br
  1157. this.ServeJSON()
  1158. }()
  1159. articleId, _ := this.GetInt("ArticleId")
  1160. companyCode := this.GetString("CompanyCode")
  1161. companyNameHt := this.GetString("CompanyName")
  1162. email := this.GetString("Email")
  1163. sign := this.GetString("Sign")
  1164. resp := new(models.ArticleDetailHtgjResp)
  1165. if companyCode == "" || email == "" {
  1166. resp.HasPermission = 2
  1167. br.Ret = 200
  1168. br.Success = true
  1169. br.Msg = "获取成功"
  1170. br.Data = resp
  1171. return
  1172. }
  1173. if articleId <= 0 {
  1174. br.Msg = "文章不存在"
  1175. br.ErrMsg = "文章不存在,文章ID错误"
  1176. return
  1177. }
  1178. errMsg, err, wxUser, companyName := services.CheckHtgj(companyCode, companyNameHt, email, sign)
  1179. if errMsg != "" {
  1180. br.Msg = errMsg
  1181. return
  1182. }
  1183. companyPermission, err := models.GetCompanyPermission(wxUser.CompanyId)
  1184. if err != nil {
  1185. br.Msg = "获取信息失败"
  1186. br.ErrMsg = "获取用户权限失败,Err:" + err.Error() + ";articleId" + strconv.Itoa(articleId)
  1187. return
  1188. }
  1189. hasPermission := 0
  1190. uid := wxUser.UserId
  1191. detail, err := models.GetArticleDetailById(articleId)
  1192. if err != nil {
  1193. br.Msg = "获取信息失败"
  1194. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  1195. return
  1196. }
  1197. detail.Body = html.UnescapeString(detail.Body)
  1198. 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)
  1199. detail.Body = strings.Replace(detail.Body, "pre", "div", -1)
  1200. detail.Abstract, _ = services.GetReportContentTextSub(detail.Abstract)
  1201. var articlePermissionPermissionName string
  1202. if detail.CategoryId > 0 {
  1203. articlePermission, err := models.GetArticlePermission(detail.CategoryId)
  1204. if err != nil {
  1205. br.Msg = "获取信息失败"
  1206. br.ErrMsg = "获取报告权限失败,Err:" + err.Error() + strconv.Itoa(wxUser.UserId) + ";articleId" + strconv.Itoa(articleId)
  1207. return
  1208. }
  1209. if articlePermission == nil {
  1210. br.Msg = "获取信息失败"
  1211. br.ErrMsg = "报告权限不存在,Err:" + strconv.Itoa(wxUser.UserId) + ";articleId" + strconv.Itoa(articleId)
  1212. return
  1213. }
  1214. articlePermissionPermissionName = articlePermission.PermissionName
  1215. } else {
  1216. articlePermissionPermissionName = detail.CategoryName
  1217. }
  1218. var hasPersion bool
  1219. slice := strings.Split(articlePermissionPermissionName, ",")
  1220. for _, v := range slice {
  1221. if strings.Contains(companyPermission, v) {
  1222. hasPersion = true
  1223. }
  1224. }
  1225. if hasPersion {
  1226. hasPermission = 1
  1227. }
  1228. if strings.Contains(detail.CategoryName, "研选") {
  1229. detail.IsResearch = true
  1230. }
  1231. resp.HasPermission = hasPermission
  1232. if hasPermission == 1 {
  1233. //获取销售手机号
  1234. sellerItem, err := models.GetSellerByCompanyId(wxUser.CompanyId)
  1235. if err != nil {
  1236. br.Msg = "获取信息失败"
  1237. br.ErrMsg = "获取销售数据失败2,Err:" + strconv.Itoa(wxUser.UserId) + ";articleId" + strconv.Itoa(articleId)
  1238. return
  1239. }
  1240. if sellerItem != nil {
  1241. detail.SellerMobile = sellerItem.Mobile
  1242. detail.SellerName = sellerItem.RealName
  1243. }
  1244. sellerList, err := models.GetSellerList(articleId)
  1245. if err != nil {
  1246. br.Msg = "获取信息失败"
  1247. br.ErrMsg = "获取销售数据失败,Err:" + err.Error() + strconv.Itoa(wxUser.UserId) + ";articleId" + strconv.Itoa(articleId)
  1248. return
  1249. }
  1250. if detail.ArticleId >= utils.SummaryArticleId && strings.Contains(detail.SellerAndMobile, "-") {
  1251. strnum := strings.Index(detail.SellerAndMobile, "-")
  1252. detail.SellerAndMobile = detail.SellerAndMobile[0:strnum]
  1253. if strnum > 0 {
  1254. nickName := detail.SellerAndMobile[0:strnum]
  1255. sellerAndMobile := &models.SellerRep{
  1256. SellerMobile: "",
  1257. SellerName: nickName,
  1258. }
  1259. sellerList = append(sellerList, sellerAndMobile)
  1260. }
  1261. }
  1262. detail.SellerList = sellerList
  1263. resp.Detail = detail
  1264. historyRecord := new(models.CygxArticleHistoryRecord)
  1265. historyRecord.UserId = wxUser.UserId
  1266. historyRecord.ArticleId = articleId
  1267. historyRecord.CreateTime = time.Now()
  1268. historyRecord.Mobile = wxUser.Mobile
  1269. historyRecord.Email = wxUser.Email
  1270. historyRecord.CompanyId = wxUser.CompanyId
  1271. historyRecord.CompanyName = companyName
  1272. recordCount, _ := models.GetNoAddStoptimeArticleCount(wxUser.UserId, articleId)
  1273. if recordCount == 0 {
  1274. go models.AddCygxArticleHistoryRecord(historyRecord)
  1275. } else {
  1276. detailNew, err := models.GetNewArticleHistoryRecord(wxUser.UserId, articleId)
  1277. if err != nil {
  1278. br.Msg = "获取信息失败"
  1279. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  1280. return
  1281. }
  1282. if detailNew.StopTime > 0 {
  1283. go models.AddCygxArticleHistoryRecord(historyRecord)
  1284. }
  1285. }
  1286. key := "CYGX_ARTICLE_" + strconv.Itoa(articleId) + "_" + strconv.Itoa(wxUser.UserId)
  1287. if !utils.Rc.IsExist(key) {
  1288. //新增浏览记录
  1289. record := new(models.CygxArticleViewRecord)
  1290. record.UserId = wxUser.UserId
  1291. record.ArticleId = articleId
  1292. record.CreateTime = time.Now()
  1293. record.Mobile = wxUser.Mobile
  1294. record.Email = wxUser.Email
  1295. record.CompanyId = wxUser.CompanyId
  1296. record.CompanyName = companyName
  1297. go models.AddCygxArticleViewRecord(record)
  1298. utils.Rc.Put(key, 1, 5*time.Second)
  1299. models.ModifyReportLastViewTime(wxUser.UserId)
  1300. }
  1301. if detail.ArticleId < utils.SummaryArticleId {
  1302. chartUserTokenByMobile, _ := services.GetUserTokenByMobile(utils.HtgjPublicMobile)
  1303. detail.HttpUrl = utils.StrategyPlatform + strconv.Itoa(articleId) + "?token=" + chartUserTokenByMobile
  1304. detail.IsNeedJump = true
  1305. }
  1306. if detail.ArticleId < utils.SummaryArticleId {
  1307. chartUserTokenByMobile, _ := services.GetUserTokenByMobile(utils.HtgjPublicMobile)
  1308. detail.HttpUrl = utils.StrategyPlatform + strconv.Itoa(articleId) + "?token=" + chartUserTokenByMobile
  1309. detail.IsNeedJump = true
  1310. }
  1311. collectCount, err := models.GetArticleCollectCount(uid, articleId)
  1312. if err != nil && err.Error() != utils.ErrNoRow() {
  1313. br.Msg = "获取信息失败"
  1314. br.ErrMsg = "判断是否已收藏失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  1315. return
  1316. }
  1317. if collectCount > 0 {
  1318. detail.IsCollect = true
  1319. }
  1320. interviewApplyItem, err := models.GetArticleInterviewApply(uid, articleId)
  1321. if err != nil && err.Error() != utils.ErrNoRow() {
  1322. br.Msg = "获取信息失败"
  1323. br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  1324. return
  1325. }
  1326. if interviewApplyItem != nil && interviewApplyItem.InterviewApplyId > 0 {
  1327. detail.IsInterviewApply = true
  1328. detail.InterviewApplyStatus = interviewApplyItem.Status
  1329. }
  1330. articleFollowdetail, err := models.GetArticleFollowDetail(articleId, uid)
  1331. if err != nil {
  1332. br.Msg = "获取信息失败"
  1333. br.ErrMsg = "获取关注信息失败,Err:" + err.Error()
  1334. return
  1335. }
  1336. detail.FollowNum = articleFollowdetail.DNum
  1337. detail.CollectionNum = articleFollowdetail.AcNum
  1338. resp.Detail = detail
  1339. }
  1340. resp.CompanyName = companyName
  1341. br.Ret = 200
  1342. br.Success = true
  1343. br.Msg = "获取成功"
  1344. br.Data = resp
  1345. }
  1346. // @Title 上传文章阅读时间(无需token)
  1347. // @Description 上传文章阅读时间接口(无需token)
  1348. // @Param request body models.AddStopTimeHtgjRep true "type json string"
  1349. // @Success 200 {object} models.ArticleDetailResp
  1350. // @router /addStopTimePublic [post]
  1351. func (this *ArticleCommonController) AddStopTimePublic() {
  1352. br := new(models.BaseResponse).Init()
  1353. defer func() {
  1354. this.Data["json"] = br
  1355. this.ServeJSON()
  1356. }()
  1357. var req models.AddStopTimeHtgjRep
  1358. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1359. if err != nil {
  1360. br.Msg = "参数解析异常!"
  1361. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1362. return
  1363. }
  1364. articleId := req.ArticleId
  1365. stopTime := req.StopTime
  1366. outType := req.OutType
  1367. source := req.Source
  1368. companyCode := req.CompanyCode
  1369. companyName := req.CompanyName
  1370. wxuUserName := req.Email
  1371. sign := req.Sign
  1372. if companyCode == "" || companyName == "" || wxuUserName == "" || sign == "" {
  1373. br.Msg = "上传失败"
  1374. br.ErrMsg = "必填参数不能为空"
  1375. return
  1376. }
  1377. companyNameHt := companyCode + "_" + companyName
  1378. errMsg := services.CheckSign(companyCode+companyName+wxuUserName, sign)
  1379. if errMsg != "" {
  1380. br.Msg = errMsg
  1381. return
  1382. }
  1383. companyInfo, err := models.GetCompanyByThirdName(companyNameHt)
  1384. if err != nil {
  1385. br.Msg = "获取信息失败"
  1386. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  1387. return
  1388. }
  1389. user, err := models.GetUserByThirdName(companyInfo.CompanyId, wxuUserName)
  1390. if err != nil {
  1391. br.Msg = "获取信息失败"
  1392. br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
  1393. return
  1394. }
  1395. uid := user.UserId
  1396. if articleId <= 0 {
  1397. br.Msg = "文章ID不存在"
  1398. br.ErrMsg = "参数错误"
  1399. return
  1400. }
  1401. if stopTime == 0 {
  1402. stopTime = 1
  1403. }
  1404. if outType != 2 {
  1405. outType = 1
  1406. }
  1407. if source != "PC" {
  1408. source = "MOBILE"
  1409. }
  1410. detail := new(models.ArticleDetail)
  1411. hasPermission := 0
  1412. hasFree := 0
  1413. //判断是否已经申请过
  1414. applyCount, err := models.GetApplyRecordCount(uid)
  1415. if err != nil && err.Error() != utils.ErrNoRow() {
  1416. br.Msg = "获取信息失败"
  1417. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  1418. return
  1419. }
  1420. //`description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,4:潜在客户,未提交过申请,5:潜在客户,已提交过申请"`
  1421. if user.CompanyId > 1 {
  1422. companyPermission, err := models.GetCompanyPermission(user.CompanyId)
  1423. if err != nil {
  1424. br.Msg = "获取信息失败"
  1425. br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  1426. return
  1427. }
  1428. detail, err = models.GetArticleDetailById(articleId)
  1429. if err != nil {
  1430. br.Msg = "获取信息失败"
  1431. br.ErrMsg = "获取文章信息失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  1432. return
  1433. }
  1434. if companyPermission == "" {
  1435. if applyCount > 0 {
  1436. hasPermission = 5
  1437. } else {
  1438. hasPermission = 2
  1439. }
  1440. hasFree = 2
  1441. goto Loop
  1442. } else {
  1443. hasFree = 1
  1444. var articlePermissionPermissionName string
  1445. if detail.CategoryId > 0 {
  1446. articlePermission, err := models.GetArticlePermission(detail.CategoryId)
  1447. if err != nil {
  1448. br.Msg = "获取信息失败"
  1449. br.ErrMsg = "获取报告权限失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  1450. return
  1451. }
  1452. if articlePermission == nil {
  1453. br.Msg = "获取信息失败"
  1454. br.ErrMsg = "报告权限不存在,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  1455. return
  1456. }
  1457. articlePermissionPermissionName = articlePermission.PermissionName
  1458. } else {
  1459. articlePermissionPermissionName = detail.CategoryName
  1460. }
  1461. var hasPersion bool
  1462. slice := strings.Split(articlePermissionPermissionName, ",")
  1463. for _, v := range slice {
  1464. if strings.Contains(companyPermission, v) {
  1465. hasPersion = true
  1466. }
  1467. }
  1468. if hasPersion {
  1469. detailNew, err := models.GetNewArticleHistoryRecord(uid, articleId)
  1470. if err == nil {
  1471. hasPermission = 1
  1472. historyRecord := new(models.AddStopTimeNewRep)
  1473. historyRecord.StopTime = detailNew.StopTime + stopTime
  1474. historyRecord.Id = detailNew.Id
  1475. historyRecord.OutType = outType
  1476. go models.UpdateArticleStopTime(historyRecord)
  1477. }
  1478. //不统计本公司的阅读记录、正常退出的不做时间差统计
  1479. if user.CompanyId != 16 && stopTime > 3 {
  1480. key := "CYGX_ARTICLE_PV" + strconv.Itoa(articleId) + "_" + strconv.Itoa(uid) + "_" + strconv.Itoa(user.CompanyId) + "_" + strconv.Itoa(outType)
  1481. record := new(models.CygxArticleHistoryRecordNewpv)
  1482. record.UserId = uid
  1483. record.ArticleId = articleId
  1484. record.CreateTime = time.Now().Add(-time.Second * time.Duration(stopTime))
  1485. record.ModifyTime = time.Now()
  1486. record.Mobile = user.Mobile
  1487. record.Email = user.Email
  1488. record.CompanyId = user.CompanyId
  1489. record.CompanyName = companyInfo.CompanyName
  1490. record.StopTime = stopTime
  1491. record.OutType = outType
  1492. record.Source = source
  1493. if !utils.Rc.IsExist(key) || outType != 2 {
  1494. //新增浏览记录
  1495. go models.AddCygxArticleViewRecordNewpv(record)
  1496. recordRedis := new(services.ReportViewRecord)
  1497. recordRedis.UserId = user.UserId
  1498. recordRedis.ReportId = articleId
  1499. recordRedis.Mobile = user.Mobile
  1500. recordRedis.Email = user.Email
  1501. recordRedis.RealName = user.RealName
  1502. recordRedis.CompanyName = companyName
  1503. recordRedis.CreateTime = time.Now().Add(-time.Second * time.Duration(stopTime))
  1504. go services.PushViewRecordNewRedisData(recordRedis, user.CompanyId)
  1505. } else {
  1506. go models.UpdateCygxArticleViewRecordNewpv(record, stopTime)
  1507. }
  1508. utils.Rc.Put(key, 1, 10*time.Minute)
  1509. }
  1510. models.ModifyReportLastViewTime(uid)
  1511. } else { //无该行业权限
  1512. hasPermission = 3
  1513. }
  1514. }
  1515. } else { //潜在客户
  1516. if applyCount > 0 {
  1517. hasPermission = 5
  1518. } else {
  1519. hasPermission = 4
  1520. }
  1521. }
  1522. Loop:
  1523. resp := new(models.ArticleDetailAddStopTimeRep)
  1524. resp.HasPermission = hasPermission
  1525. resp.HasFree = hasFree
  1526. br.Ret = 200
  1527. br.Success = true
  1528. br.Msg = "操作成功"
  1529. br.Data = resp
  1530. }
  1531. // @Title 页面访问统计(无需token)
  1532. // @Description 上传页面访问统计(无需token)
  1533. // @Param request body models.CygxPageHistoryRecordHtgjRep true "type json string"
  1534. // @Success Ret=200 新增成功
  1535. // @router /pageHistoryPublic [post]
  1536. func (this *ArticleCommonController) PageHistoryPublic() {
  1537. br := new(models.BaseResponse).Init()
  1538. defer func() {
  1539. this.Data["json"] = br
  1540. this.ServeJSON()
  1541. }()
  1542. var req models.CygxPageHistoryRecordHtgjRep
  1543. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1544. if err != nil {
  1545. br.Msg = "参数解析异常!"
  1546. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1547. return
  1548. }
  1549. companyCode := req.CompanyCode
  1550. companyName := req.CompanyName
  1551. wxuUserName := req.Email
  1552. sign := req.Sign
  1553. if companyCode == "" || companyName == "" || wxuUserName == "" || sign == "" {
  1554. br.Msg = "上传失败"
  1555. br.ErrMsg = "必填参数不能为空"
  1556. return
  1557. }
  1558. companyNameHt := companyCode + "_" + companyName
  1559. errMsg := services.CheckSign(companyCode+companyName+wxuUserName, sign)
  1560. if errMsg != "" {
  1561. br.Msg = errMsg
  1562. return
  1563. }
  1564. companyInfo, err := models.GetCompanyByThirdName(companyNameHt)
  1565. if err != nil {
  1566. br.Msg = "获取信息失败"
  1567. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  1568. return
  1569. }
  1570. user, err := models.GetUserByThirdName(companyInfo.CompanyId, wxuUserName)
  1571. if err != nil {
  1572. br.Msg = "获取信息失败"
  1573. br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
  1574. return
  1575. }
  1576. item := new(models.CygxPageHistoryRecord)
  1577. item.UserId = user.UserId
  1578. item.CreateTime = time.Now()
  1579. item.Mobile = user.Mobile
  1580. item.Email = user.Email
  1581. item.CompanyId = user.CompanyId
  1582. item.CompanyName = companyName
  1583. item.DetailId = req.DetailId
  1584. item.ChartPermissionId = req.ChartPermissionId
  1585. item.IndustrialManagementId = req.IndustrialManagementId
  1586. item.PageType = "ArticleCopy"
  1587. _, err = models.AddCygxPageHistoryRecord(item)
  1588. if err != nil {
  1589. br.Msg = "记录信息失败"
  1590. br.ErrMsg = "新增访问记录失败,Err:" + err.Error()
  1591. return
  1592. }
  1593. br.Ret = 200
  1594. br.Success = true
  1595. br.Msg = "新增成功"
  1596. }