article.go 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423
  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. _, err = models.AddCygxArticleCollect(item)
  372. if err != nil {
  373. br.Msg = "收藏失败"
  374. br.ErrMsg = "收藏失败,Err:" + err.Error()
  375. return
  376. }
  377. br.Msg = "收藏成功"
  378. resp.Status = 1
  379. } else {
  380. err = models.RemoveArticleCollect(uid, req.ArticleId)
  381. if err != nil {
  382. br.Msg = "取消收藏失败"
  383. br.ErrMsg = "取消收藏失败,Err:" + err.Error()
  384. return
  385. }
  386. br.Msg = "已取消收藏"
  387. resp.Status = 2
  388. }
  389. collectTotal, err := models.GetArticleCollectUsersCount(req.ArticleId)
  390. if err != nil {
  391. br.Msg = "获取数据失败"
  392. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  393. return
  394. }
  395. resp.CollectCount = collectTotal
  396. br.Ret = 200
  397. br.Success = true
  398. br.Data = resp
  399. }
  400. // @Title 访谈申请
  401. // @Description 访谈申请
  402. // @Param request body models.ArticleInterviewApplyReq true "type json string"
  403. // @Success 200 {object} models.FontsCollectResp
  404. // @router /interview/apply [post]
  405. func (this *ArticleController) InterviewApply() {
  406. br := new(models.BaseResponse).Init()
  407. defer func() {
  408. this.Data["json"] = br
  409. this.ServeJSON()
  410. }()
  411. user := this.User
  412. if user == nil {
  413. br.Msg = "请重新登录"
  414. br.Ret = 408
  415. return
  416. }
  417. uid := user.UserId
  418. var req models.ArticleInterviewApplyReq
  419. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  420. if err != nil {
  421. br.Msg = "参数解析异常!"
  422. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  423. return
  424. }
  425. article, err := models.GetArticleDetailById(req.ArticleId)
  426. if err != nil {
  427. br.Msg = "获取纪要失败!"
  428. br.ErrMsg = "获取纪要失败,Err:" + err.Error()
  429. return
  430. }
  431. count, err := models.GetArticleInterviewApplyCount(uid, req.ArticleId)
  432. if err != nil {
  433. br.Msg = "获取数据失败!"
  434. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  435. return
  436. }
  437. resp := new(models.ArticleInterviewApplyResp)
  438. if count <= 0 {
  439. item := new(models.CygxInterviewApply)
  440. item.ArticleId = req.ArticleId
  441. item.UserId = uid
  442. item.CompanyId = user.CompanyId
  443. item.Status = "待邀请"
  444. item.Sort = 1
  445. item.ArticleTitle = article.Title
  446. item.CreateTime = time.Now()
  447. item.ModifyTime = time.Now()
  448. item.ArticleIdMd5 = article.ArticleIdMd5
  449. _, err = models.AddCygxInterviewApply(item)
  450. if err != nil {
  451. br.Msg = "申请失败"
  452. br.ErrMsg = "申请失败,Err:" + err.Error()
  453. return
  454. }
  455. br.Msg = "申请成功"
  456. resp.Status = 1
  457. //发送模板消息
  458. if user.CompanyId > 1 {
  459. mobile := user.Mobile
  460. if mobile == "" {
  461. mobile = user.Email
  462. }
  463. sellerItem, _ := models.GetSellerByCompanyId(user.CompanyId)
  464. if sellerItem != nil && sellerItem.AdminId > 0 && user.Mobile != "" {
  465. openIpItem, _ := models.GetUserRecordByUserIdByXzs(sellerItem.Mobile, 4)
  466. fmt.Println(openIpItem)
  467. if openIpItem != nil && openIpItem.OpenId != "" {
  468. go services.SendInterviewApplyTemplateMsg(user.RealName, sellerItem.CompanyName, mobile, article.Title, openIpItem.OpenId)
  469. }
  470. }
  471. }
  472. } else {
  473. err = models.RemoveArticleInterviewApply(uid, req.ArticleId)
  474. if err != nil {
  475. br.Msg = "取消申请失败"
  476. br.ErrMsg = "取消申请失败,Err:" + err.Error()
  477. return
  478. }
  479. br.Msg = "已取消申请"
  480. resp.Status = 2
  481. if user.CompanyId > 1 {
  482. mobile := user.Mobile
  483. if mobile == "" {
  484. mobile = user.Email
  485. }
  486. sellerItem, _ := models.GetSellerByCompanyId(user.CompanyId)
  487. if sellerItem != nil && sellerItem.AdminId > 0 && user.Mobile != "" {
  488. openIpItem, _ := models.GetUserRecordByUserIdByXzs(sellerItem.Mobile, 4)
  489. fmt.Println(openIpItem)
  490. if openIpItem != nil && openIpItem.OpenId != "" {
  491. go services.SendInterviewApplyCancelTemplateMsg(user.RealName, sellerItem.CompanyName, mobile, article.Title, openIpItem.OpenId)
  492. }
  493. }
  494. }
  495. }
  496. br.Ret = 200
  497. br.Success = true
  498. br.Data = resp
  499. }
  500. // @Title 获取报告详情
  501. // @Description 获取报告详情接口
  502. // @Param ArticleIdMd5 query int true "报告ID"
  503. // @Success 200 {object} models.ArticleDetailResp
  504. // @router /look/detail [get]
  505. func (this *ArticleCommonController) Detail() {
  506. br := new(models.BaseResponse).Init()
  507. defer func() {
  508. this.Data["json"] = br
  509. this.ServeJSON()
  510. }()
  511. articleIdMd5 := this.GetString("ArticleIdMd5")
  512. if articleIdMd5 == "" {
  513. br.Msg = "参数错误"
  514. br.ErrMsg = "参数错误"
  515. return
  516. }
  517. resp := new(models.ArticleDetailResp)
  518. detail, err := models.GetArticleDetailByIdMd5(articleIdMd5)
  519. if err != nil {
  520. br.Msg = "获取信息失败"
  521. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  522. return
  523. }
  524. detail.Body = html.UnescapeString(detail.Body)
  525. //detail.Abstract = html.UnescapeString(detail.Abstract)
  526. sellerList, err := models.GetSellerList(detail.ArticleId)
  527. if err != nil {
  528. br.Msg = "获取信息失败"
  529. br.ErrMsg = "获取销售数据失败,Err:" + err.Error() + ";articleId" + strconv.Itoa(detail.ArticleId)
  530. return
  531. }
  532. if detail.ArticleId > 1000000 {
  533. var hrefRegexp = regexp.MustCompile("[0-9]\\d*")
  534. match := hrefRegexp.FindAllString(detail.SellerAndMobile, -1)
  535. if match != nil {
  536. for _, v := range match {
  537. sellerAndMobile := &models.SellerRep{
  538. SellerMobile: v,
  539. SellerName: strings.Replace(detail.SellerAndMobile, v, "", -1),
  540. }
  541. sellerList = append(sellerList, sellerAndMobile)
  542. }
  543. }
  544. }
  545. resp.HasPermission = 1
  546. detail.Abstract, _ = services.GetReportContentTextSub(detail.Abstract)
  547. detail.SellerList = sellerList
  548. resp.Detail = detail
  549. br.Ret = 200
  550. br.Success = true
  551. br.Msg = "获取成功"
  552. br.Data = resp
  553. }
  554. // @Title 上传文章阅读时间
  555. // @Description 上传文章阅读时间接口
  556. // @Param request body models.AddStopTimeRep true "type json string"
  557. // @Success 200 {object} models.ArticleDetailResp
  558. // @router /addStopTime [post]
  559. func (this *ArticleController) AddStopTime() {
  560. br := new(models.BaseResponse).Init()
  561. defer func() {
  562. this.Data["json"] = br
  563. this.ServeJSON()
  564. }()
  565. user := this.User
  566. if user == nil {
  567. br.Msg = "请登录"
  568. br.ErrMsg = "请登录,用户信息为空"
  569. br.Ret = 408
  570. return
  571. }
  572. var req models.AddStopTimeRep
  573. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  574. if err != nil {
  575. br.Msg = "参数解析异常!"
  576. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  577. return
  578. }
  579. uid := user.UserId
  580. articleId := req.ArticleId
  581. stopTime := req.StopTime
  582. outType := req.OutType
  583. source := req.Source
  584. if articleId <= 0 {
  585. br.Msg = "参数错误"
  586. br.ErrMsg = "参数错误"
  587. return
  588. }
  589. if stopTime == 0 {
  590. stopTime = 1
  591. }
  592. if outType != 2 {
  593. outType = 1
  594. }
  595. if source != "PC" {
  596. source = "MOBILE"
  597. }
  598. detail := new(models.ArticleDetail)
  599. hasPermission := 0
  600. hasFree := 0
  601. //判断是否已经申请过
  602. applyCount, err := models.GetApplyRecordCount(uid)
  603. if err != nil && err.Error() != utils.ErrNoRow() {
  604. br.Msg = "获取信息失败"
  605. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  606. return
  607. }
  608. //`description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,4:潜在客户,未提交过申请,5:潜在客户,已提交过申请"`
  609. if user.CompanyId > 1 {
  610. companyPermission, err := models.GetCompanyPermission(user.CompanyId)
  611. if err != nil {
  612. br.Msg = "获取信息失败"
  613. br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  614. return
  615. }
  616. detail, err = models.GetArticleDetailById(articleId)
  617. if err != nil {
  618. br.Msg = "获取信息失败"
  619. br.ErrMsg = "获取文章信息失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  620. return
  621. }
  622. if companyPermission == "" {
  623. if applyCount > 0 {
  624. hasPermission = 5
  625. } else {
  626. hasPermission = 2
  627. }
  628. hasFree = 2
  629. goto Loop
  630. } else {
  631. hasFree = 1
  632. var articlePermissionPermissionName string
  633. if detail.CategoryId > 0 {
  634. articlePermission, err := models.GetArticlePermission(detail.CategoryId)
  635. if err != nil {
  636. br.Msg = "获取信息失败"
  637. br.ErrMsg = "获取报告权限失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  638. return
  639. }
  640. if articlePermission == nil {
  641. br.Msg = "获取信息失败"
  642. br.ErrMsg = "报告权限不存在,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  643. return
  644. }
  645. articlePermissionPermissionName = articlePermission.PermissionName
  646. } else {
  647. articlePermissionPermissionName = detail.CategoryName
  648. }
  649. var hasPersion bool
  650. slice := strings.Split(articlePermissionPermissionName, ",")
  651. for _, v := range slice {
  652. if strings.Contains(companyPermission, v) {
  653. hasPersion = true
  654. }
  655. }
  656. if hasPersion {
  657. detailNew, err := models.GetNewArticleHistoryRecord(uid, articleId)
  658. if err == nil {
  659. hasPermission = 1
  660. historyRecord := new(models.AddStopTimeNewRep)
  661. historyRecord.StopTime = detailNew.StopTime + stopTime
  662. historyRecord.Id = detailNew.Id
  663. historyRecord.OutType = outType
  664. go models.UpdateArticleStopTime(historyRecord)
  665. }
  666. //不统计本公司的阅读记录、正常退出的不做时间差统计
  667. if user.CompanyId != 16 && stopTime > 3 {
  668. key := "CYGX_ARTICLE_PV" + strconv.Itoa(articleId) + "_" + strconv.Itoa(uid) + "_" + strconv.Itoa(user.CompanyId) + "_" + strconv.Itoa(outType)
  669. record := new(models.CygxArticleHistoryRecordNewpv)
  670. record.UserId = uid
  671. record.ArticleId = articleId
  672. record.CreateTime = time.Now().Add(-time.Second * time.Duration(stopTime))
  673. record.ModifyTime = time.Now()
  674. record.Mobile = user.Mobile
  675. record.Email = user.Email
  676. record.CompanyId = user.CompanyId
  677. record.CompanyName = user.CompanyName
  678. record.StopTime = stopTime
  679. record.OutType = outType
  680. record.Source = source
  681. if !utils.Rc.IsExist(key) || outType != 2 {
  682. //新增浏览记录
  683. go models.AddCygxArticleViewRecordNewpv(record)
  684. recordRedis := new(services.ReportViewRecord)
  685. recordRedis.UserId = user.UserId
  686. recordRedis.ReportId = articleId
  687. recordRedis.Mobile = user.Mobile
  688. recordRedis.Email = user.Email
  689. recordRedis.RealName = user.RealName
  690. recordRedis.CompanyName = user.CompanyName
  691. recordRedis.CreateTime = time.Now().Add(-time.Second * time.Duration(stopTime))
  692. go services.PushViewRecordNewRedisData(recordRedis, user.CompanyId)
  693. } else {
  694. go models.UpdateCygxArticleViewRecordNewpv(record, stopTime)
  695. }
  696. utils.Rc.Put(key, 1, 10*time.Minute)
  697. }
  698. models.ModifyReportLastViewTime(uid)
  699. } else { //无该行业权限
  700. hasPermission = 3
  701. }
  702. }
  703. } else { //潜在客户
  704. if applyCount > 0 {
  705. hasPermission = 5
  706. } else {
  707. hasPermission = 4
  708. }
  709. }
  710. Loop:
  711. resp := new(models.ArticleDetailAddStopTimeRep)
  712. resp.HasPermission = hasPermission
  713. resp.HasFree = hasFree
  714. br.Ret = 200
  715. br.Success = true
  716. br.Msg = "操作成功"
  717. br.Data = resp
  718. }
  719. // @Title 文章带问
  720. // @Description 新增文章带问接口
  721. // @Param request body models.AddArticleAskRep true "type json string"
  722. // @Success Ret=200 新增成功
  723. // @router /askAdd [post]
  724. func (this *ArticleController) AskAdd() {
  725. br := new(models.BaseResponse).Init()
  726. defer func() {
  727. this.Data["json"] = br
  728. this.ServeJSON()
  729. }()
  730. user := this.User
  731. if user == nil {
  732. br.Msg = "请登录"
  733. br.ErrMsg = "请登录,SysUser Is Empty"
  734. br.Ret = 408
  735. return
  736. }
  737. var req models.AddArticleAskRep
  738. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  739. if err != nil {
  740. br.Msg = "参数解析异常!"
  741. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  742. return
  743. }
  744. if req.Content == "" {
  745. br.Msg = "建议内容不可为空"
  746. return
  747. }
  748. content := req.Content
  749. itemToken, err := services.WxGetToken()
  750. if err != nil {
  751. br.Msg = "GetWxAccessToken Err:" + err.Error()
  752. return
  753. }
  754. if itemToken.AccessToken == "" {
  755. br.Msg = "accessToken is empty"
  756. return
  757. }
  758. commerr, err := weapp.MSGSecCheck(itemToken.AccessToken, content)
  759. if err != nil {
  760. br.Msg = "内容校验失败!"
  761. br.ErrMsg = "内容校验失败,Err:" + err.Error()
  762. return
  763. }
  764. if commerr.ErrCode != 0 {
  765. br.Msg = "内容违规,请重新提交!"
  766. br.ErrMsg = "颜文字内容违规,Err:" + commerr.ErrMSG
  767. return
  768. }
  769. articleId := req.ArticleId
  770. count, _ := models.GetArticleCountById(articleId)
  771. if count == 0 {
  772. br.Msg = "操作失败"
  773. br.ErrMsg = "文章ID错误,不存在 articleId:" + strconv.Itoa(articleId)
  774. return
  775. }
  776. companyDetail, err := models.GetCompanyDetailById(user.CompanyId)
  777. if err != nil {
  778. br.Msg = "提交失败!"
  779. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  780. return
  781. }
  782. if companyDetail == nil {
  783. br.Msg = "提交失败!"
  784. br.ErrMsg = "客户不存在,uid:" + strconv.Itoa(user.UserId)
  785. return
  786. }
  787. item := new(models.CygxArticleAsk)
  788. item.UserId = user.UserId
  789. item.ArticleId = req.ArticleId
  790. item.CompanyId = user.CompanyId
  791. item.CompanyName = companyDetail.CompanyName
  792. item.CreateTime = time.Now()
  793. item.Mobile = user.Mobile
  794. item.Email = user.Email
  795. item.Content = content
  796. _, err = models.AddArticleAsk(item)
  797. if err != nil {
  798. br.Msg = "提交失败"
  799. br.ErrMsg = "提交失败,Err:" + err.Error()
  800. return
  801. }
  802. companyItem, err := models.GetSellerDetailAllByCompanyId(user.CompanyId)
  803. if err != nil {
  804. br.Msg = "获取信息失败"
  805. br.ErrMsg = "获取所属销售信息失败,Err:" + err.Error()
  806. return
  807. }
  808. var mobile string
  809. if utils.RunMode == "release" {
  810. //mobile = utils.WxMsgTemplateIdAskMsgMobileAll + "," + companyItem.Mobile
  811. mobile = utils.WxMsgTemplateIdAskMsgMobileAll
  812. } else {
  813. mobile = utils.WxMsgTemplateIdAskMsgMobile
  814. }
  815. openIdList, err := models.GetWxOpenIdByMobileList(mobile)
  816. if err != nil {
  817. br.Msg = "提交失败"
  818. br.ErrMsg = "提交失败,Err:" + err.Error()
  819. return
  820. }
  821. detail, err := models.GetArticleDetailById(articleId)
  822. if err != nil {
  823. br.Msg = "获取信息失败"
  824. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  825. return
  826. }
  827. companyName := user.CompanyName + "-" + user.RealName + "(" + companyItem.SellerName + ")"
  828. go services.SendWxMsgWithAsk(companyName, time.Now().Format(utils.FormatDateTime), content, detail.Title, openIdList, req.ArticleId)
  829. br.Ret = 200
  830. br.Success = true
  831. br.Msg = "提交成功"
  832. }
  833. // @Title 下载PDF打水印
  834. // @Description 下载PDF打水印接口
  835. // @Param ArticleId query int true "报告ID"
  836. // @Success 200 {object} models.ArticleDetailFileLink
  837. // @router /pdfwatermark [get]
  838. func (this *ArticleController) Pdfwatermark() {
  839. br := new(models.BaseResponse).Init()
  840. defer func() {
  841. this.Data["json"] = br
  842. this.ServeJSON()
  843. }()
  844. user := this.User
  845. if user == nil {
  846. br.Msg = "请登录"
  847. br.ErrMsg = "请登录,用户信息为空"
  848. br.Ret = 408
  849. return
  850. }
  851. uid := user.UserId
  852. articleId, err := this.GetInt("ArticleId")
  853. if articleId <= 0 {
  854. br.Msg = "文章不存在"
  855. br.ErrMsg = "文章不存在,文章ID错误"
  856. return
  857. }
  858. //缓存校验
  859. cacheKey := fmt.Sprint("xygx:apply_record:add:", uid, "ArticleId_", articleId)
  860. ttlTime := utils.Rc.GetRedisTTL(cacheKey)
  861. if ttlTime > 0 && user.CompanyId != 16 {
  862. br.Msg = "下载失败,下载过于频繁"
  863. br.ErrMsg = "下载失败,下载过于频繁:mobile" + user.Mobile
  864. return
  865. }
  866. resp := new(models.ArticleDetailFileLink)
  867. detail := new(models.ArticleDetail)
  868. detail, err = models.GetArticleDetailById(articleId)
  869. if err != nil {
  870. br.Msg = "获取信息失败"
  871. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  872. return
  873. }
  874. fileLink := detail.FileLink
  875. if fileLink == "" {
  876. br.Msg = "下载失败"
  877. br.ErrMsg = "下载失败,报告链接不存在"
  878. return
  879. }
  880. mobile := user.Mobile
  881. if mobile == "" {
  882. mobile = user.Email
  883. }
  884. sliceLink := strings.Split(fileLink, "/")
  885. uploadDir := "static/pdf/"
  886. //判断文件夹是否存在,不存在则创建
  887. if !utils.FileIsExist(uploadDir) {
  888. err = os.MkdirAll(uploadDir, 0755)
  889. if err != nil {
  890. br.Msg = "下载失败"
  891. br.ErrMsg = "存储目录创建失败,Err:" + err.Error()
  892. return
  893. }
  894. }
  895. var oldFile string
  896. var newFile string
  897. //获取PDF源文件名称
  898. pdfName := sliceLink[len(sliceLink)-1]
  899. pdfName = utils.MD5(pdfName) + ".pdf"
  900. oldFile = uploadDir + pdfName
  901. //判断PDF本地是否存在,不存在则保存到本地
  902. if !utils.FileIsExist(oldFile) {
  903. res, err := nhttp.Get(fileLink)
  904. if err != nil {
  905. br.Msg = "下载失败"
  906. br.ErrMsg = "获取源文件失败,Err:" + err.Error()
  907. return
  908. }
  909. defer res.Body.Close()
  910. // 获得get请求响应的reader对象
  911. reader := bufio.NewReaderSize(res.Body, 32*1024)
  912. file, err := os.Create(oldFile)
  913. if err != nil {
  914. br.Msg = "下载失败"
  915. br.ErrMsg = "保存源文件到本地失败,Err:" + err.Error()
  916. return
  917. }
  918. defer file.Close()
  919. //获得文件的writer对象
  920. writer := bufio.NewWriter(file)
  921. written, _ := io.Copy(writer, reader)
  922. fmt.Printf("Total length: %d", written)
  923. }
  924. newFile = uploadDir + "new_" + pdfName
  925. onTop := true
  926. wm, err := pdfcpu.ParseTextWatermarkDetails(mobile, " op:.4, pos:c ,points:16 ", onTop, 1)
  927. if err != nil {
  928. br.Msg = "下载失败"
  929. br.ErrMsg = "生成水印文件失败,Err:" + err.Error()
  930. return
  931. }
  932. err = api.AddWatermarksFile(oldFile, newFile, nil, wm, nil)
  933. if err != nil {
  934. //br.Msg = "下载失败"
  935. //br.ErrMsg = "生成水印PDF失败,Err:" + err.Error()
  936. resp.FileLink = fileLink
  937. br.Ret = 200
  938. br.Success = true
  939. br.Msg = "获取成功"
  940. br.Data = resp
  941. return
  942. }
  943. randStr := utils.GetRandStringNoSpecialChar(28)
  944. fileName := randStr + ".pdf"
  945. savePath := uploadDir + time.Now().Format("200601/20060102/")
  946. savePath += fileName
  947. //上传到阿里云
  948. err = services.UploadFileToAliyun(fileName, newFile, savePath)
  949. if err != nil {
  950. br.Msg = "下载失败"
  951. br.ErrMsg = "文件上传失败,Err:" + err.Error()
  952. return
  953. }
  954. fileHost := "https://hzstatic.hzinsights.com/"
  955. resourceUrl := fileHost + savePath
  956. defer func() {
  957. os.Remove(newFile)
  958. }()
  959. utils.Rc.SetNX(cacheKey, user.Mobile, time.Minute*5)
  960. resp.FileLink = resourceUrl
  961. br.Ret = 200
  962. br.Success = true
  963. br.Msg = "获取成功"
  964. br.Data = resp
  965. }
  966. // @Title 获取报告详情(无需token)
  967. // @Description 获取报告详情接口
  968. // @Param ArticleId query int true "报告ID"
  969. // @Param CompanyCode query string false "机构编号"
  970. // @Param CompanyName query string false "机构名称"
  971. // @Param Email query string false "邮箱"
  972. // @Param Sign query string false "加密签名"
  973. // @Success 200 {object} models.ArticleDetailHtgjResp
  974. // @router /detailPublic [get]
  975. func (this *ArticleCommonController) DetailPublic() {
  976. br := new(models.BaseResponse).Init()
  977. defer func() {
  978. this.Data["json"] = br
  979. this.ServeJSON()
  980. }()
  981. articleId, _ := this.GetInt("ArticleId")
  982. companyCode := this.GetString("CompanyCode")
  983. companyNameHt := this.GetString("CompanyName")
  984. email := this.GetString("Email")
  985. sign := this.GetString("Sign")
  986. resp := new(models.ArticleDetailHtgjResp)
  987. if companyCode == "" || email == "" {
  988. resp.HasPermission = 2
  989. br.Ret = 200
  990. br.Success = true
  991. br.Msg = "获取成功"
  992. br.Data = resp
  993. return
  994. }
  995. if articleId <= 0 {
  996. br.Msg = "文章不存在"
  997. br.ErrMsg = "文章不存在,文章ID错误"
  998. return
  999. }
  1000. errMsg, err, wxUser, companyName := services.CheckHtgj(companyCode, companyNameHt, email, sign)
  1001. if errMsg != "" {
  1002. br.Msg = errMsg
  1003. return
  1004. }
  1005. companyPermission, err := models.GetCompanyPermission(wxUser.CompanyId)
  1006. if err != nil {
  1007. br.Msg = "获取信息失败"
  1008. br.ErrMsg = "获取用户权限失败,Err:" + err.Error() + ";articleId" + strconv.Itoa(articleId)
  1009. return
  1010. }
  1011. hasPermission := 0
  1012. detail, err := models.GetArticleDetailById(articleId)
  1013. if err != nil {
  1014. br.Msg = "获取信息失败"
  1015. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  1016. return
  1017. }
  1018. detail.Body = html.UnescapeString(detail.Body)
  1019. 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)
  1020. detail.Body = strings.Replace(detail.Body, "pre", "div", -1)
  1021. detail.Abstract, _ = services.GetReportContentTextSub(detail.Abstract)
  1022. var articlePermissionPermissionName string
  1023. if detail.CategoryId > 0 {
  1024. articlePermission, err := models.GetArticlePermission(detail.CategoryId)
  1025. if err != nil {
  1026. br.Msg = "获取信息失败"
  1027. br.ErrMsg = "获取报告权限失败,Err:" + err.Error() + strconv.Itoa(wxUser.UserId) + ";articleId" + strconv.Itoa(articleId)
  1028. return
  1029. }
  1030. if articlePermission == nil {
  1031. br.Msg = "获取信息失败"
  1032. br.ErrMsg = "报告权限不存在,Err:" + strconv.Itoa(wxUser.UserId) + ";articleId" + strconv.Itoa(articleId)
  1033. return
  1034. }
  1035. articlePermissionPermissionName = articlePermission.PermissionName
  1036. } else {
  1037. articlePermissionPermissionName = detail.CategoryName
  1038. }
  1039. var hasPersion bool
  1040. slice := strings.Split(articlePermissionPermissionName, ",")
  1041. for _, v := range slice {
  1042. if strings.Contains(companyPermission, v) {
  1043. hasPersion = true
  1044. }
  1045. }
  1046. if hasPersion {
  1047. hasPermission = 1
  1048. }
  1049. if strings.Contains(detail.CategoryName, "研选") {
  1050. detail.IsResearch = true
  1051. }
  1052. resp.HasPermission = hasPermission
  1053. if hasPermission == 1 {
  1054. //获取销售手机号
  1055. sellerItem, err := models.GetSellerByCompanyId(wxUser.CompanyId)
  1056. if err != nil {
  1057. br.Msg = "获取信息失败"
  1058. br.ErrMsg = "获取销售数据失败2,Err:" + strconv.Itoa(wxUser.UserId) + ";articleId" + strconv.Itoa(articleId)
  1059. return
  1060. }
  1061. if sellerItem != nil {
  1062. detail.SellerMobile = sellerItem.Mobile
  1063. detail.SellerName = sellerItem.RealName
  1064. }
  1065. sellerList, err := models.GetSellerList(articleId)
  1066. if err != nil {
  1067. br.Msg = "获取信息失败"
  1068. br.ErrMsg = "获取销售数据失败,Err:" + err.Error() + strconv.Itoa(wxUser.UserId) + ";articleId" + strconv.Itoa(articleId)
  1069. return
  1070. }
  1071. if detail.ArticleId >= utils.SummaryArticleId && strings.Contains(detail.SellerAndMobile, "-") {
  1072. strnum := strings.Index(detail.SellerAndMobile, "-")
  1073. detail.SellerAndMobile = detail.SellerAndMobile[0:strnum]
  1074. if strnum > 0 {
  1075. nickName := detail.SellerAndMobile[0:strnum]
  1076. sellerAndMobile := &models.SellerRep{
  1077. SellerMobile: "",
  1078. SellerName: nickName,
  1079. }
  1080. sellerList = append(sellerList, sellerAndMobile)
  1081. }
  1082. }
  1083. detail.SellerList = sellerList
  1084. resp.Detail = detail
  1085. historyRecord := new(models.CygxArticleHistoryRecord)
  1086. historyRecord.UserId = wxUser.UserId
  1087. historyRecord.ArticleId = articleId
  1088. historyRecord.CreateTime = time.Now()
  1089. historyRecord.Mobile = wxUser.Mobile
  1090. historyRecord.Email = wxUser.Email
  1091. historyRecord.CompanyId = wxUser.CompanyId
  1092. historyRecord.CompanyName = companyName
  1093. recordCount, _ := models.GetNoAddStoptimeArticleCount(wxUser.UserId, articleId)
  1094. if recordCount == 0 {
  1095. go models.AddCygxArticleHistoryRecord(historyRecord)
  1096. } else {
  1097. detailNew, err := models.GetNewArticleHistoryRecord(wxUser.UserId, articleId)
  1098. if err != nil {
  1099. br.Msg = "获取信息失败"
  1100. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  1101. return
  1102. }
  1103. if detailNew.StopTime > 0 {
  1104. go models.AddCygxArticleHistoryRecord(historyRecord)
  1105. }
  1106. }
  1107. key := "CYGX_ARTICLE_" + strconv.Itoa(articleId) + "_" + strconv.Itoa(wxUser.UserId)
  1108. if !utils.Rc.IsExist(key) {
  1109. //新增浏览记录
  1110. record := new(models.CygxArticleViewRecord)
  1111. record.UserId = wxUser.UserId
  1112. record.ArticleId = articleId
  1113. record.CreateTime = time.Now()
  1114. record.Mobile = wxUser.Mobile
  1115. record.Email = wxUser.Email
  1116. record.CompanyId = wxUser.CompanyId
  1117. record.CompanyName = companyName
  1118. go models.AddCygxArticleViewRecord(record)
  1119. utils.Rc.Put(key, 1, 5*time.Second)
  1120. models.ModifyReportLastViewTime(wxUser.UserId)
  1121. }
  1122. }
  1123. resp.CompanyName = companyName
  1124. br.Ret = 200
  1125. br.Success = true
  1126. br.Msg = "获取成功"
  1127. br.Data = resp
  1128. }
  1129. // @Title 上传文章阅读时间(无需token)
  1130. // @Description 上传文章阅读时间接口(无需token)
  1131. // @Param request body models.AddStopTimeHtgjRep true "type json string"
  1132. // @Success 200 {object} models.ArticleDetailResp
  1133. // @router /addStopTimePublic [post]
  1134. func (this *ArticleCommonController) AddStopTimePublic() {
  1135. br := new(models.BaseResponse).Init()
  1136. defer func() {
  1137. this.Data["json"] = br
  1138. this.ServeJSON()
  1139. }()
  1140. var req models.AddStopTimeHtgjRep
  1141. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1142. if err != nil {
  1143. br.Msg = "参数解析异常!"
  1144. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1145. return
  1146. }
  1147. articleId := req.ArticleId
  1148. stopTime := req.StopTime
  1149. outType := req.OutType
  1150. source := req.Source
  1151. companyCode := req.CompanyCode
  1152. companyName := req.CompanyName
  1153. wxuUserName := req.Email
  1154. sign := req.Sign
  1155. if companyCode == "" || companyName == "" || wxuUserName == "" || sign == "" {
  1156. br.Msg = "上传失败"
  1157. br.ErrMsg = "必填参数不能为空"
  1158. return
  1159. }
  1160. companyNameHt := companyCode + "_" + companyName
  1161. errMsg := services.CheckSign(companyCode+companyName+wxuUserName, sign)
  1162. if errMsg != "" {
  1163. br.Msg = errMsg
  1164. return
  1165. }
  1166. companyInfo, err := models.GetCompanyByThirdName(companyNameHt)
  1167. if err != nil {
  1168. br.Msg = "获取信息失败"
  1169. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  1170. return
  1171. }
  1172. user, err := models.GetUserByThirdName(companyInfo.CompanyId, wxuUserName)
  1173. if err != nil {
  1174. br.Msg = "获取信息失败"
  1175. br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
  1176. return
  1177. }
  1178. uid := user.UserId
  1179. if articleId <= 0 {
  1180. br.Msg = "文章ID不存在"
  1181. br.ErrMsg = "参数错误"
  1182. return
  1183. }
  1184. if stopTime == 0 {
  1185. stopTime = 1
  1186. }
  1187. if outType != 2 {
  1188. outType = 1
  1189. }
  1190. if source != "PC" {
  1191. source = "MOBILE"
  1192. }
  1193. detail := new(models.ArticleDetail)
  1194. hasPermission := 0
  1195. hasFree := 0
  1196. //判断是否已经申请过
  1197. applyCount, err := models.GetApplyRecordCount(uid)
  1198. if err != nil && err.Error() != utils.ErrNoRow() {
  1199. br.Msg = "获取信息失败"
  1200. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  1201. return
  1202. }
  1203. //`description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,4:潜在客户,未提交过申请,5:潜在客户,已提交过申请"`
  1204. if user.CompanyId > 1 {
  1205. companyPermission, err := models.GetCompanyPermission(user.CompanyId)
  1206. if err != nil {
  1207. br.Msg = "获取信息失败"
  1208. br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  1209. return
  1210. }
  1211. detail, err = models.GetArticleDetailById(articleId)
  1212. if err != nil {
  1213. br.Msg = "获取信息失败"
  1214. br.ErrMsg = "获取文章信息失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  1215. return
  1216. }
  1217. if companyPermission == "" {
  1218. if applyCount > 0 {
  1219. hasPermission = 5
  1220. } else {
  1221. hasPermission = 2
  1222. }
  1223. hasFree = 2
  1224. goto Loop
  1225. } else {
  1226. hasFree = 1
  1227. var articlePermissionPermissionName string
  1228. if detail.CategoryId > 0 {
  1229. articlePermission, err := models.GetArticlePermission(detail.CategoryId)
  1230. if err != nil {
  1231. br.Msg = "获取信息失败"
  1232. br.ErrMsg = "获取报告权限失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  1233. return
  1234. }
  1235. if articlePermission == nil {
  1236. br.Msg = "获取信息失败"
  1237. br.ErrMsg = "报告权限不存在,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  1238. return
  1239. }
  1240. articlePermissionPermissionName = articlePermission.PermissionName
  1241. } else {
  1242. articlePermissionPermissionName = detail.CategoryName
  1243. }
  1244. var hasPersion bool
  1245. slice := strings.Split(articlePermissionPermissionName, ",")
  1246. for _, v := range slice {
  1247. if strings.Contains(companyPermission, v) {
  1248. hasPersion = true
  1249. }
  1250. }
  1251. if hasPersion {
  1252. detailNew, err := models.GetNewArticleHistoryRecord(uid, articleId)
  1253. if err == nil {
  1254. hasPermission = 1
  1255. historyRecord := new(models.AddStopTimeNewRep)
  1256. historyRecord.StopTime = detailNew.StopTime + stopTime
  1257. historyRecord.Id = detailNew.Id
  1258. historyRecord.OutType = outType
  1259. go models.UpdateArticleStopTime(historyRecord)
  1260. }
  1261. //不统计本公司的阅读记录、正常退出的不做时间差统计
  1262. if user.CompanyId != 16 && stopTime > 3 {
  1263. key := "CYGX_ARTICLE_PV" + strconv.Itoa(articleId) + "_" + strconv.Itoa(uid) + "_" + strconv.Itoa(user.CompanyId) + "_" + strconv.Itoa(outType)
  1264. record := new(models.CygxArticleHistoryRecordNewpv)
  1265. record.UserId = uid
  1266. record.ArticleId = articleId
  1267. record.CreateTime = time.Now().Add(-time.Second * time.Duration(stopTime))
  1268. record.ModifyTime = time.Now()
  1269. record.Mobile = user.Mobile
  1270. record.Email = user.Email
  1271. record.CompanyId = user.CompanyId
  1272. record.CompanyName = companyInfo.CompanyName
  1273. record.StopTime = stopTime
  1274. record.OutType = outType
  1275. record.Source = source
  1276. if !utils.Rc.IsExist(key) || outType != 2 {
  1277. //新增浏览记录
  1278. go models.AddCygxArticleViewRecordNewpv(record)
  1279. recordRedis := new(services.ReportViewRecord)
  1280. recordRedis.UserId = user.UserId
  1281. recordRedis.ReportId = articleId
  1282. recordRedis.Mobile = user.Mobile
  1283. recordRedis.Email = user.Email
  1284. recordRedis.RealName = user.RealName
  1285. recordRedis.CompanyName = companyName
  1286. recordRedis.CreateTime = time.Now().Add(-time.Second * time.Duration(stopTime))
  1287. go services.PushViewRecordNewRedisData(recordRedis, user.CompanyId)
  1288. } else {
  1289. go models.UpdateCygxArticleViewRecordNewpv(record, stopTime)
  1290. }
  1291. utils.Rc.Put(key, 1, 10*time.Minute)
  1292. }
  1293. models.ModifyReportLastViewTime(uid)
  1294. } else { //无该行业权限
  1295. hasPermission = 3
  1296. }
  1297. }
  1298. } else { //潜在客户
  1299. if applyCount > 0 {
  1300. hasPermission = 5
  1301. } else {
  1302. hasPermission = 4
  1303. }
  1304. }
  1305. Loop:
  1306. resp := new(models.ArticleDetailAddStopTimeRep)
  1307. resp.HasPermission = hasPermission
  1308. resp.HasFree = hasFree
  1309. br.Ret = 200
  1310. br.Success = true
  1311. br.Msg = "操作成功"
  1312. br.Data = resp
  1313. }
  1314. // @Title 页面访问统计(无需token)
  1315. // @Description 上传页面访问统计(无需token)
  1316. // @Param request body models.CygxPageHistoryRecordHtgjRep true "type json string"
  1317. // @Success Ret=200 新增成功
  1318. // @router /pageHistoryPublic [post]
  1319. func (this *ArticleCommonController) PageHistoryPublic() {
  1320. br := new(models.BaseResponse).Init()
  1321. defer func() {
  1322. this.Data["json"] = br
  1323. this.ServeJSON()
  1324. }()
  1325. var req models.CygxPageHistoryRecordHtgjRep
  1326. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1327. if err != nil {
  1328. br.Msg = "参数解析异常!"
  1329. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1330. return
  1331. }
  1332. companyCode := req.CompanyCode
  1333. companyName := req.CompanyName
  1334. wxuUserName := req.Email
  1335. sign := req.Sign
  1336. if companyCode == "" || companyName == "" || wxuUserName == "" || sign == "" {
  1337. br.Msg = "上传失败"
  1338. br.ErrMsg = "必填参数不能为空"
  1339. return
  1340. }
  1341. companyNameHt := companyCode + "_" + companyName
  1342. errMsg := services.CheckSign(companyCode+companyName+wxuUserName, sign)
  1343. if errMsg != "" {
  1344. br.Msg = errMsg
  1345. return
  1346. }
  1347. companyInfo, err := models.GetCompanyByThirdName(companyNameHt)
  1348. if err != nil {
  1349. br.Msg = "获取信息失败"
  1350. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  1351. return
  1352. }
  1353. user, err := models.GetUserByThirdName(companyInfo.CompanyId, wxuUserName)
  1354. if err != nil {
  1355. br.Msg = "获取信息失败"
  1356. br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
  1357. return
  1358. }
  1359. item := new(models.CygxPageHistoryRecord)
  1360. item.UserId = user.UserId
  1361. item.CreateTime = time.Now()
  1362. item.Mobile = user.Mobile
  1363. item.Email = user.Email
  1364. item.CompanyId = user.CompanyId
  1365. item.CompanyName = companyName
  1366. item.DetailId = req.DetailId
  1367. item.ChartPermissionId = req.ChartPermissionId
  1368. item.IndustrialManagementId = req.IndustrialManagementId
  1369. item.PageType = "ArticleCopy"
  1370. _, err = models.AddCygxPageHistoryRecord(item)
  1371. if err != nil {
  1372. br.Msg = "记录信息失败"
  1373. br.ErrMsg = "新增访问记录失败,Err:" + err.Error()
  1374. return
  1375. }
  1376. br.Ret = 200
  1377. br.Success = true
  1378. br.Msg = "新增成功"
  1379. }