article.go 55 KB

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