article.go 53 KB

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