article.go 51 KB

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