article.go 54 KB

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