article.go 49 KB

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