article.go 54 KB

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