article.go 53 KB

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