article.go 44 KB

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