article.go 54 KB

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