article.go 42 KB

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