article.go 53 KB

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