article.go 43 KB

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