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