article.go 51 KB

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