article.go 54 KB

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