article.go 53 KB

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