article.go 53 KB

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