article.go 54 KB

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