article.go 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110
  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_mfyx/models"
  15. "hongze/hongze_mfyx/services"
  16. "hongze/hongze_mfyx/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. //detailInit := new(models.ArticleDetail) // 初始化的文章信息,用来处理body 内容回显
  61. hasPermission := 0
  62. var haveResearch bool
  63. //判断是否已经申请过
  64. applyCount, err := models.GetApplyRecordCount(uid)
  65. if err != nil && err.Error() != utils.ErrNoRow() {
  66. br.Msg = "获取信息失败"
  67. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  68. return
  69. }
  70. resp := new(models.ArticleDetailResp)
  71. detail, err = models.GetArticleDetailById(articleId)
  72. if err != nil {
  73. br.Msg = "获取信息失败"
  74. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  75. return
  76. }
  77. detail.PublishDate = utils.TimeRemoveHms2(detail.PublishDate)
  78. detail.Body = html.UnescapeString(detail.Body)
  79. 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)
  80. detail.Body = strings.Replace(detail.Body, "pre", "div", -1)
  81. detail.Abstract = html.UnescapeString(detail.Abstract)
  82. //detail.Abstract, _ = services.GetReportContentTextSubNew(detail.Abstract)
  83. //作者头像
  84. if detail.DepartmentId > 0 {
  85. departmentDetail, err := models.GetArticleDepartmentDateilById(detail.DepartmentId)
  86. if err == nil {
  87. detail.DepartmentImgUrl = departmentDetail.ImgUrl
  88. }
  89. }
  90. lyjhTypeMap, _ := services.GetLyjhTypeMap()
  91. if _, ok := lyjhTypeMap[detail.CategoryId]; ok {
  92. detail.IsRoadShow = true
  93. }
  94. // 判断是否属于研选类型的报告
  95. if strings.Contains(detail.CategoryName, utils.CHART_PERMISSION_NAME_YANXUAN) {
  96. detail.IsResearch = true
  97. }
  98. // 高毅资产的联系人,有权限的行业也不能查看报告详情页。提示无权限页面
  99. if detail.ArticleTypeId == 0 && user.CompanyId == utils.GAO_YI_ZI_CHAN_COMPANY_ID {
  100. _, sellerName, sellerMobile, popupMsg, err := services.GetUserHasPermissionArticle(user)
  101. if err != nil {
  102. br.Msg = "获取信息失败"
  103. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  104. return
  105. }
  106. resp.PopupMsg = popupMsg
  107. resp.HasPermission = 3
  108. resp.SellerName = sellerName
  109. resp.SellerMobile = sellerMobile
  110. detail.Body = ""
  111. detail.Abstract = ""
  112. detail.BodyText = ""
  113. detail.SellerName = sellerName
  114. detail.SellerMobile = sellerMobile
  115. resp.Detail = detail
  116. br.Ret = 200
  117. br.Success = true
  118. br.Msg = "获取成功"
  119. br.Data = resp
  120. return
  121. }
  122. articleCollectMap, _ := services.GetCygxArticleCollectMap(user.UserId)
  123. detail.IsCollect = articleCollectMap[detail.ArticleId]
  124. //detailInit = detail
  125. if isSendWx == 1 {
  126. var condition string
  127. var pars []interface{}
  128. pars = make([]interface{}, 0)
  129. condition = ` AND article_id = ? `
  130. reportMappingMap, _ := services.GetReportMappingMap()
  131. if reportMappingMap[detail.CategoryId] {
  132. chooseCategoryMap, _ := services.GetChooseCategoryMap(user)
  133. detail.IsShowFollowButton = true
  134. detail.IsFollowButton = chooseCategoryMap[detail.CategoryId]
  135. } else {
  136. pars = append(pars, articleId)
  137. industrialList, err := models.GetIndustrialArticleGroupManagementList(condition, pars)
  138. if err != nil && err.Error() != utils.ErrNoRow() {
  139. br.Msg = "获取信息失败"
  140. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  141. return
  142. }
  143. if len(industrialList) > 0 {
  144. industryUserFollowMap, err := services.GetIndustryUserFollowMap(user)
  145. if err != nil {
  146. br.Msg = "获取信息失败"
  147. br.ErrMsg = "GetActivitySignupResp,Err:" + err.Error()
  148. return
  149. }
  150. for _, v := range industrialList {
  151. if industryUserFollowMap[v.IndustrialManagementId] {
  152. detail.IsFollowButton = true
  153. }
  154. }
  155. detail.IsShowFollowButton = true
  156. }
  157. }
  158. }
  159. //是否属于专项调研报告
  160. if detail.SubCategoryName == "专项调研" {
  161. detail.IsSpecialArticle = true
  162. havePower, err := services.GetSpecialArticleDetailUserPower(user, detail)
  163. if err != nil {
  164. br.Msg = "获取信息失败"
  165. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  166. return
  167. }
  168. resp.IsSpecialArticle = true
  169. if !havePower {
  170. hasPermission, sellerName, sellerMobile, popupMsg, err := services.GetUserHasPermissionArticle(user)
  171. if err != nil {
  172. br.Msg = "获取信息失败"
  173. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  174. return
  175. }
  176. resp.PopupMsg = popupMsg
  177. resp.HasPermission = hasPermission
  178. resp.SellerName = sellerName
  179. resp.SellerMobile = sellerMobile
  180. detail.Body = ""
  181. detail.Abstract = ""
  182. detail.BodyText = ""
  183. detail.SellerName = sellerName
  184. detail.SellerMobile = sellerMobile
  185. resp.Detail = detail
  186. br.Ret = 200
  187. br.Success = true
  188. br.Msg = "获取成功"
  189. br.Data = resp
  190. return
  191. }
  192. }
  193. //`description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,4:潜在客户,未提交过申请,5:潜在客户,已提交过申请"`
  194. if user.CompanyId > 1 {
  195. companyPermission, err := models.GetCompanyPermission(user.CompanyId)
  196. if err != nil {
  197. br.Msg = "获取信息失败"
  198. br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  199. return
  200. }
  201. //判断用户是否开通了个人研选权限,如果有权限后缀拼接权限名称
  202. mfyxUserPermissionTotal := services.GetMfyxUserPermissionTotal(uid)
  203. if mfyxUserPermissionTotal == 1 {
  204. companyPermission += "," + utils.CHART_PERMISSION_NAME_MF_YANXUAN
  205. companyPermission += "," + utils.MAI_FANG_YAN_XUAN_NAME
  206. }
  207. //如果有研选订阅的权限,那么就拼接一个 买方研选的权限做校验
  208. if strings.Contains(companyPermission, utils.CHART_PERMISSION_NAME_MF_YANXUAN) {
  209. companyPermission += "," + utils.MAI_FANG_YAN_XUAN_NAME
  210. }
  211. if companyPermission == "" {
  212. if applyCount > 0 {
  213. hasPermission = 5
  214. } else {
  215. hasPermission = 2
  216. }
  217. goto Loop
  218. } else {
  219. var articlePermissionName string
  220. if detail.CategoryId > 0 {
  221. articlePermission, err := models.GetArticlePermission(detail.CategoryId)
  222. if err != nil {
  223. br.Msg = "获取信息失败"
  224. br.ErrMsg = "获取报告权限失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  225. return
  226. }
  227. if articlePermission == nil {
  228. br.Msg = "获取信息失败"
  229. br.ErrMsg = "报告权限不存在,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  230. return
  231. }
  232. articlePermissionName = articlePermission.PermissionName
  233. } else {
  234. articlePermissionName = detail.CategoryName
  235. }
  236. var hasPersion bool
  237. slice := strings.Split(articlePermissionName, ",")
  238. for _, v := range slice {
  239. if strings.Contains(companyPermission, v) {
  240. hasPersion = true
  241. }
  242. }
  243. if strings.Contains(detail.CategoryName, "研选") {
  244. detail.IsResearch = true
  245. }
  246. userType, _, err := services.GetUserType(user.CompanyId)
  247. if err != nil {
  248. br.Msg = "获取信息失败"
  249. br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
  250. return
  251. }
  252. //永续客户,无法查看研选权限,但是下面的联系人,单独开通研选后,也可以查看研选内容
  253. if userType == 1 && strings.Contains(detail.CategoryName, "研选") && mfyxUserPermissionTotal == 0 {
  254. hasPersion = false
  255. }
  256. //if detail.IsReport == 1 {
  257. //detailCategory, err := models.GetdetailByCategoryIdSando(detail.CategoryId)
  258. //if err != nil && err.Error() != utils.ErrNoRow() {
  259. // br.Msg = "获取信息失败"
  260. // br.ErrMsg = "获取信息失败,Err:" + err.Error() + "categoryID 不存在:" + strconv.Itoa(detail.CategoryId)
  261. // return
  262. //}
  263. //permissionStr, err := models.GetCompanyPermissionByUser(user.CompanyId)
  264. //if err != nil {
  265. // br.Msg = "获取信息失败"
  266. // br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  267. // return
  268. //}
  269. //if detailCategory != nil {
  270. // if detailCategory.PermissionType == 1 {
  271. // if !strings.Contains(permissionStr, detailCategory.ChartPermissionName+"(主观)") {
  272. // hasPersion = false
  273. // }
  274. // } else if detailCategory.PermissionType == 2 {
  275. // if !strings.Contains(permissionStr, detailCategory.ChartPermissionName+"(客观)") {
  276. // hasPersion = false
  277. // }
  278. // }
  279. //}
  280. //}
  281. //大行业通过权限校验,再校验主客观权限。只有医药、消费、科技、智造,才会校验主客观权限
  282. if hasPersion && utils.InArrayByStr([]string{utils.YI_YAO_NAME, utils.XIAO_FEI_NAME, utils.KE_JI_NAME, utils.ZHI_ZAO_NAME}, articlePermissionName) {
  283. hasPersion = services.CheckArticlePermissionType(articleId, user)
  284. }
  285. if hasPersion {
  286. hasPermission = 1
  287. go services.ArticleHistory(articleId, user)
  288. //30分钟之内阅读同一篇文章不错二次推送
  289. key := "CYGX_ARTICLE_READ" + strconv.Itoa(articleId) + "_" + strconv.Itoa(uid)
  290. if !utils.Rc.IsExist(key) {
  291. go services.ArticleUserRemind(user, detail, 1)
  292. // 互动提醒
  293. go services.SendWxCategoryMsgInteractive(user, "阅读报告", articleId)
  294. utils.Rc.Put(key, 1, 30*time.Second)
  295. }
  296. } else { //无该行业权限
  297. companyDetail, err := models.GetCompanyDetailById(user.CompanyId)
  298. if err == nil && companyDetail.ProductId == 1 {
  299. hasPermission = 2
  300. } else {
  301. hasPermission = 3
  302. }
  303. }
  304. }
  305. interviewApplyItem, err := models.GetArticleInterviewApply(uid, articleId)
  306. if err != nil && err.Error() != utils.ErrNoRow() {
  307. br.Msg = "获取信息失败"
  308. br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  309. return
  310. }
  311. if interviewApplyItem != nil && interviewApplyItem.InterviewApplyId > 0 {
  312. detail.IsInterviewApply = true
  313. detail.InterviewApplyStatus = interviewApplyItem.Status
  314. }
  315. //获取销售手机号
  316. sellerItem, err := models.GetSellerByCompanyId(user.CompanyId)
  317. if err != nil && err.Error() != utils.ErrNoRow() {
  318. br.Msg = "获取信息失败"
  319. br.ErrMsg = "获取销售数据失败2,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  320. return
  321. }
  322. if sellerItem != nil {
  323. detail.SellerMobile = sellerItem.Mobile
  324. detail.SellerName = sellerItem.RealName
  325. }
  326. sellerList, err := models.GetSellerList(articleId)
  327. if err != nil {
  328. br.Msg = "获取信息失败"
  329. br.ErrMsg = "获取销售数据失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  330. return
  331. }
  332. if detail.ArticleId >= utils.SummaryArticleId && strings.Contains(detail.SellerAndMobile, "-") {
  333. strnum := strings.Index(detail.SellerAndMobile, "-")
  334. detail.SellerAndMobile = detail.SellerAndMobile[0:strnum]
  335. if strnum > 0 {
  336. nickName := detail.SellerAndMobile[0:strnum]
  337. sellerAndMobile := &models.SellerRep{
  338. SellerMobile: "",
  339. SellerName: nickName,
  340. }
  341. sellerList = append(sellerList, sellerAndMobile)
  342. }
  343. }
  344. detail.SellerList = sellerList
  345. } else { //潜在客户
  346. if applyCount > 0 {
  347. hasPermission = 5
  348. } else {
  349. hasPermission = 4
  350. }
  351. }
  352. Loop:
  353. if hasPermission != 1 && user.UserId > 0 {
  354. detail.Body = ""
  355. detail.BodyText = ""
  356. } else {
  357. articleFollowdetail, err := models.GetArticleFollowDetail(articleId, uid)
  358. if err != nil {
  359. br.Msg = "获取信息失败"
  360. br.ErrMsg = "获取关注信息失败,Err:" + err.Error()
  361. return
  362. }
  363. detail.FollowNum = articleFollowdetail.DNum
  364. detail.CollectionNum = articleFollowdetail.AcNum
  365. if articleFollowdetail.MdNum > 0 {
  366. detail.IsFollow = true
  367. }
  368. if detail.IsSummary == 1 {
  369. detail.IsBelongSummary = true
  370. }
  371. if detail.IsReport == 1 {
  372. detail.IsBelongReport = true
  373. }
  374. haveResearch = true
  375. }
  376. if hasPermission == 5 {
  377. companyPermissionNoStatus, err := models.GetCompanyPermissionByUserNoStatus(user.CompanyId)
  378. if err != nil {
  379. br.Msg = "获取信息失败"
  380. br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  381. return
  382. }
  383. if companyPermissionNoStatus != "" {
  384. sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  385. if err != nil && err.Error() != utils.ErrNoRow() {
  386. br.Msg = "获取信息失败"
  387. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  388. return
  389. }
  390. if sellerItemQy != nil {
  391. hasPermission = 3
  392. detail.SellerMobile = sellerItemQy.Mobile
  393. detail.SellerName = sellerItemQy.RealName
  394. }
  395. }
  396. }
  397. if hasPermission == 2 || hasPermission == 4 {
  398. //获取销售手机号
  399. sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  400. if err != nil && err.Error() != utils.ErrNoRow() {
  401. br.Msg = "获取信息失败"
  402. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  403. return
  404. }
  405. if sellerItemQy != nil {
  406. hasPermission = 3
  407. detail.SellerMobile = sellerItemQy.Mobile
  408. detail.SellerName = sellerItemQy.RealName
  409. }
  410. }
  411. if detail.ArticleId < utils.SummaryArticleId {
  412. if user.Mobile != "" {
  413. detail.HttpUrl = utils.StrategyPlatform + strconv.Itoa(articleId) + "?token="
  414. } else {
  415. detail.HttpUrl = utils.StrategyPlatform + strconv.Itoa(articleId)
  416. }
  417. detail.IsNeedJump = true
  418. }
  419. // 处理研选下面的路演精华 的报告链接是否跳转
  420. if hasPermission == 1 && detail.ArticleId > utils.SummaryArticleId && detail.ArticleTypeId > 0 {
  421. //detail.PublishDate = utils.TimeRemoveHms2(detail.PublishDate)
  422. if detail.ReportLink != "" {
  423. detail.ReportLink += "?token="
  424. }
  425. }
  426. if articleId < utils.SummaryArticleId {
  427. detail.Abstract, _ = services.GetReportContentTextSubNew(detail.Abstract)
  428. }
  429. if detail.ArticleTypeId == 14 {
  430. detail.IsApplyAppointmentExpert = true //判断文章类型是否属于专家访谈 查研观向11.0
  431. }
  432. resp.HasPermission = hasPermission
  433. resp.HaveResearch = haveResearch
  434. if user.UserId == 0 {
  435. resp.HasPermission = 1
  436. if detail.UpdateFrequency == "daily" {
  437. detail.Frequency = "日度"
  438. } else if detail.UpdateFrequency == "weekly" {
  439. detail.Frequency = "周度"
  440. } else if detail.UpdateFrequency == "monthly" {
  441. detail.Frequency = "月度"
  442. } else if detail.UpdateFrequency == "quarterly" {
  443. detail.Frequency = "季度"
  444. } else if detail.UpdateFrequency == "yearly" {
  445. detail.Frequency = "年度"
  446. }
  447. }
  448. resp.Detail = detail
  449. if user.Mobile != "" {
  450. resp.Mobile = user.Mobile
  451. } else {
  452. resp.Mobile = user.Email
  453. }
  454. br.Ret = 200
  455. br.Success = true
  456. br.Msg = "获取成功"
  457. br.Data = resp
  458. }
  459. // @Title 收藏
  460. // @Description 收藏
  461. // @Param request body models.ArticleCollectReq true "type json string"
  462. // @Success 200 {object} models.FontsCollectResp
  463. // @router /collect [post]
  464. func (this *ArticleController) ArticleCollect() {
  465. br := new(models.BaseResponse).Init()
  466. defer func() {
  467. this.Data["json"] = br
  468. this.ServeJSON()
  469. }()
  470. user := this.User
  471. if user == nil {
  472. br.Msg = "请重新登录"
  473. br.Ret = 408
  474. return
  475. }
  476. uid := user.UserId
  477. var req models.ArticleCollectReq
  478. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  479. if err != nil {
  480. br.Msg = "参数解析异常!"
  481. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  482. return
  483. }
  484. articleId := req.ArticleId
  485. detail, err := models.GetArticleDetailById(articleId)
  486. if err != nil {
  487. br.Msg = "获取信息失败"
  488. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  489. return
  490. }
  491. count, err := models.GetArticleCollectCount(uid, articleId)
  492. if err != nil {
  493. br.Msg = "获取数据失败!"
  494. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  495. return
  496. }
  497. resp := new(models.ArticleCollectResp)
  498. if count <= 0 {
  499. item := new(models.CygxArticleCollect)
  500. item.ArticleId = req.ArticleId
  501. item.UserId = uid
  502. item.CreateTime = time.Now()
  503. item.Mobile = user.Mobile
  504. item.Email = user.Email
  505. item.CompanyId = user.CompanyId
  506. item.CompanyName = user.CompanyName
  507. item.RealName = user.RealName
  508. _, err = models.AddCygxArticleCollect(item)
  509. if err != nil {
  510. br.Msg = "收藏失败"
  511. br.ErrMsg = "收藏失败,Err:" + err.Error()
  512. return
  513. }
  514. br.Msg = "收藏成功"
  515. resp.Status = 1
  516. // 文章收藏消息发送
  517. go services.ArticleUserRemind(user, detail, 2)
  518. go services.ArticleHistoryUserLabelLogAdd(articleId, user.UserId)
  519. // 互动提醒
  520. go services.SendWxCategoryMsgInteractive(user, "收藏报告", articleId)
  521. } else {
  522. err = models.RemoveArticleCollect(uid, articleId)
  523. if err != nil {
  524. br.Msg = "取消收藏失败"
  525. br.ErrMsg = "取消收藏失败,Err:" + err.Error()
  526. return
  527. }
  528. br.Msg = "已取消收藏"
  529. resp.Status = 2
  530. }
  531. collectTotal, err := models.GetArticleCollectUsersCount(articleId)
  532. if err != nil {
  533. br.Msg = "获取数据失败"
  534. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  535. return
  536. }
  537. resp.CollectCount = collectTotal
  538. br.Ret = 200
  539. br.Success = true
  540. br.Data = resp
  541. }
  542. // @Title 访谈申请
  543. // @Description 访谈申请
  544. // @Param request body models.ArticleInterviewApplyReq true "type json string"
  545. // @Success 200 {object} models.FontsCollectResp
  546. // @router /interview/apply [post]
  547. func (this *ArticleController) InterviewApply() {
  548. br := new(models.BaseResponse).Init()
  549. defer func() {
  550. this.Data["json"] = br
  551. this.ServeJSON()
  552. }()
  553. user := this.User
  554. if user == nil {
  555. br.Msg = "请重新登录"
  556. br.Ret = 408
  557. return
  558. }
  559. uid := user.UserId
  560. var req models.ArticleInterviewApplyReq
  561. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  562. if err != nil {
  563. br.Msg = "参数解析异常!"
  564. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  565. return
  566. }
  567. article, err := models.GetArticleDetailById(req.ArticleId)
  568. if err != nil {
  569. br.Msg = "获取纪要失败!"
  570. br.ErrMsg = "获取纪要失败,Err:" + err.Error()
  571. return
  572. }
  573. count, err := models.GetArticleInterviewApplyCount(uid, req.ArticleId)
  574. if err != nil {
  575. br.Msg = "获取数据失败!"
  576. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  577. return
  578. }
  579. resp := new(models.ArticleInterviewApplyResp)
  580. if count <= 0 {
  581. item := new(models.CygxInterviewApply)
  582. item.ArticleId = req.ArticleId
  583. item.UserId = uid
  584. item.CompanyId = user.CompanyId
  585. item.Status = "待邀请"
  586. item.Sort = 1
  587. item.ArticleTitle = article.Title
  588. item.CreateTime = time.Now()
  589. item.ModifyTime = time.Now()
  590. item.ArticleIdMd5 = article.ArticleIdMd5
  591. _, err = models.AddCygxInterviewApply(item)
  592. if err != nil {
  593. br.Msg = "申请失败"
  594. br.ErrMsg = "申请失败,Err:" + err.Error()
  595. return
  596. }
  597. br.Msg = "申请成功"
  598. resp.Status = 1
  599. //发送模板消息
  600. if user.CompanyId > 1 {
  601. mobile := user.Mobile
  602. if mobile == "" {
  603. mobile = user.Email
  604. }
  605. sellerItem, _ := models.GetSellerByCompanyId(user.CompanyId)
  606. if sellerItem != nil && sellerItem.AdminId > 0 && user.Mobile != "" {
  607. openIpItem, _ := models.GetUserRecordByMobile(4, sellerItem.Mobile)
  608. if openIpItem != nil && openIpItem.OpenId != "" {
  609. go services.SendInterviewApplyTemplateMsg(user.RealName, sellerItem.CompanyName, mobile, article.Title, openIpItem)
  610. }
  611. }
  612. }
  613. } else {
  614. err = models.RemoveArticleInterviewApply(uid, req.ArticleId)
  615. if err != nil {
  616. br.Msg = "取消申请失败"
  617. br.ErrMsg = "取消申请失败,Err:" + err.Error()
  618. return
  619. }
  620. br.Msg = "已取消申请"
  621. resp.Status = 2
  622. if user.CompanyId > 1 {
  623. mobile := user.Mobile
  624. if mobile == "" {
  625. mobile = user.Email
  626. }
  627. sellerItem, _ := models.GetSellerByCompanyId(user.CompanyId)
  628. if sellerItem != nil && sellerItem.AdminId > 0 && user.Mobile != "" {
  629. openIpItem, _ := models.GetUserRecordByMobile(4, sellerItem.Mobile)
  630. if openIpItem != nil && openIpItem.OpenId != "" {
  631. go services.SendInterviewApplyCancelTemplateMsg(user.RealName, sellerItem.CompanyName, mobile, article.Title, openIpItem)
  632. }
  633. }
  634. }
  635. }
  636. br.Ret = 200
  637. br.Success = true
  638. br.Data = resp
  639. }
  640. // @Title 上传文章阅读时间
  641. // @Description 上传文章阅读时间接口
  642. // @Param request body models.AddStopTimeRep true "type json string"
  643. // @Success 200 {object} models.ArticleDetailResp
  644. // @router /addStopTime [post]
  645. func (this *ArticleController) AddStopTime() {
  646. br := new(models.BaseResponse).Init()
  647. defer func() {
  648. this.Data["json"] = br
  649. this.ServeJSON()
  650. }()
  651. user := this.User
  652. if user == nil {
  653. br.Msg = "请登录"
  654. br.ErrMsg = "请登录,用户信息为空"
  655. br.Ret = 408
  656. return
  657. }
  658. var req models.AddStopTimeRep
  659. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  660. if err != nil {
  661. br.Msg = "参数解析异常!"
  662. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  663. return
  664. }
  665. uid := user.UserId
  666. articleId := req.ArticleId
  667. stopTime := req.StopTime
  668. outType := req.OutType
  669. source := req.Source
  670. if articleId <= 0 {
  671. br.Msg = "参数错误"
  672. br.ErrMsg = "参数错误"
  673. return
  674. }
  675. if stopTime == 0 {
  676. stopTime = 1
  677. }
  678. if outType != 2 {
  679. outType = 1
  680. }
  681. if source != "PC" {
  682. source = "MOBILE"
  683. }
  684. detail := new(models.ArticleDetail)
  685. hasPermission := 0
  686. hasFree := 0
  687. //判断是否已经申请过
  688. applyCount, err := models.GetApplyRecordCount(uid)
  689. if err != nil && err.Error() != utils.ErrNoRow() {
  690. br.Msg = "获取信息失败"
  691. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  692. return
  693. }
  694. //`description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,4:潜在客户,未提交过申请,5:潜在客户,已提交过申请"`
  695. if user.CompanyId > 1 {
  696. companyPermission, err := models.GetCompanyPermission(user.CompanyId)
  697. if err != nil {
  698. br.Msg = "获取信息失败"
  699. br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  700. return
  701. }
  702. detail, err = models.GetArticleDetailById(articleId)
  703. if err != nil {
  704. br.Msg = "获取信息失败"
  705. br.ErrMsg = "获取文章信息失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  706. return
  707. }
  708. if companyPermission == "" {
  709. if applyCount > 0 {
  710. hasPermission = 5
  711. } else {
  712. hasPermission = 2
  713. }
  714. hasFree = 2
  715. goto Loop
  716. } else {
  717. hasFree = 1
  718. var articlePermissionPermissionName string
  719. if detail.CategoryId > 0 {
  720. articlePermission, err := models.GetArticlePermission(detail.CategoryId)
  721. if err != nil {
  722. br.Msg = "获取信息失败"
  723. br.ErrMsg = "获取报告权限失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  724. return
  725. }
  726. if articlePermission == nil {
  727. br.Msg = "获取信息失败"
  728. br.ErrMsg = "报告权限不存在,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  729. return
  730. }
  731. articlePermissionPermissionName = articlePermission.PermissionName
  732. } else {
  733. articlePermissionPermissionName = detail.CategoryName
  734. }
  735. var hasPersion bool
  736. slice := strings.Split(articlePermissionPermissionName, ",")
  737. //判断用户是否开通了个人研选权限,如果有权限后缀拼接权限名称
  738. mfyxUserPermissionTotal := services.GetMfyxUserPermissionTotal(uid)
  739. if mfyxUserPermissionTotal == 1 {
  740. companyPermission += "," + utils.CHART_PERMISSION_NAME_MF_YANXUAN
  741. companyPermission += "," + utils.MAI_FANG_YAN_XUAN_NAME
  742. }
  743. //如果有研选订阅的权限,那么就拼接一个 买方研选的权限做校验
  744. if strings.Contains(companyPermission, utils.CHART_PERMISSION_NAME_MF_YANXUAN) {
  745. companyPermission += "," + utils.MAI_FANG_YAN_XUAN_NAME
  746. }
  747. for _, v := range slice {
  748. if strings.Contains(companyPermission, v) {
  749. hasPersion = true
  750. }
  751. }
  752. if hasPersion {
  753. go services.ArticleHistoryStopTime(articleId, stopTime, outType, user)
  754. } else { //无该行业权限
  755. hasPermission = 3
  756. }
  757. }
  758. } else { //潜在客户
  759. if applyCount > 0 {
  760. hasPermission = 5
  761. } else {
  762. hasPermission = 4
  763. }
  764. }
  765. Loop:
  766. resp := new(models.ArticleDetailAddStopTimeRep)
  767. resp.HasPermission = hasPermission
  768. resp.HasFree = hasFree
  769. br.Ret = 200
  770. br.Success = true
  771. br.Msg = "操作成功"
  772. br.Data = resp
  773. }
  774. // @Title 文章带问
  775. // @Description 新增文章带问接口
  776. // @Param request body models.AddArticleAskRep true "type json string"
  777. // @Success Ret=200 新增成功
  778. // @router /askAdd [post]
  779. func (this *ArticleController) AskAdd() {
  780. br := new(models.BaseResponse).Init()
  781. defer func() {
  782. this.Data["json"] = br
  783. this.ServeJSON()
  784. }()
  785. user := this.User
  786. if user == nil {
  787. br.Msg = "请登录"
  788. br.ErrMsg = "请登录,SysUser Is Empty"
  789. br.Ret = 408
  790. return
  791. }
  792. var req models.AddArticleAskRep
  793. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  794. if err != nil {
  795. br.Msg = "参数解析异常!"
  796. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  797. return
  798. }
  799. if req.Content == "" {
  800. br.Msg = "建议内容不可为空"
  801. return
  802. }
  803. content := req.Content
  804. itemToken, err := services.WxGetToken()
  805. if err != nil {
  806. br.Msg = "GetWxAccessToken Err:" + err.Error()
  807. return
  808. }
  809. if itemToken.AccessToken == "" {
  810. br.Msg = "accessToken is empty"
  811. return
  812. }
  813. commerr, err := weapp.MSGSecCheck(itemToken.AccessToken, content)
  814. if err != nil {
  815. br.Msg = "内容校验失败!"
  816. br.ErrMsg = "内容校验失败,Err:" + err.Error()
  817. return
  818. }
  819. if commerr.ErrCode != 0 {
  820. br.Msg = "内容违规,请重新提交!"
  821. br.ErrMsg = "颜文字内容违规,Err:" + commerr.ErrMSG
  822. return
  823. }
  824. articleId := req.ArticleId
  825. count, _ := models.GetArticleCountById(articleId)
  826. if count == 0 {
  827. br.Msg = "操作失败"
  828. br.ErrMsg = "文章ID错误,不存在 articleId:" + strconv.Itoa(articleId)
  829. return
  830. }
  831. companyDetail, err := models.GetCompanyDetailById(user.CompanyId)
  832. if err != nil {
  833. br.Msg = "提交失败!"
  834. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  835. return
  836. }
  837. if companyDetail == nil {
  838. br.Msg = "提交失败!"
  839. br.ErrMsg = "客户不存在,uid:" + strconv.Itoa(user.UserId)
  840. return
  841. }
  842. item := new(models.CygxArticleAsk)
  843. item.UserId = user.UserId
  844. item.ArticleId = req.ArticleId
  845. item.CompanyId = user.CompanyId
  846. item.CompanyName = companyDetail.CompanyName
  847. item.CreateTime = time.Now()
  848. item.Mobile = user.Mobile
  849. item.Email = user.Email
  850. item.Content = content
  851. _, err = models.AddArticleAsk(item)
  852. if err != nil {
  853. br.Msg = "提交失败"
  854. br.ErrMsg = "提交失败,Err:" + err.Error()
  855. return
  856. }
  857. companyItem, err := models.GetSellerDetailAllByCompanyId(user.CompanyId)
  858. if err != nil {
  859. br.Msg = "获取信息失败"
  860. br.ErrMsg = "获取所属销售信息失败,Err:" + err.Error()
  861. return
  862. }
  863. var mobile string
  864. if utils.RunMode == "release" {
  865. mobile = utils.WxMsgTemplateIdAskMsgMobileAll+ "," + companyItem.Mobile
  866. } else {
  867. mobile = utils.WxMsgTemplateIdAskMsgMobile+ "," + companyItem.Mobile
  868. }
  869. openIdList, err := models.GetWxOpenIdByMobileList(mobile)
  870. if err != nil {
  871. br.Msg = "提交失败"
  872. br.ErrMsg = "提交失败,Err:" + err.Error()
  873. return
  874. }
  875. detail, err := models.GetArticleDetailById(articleId)
  876. if err != nil {
  877. br.Msg = "获取信息失败"
  878. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  879. return
  880. }
  881. companyName := user.CompanyName + "-" + user.RealName + "(" + companyItem.SellerName + ")"
  882. go services.SendWxMsgWithAsk(companyName, time.Now().Format(utils.FormatDateTime), content, detail.Title, openIdList, req.ArticleId)
  883. //go services.SendWxCategoryMsgWithAsk(user.CompanyName, user.RealName, companyItem.SellerName, time.Now().Format(utils.FormatDateTimeMinute2), content, openIdList, req.ArticleId)
  884. br.Ret = 200
  885. br.Success = true
  886. br.Msg = "提交成功"
  887. }
  888. // @Title 下载PDF打水印
  889. // @Description 下载PDF打水印接口
  890. // @Param ArticleId query int true "报告ID"
  891. // @Success 200 {object} models.ArticleDetailFileLink
  892. // @router /pdfwatermark [get]
  893. func (this *ArticleController) Pdfwatermark() {
  894. br := new(models.BaseResponse).Init()
  895. defer func() {
  896. this.Data["json"] = br
  897. this.ServeJSON()
  898. }()
  899. user := this.User
  900. if user == nil {
  901. br.Msg = "请登录"
  902. br.ErrMsg = "请登录,用户信息为空"
  903. br.Ret = 408
  904. return
  905. }
  906. uid := user.UserId
  907. articleId, err := this.GetInt("ArticleId")
  908. if articleId <= 0 {
  909. br.Msg = "文章不存在"
  910. br.ErrMsg = "文章不存在,文章ID错误"
  911. return
  912. }
  913. //缓存校验
  914. cacheKey := fmt.Sprint("xygx:apply_record:add:", uid, "ArticleId_", articleId)
  915. ttlTime := utils.Rc.GetRedisTTL(cacheKey)
  916. if ttlTime > 0 && user.CompanyId != 16 {
  917. br.Msg = "下载失败,下载过于频繁"
  918. br.ErrMsg = "下载失败,下载过于频繁:mobile" + user.Mobile
  919. return
  920. }
  921. resp := new(models.ArticleDetailFileLink)
  922. detail := new(models.ArticleDetail)
  923. detail, err = models.GetArticleDetailById(articleId)
  924. if err != nil {
  925. br.Msg = "获取信息失败"
  926. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  927. return
  928. }
  929. fileLink := detail.FileLink
  930. if fileLink == "" {
  931. br.Msg = "下载失败"
  932. br.ErrMsg = "下载失败,报告链接不存在"
  933. return
  934. }
  935. mobile := user.Mobile
  936. if mobile == "" {
  937. mobile = user.Email
  938. }
  939. sliceLink := strings.Split(fileLink, "/")
  940. uploadDir := "static/pdf/"
  941. //判断文件夹是否存在,不存在则创建
  942. if !utils.FileIsExist(uploadDir) {
  943. err = os.MkdirAll(uploadDir, 0755)
  944. if err != nil {
  945. br.Msg = "下载失败"
  946. br.ErrMsg = "存储目录创建失败,Err:" + err.Error()
  947. return
  948. }
  949. }
  950. var oldFile string
  951. var newFile string
  952. //获取PDF源文件名称
  953. pdfName := sliceLink[len(sliceLink)-1]
  954. pdfName = utils.MD5(pdfName) + ".pdf"
  955. oldFile = uploadDir + pdfName
  956. //判断PDF本地是否存在,不存在则保存到本地
  957. if !utils.FileIsExist(oldFile) {
  958. res, err := nhttp.Get(fileLink)
  959. if err != nil {
  960. br.Msg = "下载失败"
  961. br.ErrMsg = "获取源文件失败,Err:" + err.Error()
  962. return
  963. }
  964. defer res.Body.Close()
  965. // 获得get请求响应的reader对象
  966. reader := bufio.NewReaderSize(res.Body, 32*1024)
  967. file, err := os.Create(oldFile)
  968. if err != nil {
  969. br.Msg = "下载失败"
  970. br.ErrMsg = "保存源文件到本地失败,Err:" + err.Error()
  971. return
  972. }
  973. defer file.Close()
  974. //获得文件的writer对象
  975. writer := bufio.NewWriter(file)
  976. written, _ := io.Copy(writer, reader)
  977. fmt.Printf("Total length: %d", written)
  978. }
  979. newFile = uploadDir + "new_" + pdfName
  980. onTop := true
  981. wm, err := pdfcpu.ParseTextWatermarkDetails(mobile, " op:.4, pos:c ,points:16 ", onTop, 1)
  982. if err != nil {
  983. br.Msg = "下载失败"
  984. br.ErrMsg = "生成水印文件失败,Err:" + err.Error()
  985. return
  986. }
  987. err = api.AddWatermarksFile(oldFile, newFile, nil, wm, nil)
  988. if err != nil {
  989. //br.Msg = "下载失败"
  990. //br.ErrMsg = "生成水印PDF失败,Err:" + err.Error()
  991. resp.FileLink = fileLink
  992. br.Ret = 200
  993. br.Success = true
  994. br.Msg = "获取成功"
  995. br.Data = resp
  996. return
  997. }
  998. randStr := utils.GetRandStringNoSpecialChar(28)
  999. fileName := randStr + ".pdf"
  1000. savePath := uploadDir + time.Now().Format("200601/20060102/")
  1001. savePath += fileName
  1002. //上传到阿里云
  1003. err = services.UploadFileToAliyun(fileName, newFile, savePath)
  1004. if err != nil {
  1005. br.Msg = "下载失败"
  1006. br.ErrMsg = "文件上传失败,Err:" + err.Error()
  1007. return
  1008. }
  1009. fileHost := "https://hzstatic.hzinsights.com/"
  1010. resourceUrl := fileHost + savePath
  1011. defer func() {
  1012. os.Remove(newFile)
  1013. }()
  1014. utils.Rc.SetNX(cacheKey, user.Mobile, time.Minute*5)
  1015. resp.FileLink = resourceUrl
  1016. br.Ret = 200
  1017. br.Success = true
  1018. br.Msg = "获取成功"
  1019. br.Data = resp
  1020. }
  1021. // @Title 约访专家
  1022. // @Description 约访专家接口
  1023. // @Param request body models.CygxArticleIdReq true "type json string"
  1024. // @Success 200 {object}
  1025. // @router /applyAppointmentExpert [post]
  1026. func (this *ArticleController) ApplyAppointmentExpert() {
  1027. br := new(models.BaseResponse).Init()
  1028. defer func() {
  1029. this.Data["json"] = br
  1030. this.ServeJSON()
  1031. }()
  1032. user := this.User
  1033. if user == nil {
  1034. br.Msg = "请登录"
  1035. br.ErrMsg = "请登录,用户信息为空"
  1036. br.Ret = 408
  1037. return
  1038. }
  1039. fmt.Println(user)
  1040. var req models.CygxArticleIdReq
  1041. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1042. if err != nil {
  1043. br.Msg = "参数解析异常!"
  1044. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1045. return
  1046. }
  1047. articleId := req.ArticleId
  1048. var condition string
  1049. var pars []interface{}
  1050. condition += ` AND article_id =? AND user_id = ? `
  1051. pars = append(pars, articleId, user.UserId)
  1052. total, err := models.GetCygxArticleApplyAppointmentExpertCount(condition, pars)
  1053. if err != nil {
  1054. br.Msg = "约访专家失败"
  1055. br.ErrMsg = "约访专家失败,Err:" + err.Error()
  1056. return
  1057. }
  1058. if total > 0 {
  1059. br.Msg = "您已提交申请,请勿重复提交。"
  1060. return
  1061. }
  1062. err = services.AddArticleApplyAppointmentExpert(user, articleId)
  1063. if err != nil {
  1064. br.Msg = "约访专家失败"
  1065. br.ErrMsg = "约访专家失败,Err:" + err.Error()
  1066. return
  1067. }
  1068. services.SendArticleApplyAppointmentExpertTemplateMsg(user, articleId)
  1069. br.Ret = 200
  1070. br.Success = true
  1071. br.Msg = "操作成功"
  1072. }