article.go 44 KB

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