article.go 44 KB

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