article.go 53 KB

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