article.go 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425
  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. //"os"
  20. "regexp"
  21. "strconv"
  22. "strings"
  23. "time"
  24. )
  25. type ArticleController struct {
  26. BaseAuthController
  27. }
  28. type ArticleCommonController struct {
  29. BaseCommonController
  30. }
  31. // @Title 获取报告详情
  32. // @Description 获取报告详情接口
  33. // @Param ArticleId query int true "报告ID"
  34. // @Success 200 {object} models.ArticleDetailResp
  35. // @router /detail [get]
  36. func (this *ArticleController) Detail() {
  37. br := new(models.BaseResponse).Init()
  38. defer func() {
  39. this.Data["json"] = br
  40. this.ServeJSON()
  41. }()
  42. user := this.User
  43. if user == nil {
  44. br.Msg = "请登录"
  45. br.ErrMsg = "请登录,用户信息为空"
  46. br.Ret = 408
  47. return
  48. }
  49. uid := user.UserId
  50. articleId, err := this.GetInt("ArticleId")
  51. if articleId <= 0 {
  52. br.Msg = "文章不存在"
  53. br.ErrMsg = "文章不存在,文章ID错误"
  54. return
  55. }
  56. detail := new(models.ArticleDetail)
  57. hasPermission := 0
  58. hasFree := 0
  59. var haveResearch bool
  60. //判断是否已经申请过
  61. applyCount, err := models.GetApplyRecordCount(uid)
  62. if err != nil && err.Error() != utils.ErrNoRow() {
  63. br.Msg = "获取信息失败"
  64. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  65. return
  66. }
  67. //`description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,4:潜在客户,未提交过申请,5:潜在客户,已提交过申请"`
  68. if user.CompanyId > 1 {
  69. companyPermission, err := models.GetCompanyPermission(user.CompanyId)
  70. if err != nil {
  71. br.Msg = "获取信息失败"
  72. br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  73. return
  74. }
  75. detail, err = models.GetArticleDetailById(articleId)
  76. if err != nil {
  77. br.Msg = "获取信息失败"
  78. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  79. return
  80. }
  81. detail.Body = html.UnescapeString(detail.Body)
  82. 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)
  83. detail.Body = strings.Replace(detail.Body, "pre", "div", -1)
  84. //detail.Abstract = html.UnescapeString(detail.Abstract)
  85. detail.Abstract, _ = services.GetReportContentTextSubNew(detail.Abstract)
  86. if companyPermission == "" {
  87. if applyCount > 0 {
  88. hasPermission = 5
  89. } else {
  90. hasPermission = 2
  91. }
  92. hasFree = 2
  93. goto Loop
  94. } else {
  95. hasFree = 1
  96. var articlePermissionPermissionName string
  97. if detail.CategoryId > 0 {
  98. articlePermission, err := models.GetArticlePermission(detail.CategoryId)
  99. if err != nil {
  100. br.Msg = "获取信息失败"
  101. br.ErrMsg = "获取报告权限失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  102. return
  103. }
  104. if articlePermission == nil {
  105. br.Msg = "获取信息失败"
  106. br.ErrMsg = "报告权限不存在,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  107. return
  108. }
  109. articlePermissionPermissionName = articlePermission.PermissionName
  110. } else {
  111. articlePermissionPermissionName = detail.CategoryName
  112. }
  113. var hasPersion bool
  114. slice := strings.Split(articlePermissionPermissionName, ",")
  115. for _, v := range slice {
  116. if strings.Contains(companyPermission, v) {
  117. hasPersion = true
  118. }
  119. }
  120. if strings.Contains(detail.CategoryName, "研选") {
  121. detail.IsResearch = true
  122. }
  123. userType, _, err := services.GetUserType(user.CompanyId)
  124. if err != nil {
  125. br.Msg = "获取信息失败"
  126. br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
  127. return
  128. }
  129. if userType == 1 && strings.Contains(detail.CategoryName, "研选") {
  130. hasPersion = false
  131. }
  132. if detail.IsReport == 1 {
  133. fmt.Println("报告权限")
  134. detailCategory, err := models.GetdetailByCategoryIdSando(detail.CategoryId)
  135. if err != nil && err.Error() != utils.ErrNoRow() {
  136. br.Msg = "获取信息失败"
  137. br.ErrMsg = "获取信息失败,Err:" + err.Error() + "categoryID 不存在:" + strconv.Itoa(detail.CategoryId)
  138. return
  139. }
  140. fmt.Println(detailCategory)
  141. permissionStr, err := models.GetCompanyPermissionByUser(user.CompanyId)
  142. if err != nil {
  143. br.Msg = "获取信息失败"
  144. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  145. return
  146. }
  147. if detailCategory != nil {
  148. if detailCategory.PermissionType == 1 {
  149. if !strings.Contains(permissionStr, detailCategory.ChartPermissionName+"(主观)") {
  150. hasPersion = false
  151. }
  152. } else if detailCategory.PermissionType == 2 {
  153. if !strings.Contains(permissionStr, detailCategory.ChartPermissionName+"(客观)") {
  154. hasPersion = false
  155. }
  156. }
  157. }
  158. }
  159. if hasPersion {
  160. hasPermission = 1
  161. historyRecord := new(models.CygxArticleHistoryRecord)
  162. historyRecord.UserId = uid
  163. historyRecord.ArticleId = articleId
  164. historyRecord.CreateTime = time.Now()
  165. historyRecord.Mobile = user.Mobile
  166. historyRecord.Email = user.Email
  167. historyRecord.CompanyId = user.CompanyId
  168. historyRecord.CompanyName = user.CompanyName
  169. recordCount, _ := models.GetNoAddStoptimeArticleCount(uid, articleId)
  170. if recordCount == 0 {
  171. go models.AddCygxArticleHistoryRecord(historyRecord)
  172. } else {
  173. detailNew, err := models.GetNewArticleHistoryRecord(uid, articleId)
  174. if err != nil {
  175. br.Msg = "获取信息失败"
  176. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  177. return
  178. }
  179. if detailNew.StopTime > 0 {
  180. go models.AddCygxArticleHistoryRecord(historyRecord)
  181. }
  182. }
  183. } else { //无该行业权限
  184. companyDetail, err := models.GetCompanyDetailById(user.CompanyId)
  185. if err == nil && companyDetail.ProductId == 1 {
  186. hasPermission = 2
  187. } else {
  188. hasPermission = 3
  189. }
  190. }
  191. if hasPermission == 1 {
  192. key := "CYGX_ARTICLE_" + strconv.Itoa(articleId) + "_" + strconv.Itoa(uid)
  193. if !utils.Rc.IsExist(key) {
  194. //新增浏览记录
  195. record := new(models.CygxArticleViewRecord)
  196. record.UserId = uid
  197. record.ArticleId = articleId
  198. record.CreateTime = time.Now()
  199. record.Mobile = user.Mobile
  200. record.Email = user.Email
  201. record.CompanyId = user.CompanyId
  202. record.CompanyName = user.CompanyName
  203. go models.AddCygxArticleViewRecord(record)
  204. utils.Rc.Put(key, 1, 5*time.Second)
  205. models.ModifyReportLastViewTime(uid)
  206. }
  207. }
  208. }
  209. collectCount, err := models.GetArticleCollectCount(uid, articleId)
  210. if err != nil && err.Error() != utils.ErrNoRow() {
  211. br.Msg = "获取信息失败"
  212. br.ErrMsg = "判断是否已收藏失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  213. return
  214. }
  215. if collectCount > 0 {
  216. detail.IsCollect = true
  217. }
  218. interviewApplyItem, err := models.GetArticleInterviewApply(uid, articleId)
  219. if err != nil && err.Error() != utils.ErrNoRow() {
  220. br.Msg = "获取信息失败"
  221. br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  222. return
  223. }
  224. if interviewApplyItem != nil && interviewApplyItem.InterviewApplyId > 0 {
  225. detail.IsInterviewApply = true
  226. detail.InterviewApplyStatus = interviewApplyItem.Status
  227. }
  228. //获取销售手机号
  229. sellerItem, err := models.GetSellerByCompanyId(user.CompanyId)
  230. if err != nil && err.Error() != utils.ErrNoRow() {
  231. br.Msg = "获取信息失败"
  232. br.ErrMsg = "获取销售数据失败2,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  233. return
  234. }
  235. if sellerItem != nil {
  236. detail.SellerMobile = sellerItem.Mobile
  237. detail.SellerName = sellerItem.RealName
  238. }
  239. sellerList, err := models.GetSellerList(articleId)
  240. if err != nil {
  241. br.Msg = "获取信息失败"
  242. br.ErrMsg = "获取销售数据失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  243. return
  244. }
  245. if detail.ArticleId >= utils.SummaryArticleId && strings.Contains(detail.SellerAndMobile, "-") {
  246. strnum := strings.Index(detail.SellerAndMobile, "-")
  247. detail.SellerAndMobile = detail.SellerAndMobile[0:strnum]
  248. if strnum > 0 {
  249. nickName := detail.SellerAndMobile[0:strnum]
  250. sellerAndMobile := &models.SellerRep{
  251. SellerMobile: "",
  252. SellerName: nickName,
  253. }
  254. sellerList = append(sellerList, sellerAndMobile)
  255. }
  256. }
  257. detail.SellerList = sellerList
  258. //作者头像
  259. if detail.DepartmentId > 0 {
  260. departmentDetail, err := models.GetArticleDepartmentDateilById(detail.DepartmentId)
  261. if err == nil {
  262. detail.DepartmentImgUrl = departmentDetail.ImgUrl
  263. }
  264. }
  265. } else { //潜在客户
  266. if applyCount > 0 {
  267. hasPermission = 5
  268. } else {
  269. hasPermission = 4
  270. }
  271. }
  272. Loop:
  273. if hasPermission != 1 {
  274. detail.Body = ""
  275. detail.BodyText = ""
  276. } else {
  277. articleFollowdetail, err := models.GetArticleFollowDetail(articleId, uid)
  278. if err != nil {
  279. br.Msg = "获取信息失败"
  280. br.ErrMsg = "获取关注信息失败,Err:" + err.Error()
  281. return
  282. }
  283. detail.FollowNum = articleFollowdetail.DNum
  284. detail.CollectionNum = articleFollowdetail.AcNum
  285. if articleFollowdetail.MdNum > 0 {
  286. detail.IsFollow = true
  287. }
  288. if detail.IsSummary == 1 {
  289. detail.IsBelongSummary = true
  290. }
  291. if detail.IsReport == 1 {
  292. detail.IsBelongReport = true
  293. }
  294. haveResearch = true
  295. }
  296. if hasPermission == 2 || hasPermission == 4 {
  297. //获取销售手机号
  298. sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  299. if err != nil && err.Error() != utils.ErrNoRow() {
  300. br.Msg = "获取信息失败"
  301. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  302. return
  303. }
  304. if sellerItemQy != nil {
  305. hasPermission = 3
  306. detail.SellerMobile = sellerItemQy.Mobile
  307. detail.SellerName = sellerItemQy.RealName
  308. }
  309. }
  310. if detail.ArticleId < utils.SummaryArticleId {
  311. detail.HttpUrl = utils.StrategyPlatform + strconv.Itoa(articleId)
  312. detail.IsNeedJump = true
  313. }
  314. resp := new(models.ArticleDetailResp)
  315. detailConfig, err := models.GetConfigByCode("free_trial_card")
  316. if err != nil {
  317. br.Msg = "获取数据失败"
  318. br.ErrMsg = "城市配置信息失败,Err:" + err.Error()
  319. return
  320. }
  321. if detailConfig.ConfigValue == "1" {
  322. if hasPermission == 5 {
  323. resp.IsShow = true
  324. }
  325. }
  326. resp.HasPermission = hasPermission
  327. resp.HaveResearch = haveResearch
  328. resp.HasFree = hasFree
  329. resp.Detail = detail
  330. if user.Mobile != "" {
  331. resp.Mobile = user.Mobile
  332. } else {
  333. resp.Mobile = user.Email
  334. }
  335. br.Ret = 200
  336. br.Success = true
  337. br.Msg = "获取成功"
  338. br.Data = resp
  339. }
  340. // @Title 收藏
  341. // @Description 收藏
  342. // @Param request body models.ArticleCollectReq true "type json string"
  343. // @Success 200 {object} models.FontsCollectResp
  344. // @router /collect [post]
  345. func (this *ArticleController) ArticleCollect() {
  346. br := new(models.BaseResponse).Init()
  347. defer func() {
  348. this.Data["json"] = br
  349. this.ServeJSON()
  350. }()
  351. user := this.User
  352. if user == nil {
  353. br.Msg = "请重新登录"
  354. br.Ret = 408
  355. return
  356. }
  357. uid := user.UserId
  358. var req models.ArticleCollectReq
  359. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  360. if err != nil {
  361. br.Msg = "参数解析异常!"
  362. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  363. return
  364. }
  365. count, err := models.GetArticleCollectCount(uid, req.ArticleId)
  366. if err != nil {
  367. br.Msg = "获取数据失败!"
  368. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  369. return
  370. }
  371. resp := new(models.ArticleCollectResp)
  372. if count <= 0 {
  373. item := new(models.CygxArticleCollect)
  374. item.ArticleId = req.ArticleId
  375. item.UserId = uid
  376. item.CreateTime = time.Now()
  377. _, err = models.AddCygxArticleCollect(item)
  378. if err != nil {
  379. br.Msg = "收藏失败"
  380. br.ErrMsg = "收藏失败,Err:" + err.Error()
  381. return
  382. }
  383. br.Msg = "收藏成功"
  384. resp.Status = 1
  385. } else {
  386. err = models.RemoveArticleCollect(uid, req.ArticleId)
  387. if err != nil {
  388. br.Msg = "取消收藏失败"
  389. br.ErrMsg = "取消收藏失败,Err:" + err.Error()
  390. return
  391. }
  392. br.Msg = "已取消收藏"
  393. resp.Status = 2
  394. }
  395. collectTotal, err := models.GetArticleCollectUsersCount(req.ArticleId)
  396. if err != nil {
  397. br.Msg = "获取数据失败"
  398. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  399. return
  400. }
  401. resp.CollectCount = collectTotal
  402. br.Ret = 200
  403. br.Success = true
  404. br.Data = resp
  405. }
  406. // @Title 访谈申请
  407. // @Description 访谈申请
  408. // @Param request body models.ArticleInterviewApplyReq true "type json string"
  409. // @Success 200 {object} models.FontsCollectResp
  410. // @router /interview/apply [post]
  411. func (this *ArticleController) InterviewApply() {
  412. br := new(models.BaseResponse).Init()
  413. defer func() {
  414. this.Data["json"] = br
  415. this.ServeJSON()
  416. }()
  417. user := this.User
  418. if user == nil {
  419. br.Msg = "请重新登录"
  420. br.Ret = 408
  421. return
  422. }
  423. uid := user.UserId
  424. var req models.ArticleInterviewApplyReq
  425. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  426. if err != nil {
  427. br.Msg = "参数解析异常!"
  428. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  429. return
  430. }
  431. article, err := models.GetArticleDetailById(req.ArticleId)
  432. if err != nil {
  433. br.Msg = "获取纪要失败!"
  434. br.ErrMsg = "获取纪要失败,Err:" + err.Error()
  435. return
  436. }
  437. count, err := models.GetArticleInterviewApplyCount(uid, req.ArticleId)
  438. if err != nil {
  439. br.Msg = "获取数据失败!"
  440. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  441. return
  442. }
  443. resp := new(models.ArticleInterviewApplyResp)
  444. if count <= 0 {
  445. item := new(models.CygxInterviewApply)
  446. item.ArticleId = req.ArticleId
  447. item.UserId = uid
  448. item.CompanyId = user.CompanyId
  449. item.Status = "待邀请"
  450. item.Sort = 1
  451. item.ArticleTitle = article.Title
  452. item.CreateTime = time.Now()
  453. item.ModifyTime = time.Now()
  454. item.ArticleIdMd5 = article.ArticleIdMd5
  455. _, err = models.AddCygxInterviewApply(item)
  456. if err != nil {
  457. br.Msg = "申请失败"
  458. br.ErrMsg = "申请失败,Err:" + err.Error()
  459. return
  460. }
  461. br.Msg = "申请成功"
  462. resp.Status = 1
  463. //发送模板消息
  464. if user.CompanyId > 1 {
  465. mobile := user.Mobile
  466. if mobile == "" {
  467. mobile = user.Email
  468. }
  469. sellerItem, _ := models.GetSellerByCompanyId(user.CompanyId)
  470. if sellerItem != nil && sellerItem.AdminId > 0 && user.Mobile != "" {
  471. openIpItem, _ := models.GetUserRecordByUserIdByXzs(sellerItem.Mobile, 4)
  472. fmt.Println(openIpItem)
  473. if openIpItem != nil && openIpItem.OpenId != "" {
  474. go services.SendInterviewApplyTemplateMsg(user.RealName, sellerItem.CompanyName, mobile, article.Title, openIpItem.OpenId)
  475. }
  476. }
  477. }
  478. } else {
  479. err = models.RemoveArticleInterviewApply(uid, req.ArticleId)
  480. if err != nil {
  481. br.Msg = "取消申请失败"
  482. br.ErrMsg = "取消申请失败,Err:" + err.Error()
  483. return
  484. }
  485. br.Msg = "已取消申请"
  486. resp.Status = 2
  487. if user.CompanyId > 1 {
  488. mobile := user.Mobile
  489. if mobile == "" {
  490. mobile = user.Email
  491. }
  492. sellerItem, _ := models.GetSellerByCompanyId(user.CompanyId)
  493. if sellerItem != nil && sellerItem.AdminId > 0 && user.Mobile != "" {
  494. openIpItem, _ := models.GetUserRecordByUserIdByXzs(sellerItem.Mobile, 4)
  495. fmt.Println(openIpItem)
  496. if openIpItem != nil && openIpItem.OpenId != "" {
  497. go services.SendInterviewApplyCancelTemplateMsg(user.RealName, sellerItem.CompanyName, mobile, article.Title, openIpItem.OpenId)
  498. }
  499. }
  500. }
  501. }
  502. br.Ret = 200
  503. br.Success = true
  504. br.Data = resp
  505. }
  506. // @Title 获取报告详情
  507. // @Description 获取报告详情接口
  508. // @Param ArticleIdMd5 query int true "报告ID"
  509. // @Success 200 {object} models.ArticleDetailResp
  510. // @router /look/detail [get]
  511. func (this *ArticleCommonController) Detail() {
  512. br := new(models.BaseResponse).Init()
  513. defer func() {
  514. this.Data["json"] = br
  515. this.ServeJSON()
  516. }()
  517. articleIdMd5 := this.GetString("ArticleIdMd5")
  518. if articleIdMd5 == "" {
  519. br.Msg = "参数错误"
  520. br.ErrMsg = "参数错误"
  521. return
  522. }
  523. resp := new(models.ArticleDetailResp)
  524. detail, err := models.GetArticleDetailByIdMd5(articleIdMd5)
  525. if err != nil {
  526. br.Msg = "获取信息失败"
  527. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  528. return
  529. }
  530. detail.Body = html.UnescapeString(detail.Body)
  531. //detail.Abstract = html.UnescapeString(detail.Abstract)
  532. sellerList, err := models.GetSellerList(detail.ArticleId)
  533. if err != nil {
  534. br.Msg = "获取信息失败"
  535. br.ErrMsg = "获取销售数据失败,Err:" + err.Error() + ";articleId" + strconv.Itoa(detail.ArticleId)
  536. return
  537. }
  538. if detail.ArticleId > 1000000 {
  539. var hrefRegexp = regexp.MustCompile("[0-9]\\d*")
  540. match := hrefRegexp.FindAllString(detail.SellerAndMobile, -1)
  541. if match != nil {
  542. for _, v := range match {
  543. sellerAndMobile := &models.SellerRep{
  544. SellerMobile: v,
  545. SellerName: strings.Replace(detail.SellerAndMobile, v, "", -1),
  546. }
  547. sellerList = append(sellerList, sellerAndMobile)
  548. }
  549. }
  550. }
  551. resp.HasPermission = 1
  552. detail.Abstract, _ = services.GetReportContentTextSub(detail.Abstract)
  553. detail.SellerList = sellerList
  554. resp.Detail = detail
  555. br.Ret = 200
  556. br.Success = true
  557. br.Msg = "获取成功"
  558. br.Data = resp
  559. }
  560. // @Title 上传文章阅读时间
  561. // @Description 上传文章阅读时间接口
  562. // @Param request body models.AddStopTimeRep true "type json string"
  563. // @Success 200 {object} models.ArticleDetailResp
  564. // @router /addStopTime [post]
  565. func (this *ArticleController) AddStopTime() {
  566. br := new(models.BaseResponse).Init()
  567. defer func() {
  568. this.Data["json"] = br
  569. this.ServeJSON()
  570. }()
  571. user := this.User
  572. if user == nil {
  573. br.Msg = "请登录"
  574. br.ErrMsg = "请登录,用户信息为空"
  575. br.Ret = 408
  576. return
  577. }
  578. var req models.AddStopTimeRep
  579. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  580. if err != nil {
  581. br.Msg = "参数解析异常!"
  582. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  583. return
  584. }
  585. uid := user.UserId
  586. articleId := req.ArticleId
  587. stopTime := req.StopTime
  588. outType := req.OutType
  589. source := req.Source
  590. if articleId <= 0 {
  591. br.Msg = "参数错误"
  592. br.ErrMsg = "参数错误"
  593. return
  594. }
  595. if stopTime == 0 {
  596. stopTime = 1
  597. }
  598. if outType != 2 {
  599. outType = 1
  600. }
  601. if source != "PC" {
  602. source = "MOBILE"
  603. }
  604. detail := new(models.ArticleDetail)
  605. hasPermission := 0
  606. hasFree := 0
  607. //判断是否已经申请过
  608. applyCount, err := models.GetApplyRecordCount(uid)
  609. if err != nil && err.Error() != utils.ErrNoRow() {
  610. br.Msg = "获取信息失败"
  611. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  612. return
  613. }
  614. //`description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,4:潜在客户,未提交过申请,5:潜在客户,已提交过申请"`
  615. if user.CompanyId > 1 {
  616. companyPermission, err := models.GetCompanyPermission(user.CompanyId)
  617. if err != nil {
  618. br.Msg = "获取信息失败"
  619. br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  620. return
  621. }
  622. detail, err = models.GetArticleDetailById(articleId)
  623. if err != nil {
  624. br.Msg = "获取信息失败"
  625. br.ErrMsg = "获取文章信息失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  626. return
  627. }
  628. if companyPermission == "" {
  629. if applyCount > 0 {
  630. hasPermission = 5
  631. } else {
  632. hasPermission = 2
  633. }
  634. hasFree = 2
  635. goto Loop
  636. } else {
  637. hasFree = 1
  638. var articlePermissionPermissionName string
  639. if detail.CategoryId > 0 {
  640. articlePermission, err := models.GetArticlePermission(detail.CategoryId)
  641. if err != nil {
  642. br.Msg = "获取信息失败"
  643. br.ErrMsg = "获取报告权限失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  644. return
  645. }
  646. if articlePermission == nil {
  647. br.Msg = "获取信息失败"
  648. br.ErrMsg = "报告权限不存在,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  649. return
  650. }
  651. articlePermissionPermissionName = articlePermission.PermissionName
  652. } else {
  653. articlePermissionPermissionName = detail.CategoryName
  654. }
  655. var hasPersion bool
  656. slice := strings.Split(articlePermissionPermissionName, ",")
  657. for _, v := range slice {
  658. if strings.Contains(companyPermission, v) {
  659. hasPersion = true
  660. }
  661. }
  662. if hasPersion {
  663. detailNew, err := models.GetNewArticleHistoryRecord(uid, articleId)
  664. if err == nil {
  665. hasPermission = 1
  666. historyRecord := new(models.AddStopTimeNewRep)
  667. historyRecord.StopTime = detailNew.StopTime + stopTime
  668. historyRecord.Id = detailNew.Id
  669. historyRecord.OutType = outType
  670. go models.UpdateArticleStopTime(historyRecord)
  671. }
  672. //不统计本公司的阅读记录、正常退出的不做时间差统计
  673. if user.CompanyId != 16 && stopTime > 3 {
  674. key := "CYGX_ARTICLE_PV" + strconv.Itoa(articleId) + "_" + strconv.Itoa(uid) + "_" + strconv.Itoa(user.CompanyId) + "_" + strconv.Itoa(outType)
  675. record := new(models.CygxArticleHistoryRecordNewpv)
  676. record.UserId = uid
  677. record.ArticleId = articleId
  678. record.CreateTime = time.Now().Add(-time.Second * time.Duration(stopTime))
  679. record.ModifyTime = time.Now()
  680. record.Mobile = user.Mobile
  681. record.Email = user.Email
  682. record.CompanyId = user.CompanyId
  683. record.CompanyName = user.CompanyName
  684. record.StopTime = stopTime
  685. record.OutType = outType
  686. record.Source = source
  687. if !utils.Rc.IsExist(key) || outType != 2 {
  688. //新增浏览记录
  689. go models.AddCygxArticleViewRecordNewpv(record)
  690. recordRedis := new(services.ReportViewRecord)
  691. recordRedis.UserId = user.UserId
  692. recordRedis.ReportId = articleId
  693. recordRedis.Mobile = user.Mobile
  694. recordRedis.Email = user.Email
  695. recordRedis.RealName = user.RealName
  696. recordRedis.CompanyName = user.CompanyName
  697. recordRedis.CreateTime = time.Now().Add(-time.Second * time.Duration(stopTime))
  698. go services.PushViewRecordNewRedisData(recordRedis, user.CompanyId)
  699. } else {
  700. go models.UpdateCygxArticleViewRecordNewpv(record, stopTime)
  701. }
  702. utils.Rc.Put(key, 1, 10*time.Minute)
  703. }
  704. models.ModifyReportLastViewTime(uid)
  705. } else { //无该行业权限
  706. hasPermission = 3
  707. }
  708. }
  709. } else { //潜在客户
  710. if applyCount > 0 {
  711. hasPermission = 5
  712. } else {
  713. hasPermission = 4
  714. }
  715. }
  716. Loop:
  717. resp := new(models.ArticleDetailAddStopTimeRep)
  718. resp.HasPermission = hasPermission
  719. resp.HasFree = hasFree
  720. br.Ret = 200
  721. br.Success = true
  722. br.Msg = "操作成功"
  723. br.Data = resp
  724. }
  725. // @Title 文章带问
  726. // @Description 新增文章带问接口
  727. // @Param request body models.AddArticleAskRep true "type json string"
  728. // @Success Ret=200 新增成功
  729. // @router /askAdd [post]
  730. func (this *ArticleController) AskAdd() {
  731. br := new(models.BaseResponse).Init()
  732. defer func() {
  733. this.Data["json"] = br
  734. this.ServeJSON()
  735. }()
  736. user := this.User
  737. if user == nil {
  738. br.Msg = "请登录"
  739. br.ErrMsg = "请登录,SysUser Is Empty"
  740. br.Ret = 408
  741. return
  742. }
  743. var req models.AddArticleAskRep
  744. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  745. if err != nil {
  746. br.Msg = "参数解析异常!"
  747. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  748. return
  749. }
  750. if req.Content == "" {
  751. br.Msg = "建议内容不可为空"
  752. return
  753. }
  754. content := req.Content
  755. itemToken, err := services.WxGetToken()
  756. if err != nil {
  757. br.Msg = "GetWxAccessToken Err:" + err.Error()
  758. return
  759. }
  760. if itemToken.AccessToken == "" {
  761. br.Msg = "accessToken is empty"
  762. return
  763. }
  764. commerr, err := weapp.MSGSecCheck(itemToken.AccessToken, content)
  765. if err != nil {
  766. br.Msg = "内容校验失败!"
  767. br.ErrMsg = "内容校验失败,Err:" + err.Error()
  768. return
  769. }
  770. if commerr.ErrCode != 0 {
  771. br.Msg = "内容违规,请重新提交!"
  772. br.ErrMsg = "颜文字内容违规,Err:" + commerr.ErrMSG
  773. return
  774. }
  775. articleId := req.ArticleId
  776. count, _ := models.GetArticleCountById(articleId)
  777. if count == 0 {
  778. br.Msg = "操作失败"
  779. br.ErrMsg = "文章ID错误,不存在 articleId:" + strconv.Itoa(articleId)
  780. return
  781. }
  782. companyDetail, err := models.GetCompanyDetailById(user.CompanyId)
  783. if err != nil {
  784. br.Msg = "提交失败!"
  785. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  786. return
  787. }
  788. if companyDetail == nil {
  789. br.Msg = "提交失败!"
  790. br.ErrMsg = "客户不存在,uid:" + strconv.Itoa(user.UserId)
  791. return
  792. }
  793. item := new(models.CygxArticleAsk)
  794. item.UserId = user.UserId
  795. item.ArticleId = req.ArticleId
  796. item.CompanyId = user.CompanyId
  797. item.CompanyName = companyDetail.CompanyName
  798. item.CreateTime = time.Now()
  799. item.Mobile = user.Mobile
  800. item.Email = user.Email
  801. item.Content = content
  802. _, err = models.AddArticleAsk(item)
  803. if err != nil {
  804. br.Msg = "提交失败"
  805. br.ErrMsg = "提交失败,Err:" + err.Error()
  806. return
  807. }
  808. companyItem, err := models.GetSellerDetailAllByCompanyId(user.CompanyId)
  809. if err != nil {
  810. br.Msg = "获取信息失败"
  811. br.ErrMsg = "获取所属销售信息失败,Err:" + err.Error()
  812. return
  813. }
  814. var mobile string
  815. if utils.RunMode == "release" {
  816. //mobile = utils.WxMsgTemplateIdAskMsgMobileAll + "," + companyItem.Mobile
  817. mobile = utils.WxMsgTemplateIdAskMsgMobileAll
  818. } else {
  819. mobile = utils.WxMsgTemplateIdAskMsgMobile
  820. }
  821. openIdList, err := models.GetWxOpenIdByMobileList(mobile)
  822. if err != nil {
  823. br.Msg = "提交失败"
  824. br.ErrMsg = "提交失败,Err:" + err.Error()
  825. return
  826. }
  827. detail, err := models.GetArticleDetailById(articleId)
  828. if err != nil {
  829. br.Msg = "获取信息失败"
  830. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  831. return
  832. }
  833. companyName := user.CompanyName + "-" + user.RealName + "(" + companyItem.SellerName + ")"
  834. go services.SendWxMsgWithAsk(companyName, time.Now().Format(utils.FormatDateTime), content, detail.Title, openIdList, req.ArticleId)
  835. br.Ret = 200
  836. br.Success = true
  837. br.Msg = "提交成功"
  838. }
  839. // @Title 下载PDF打水印
  840. // @Description 下载PDF打水印接口
  841. // @Param ArticleId query int true "报告ID"
  842. // @Success 200 {object} models.ArticleDetailFileLink
  843. // @router /pdfwatermark [get]
  844. func (this *ArticleController) Pdfwatermark() {
  845. br := new(models.BaseResponse).Init()
  846. defer func() {
  847. this.Data["json"] = br
  848. this.ServeJSON()
  849. }()
  850. user := this.User
  851. if user == nil {
  852. br.Msg = "请登录"
  853. br.ErrMsg = "请登录,用户信息为空"
  854. br.Ret = 408
  855. return
  856. }
  857. uid := user.UserId
  858. articleId, err := this.GetInt("ArticleId")
  859. if articleId <= 0 {
  860. br.Msg = "文章不存在"
  861. br.ErrMsg = "文章不存在,文章ID错误"
  862. return
  863. }
  864. //缓存校验
  865. cacheKey := fmt.Sprint("xygx:apply_record:add:", uid, "ArticleId_", articleId)
  866. ttlTime := utils.Rc.GetRedisTTL(cacheKey)
  867. if ttlTime > 0 {
  868. br.Msg = "下载失败,下载过于频繁"
  869. br.ErrMsg = "下载失败,下载过于频繁:mobile" + user.Mobile
  870. return
  871. }
  872. detail := new(models.ArticleDetail)
  873. detail, err = models.GetArticleDetailById(articleId)
  874. if err != nil {
  875. br.Msg = "获取信息失败"
  876. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  877. return
  878. }
  879. fileLink := detail.FileLink
  880. if fileLink == "" {
  881. br.Msg = "下载失败"
  882. br.ErrMsg = "下载失败,报告链接不存在"
  883. return
  884. }
  885. mobile := user.Mobile
  886. if mobile == "" {
  887. mobile = user.Email
  888. }
  889. sliceLink := strings.Split(fileLink, "/")
  890. uploadDir := "static/pdf/"
  891. //判断文件夹是否存在,不存在则创建
  892. if !utils.FileIsExist(uploadDir) {
  893. err = os.MkdirAll(uploadDir, 0755)
  894. if err != nil {
  895. br.Msg = "下载失败"
  896. br.ErrMsg = "存储目录创建失败,Err:" + err.Error()
  897. return
  898. }
  899. }
  900. var oldFile string
  901. var newFile string
  902. //获取PDF源文件名称
  903. pdfName := sliceLink[len(sliceLink)-1]
  904. pdfName = utils.MD5(pdfName) + ".pdf"
  905. oldFile = uploadDir + pdfName
  906. //判断PDF本地是否存在,不存在则保存到本地
  907. if !utils.FileIsExist(oldFile) {
  908. res, err := nhttp.Get(fileLink)
  909. if err != nil {
  910. br.Msg = "下载失败"
  911. br.ErrMsg = "获取源文件失败,Err:" + err.Error()
  912. return
  913. }
  914. defer res.Body.Close()
  915. // 获得get请求响应的reader对象
  916. reader := bufio.NewReaderSize(res.Body, 32*1024)
  917. file, err := os.Create(oldFile)
  918. if err != nil {
  919. br.Msg = "下载失败"
  920. br.ErrMsg = "保存源文件到本地失败,Err:" + err.Error()
  921. return
  922. }
  923. defer file.Close()
  924. //获得文件的writer对象
  925. writer := bufio.NewWriter(file)
  926. written, _ := io.Copy(writer, reader)
  927. fmt.Printf("Total length: %d", written)
  928. }
  929. newFile = uploadDir + "new_" + pdfName
  930. onTop := true
  931. wm, err := pdfcpu.ParseTextWatermarkDetails(mobile, " op:.4, pos:c ,points:16 ", onTop, 1)
  932. if err != nil {
  933. br.Msg = "下载失败"
  934. br.ErrMsg = "生成水印文件失败,Err:" + err.Error()
  935. return
  936. }
  937. err = api.AddWatermarksFile(oldFile, newFile, nil, wm, nil)
  938. if err != nil {
  939. br.Msg = "下载失败"
  940. br.ErrMsg = "生成水印PDF失败,Err:" + err.Error()
  941. return
  942. }
  943. resp := new(models.ArticleDetailFileLink)
  944. randStr := utils.GetRandStringNoSpecialChar(28)
  945. fileName := randStr + ".pdf"
  946. savePath := uploadDir + time.Now().Format("200601/20060102/")
  947. savePath += fileName
  948. //上传到阿里云
  949. err = services.UploadFileToAliyun(fileName, newFile, savePath)
  950. if err != nil {
  951. br.Msg = "下载失败"
  952. br.ErrMsg = "文件上传失败,Err:" + err.Error()
  953. return
  954. }
  955. fileHost := "https://hzstatic.hzinsights.com/"
  956. resourceUrl := fileHost + savePath
  957. defer func() {
  958. os.Remove(newFile)
  959. }()
  960. utils.Rc.SetNX(cacheKey, user.Mobile, time.Minute*5)
  961. resp.FileLink = resourceUrl
  962. br.Ret = 200
  963. br.Success = true
  964. br.Msg = "获取成功"
  965. br.Data = resp
  966. }
  967. // @Title 获取报告详情(无需token)
  968. // @Description 获取报告详情接口
  969. // @Param ArticleId query int true "报告ID"
  970. // @Param CompanyCode query string false "机构编号"
  971. // @Param CompanyName query string false "机构名称"
  972. // @Param Email query string false "邮箱"
  973. // @Param Sign query string false "加密签名"
  974. // @Success 200 {object} models.ArticleDetailHtgjResp
  975. // @router /detailPublic [get]
  976. func (this *ArticleCommonController) DetailPublic() {
  977. br := new(models.BaseResponse).Init()
  978. defer func() {
  979. this.Data["json"] = br
  980. this.ServeJSON()
  981. }()
  982. articleId, _ := this.GetInt("ArticleId")
  983. companyCode := this.GetString("CompanyCode")
  984. companyNameHt := this.GetString("CompanyName")
  985. email := this.GetString("Email")
  986. sign := this.GetString("Sign")
  987. resp := new(models.ArticleDetailHtgjResp)
  988. if companyCode == "" || email == "" {
  989. resp.HasPermission = 2
  990. br.Ret = 200
  991. br.Success = true
  992. br.Msg = "获取成功"
  993. br.Data = resp
  994. return
  995. }
  996. if articleId <= 0 {
  997. br.Msg = "文章不存在"
  998. br.ErrMsg = "文章不存在,文章ID错误"
  999. return
  1000. }
  1001. errMsg, err, wxUser, companyName := services.CheckHtgj(companyCode, companyNameHt, email, sign)
  1002. if errMsg != "" {
  1003. br.Msg = errMsg
  1004. return
  1005. }
  1006. companyPermission, err := models.GetCompanyPermission(wxUser.CompanyId)
  1007. if err != nil {
  1008. br.Msg = "获取信息失败"
  1009. br.ErrMsg = "获取用户权限失败,Err:" + err.Error() + ";articleId" + strconv.Itoa(articleId)
  1010. return
  1011. }
  1012. hasPermission := 0
  1013. detail, err := models.GetArticleDetailById(articleId)
  1014. if err != nil {
  1015. br.Msg = "获取信息失败"
  1016. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  1017. return
  1018. }
  1019. detail.Body = html.UnescapeString(detail.Body)
  1020. 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)
  1021. detail.Body = strings.Replace(detail.Body, "pre", "div", -1)
  1022. detail.Abstract, _ = services.GetReportContentTextSub(detail.Abstract)
  1023. var articlePermissionPermissionName string
  1024. if detail.CategoryId > 0 {
  1025. articlePermission, err := models.GetArticlePermission(detail.CategoryId)
  1026. if err != nil {
  1027. br.Msg = "获取信息失败"
  1028. br.ErrMsg = "获取报告权限失败,Err:" + err.Error() + strconv.Itoa(wxUser.UserId) + ";articleId" + strconv.Itoa(articleId)
  1029. return
  1030. }
  1031. if articlePermission == nil {
  1032. br.Msg = "获取信息失败"
  1033. br.ErrMsg = "报告权限不存在,Err:" + strconv.Itoa(wxUser.UserId) + ";articleId" + strconv.Itoa(articleId)
  1034. return
  1035. }
  1036. articlePermissionPermissionName = articlePermission.PermissionName
  1037. } else {
  1038. articlePermissionPermissionName = detail.CategoryName
  1039. }
  1040. var hasPersion bool
  1041. slice := strings.Split(articlePermissionPermissionName, ",")
  1042. for _, v := range slice {
  1043. if strings.Contains(companyPermission, v) {
  1044. hasPersion = true
  1045. }
  1046. }
  1047. if hasPersion {
  1048. hasPermission = 1
  1049. }
  1050. if strings.Contains(detail.CategoryName, "研选") {
  1051. detail.IsResearch = true
  1052. }
  1053. resp.HasPermission = hasPermission
  1054. if hasPermission == 1 {
  1055. //获取销售手机号
  1056. sellerItem, err := models.GetSellerByCompanyId(wxUser.CompanyId)
  1057. if err != nil {
  1058. br.Msg = "获取信息失败"
  1059. br.ErrMsg = "获取销售数据失败2,Err:" + strconv.Itoa(wxUser.UserId) + ";articleId" + strconv.Itoa(articleId)
  1060. return
  1061. }
  1062. if sellerItem != nil {
  1063. detail.SellerMobile = sellerItem.Mobile
  1064. detail.SellerName = sellerItem.RealName
  1065. }
  1066. sellerList, err := models.GetSellerList(articleId)
  1067. if err != nil {
  1068. br.Msg = "获取信息失败"
  1069. br.ErrMsg = "获取销售数据失败,Err:" + err.Error() + strconv.Itoa(wxUser.UserId) + ";articleId" + strconv.Itoa(articleId)
  1070. return
  1071. }
  1072. if detail.ArticleId >= utils.SummaryArticleId && strings.Contains(detail.SellerAndMobile, "-") {
  1073. strnum := strings.Index(detail.SellerAndMobile, "-")
  1074. detail.SellerAndMobile = detail.SellerAndMobile[0:strnum]
  1075. if strnum > 0 {
  1076. nickName := detail.SellerAndMobile[0:strnum]
  1077. sellerAndMobile := &models.SellerRep{
  1078. SellerMobile: "",
  1079. SellerName: nickName,
  1080. }
  1081. sellerList = append(sellerList, sellerAndMobile)
  1082. }
  1083. }
  1084. detail.SellerList = sellerList
  1085. resp.Detail = detail
  1086. historyRecord := new(models.CygxArticleHistoryRecord)
  1087. historyRecord.UserId = wxUser.UserId
  1088. historyRecord.ArticleId = articleId
  1089. historyRecord.CreateTime = time.Now()
  1090. historyRecord.Mobile = wxUser.Mobile
  1091. historyRecord.Email = wxUser.Email
  1092. historyRecord.CompanyId = wxUser.CompanyId
  1093. historyRecord.CompanyName = companyName
  1094. recordCount, _ := models.GetNoAddStoptimeArticleCount(wxUser.UserId, articleId)
  1095. if recordCount == 0 {
  1096. go models.AddCygxArticleHistoryRecord(historyRecord)
  1097. } else {
  1098. detailNew, err := models.GetNewArticleHistoryRecord(wxUser.UserId, articleId)
  1099. if err != nil {
  1100. br.Msg = "获取信息失败"
  1101. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  1102. return
  1103. }
  1104. if detailNew.StopTime > 0 {
  1105. go models.AddCygxArticleHistoryRecord(historyRecord)
  1106. }
  1107. }
  1108. key := "CYGX_ARTICLE_" + strconv.Itoa(articleId) + "_" + strconv.Itoa(wxUser.UserId)
  1109. if !utils.Rc.IsExist(key) {
  1110. //新增浏览记录
  1111. record := new(models.CygxArticleViewRecord)
  1112. record.UserId = wxUser.UserId
  1113. record.ArticleId = articleId
  1114. record.CreateTime = time.Now()
  1115. record.Mobile = wxUser.Mobile
  1116. record.Email = wxUser.Email
  1117. record.CompanyId = wxUser.CompanyId
  1118. record.CompanyName = companyName
  1119. go models.AddCygxArticleViewRecord(record)
  1120. utils.Rc.Put(key, 1, 5*time.Second)
  1121. models.ModifyReportLastViewTime(wxUser.UserId)
  1122. }
  1123. }
  1124. resp.CompanyName = companyName
  1125. br.Ret = 200
  1126. br.Success = true
  1127. br.Msg = "获取成功"
  1128. br.Data = resp
  1129. }
  1130. // @Title 上传文章阅读时间(无需token)
  1131. // @Description 上传文章阅读时间接口(无需token)
  1132. // @Param request body models.AddStopTimeHtgjRep true "type json string"
  1133. // @Success 200 {object} models.ArticleDetailResp
  1134. // @router /addStopTimePublic [post]
  1135. func (this *ArticleCommonController) AddStopTimePublic() {
  1136. br := new(models.BaseResponse).Init()
  1137. defer func() {
  1138. this.Data["json"] = br
  1139. this.ServeJSON()
  1140. }()
  1141. var req models.AddStopTimeHtgjRep
  1142. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1143. if err != nil {
  1144. br.Msg = "参数解析异常!"
  1145. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1146. return
  1147. }
  1148. articleId := req.ArticleId
  1149. stopTime := req.StopTime
  1150. outType := req.OutType
  1151. source := req.Source
  1152. companyCode := req.CompanyCode
  1153. companyName := req.CompanyName
  1154. wxuUserName := req.Email
  1155. sign := req.Sign
  1156. if companyCode == "" || companyName == "" || wxuUserName == "" || sign == "" {
  1157. br.Msg = "上传失败"
  1158. br.ErrMsg = "必填参数不能为空"
  1159. return
  1160. }
  1161. companyNameHt := companyCode + "_" + companyName
  1162. errMsg := services.CheckSign(companyCode+companyName+wxuUserName, sign)
  1163. if errMsg != "" {
  1164. br.Msg = errMsg
  1165. return
  1166. }
  1167. companyInfo, err := models.GetCompanyByThirdName(companyNameHt)
  1168. if err != nil {
  1169. br.Msg = "获取信息失败"
  1170. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  1171. return
  1172. }
  1173. user, err := models.GetUserByThirdName(companyInfo.CompanyId, wxuUserName)
  1174. if err != nil {
  1175. br.Msg = "获取信息失败"
  1176. br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
  1177. return
  1178. }
  1179. uid := user.UserId
  1180. if articleId <= 0 {
  1181. br.Msg = "文章ID不存在"
  1182. br.ErrMsg = "参数错误"
  1183. return
  1184. }
  1185. if stopTime == 0 {
  1186. stopTime = 1
  1187. }
  1188. if outType != 2 {
  1189. outType = 1
  1190. }
  1191. if source != "PC" {
  1192. source = "MOBILE"
  1193. }
  1194. detail := new(models.ArticleDetail)
  1195. hasPermission := 0
  1196. hasFree := 0
  1197. //判断是否已经申请过
  1198. applyCount, err := models.GetApplyRecordCount(uid)
  1199. if err != nil && err.Error() != utils.ErrNoRow() {
  1200. br.Msg = "获取信息失败"
  1201. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  1202. return
  1203. }
  1204. //`description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,4:潜在客户,未提交过申请,5:潜在客户,已提交过申请"`
  1205. if user.CompanyId > 1 {
  1206. companyPermission, err := models.GetCompanyPermission(user.CompanyId)
  1207. if err != nil {
  1208. br.Msg = "获取信息失败"
  1209. br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  1210. return
  1211. }
  1212. detail, err = models.GetArticleDetailById(articleId)
  1213. if err != nil {
  1214. br.Msg = "获取信息失败"
  1215. br.ErrMsg = "获取文章信息失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  1216. return
  1217. }
  1218. if companyPermission == "" {
  1219. if applyCount > 0 {
  1220. hasPermission = 5
  1221. } else {
  1222. hasPermission = 2
  1223. }
  1224. hasFree = 2
  1225. goto Loop
  1226. } else {
  1227. hasFree = 1
  1228. var articlePermissionPermissionName string
  1229. if detail.CategoryId > 0 {
  1230. articlePermission, err := models.GetArticlePermission(detail.CategoryId)
  1231. if err != nil {
  1232. br.Msg = "获取信息失败"
  1233. br.ErrMsg = "获取报告权限失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  1234. return
  1235. }
  1236. if articlePermission == nil {
  1237. br.Msg = "获取信息失败"
  1238. br.ErrMsg = "报告权限不存在,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  1239. return
  1240. }
  1241. articlePermissionPermissionName = articlePermission.PermissionName
  1242. } else {
  1243. articlePermissionPermissionName = detail.CategoryName
  1244. }
  1245. var hasPersion bool
  1246. slice := strings.Split(articlePermissionPermissionName, ",")
  1247. for _, v := range slice {
  1248. if strings.Contains(companyPermission, v) {
  1249. hasPersion = true
  1250. }
  1251. }
  1252. if hasPersion {
  1253. detailNew, err := models.GetNewArticleHistoryRecord(uid, articleId)
  1254. if err == nil {
  1255. hasPermission = 1
  1256. historyRecord := new(models.AddStopTimeNewRep)
  1257. historyRecord.StopTime = detailNew.StopTime + stopTime
  1258. historyRecord.Id = detailNew.Id
  1259. historyRecord.OutType = outType
  1260. go models.UpdateArticleStopTime(historyRecord)
  1261. }
  1262. //不统计本公司的阅读记录、正常退出的不做时间差统计
  1263. if user.CompanyId != 16 && stopTime > 3 {
  1264. key := "CYGX_ARTICLE_PV" + strconv.Itoa(articleId) + "_" + strconv.Itoa(uid) + "_" + strconv.Itoa(user.CompanyId) + "_" + strconv.Itoa(outType)
  1265. record := new(models.CygxArticleHistoryRecordNewpv)
  1266. record.UserId = uid
  1267. record.ArticleId = articleId
  1268. record.CreateTime = time.Now().Add(-time.Second * time.Duration(stopTime))
  1269. record.ModifyTime = time.Now()
  1270. record.Mobile = user.Mobile
  1271. record.Email = user.Email
  1272. record.CompanyId = user.CompanyId
  1273. record.CompanyName = companyInfo.CompanyName
  1274. record.StopTime = stopTime
  1275. record.OutType = outType
  1276. record.Source = source
  1277. if !utils.Rc.IsExist(key) || outType != 2 {
  1278. //新增浏览记录
  1279. go models.AddCygxArticleViewRecordNewpv(record)
  1280. recordRedis := new(services.ReportViewRecord)
  1281. recordRedis.UserId = user.UserId
  1282. recordRedis.ReportId = articleId
  1283. recordRedis.Mobile = user.Mobile
  1284. recordRedis.Email = user.Email
  1285. recordRedis.RealName = user.RealName
  1286. recordRedis.CompanyName = companyName
  1287. recordRedis.CreateTime = time.Now().Add(-time.Second * time.Duration(stopTime))
  1288. go services.PushViewRecordNewRedisData(recordRedis, user.CompanyId)
  1289. } else {
  1290. go models.UpdateCygxArticleViewRecordNewpv(record, stopTime)
  1291. }
  1292. utils.Rc.Put(key, 1, 10*time.Minute)
  1293. }
  1294. models.ModifyReportLastViewTime(uid)
  1295. } else { //无该行业权限
  1296. hasPermission = 3
  1297. }
  1298. }
  1299. } else { //潜在客户
  1300. if applyCount > 0 {
  1301. hasPermission = 5
  1302. } else {
  1303. hasPermission = 4
  1304. }
  1305. }
  1306. Loop:
  1307. resp := new(models.ArticleDetailAddStopTimeRep)
  1308. resp.HasPermission = hasPermission
  1309. resp.HasFree = hasFree
  1310. br.Ret = 200
  1311. br.Success = true
  1312. br.Msg = "操作成功"
  1313. br.Data = resp
  1314. }
  1315. // @Title 页面访问统计(无需token)
  1316. // @Description 上传页面访问统计(无需token)
  1317. // @Param request body models.CygxPageHistoryRecordHtgjRep true "type json string"
  1318. // @Success Ret=200 新增成功
  1319. // @router /pageHistoryPublic [post]
  1320. func (this *ArticleCommonController) PageHistoryPublic() {
  1321. br := new(models.BaseResponse).Init()
  1322. defer func() {
  1323. this.Data["json"] = br
  1324. this.ServeJSON()
  1325. }()
  1326. var req models.CygxPageHistoryRecordHtgjRep
  1327. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1328. if err != nil {
  1329. br.Msg = "参数解析异常!"
  1330. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1331. return
  1332. }
  1333. companyCode := req.CompanyCode
  1334. companyName := req.CompanyName
  1335. wxuUserName := req.Email
  1336. sign := req.Sign
  1337. if companyCode == "" || companyName == "" || wxuUserName == "" || sign == "" {
  1338. br.Msg = "上传失败"
  1339. br.ErrMsg = "必填参数不能为空"
  1340. return
  1341. }
  1342. companyNameHt := companyCode + "_" + companyName
  1343. errMsg := services.CheckSign(companyCode+companyName+wxuUserName, sign)
  1344. if errMsg != "" {
  1345. br.Msg = errMsg
  1346. return
  1347. }
  1348. companyInfo, err := models.GetCompanyByThirdName(companyNameHt)
  1349. if err != nil {
  1350. br.Msg = "获取信息失败"
  1351. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  1352. return
  1353. }
  1354. user, err := models.GetUserByThirdName(companyInfo.CompanyId, wxuUserName)
  1355. if err != nil {
  1356. br.Msg = "获取信息失败"
  1357. br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
  1358. return
  1359. }
  1360. item := new(models.CygxPageHistoryRecord)
  1361. item.UserId = user.UserId
  1362. item.CreateTime = time.Now()
  1363. item.Mobile = user.Mobile
  1364. item.Email = user.Email
  1365. item.CompanyId = user.CompanyId
  1366. item.CompanyName = companyName
  1367. item.DetailId = req.DetailId
  1368. item.ChartPermissionId = req.ChartPermissionId
  1369. item.IndustrialManagementId = req.IndustrialManagementId
  1370. item.PageType = "ArticleCopy"
  1371. _, err = models.AddCygxPageHistoryRecord(item)
  1372. if err != nil {
  1373. br.Msg = "记录信息失败"
  1374. br.ErrMsg = "新增访问记录失败,Err:" + err.Error()
  1375. return
  1376. }
  1377. br.Ret = 200
  1378. br.Success = true
  1379. br.Msg = "新增成功"
  1380. }