article.go 34 KB

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