article.go 53 KB

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