article.go 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259
  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. if companyPermission == "" {
  202. if applyCount > 0 {
  203. hasPermission = 5
  204. } else {
  205. hasPermission = 2
  206. }
  207. goto Loop
  208. } else {
  209. var articlePermissionName string
  210. if detail.CategoryId > 0 {
  211. articlePermission, err := models.GetArticlePermission(detail.CategoryId)
  212. if err != nil {
  213. br.Msg = "获取信息失败"
  214. br.ErrMsg = "获取报告权限失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  215. return
  216. }
  217. if articlePermission == nil {
  218. br.Msg = "获取信息失败"
  219. br.ErrMsg = "报告权限不存在,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  220. return
  221. }
  222. articlePermissionName = articlePermission.PermissionName
  223. } else {
  224. articlePermissionName = detail.CategoryName
  225. }
  226. var hasPersion bool
  227. slice := strings.Split(articlePermissionName, ",")
  228. for _, v := range slice {
  229. if strings.Contains(companyPermission, v) {
  230. hasPersion = true
  231. }
  232. }
  233. if strings.Contains(detail.CategoryName, "研选") {
  234. detail.IsResearch = true
  235. }
  236. userType, _, err := services.GetUserType(user.CompanyId)
  237. if err != nil {
  238. br.Msg = "获取信息失败"
  239. br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
  240. return
  241. }
  242. if userType == 1 && strings.Contains(detail.CategoryName, "研选") {
  243. hasPersion = false
  244. }
  245. //if detail.IsReport == 1 {
  246. //detailCategory, err := models.GetdetailByCategoryIdSando(detail.CategoryId)
  247. //if err != nil && err.Error() != utils.ErrNoRow() {
  248. // br.Msg = "获取信息失败"
  249. // br.ErrMsg = "获取信息失败,Err:" + err.Error() + "categoryID 不存在:" + strconv.Itoa(detail.CategoryId)
  250. // return
  251. //}
  252. //permissionStr, err := models.GetCompanyPermissionByUser(user.CompanyId)
  253. //if err != nil {
  254. // br.Msg = "获取信息失败"
  255. // br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  256. // return
  257. //}
  258. //if detailCategory != nil {
  259. // if detailCategory.PermissionType == 1 {
  260. // if !strings.Contains(permissionStr, detailCategory.ChartPermissionName+"(主观)") {
  261. // hasPersion = false
  262. // }
  263. // } else if detailCategory.PermissionType == 2 {
  264. // if !strings.Contains(permissionStr, detailCategory.ChartPermissionName+"(客观)") {
  265. // hasPersion = false
  266. // }
  267. // }
  268. //}
  269. //}
  270. //大行业通过权限校验,再校验主客观权限。只有医药、消费、科技、智造,才会校验主客观权限
  271. if hasPersion && utils.InArrayByStr([]string{utils.YI_YAO_NAME, utils.XIAO_FEI_NAME, utils.KE_JI_NAME, utils.ZHI_ZAO_NAME}, articlePermissionName) {
  272. hasPersion = services.CheckArticlePermissionType(articleId, user)
  273. }
  274. if hasPersion {
  275. hasPermission = 1
  276. go services.ArticleHistory(articleId, user)
  277. //30分钟之内阅读同一篇文章不错二次推送
  278. key := "CYGX_ARTICLE_READ" + strconv.Itoa(articleId) + "_" + strconv.Itoa(uid)
  279. if !utils.Rc.IsExist(key) {
  280. go services.ArticleUserRemind(user, detail, 1)
  281. utils.Rc.Put(key, 1, 30*time.Second)
  282. }
  283. } else { //无该行业权限
  284. companyDetail, err := models.GetCompanyDetailById(user.CompanyId)
  285. if err == nil && companyDetail.ProductId == 1 {
  286. hasPermission = 2
  287. } else {
  288. hasPermission = 3
  289. }
  290. }
  291. }
  292. interviewApplyItem, err := models.GetArticleInterviewApply(uid, articleId)
  293. if err != nil && err.Error() != utils.ErrNoRow() {
  294. br.Msg = "获取信息失败"
  295. br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  296. return
  297. }
  298. if interviewApplyItem != nil && interviewApplyItem.InterviewApplyId > 0 {
  299. detail.IsInterviewApply = true
  300. detail.InterviewApplyStatus = interviewApplyItem.Status
  301. }
  302. //获取销售手机号
  303. sellerItem, err := models.GetSellerByCompanyId(user.CompanyId)
  304. if err != nil && err.Error() != utils.ErrNoRow() {
  305. br.Msg = "获取信息失败"
  306. br.ErrMsg = "获取销售数据失败2,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  307. return
  308. }
  309. if sellerItem != nil {
  310. detail.SellerMobile = sellerItem.Mobile
  311. detail.SellerName = sellerItem.RealName
  312. }
  313. sellerList, err := models.GetSellerList(articleId)
  314. if err != nil {
  315. br.Msg = "获取信息失败"
  316. br.ErrMsg = "获取销售数据失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  317. return
  318. }
  319. if detail.ArticleId >= utils.SummaryArticleId && strings.Contains(detail.SellerAndMobile, "-") {
  320. strnum := strings.Index(detail.SellerAndMobile, "-")
  321. detail.SellerAndMobile = detail.SellerAndMobile[0:strnum]
  322. if strnum > 0 {
  323. nickName := detail.SellerAndMobile[0:strnum]
  324. sellerAndMobile := &models.SellerRep{
  325. SellerMobile: "",
  326. SellerName: nickName,
  327. }
  328. sellerList = append(sellerList, sellerAndMobile)
  329. }
  330. }
  331. detail.SellerList = sellerList
  332. } else { //潜在客户
  333. if applyCount > 0 {
  334. hasPermission = 5
  335. } else {
  336. hasPermission = 4
  337. }
  338. }
  339. Loop:
  340. if hasPermission != 1 && user.UserId > 0 {
  341. detail.Body = ""
  342. detail.BodyText = ""
  343. } else {
  344. articleFollowdetail, err := models.GetArticleFollowDetail(articleId, uid)
  345. if err != nil {
  346. br.Msg = "获取信息失败"
  347. br.ErrMsg = "获取关注信息失败,Err:" + err.Error()
  348. return
  349. }
  350. detail.FollowNum = articleFollowdetail.DNum
  351. detail.CollectionNum = articleFollowdetail.AcNum
  352. if articleFollowdetail.MdNum > 0 {
  353. detail.IsFollow = true
  354. }
  355. if detail.IsSummary == 1 {
  356. detail.IsBelongSummary = true
  357. }
  358. if detail.IsReport == 1 {
  359. detail.IsBelongReport = true
  360. }
  361. haveResearch = true
  362. }
  363. if hasPermission == 5 {
  364. companyPermissionNoStatus, err := models.GetCompanyPermissionByUserNoStatus(user.CompanyId)
  365. if err != nil {
  366. br.Msg = "获取信息失败"
  367. br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  368. return
  369. }
  370. if companyPermissionNoStatus != "" {
  371. sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  372. if err != nil && err.Error() != utils.ErrNoRow() {
  373. br.Msg = "获取信息失败"
  374. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  375. return
  376. }
  377. if sellerItemQy != nil {
  378. hasPermission = 3
  379. detail.SellerMobile = sellerItemQy.Mobile
  380. detail.SellerName = sellerItemQy.RealName
  381. }
  382. }
  383. }
  384. if hasPermission == 2 || hasPermission == 4 {
  385. //获取销售手机号
  386. sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  387. if err != nil && err.Error() != utils.ErrNoRow() {
  388. br.Msg = "获取信息失败"
  389. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  390. return
  391. }
  392. if sellerItemQy != nil {
  393. hasPermission = 3
  394. detail.SellerMobile = sellerItemQy.Mobile
  395. detail.SellerName = sellerItemQy.RealName
  396. }
  397. }
  398. if detail.ArticleId < utils.SummaryArticleId {
  399. if user.Mobile != "" {
  400. detail.HttpUrl = utils.StrategyPlatform + strconv.Itoa(articleId) + "?token="
  401. } else {
  402. detail.HttpUrl = utils.StrategyPlatform + strconv.Itoa(articleId)
  403. }
  404. detail.IsNeedJump = true
  405. }
  406. // 处理研选下面的路演精华 的报告链接是否跳转
  407. if hasPermission == 1 && detail.ArticleId > utils.SummaryArticleId && detail.ArticleTypeId > 0 {
  408. //detail.PublishDate = utils.TimeRemoveHms2(detail.PublishDate)
  409. if detail.ReportLink != "" {
  410. detail.ReportLink += "?token="
  411. }
  412. }
  413. if articleId < utils.SummaryArticleId {
  414. detail.Abstract, _ = services.GetReportContentTextSubNew(detail.Abstract)
  415. }
  416. if detail.ArticleTypeId == 14 {
  417. detail.IsApplyAppointmentExpert = true //判断文章类型是否属于专家访谈 查研观向11.0
  418. }
  419. resp.HasPermission = hasPermission
  420. resp.HaveResearch = haveResearch
  421. if user.UserId == 0 {
  422. resp.HasPermission = 1
  423. if detail.UpdateFrequency == "daily" {
  424. detail.Frequency = "日度"
  425. } else if detail.UpdateFrequency == "weekly" {
  426. detail.Frequency = "周度"
  427. } else if detail.UpdateFrequency == "monthly" {
  428. detail.Frequency = "月度"
  429. } else if detail.UpdateFrequency == "quarterly" {
  430. detail.Frequency = "季度"
  431. } else if detail.UpdateFrequency == "yearly" {
  432. detail.Frequency = "年度"
  433. }
  434. }
  435. resp.Detail = detail
  436. if user.Mobile != "" {
  437. resp.Mobile = user.Mobile
  438. } else {
  439. resp.Mobile = user.Email
  440. }
  441. br.Ret = 200
  442. br.Success = true
  443. br.Msg = "获取成功"
  444. br.Data = resp
  445. }
  446. // @Title 收藏
  447. // @Description 收藏
  448. // @Param request body models.ArticleCollectReq true "type json string"
  449. // @Success 200 {object} models.FontsCollectResp
  450. // @router /collect [post]
  451. func (this *ArticleController) ArticleCollect() {
  452. br := new(models.BaseResponse).Init()
  453. defer func() {
  454. this.Data["json"] = br
  455. this.ServeJSON()
  456. }()
  457. user := this.User
  458. if user == nil {
  459. br.Msg = "请重新登录"
  460. br.Ret = 408
  461. return
  462. }
  463. uid := user.UserId
  464. var req models.ArticleCollectReq
  465. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  466. if err != nil {
  467. br.Msg = "参数解析异常!"
  468. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  469. return
  470. }
  471. articleId := req.ArticleId
  472. detail, err := models.GetArticleDetailById(articleId)
  473. if err != nil {
  474. br.Msg = "获取信息失败"
  475. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  476. return
  477. }
  478. count, err := models.GetArticleCollectCount(uid, articleId)
  479. if err != nil {
  480. br.Msg = "获取数据失败!"
  481. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  482. return
  483. }
  484. resp := new(models.ArticleCollectResp)
  485. if count <= 0 {
  486. item := new(models.CygxArticleCollect)
  487. item.ArticleId = req.ArticleId
  488. item.UserId = uid
  489. item.CreateTime = time.Now()
  490. item.Mobile = user.Mobile
  491. item.Email = user.Email
  492. item.CompanyId = user.CompanyId
  493. item.CompanyName = user.CompanyName
  494. item.RealName = user.RealName
  495. _, err = models.AddCygxArticleCollect(item)
  496. if err != nil {
  497. br.Msg = "收藏失败"
  498. br.ErrMsg = "收藏失败,Err:" + err.Error()
  499. return
  500. }
  501. br.Msg = "收藏成功"
  502. resp.Status = 1
  503. // 文章收藏消息发送
  504. go services.ArticleUserRemind(user, detail, 2)
  505. go services.ArticleHistoryUserLabelLogAdd(articleId, user.UserId)
  506. } else {
  507. err = models.RemoveArticleCollect(uid, articleId)
  508. if err != nil {
  509. br.Msg = "取消收藏失败"
  510. br.ErrMsg = "取消收藏失败,Err:" + err.Error()
  511. return
  512. }
  513. br.Msg = "已取消收藏"
  514. resp.Status = 2
  515. }
  516. collectTotal, err := models.GetArticleCollectUsersCount(articleId)
  517. if err != nil {
  518. br.Msg = "获取数据失败"
  519. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  520. return
  521. }
  522. resp.CollectCount = collectTotal
  523. br.Ret = 200
  524. br.Success = true
  525. br.Data = resp
  526. }
  527. // @Title 访谈申请
  528. // @Description 访谈申请
  529. // @Param request body models.ArticleInterviewApplyReq true "type json string"
  530. // @Success 200 {object} models.FontsCollectResp
  531. // @router /interview/apply [post]
  532. func (this *ArticleController) InterviewApply() {
  533. br := new(models.BaseResponse).Init()
  534. defer func() {
  535. this.Data["json"] = br
  536. this.ServeJSON()
  537. }()
  538. user := this.User
  539. if user == nil {
  540. br.Msg = "请重新登录"
  541. br.Ret = 408
  542. return
  543. }
  544. uid := user.UserId
  545. var req models.ArticleInterviewApplyReq
  546. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  547. if err != nil {
  548. br.Msg = "参数解析异常!"
  549. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  550. return
  551. }
  552. article, err := models.GetArticleDetailById(req.ArticleId)
  553. if err != nil {
  554. br.Msg = "获取纪要失败!"
  555. br.ErrMsg = "获取纪要失败,Err:" + err.Error()
  556. return
  557. }
  558. count, err := models.GetArticleInterviewApplyCount(uid, req.ArticleId)
  559. if err != nil {
  560. br.Msg = "获取数据失败!"
  561. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  562. return
  563. }
  564. resp := new(models.ArticleInterviewApplyResp)
  565. if count <= 0 {
  566. item := new(models.CygxInterviewApply)
  567. item.ArticleId = req.ArticleId
  568. item.UserId = uid
  569. item.CompanyId = user.CompanyId
  570. item.Status = "待邀请"
  571. item.Sort = 1
  572. item.ArticleTitle = article.Title
  573. item.CreateTime = time.Now()
  574. item.ModifyTime = time.Now()
  575. item.ArticleIdMd5 = article.ArticleIdMd5
  576. _, err = models.AddCygxInterviewApply(item)
  577. if err != nil {
  578. br.Msg = "申请失败"
  579. br.ErrMsg = "申请失败,Err:" + err.Error()
  580. return
  581. }
  582. br.Msg = "申请成功"
  583. resp.Status = 1
  584. //发送模板消息
  585. if user.CompanyId > 1 {
  586. mobile := user.Mobile
  587. if mobile == "" {
  588. mobile = user.Email
  589. }
  590. sellerItem, _ := models.GetSellerByCompanyId(user.CompanyId)
  591. if sellerItem != nil && sellerItem.AdminId > 0 && user.Mobile != "" {
  592. openIpItem, _ := models.GetUserRecordByMobile(4, sellerItem.Mobile)
  593. if openIpItem != nil && openIpItem.OpenId != "" {
  594. go services.SendInterviewApplyTemplateMsg(user.RealName, sellerItem.CompanyName, mobile, article.Title, openIpItem)
  595. }
  596. }
  597. }
  598. } else {
  599. err = models.RemoveArticleInterviewApply(uid, req.ArticleId)
  600. if err != nil {
  601. br.Msg = "取消申请失败"
  602. br.ErrMsg = "取消申请失败,Err:" + err.Error()
  603. return
  604. }
  605. br.Msg = "已取消申请"
  606. resp.Status = 2
  607. if user.CompanyId > 1 {
  608. mobile := user.Mobile
  609. if mobile == "" {
  610. mobile = user.Email
  611. }
  612. sellerItem, _ := models.GetSellerByCompanyId(user.CompanyId)
  613. if sellerItem != nil && sellerItem.AdminId > 0 && user.Mobile != "" {
  614. openIpItem, _ := models.GetUserRecordByMobile(4, sellerItem.Mobile)
  615. if openIpItem != nil && openIpItem.OpenId != "" {
  616. go services.SendInterviewApplyCancelTemplateMsg(user.RealName, sellerItem.CompanyName, mobile, article.Title, openIpItem)
  617. }
  618. }
  619. }
  620. }
  621. br.Ret = 200
  622. br.Success = true
  623. br.Data = resp
  624. }
  625. // @Title 获取报告详情
  626. // @Description 获取报告详情接口
  627. // @Param ArticleIdMd5 query int true "报告ID"
  628. // @Success 200 {object} models.ArticleDetailResp
  629. // @router /look/detail [get]
  630. func (this *ArticleControllerMobile) DetailMd5() {
  631. br := new(models.BaseResponse).Init()
  632. defer func() {
  633. this.Data["json"] = br
  634. this.ServeJSON()
  635. }()
  636. user := this.User
  637. if user == nil {
  638. br.Msg = "请登录"
  639. br.ErrMsg = "请登录,用户信息为空"
  640. br.Ret = 408
  641. return
  642. }
  643. uid := user.UserId
  644. articleIdMd5 := this.GetString("ArticleIdMd5")
  645. if articleIdMd5 == "" {
  646. br.Msg = "参数错误"
  647. br.ErrMsg = "参数错误"
  648. return
  649. }
  650. resp := new(models.ArticleDetailResp)
  651. detail, err := models.GetArticleDetailByIdMd5(articleIdMd5)
  652. if err != nil {
  653. br.Msg = "获取信息失败"
  654. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  655. return
  656. }
  657. articleId := detail.ArticleId
  658. detail.Body = html.UnescapeString(detail.Body)
  659. hasPermission := 2
  660. //`description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,4:潜在客户,未提交过申请,5:潜在客户,已提交过申请"`
  661. if user.CompanyId > 1 {
  662. companyPermission, err := models.GetCompanyPermission(user.CompanyId)
  663. if err != nil {
  664. br.Msg = "获取信息失败"
  665. br.ErrMsg = "获取公司权限失败,Err:" + err.Error()
  666. return
  667. }
  668. detail.Body = html.UnescapeString(detail.Body)
  669. 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)
  670. detail.Body = strings.Replace(detail.Body, "pre", "div", -1)
  671. detail.Abstract, _ = services.GetReportContentTextSubNew(detail.Abstract)
  672. if companyPermission == "" {
  673. hasPermission = 2
  674. } else {
  675. var articlePermissionPermissionName string
  676. if detail.CategoryId > 0 {
  677. articlePermission, err := models.GetArticlePermission(detail.CategoryId)
  678. if err != nil {
  679. br.Msg = "获取信息失败"
  680. br.ErrMsg = "获取报告权限失败,Err:" + err.Error() + articleIdMd5
  681. return
  682. }
  683. if articlePermission == nil {
  684. br.Msg = "获取信息失败"
  685. br.ErrMsg = "报告权限不存在,Err:" + articleIdMd5
  686. return
  687. }
  688. articlePermissionPermissionName = articlePermission.PermissionName
  689. } else {
  690. articlePermissionPermissionName = detail.CategoryName
  691. }
  692. var hasPersion bool
  693. slice := strings.Split(articlePermissionPermissionName, ",")
  694. for _, v := range slice {
  695. if strings.Contains(companyPermission, v) {
  696. hasPersion = true
  697. }
  698. }
  699. userType, _, err := services.GetUserType(user.CompanyId)
  700. if err != nil {
  701. br.Msg = "获取信息失败"
  702. br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
  703. return
  704. }
  705. if userType == 1 && strings.Contains(detail.CategoryName, "研选") {
  706. hasPersion = false
  707. }
  708. if detail.IsReport == 1 {
  709. detailCategory, err := models.GetdetailByCategoryIdSando(detail.CategoryId)
  710. if err != nil && err.Error() != utils.ErrNoRow() {
  711. br.Msg = "获取信息失败"
  712. br.ErrMsg = "获取信息失败,Err:" + err.Error() + "categoryID 不存在:" + strconv.Itoa(detail.CategoryId)
  713. return
  714. }
  715. permissionStr, err := models.GetCompanyPermissionByUser(user.CompanyId)
  716. if err != nil {
  717. br.Msg = "获取信息失败"
  718. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  719. return
  720. }
  721. if detailCategory != nil {
  722. if detailCategory.PermissionType == 1 {
  723. if !strings.Contains(permissionStr, detailCategory.ChartPermissionName+"(主观)") {
  724. hasPersion = false
  725. }
  726. } else if detailCategory.PermissionType == 2 {
  727. if !strings.Contains(permissionStr, detailCategory.ChartPermissionName+"(客观)") {
  728. hasPersion = false
  729. }
  730. }
  731. }
  732. }
  733. if hasPersion {
  734. hasPermission = 1
  735. record := new(models.CygxArticleHistoryRecordNewpv)
  736. record.UserId = uid
  737. record.ArticleId = articleId
  738. record.CreateTime = time.Now()
  739. record.ModifyTime = time.Now()
  740. record.Mobile = user.Mobile
  741. record.Email = user.Email
  742. record.CompanyId = user.CompanyId
  743. record.CompanyName = user.CompanyName
  744. //新增浏览记录
  745. go models.AddCygxArticleViewRecordNewpv(record)
  746. //30分钟之内阅读同一篇文章不错二次推送
  747. key := "CYGX_ARTICLE_READ" + strconv.Itoa(articleId) + "_" + strconv.Itoa(uid)
  748. if !utils.Rc.IsExist(key) {
  749. go services.ArticleUserRemind(user, detail, 1)
  750. utils.Rc.Put(key, 1, 30*time.Second)
  751. }
  752. }
  753. if hasPermission == 1 {
  754. key := "CYGX_ARTICLE_" + strconv.Itoa(articleId) + "_" + strconv.Itoa(uid)
  755. if !utils.Rc.IsExist(key) {
  756. //新增浏览记录
  757. record := new(models.CygxArticleViewRecord)
  758. record.UserId = uid
  759. record.ArticleId = articleId
  760. record.CreateTime = time.Now()
  761. record.Mobile = user.Mobile
  762. record.Email = user.Email
  763. record.CompanyId = user.CompanyId
  764. record.CompanyName = user.CompanyName
  765. go models.AddCygxArticleViewRecord(record)
  766. utils.Rc.Put(key, 1, 5*time.Second)
  767. models.ModifyReportLastViewTime(uid)
  768. }
  769. }
  770. }
  771. //作者头像
  772. if detail.DepartmentId > 0 {
  773. departmentDetail, err := models.GetArticleDepartmentDateilById(detail.DepartmentId)
  774. if err == nil {
  775. detail.DepartmentImgUrl = departmentDetail.ImgUrl
  776. detail.NickName = departmentDetail.NickName
  777. }
  778. }
  779. }
  780. detail.SellerAndMobile = "" //业务需要强制处理为空
  781. resp.HasPermission = hasPermission
  782. if hasPermission == 1 {
  783. detail.Abstract, _ = services.GetReportContentTextSub(detail.Abstract)
  784. resp.Detail = detail
  785. } else {
  786. if user.Mobile != "" {
  787. resp.Mobile = user.Mobile
  788. } else {
  789. resp.Mobile = user.Email
  790. }
  791. }
  792. br.Ret = 200
  793. br.Success = true
  794. br.Msg = "获取成功"
  795. br.Data = resp
  796. }
  797. // @Title 上传文章阅读时间
  798. // @Description 上传文章阅读时间接口
  799. // @Param request body models.AddStopTimeRep true "type json string"
  800. // @Success 200 {object} models.ArticleDetailResp
  801. // @router /addStopTime [post]
  802. func (this *ArticleController) AddStopTime() {
  803. br := new(models.BaseResponse).Init()
  804. defer func() {
  805. this.Data["json"] = br
  806. this.ServeJSON()
  807. }()
  808. user := this.User
  809. if user == nil {
  810. br.Msg = "请登录"
  811. br.ErrMsg = "请登录,用户信息为空"
  812. br.Ret = 408
  813. return
  814. }
  815. var req models.AddStopTimeRep
  816. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  817. if err != nil {
  818. br.Msg = "参数解析异常!"
  819. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  820. return
  821. }
  822. uid := user.UserId
  823. articleId := req.ArticleId
  824. stopTime := req.StopTime
  825. outType := req.OutType
  826. source := req.Source
  827. if articleId <= 0 {
  828. br.Msg = "参数错误"
  829. br.ErrMsg = "参数错误"
  830. return
  831. }
  832. if stopTime == 0 {
  833. stopTime = 1
  834. }
  835. if outType != 2 {
  836. outType = 1
  837. }
  838. if source != "PC" {
  839. source = "MOBILE"
  840. }
  841. detail := new(models.ArticleDetail)
  842. hasPermission := 0
  843. hasFree := 0
  844. //判断是否已经申请过
  845. applyCount, err := models.GetApplyRecordCount(uid)
  846. if err != nil && err.Error() != utils.ErrNoRow() {
  847. br.Msg = "获取信息失败"
  848. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  849. return
  850. }
  851. //`description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,4:潜在客户,未提交过申请,5:潜在客户,已提交过申请"`
  852. if user.CompanyId > 1 {
  853. companyPermission, err := models.GetCompanyPermission(user.CompanyId)
  854. if err != nil {
  855. br.Msg = "获取信息失败"
  856. br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  857. return
  858. }
  859. detail, err = models.GetArticleDetailById(articleId)
  860. if err != nil {
  861. br.Msg = "获取信息失败"
  862. br.ErrMsg = "获取文章信息失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  863. return
  864. }
  865. if companyPermission == "" {
  866. if applyCount > 0 {
  867. hasPermission = 5
  868. } else {
  869. hasPermission = 2
  870. }
  871. hasFree = 2
  872. goto Loop
  873. } else {
  874. hasFree = 1
  875. var articlePermissionPermissionName string
  876. if detail.CategoryId > 0 {
  877. articlePermission, err := models.GetArticlePermission(detail.CategoryId)
  878. if err != nil {
  879. br.Msg = "获取信息失败"
  880. br.ErrMsg = "获取报告权限失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  881. return
  882. }
  883. if articlePermission == nil {
  884. br.Msg = "获取信息失败"
  885. br.ErrMsg = "报告权限不存在,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  886. return
  887. }
  888. articlePermissionPermissionName = articlePermission.PermissionName
  889. } else {
  890. articlePermissionPermissionName = detail.CategoryName
  891. }
  892. var hasPersion bool
  893. slice := strings.Split(articlePermissionPermissionName, ",")
  894. for _, v := range slice {
  895. if strings.Contains(companyPermission, v) {
  896. hasPersion = true
  897. }
  898. }
  899. if hasPersion {
  900. go services.ArticleHistoryStopTime(articleId, stopTime, outType, user)
  901. } else { //无该行业权限
  902. hasPermission = 3
  903. }
  904. }
  905. } else { //潜在客户
  906. if applyCount > 0 {
  907. hasPermission = 5
  908. } else {
  909. hasPermission = 4
  910. }
  911. }
  912. Loop:
  913. resp := new(models.ArticleDetailAddStopTimeRep)
  914. resp.HasPermission = hasPermission
  915. resp.HasFree = hasFree
  916. br.Ret = 200
  917. br.Success = true
  918. br.Msg = "操作成功"
  919. br.Data = resp
  920. }
  921. // @Title 文章带问
  922. // @Description 新增文章带问接口
  923. // @Param request body models.AddArticleAskRep true "type json string"
  924. // @Success Ret=200 新增成功
  925. // @router /askAdd [post]
  926. func (this *ArticleController) AskAdd() {
  927. br := new(models.BaseResponse).Init()
  928. defer func() {
  929. this.Data["json"] = br
  930. this.ServeJSON()
  931. }()
  932. user := this.User
  933. if user == nil {
  934. br.Msg = "请登录"
  935. br.ErrMsg = "请登录,SysUser Is Empty"
  936. br.Ret = 408
  937. return
  938. }
  939. var req models.AddArticleAskRep
  940. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  941. if err != nil {
  942. br.Msg = "参数解析异常!"
  943. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  944. return
  945. }
  946. if req.Content == "" {
  947. br.Msg = "建议内容不可为空"
  948. return
  949. }
  950. content := req.Content
  951. itemToken, err := services.WxGetToken()
  952. if err != nil {
  953. br.Msg = "GetWxAccessToken Err:" + err.Error()
  954. return
  955. }
  956. if itemToken.AccessToken == "" {
  957. br.Msg = "accessToken is empty"
  958. return
  959. }
  960. commerr, err := weapp.MSGSecCheck(itemToken.AccessToken, content)
  961. if err != nil {
  962. br.Msg = "内容校验失败!"
  963. br.ErrMsg = "内容校验失败,Err:" + err.Error()
  964. return
  965. }
  966. if commerr.ErrCode != 0 {
  967. br.Msg = "内容违规,请重新提交!"
  968. br.ErrMsg = "颜文字内容违规,Err:" + commerr.ErrMSG
  969. return
  970. }
  971. articleId := req.ArticleId
  972. count, _ := models.GetArticleCountById(articleId)
  973. if count == 0 {
  974. br.Msg = "操作失败"
  975. br.ErrMsg = "文章ID错误,不存在 articleId:" + strconv.Itoa(articleId)
  976. return
  977. }
  978. companyDetail, err := models.GetCompanyDetailById(user.CompanyId)
  979. if err != nil {
  980. br.Msg = "提交失败!"
  981. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  982. return
  983. }
  984. if companyDetail == nil {
  985. br.Msg = "提交失败!"
  986. br.ErrMsg = "客户不存在,uid:" + strconv.Itoa(user.UserId)
  987. return
  988. }
  989. item := new(models.CygxArticleAsk)
  990. item.UserId = user.UserId
  991. item.ArticleId = req.ArticleId
  992. item.CompanyId = user.CompanyId
  993. item.CompanyName = companyDetail.CompanyName
  994. item.CreateTime = time.Now()
  995. item.Mobile = user.Mobile
  996. item.Email = user.Email
  997. item.Content = content
  998. _, err = models.AddArticleAsk(item)
  999. if err != nil {
  1000. br.Msg = "提交失败"
  1001. br.ErrMsg = "提交失败,Err:" + err.Error()
  1002. return
  1003. }
  1004. companyItem, err := models.GetSellerDetailAllByCompanyId(user.CompanyId)
  1005. if err != nil {
  1006. br.Msg = "获取信息失败"
  1007. br.ErrMsg = "获取所属销售信息失败,Err:" + err.Error()
  1008. return
  1009. }
  1010. var mobile string
  1011. if utils.RunMode == "release" {
  1012. //mobile = utils.WxMsgTemplateIdAskMsgMobileAll + "," + companyItem.Mobile
  1013. mobile = utils.WxMsgTemplateIdAskMsgMobileAll
  1014. } else {
  1015. mobile = utils.WxMsgTemplateIdAskMsgMobile
  1016. }
  1017. openIdList, err := models.GetWxOpenIdByMobileList(mobile)
  1018. if err != nil {
  1019. br.Msg = "提交失败"
  1020. br.ErrMsg = "提交失败,Err:" + err.Error()
  1021. return
  1022. }
  1023. detail, err := models.GetArticleDetailById(articleId)
  1024. if err != nil {
  1025. br.Msg = "获取信息失败"
  1026. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  1027. return
  1028. }
  1029. companyName := user.CompanyName + "-" + user.RealName + "(" + companyItem.SellerName + ")"
  1030. go services.SendWxMsgWithAsk(companyName, time.Now().Format(utils.FormatDateTime), content, detail.Title, openIdList, req.ArticleId)
  1031. br.Ret = 200
  1032. br.Success = true
  1033. br.Msg = "提交成功"
  1034. }
  1035. // @Title 下载PDF打水印
  1036. // @Description 下载PDF打水印接口
  1037. // @Param ArticleId query int true "报告ID"
  1038. // @Success 200 {object} models.ArticleDetailFileLink
  1039. // @router /pdfwatermark [get]
  1040. func (this *ArticleController) Pdfwatermark() {
  1041. br := new(models.BaseResponse).Init()
  1042. defer func() {
  1043. this.Data["json"] = br
  1044. this.ServeJSON()
  1045. }()
  1046. user := this.User
  1047. if user == nil {
  1048. br.Msg = "请登录"
  1049. br.ErrMsg = "请登录,用户信息为空"
  1050. br.Ret = 408
  1051. return
  1052. }
  1053. uid := user.UserId
  1054. articleId, err := this.GetInt("ArticleId")
  1055. if articleId <= 0 {
  1056. br.Msg = "文章不存在"
  1057. br.ErrMsg = "文章不存在,文章ID错误"
  1058. return
  1059. }
  1060. //缓存校验
  1061. cacheKey := fmt.Sprint("xygx:apply_record:add:", uid, "ArticleId_", articleId)
  1062. ttlTime := utils.Rc.GetRedisTTL(cacheKey)
  1063. if ttlTime > 0 && user.CompanyId != 16 {
  1064. br.Msg = "下载失败,下载过于频繁"
  1065. br.ErrMsg = "下载失败,下载过于频繁:mobile" + user.Mobile
  1066. return
  1067. }
  1068. resp := new(models.ArticleDetailFileLink)
  1069. detail := new(models.ArticleDetail)
  1070. detail, err = models.GetArticleDetailById(articleId)
  1071. if err != nil {
  1072. br.Msg = "获取信息失败"
  1073. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  1074. return
  1075. }
  1076. fileLink := detail.FileLink
  1077. if fileLink == "" {
  1078. br.Msg = "下载失败"
  1079. br.ErrMsg = "下载失败,报告链接不存在"
  1080. return
  1081. }
  1082. mobile := user.Mobile
  1083. if mobile == "" {
  1084. mobile = user.Email
  1085. }
  1086. sliceLink := strings.Split(fileLink, "/")
  1087. uploadDir := "static/pdf/"
  1088. //判断文件夹是否存在,不存在则创建
  1089. if !utils.FileIsExist(uploadDir) {
  1090. err = os.MkdirAll(uploadDir, 0755)
  1091. if err != nil {
  1092. br.Msg = "下载失败"
  1093. br.ErrMsg = "存储目录创建失败,Err:" + err.Error()
  1094. return
  1095. }
  1096. }
  1097. var oldFile string
  1098. var newFile string
  1099. //获取PDF源文件名称
  1100. pdfName := sliceLink[len(sliceLink)-1]
  1101. pdfName = utils.MD5(pdfName) + ".pdf"
  1102. oldFile = uploadDir + pdfName
  1103. //判断PDF本地是否存在,不存在则保存到本地
  1104. if !utils.FileIsExist(oldFile) {
  1105. res, err := nhttp.Get(fileLink)
  1106. if err != nil {
  1107. br.Msg = "下载失败"
  1108. br.ErrMsg = "获取源文件失败,Err:" + err.Error()
  1109. return
  1110. }
  1111. defer res.Body.Close()
  1112. // 获得get请求响应的reader对象
  1113. reader := bufio.NewReaderSize(res.Body, 32*1024)
  1114. file, err := os.Create(oldFile)
  1115. if err != nil {
  1116. br.Msg = "下载失败"
  1117. br.ErrMsg = "保存源文件到本地失败,Err:" + err.Error()
  1118. return
  1119. }
  1120. defer file.Close()
  1121. //获得文件的writer对象
  1122. writer := bufio.NewWriter(file)
  1123. written, _ := io.Copy(writer, reader)
  1124. fmt.Printf("Total length: %d", written)
  1125. }
  1126. newFile = uploadDir + "new_" + pdfName
  1127. onTop := true
  1128. wm, err := pdfcpu.ParseTextWatermarkDetails(mobile, " op:.4, pos:c ,points:16 ", onTop, 1)
  1129. if err != nil {
  1130. br.Msg = "下载失败"
  1131. br.ErrMsg = "生成水印文件失败,Err:" + err.Error()
  1132. return
  1133. }
  1134. err = api.AddWatermarksFile(oldFile, newFile, nil, wm, nil)
  1135. if err != nil {
  1136. //br.Msg = "下载失败"
  1137. //br.ErrMsg = "生成水印PDF失败,Err:" + err.Error()
  1138. resp.FileLink = fileLink
  1139. br.Ret = 200
  1140. br.Success = true
  1141. br.Msg = "获取成功"
  1142. br.Data = resp
  1143. return
  1144. }
  1145. randStr := utils.GetRandStringNoSpecialChar(28)
  1146. fileName := randStr + ".pdf"
  1147. savePath := uploadDir + time.Now().Format("200601/20060102/")
  1148. savePath += fileName
  1149. //上传到阿里云
  1150. err = services.UploadFileToAliyun(fileName, newFile, savePath)
  1151. if err != nil {
  1152. br.Msg = "下载失败"
  1153. br.ErrMsg = "文件上传失败,Err:" + err.Error()
  1154. return
  1155. }
  1156. fileHost := "https://hzstatic.hzinsights.com/"
  1157. resourceUrl := fileHost + savePath
  1158. defer func() {
  1159. os.Remove(newFile)
  1160. }()
  1161. utils.Rc.SetNX(cacheKey, user.Mobile, time.Minute*5)
  1162. resp.FileLink = resourceUrl
  1163. br.Ret = 200
  1164. br.Success = true
  1165. br.Msg = "获取成功"
  1166. br.Data = resp
  1167. }
  1168. // @Title 约访专家
  1169. // @Description 约访专家接口
  1170. // @Param request body models.CygxArticleIdReq true "type json string"
  1171. // @Success 200 {object}
  1172. // @router /applyAppointmentExpert [post]
  1173. func (this *ArticleController) ApplyAppointmentExpert() {
  1174. br := new(models.BaseResponse).Init()
  1175. defer func() {
  1176. this.Data["json"] = br
  1177. this.ServeJSON()
  1178. }()
  1179. user := this.User
  1180. if user == nil {
  1181. br.Msg = "请登录"
  1182. br.ErrMsg = "请登录,用户信息为空"
  1183. br.Ret = 408
  1184. return
  1185. }
  1186. var req models.CygxArticleIdReq
  1187. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1188. if err != nil {
  1189. br.Msg = "参数解析异常!"
  1190. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1191. return
  1192. }
  1193. articleId := req.ArticleId
  1194. var condition string
  1195. var pars []interface{}
  1196. condition += ` AND article_id =? AND user_id = ? `
  1197. pars = append(pars, articleId, user.UserId)
  1198. total, err := models.GetCygxArticleApplyAppointmentExpertCount(condition, pars)
  1199. if err != nil {
  1200. br.Msg = "约访专家失败"
  1201. br.ErrMsg = "约访专家失败,Err:" + err.Error()
  1202. return
  1203. }
  1204. if total > 0 {
  1205. br.Msg = "您已提交申请,请勿重复提交。"
  1206. return
  1207. }
  1208. err = services.AddArticleApplyAppointmentExpert(user, articleId)
  1209. if err != nil {
  1210. br.Msg = "约访专家失败"
  1211. br.ErrMsg = "约访专家失败,Err:" + err.Error()
  1212. return
  1213. }
  1214. services.SendArticleApplyAppointmentExpertTemplateMsg(user, articleId)
  1215. br.Ret = 200
  1216. br.Success = true
  1217. br.Msg = "操作成功"
  1218. }