article.go 52 KB

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