article.go 52 KB

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