article.go 53 KB

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