article.go 53 KB

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