article.go 53 KB

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