article.go 55 KB

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