article.go 54 KB

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