article.go 48 KB

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