article.go 56 KB

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