article.go 49 KB

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