article.go 43 KB

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