article.go 53 KB

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