article.go 48 KB

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