article.go 54 KB

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