article.go 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428
  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. if user.Mobile != "" {
  312. chartUserTokenByMobile, _ := services.GetUserTokenByMobile(user.Mobile)
  313. detail.HttpUrl = utils.StrategyPlatform + strconv.Itoa(articleId) + "?token=" + chartUserTokenByMobile
  314. } else {
  315. detail.HttpUrl = utils.StrategyPlatform + strconv.Itoa(articleId)
  316. }
  317. detail.IsNeedJump = true
  318. }
  319. resp := new(models.ArticleDetailResp)
  320. resp.HasPermission = hasPermission
  321. resp.HaveResearch = haveResearch
  322. resp.HasFree = hasFree
  323. resp.Detail = detail
  324. if user.Mobile != "" {
  325. resp.Mobile = user.Mobile
  326. } else {
  327. resp.Mobile = user.Email
  328. }
  329. br.Ret = 200
  330. br.Success = true
  331. br.Msg = "获取成功"
  332. br.Data = resp
  333. }
  334. // @Title 收藏
  335. // @Description 收藏
  336. // @Param request body models.ArticleCollectReq true "type json string"
  337. // @Success 200 {object} models.FontsCollectResp
  338. // @router /collect [post]
  339. func (this *ArticleController) ArticleCollect() {
  340. br := new(models.BaseResponse).Init()
  341. defer func() {
  342. this.Data["json"] = br
  343. this.ServeJSON()
  344. }()
  345. user := this.User
  346. if user == nil {
  347. br.Msg = "请重新登录"
  348. br.Ret = 408
  349. return
  350. }
  351. uid := user.UserId
  352. var req models.ArticleCollectReq
  353. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  354. if err != nil {
  355. br.Msg = "参数解析异常!"
  356. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  357. return
  358. }
  359. count, err := models.GetArticleCollectCount(uid, req.ArticleId)
  360. if err != nil {
  361. br.Msg = "获取数据失败!"
  362. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  363. return
  364. }
  365. resp := new(models.ArticleCollectResp)
  366. if count <= 0 {
  367. item := new(models.CygxArticleCollect)
  368. item.ArticleId = req.ArticleId
  369. item.UserId = uid
  370. item.CreateTime = time.Now()
  371. item.Mobile = user.Mobile
  372. item.Email = user.Email
  373. item.CompanyId = user.CompanyId
  374. item.CompanyName = user.CompanyName
  375. item.RealName = user.RealName
  376. _, err = models.AddCygxArticleCollect(item)
  377. if err != nil {
  378. br.Msg = "收藏失败"
  379. br.ErrMsg = "收藏失败,Err:" + err.Error()
  380. return
  381. }
  382. br.Msg = "收藏成功"
  383. resp.Status = 1
  384. } else {
  385. err = models.RemoveArticleCollect(uid, req.ArticleId)
  386. if err != nil {
  387. br.Msg = "取消收藏失败"
  388. br.ErrMsg = "取消收藏失败,Err:" + err.Error()
  389. return
  390. }
  391. br.Msg = "已取消收藏"
  392. resp.Status = 2
  393. }
  394. collectTotal, err := models.GetArticleCollectUsersCount(req.ArticleId)
  395. if err != nil {
  396. br.Msg = "获取数据失败"
  397. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  398. return
  399. }
  400. resp.CollectCount = collectTotal
  401. br.Ret = 200
  402. br.Success = true
  403. br.Data = resp
  404. }
  405. // @Title 访谈申请
  406. // @Description 访谈申请
  407. // @Param request body models.ArticleInterviewApplyReq true "type json string"
  408. // @Success 200 {object} models.FontsCollectResp
  409. // @router /interview/apply [post]
  410. func (this *ArticleController) InterviewApply() {
  411. br := new(models.BaseResponse).Init()
  412. defer func() {
  413. this.Data["json"] = br
  414. this.ServeJSON()
  415. }()
  416. user := this.User
  417. if user == nil {
  418. br.Msg = "请重新登录"
  419. br.Ret = 408
  420. return
  421. }
  422. uid := user.UserId
  423. var req models.ArticleInterviewApplyReq
  424. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  425. if err != nil {
  426. br.Msg = "参数解析异常!"
  427. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  428. return
  429. }
  430. article, err := models.GetArticleDetailById(req.ArticleId)
  431. if err != nil {
  432. br.Msg = "获取纪要失败!"
  433. br.ErrMsg = "获取纪要失败,Err:" + err.Error()
  434. return
  435. }
  436. count, err := models.GetArticleInterviewApplyCount(uid, req.ArticleId)
  437. if err != nil {
  438. br.Msg = "获取数据失败!"
  439. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  440. return
  441. }
  442. resp := new(models.ArticleInterviewApplyResp)
  443. if count <= 0 {
  444. item := new(models.CygxInterviewApply)
  445. item.ArticleId = req.ArticleId
  446. item.UserId = uid
  447. item.CompanyId = user.CompanyId
  448. item.Status = "待邀请"
  449. item.Sort = 1
  450. item.ArticleTitle = article.Title
  451. item.CreateTime = time.Now()
  452. item.ModifyTime = time.Now()
  453. item.ArticleIdMd5 = article.ArticleIdMd5
  454. _, err = models.AddCygxInterviewApply(item)
  455. if err != nil {
  456. br.Msg = "申请失败"
  457. br.ErrMsg = "申请失败,Err:" + err.Error()
  458. return
  459. }
  460. br.Msg = "申请成功"
  461. resp.Status = 1
  462. //发送模板消息
  463. if user.CompanyId > 1 {
  464. mobile := user.Mobile
  465. if mobile == "" {
  466. mobile = user.Email
  467. }
  468. sellerItem, _ := models.GetSellerByCompanyId(user.CompanyId)
  469. if sellerItem != nil && sellerItem.AdminId > 0 && user.Mobile != "" {
  470. openIpItem, _ := models.GetUserRecordByUserIdByXzs(sellerItem.Mobile, 4)
  471. fmt.Println(openIpItem)
  472. if openIpItem != nil && openIpItem.OpenId != "" {
  473. go services.SendInterviewApplyTemplateMsg(user.RealName, sellerItem.CompanyName, mobile, article.Title, openIpItem.OpenId)
  474. }
  475. }
  476. }
  477. } else {
  478. err = models.RemoveArticleInterviewApply(uid, req.ArticleId)
  479. if err != nil {
  480. br.Msg = "取消申请失败"
  481. br.ErrMsg = "取消申请失败,Err:" + err.Error()
  482. return
  483. }
  484. br.Msg = "已取消申请"
  485. resp.Status = 2
  486. if user.CompanyId > 1 {
  487. mobile := user.Mobile
  488. if mobile == "" {
  489. mobile = user.Email
  490. }
  491. sellerItem, _ := models.GetSellerByCompanyId(user.CompanyId)
  492. if sellerItem != nil && sellerItem.AdminId > 0 && user.Mobile != "" {
  493. openIpItem, _ := models.GetUserRecordByUserIdByXzs(sellerItem.Mobile, 4)
  494. fmt.Println(openIpItem)
  495. if openIpItem != nil && openIpItem.OpenId != "" {
  496. go services.SendInterviewApplyCancelTemplateMsg(user.RealName, sellerItem.CompanyName, mobile, article.Title, openIpItem.OpenId)
  497. }
  498. }
  499. }
  500. }
  501. br.Ret = 200
  502. br.Success = true
  503. br.Data = resp
  504. }
  505. // @Title 获取报告详情
  506. // @Description 获取报告详情接口
  507. // @Param ArticleIdMd5 query int true "报告ID"
  508. // @Success 200 {object} models.ArticleDetailResp
  509. // @router /look/detail [get]
  510. func (this *ArticleCommonController) Detail() {
  511. br := new(models.BaseResponse).Init()
  512. defer func() {
  513. this.Data["json"] = br
  514. this.ServeJSON()
  515. }()
  516. articleIdMd5 := this.GetString("ArticleIdMd5")
  517. if articleIdMd5 == "" {
  518. br.Msg = "参数错误"
  519. br.ErrMsg = "参数错误"
  520. return
  521. }
  522. resp := new(models.ArticleDetailResp)
  523. detail, err := models.GetArticleDetailByIdMd5(articleIdMd5)
  524. if err != nil {
  525. br.Msg = "获取信息失败"
  526. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  527. return
  528. }
  529. detail.Body = html.UnescapeString(detail.Body)
  530. //detail.Abstract = html.UnescapeString(detail.Abstract)
  531. sellerList, err := models.GetSellerList(detail.ArticleId)
  532. if err != nil {
  533. br.Msg = "获取信息失败"
  534. br.ErrMsg = "获取销售数据失败,Err:" + err.Error() + ";articleId" + strconv.Itoa(detail.ArticleId)
  535. return
  536. }
  537. if detail.ArticleId > 1000000 {
  538. var hrefRegexp = regexp.MustCompile("[0-9]\\d*")
  539. match := hrefRegexp.FindAllString(detail.SellerAndMobile, -1)
  540. if match != nil {
  541. for _, v := range match {
  542. sellerAndMobile := &models.SellerRep{
  543. SellerMobile: v,
  544. SellerName: strings.Replace(detail.SellerAndMobile, v, "", -1),
  545. }
  546. sellerList = append(sellerList, sellerAndMobile)
  547. }
  548. }
  549. }
  550. resp.HasPermission = 1
  551. detail.Abstract, _ = services.GetReportContentTextSub(detail.Abstract)
  552. detail.SellerList = sellerList
  553. resp.Detail = detail
  554. br.Ret = 200
  555. br.Success = true
  556. br.Msg = "获取成功"
  557. br.Data = resp
  558. }
  559. // @Title 上传文章阅读时间
  560. // @Description 上传文章阅读时间接口
  561. // @Param request body models.AddStopTimeRep true "type json string"
  562. // @Success 200 {object} models.ArticleDetailResp
  563. // @router /addStopTime [post]
  564. func (this *ArticleController) AddStopTime() {
  565. br := new(models.BaseResponse).Init()
  566. defer func() {
  567. this.Data["json"] = br
  568. this.ServeJSON()
  569. }()
  570. user := this.User
  571. if user == nil {
  572. br.Msg = "请登录"
  573. br.ErrMsg = "请登录,用户信息为空"
  574. br.Ret = 408
  575. return
  576. }
  577. var req models.AddStopTimeRep
  578. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  579. if err != nil {
  580. br.Msg = "参数解析异常!"
  581. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  582. return
  583. }
  584. uid := user.UserId
  585. articleId := req.ArticleId
  586. stopTime := req.StopTime
  587. outType := req.OutType
  588. source := req.Source
  589. if articleId <= 0 {
  590. br.Msg = "参数错误"
  591. br.ErrMsg = "参数错误"
  592. return
  593. }
  594. if stopTime == 0 {
  595. stopTime = 1
  596. }
  597. if outType != 2 {
  598. outType = 1
  599. }
  600. if source != "PC" {
  601. source = "MOBILE"
  602. }
  603. detail := new(models.ArticleDetail)
  604. hasPermission := 0
  605. hasFree := 0
  606. //判断是否已经申请过
  607. applyCount, err := models.GetApplyRecordCount(uid)
  608. if err != nil && err.Error() != utils.ErrNoRow() {
  609. br.Msg = "获取信息失败"
  610. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  611. return
  612. }
  613. //`description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,4:潜在客户,未提交过申请,5:潜在客户,已提交过申请"`
  614. if user.CompanyId > 1 {
  615. companyPermission, err := models.GetCompanyPermission(user.CompanyId)
  616. if err != nil {
  617. br.Msg = "获取信息失败"
  618. br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  619. return
  620. }
  621. detail, err = models.GetArticleDetailById(articleId)
  622. if err != nil {
  623. br.Msg = "获取信息失败"
  624. br.ErrMsg = "获取文章信息失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  625. return
  626. }
  627. if companyPermission == "" {
  628. if applyCount > 0 {
  629. hasPermission = 5
  630. } else {
  631. hasPermission = 2
  632. }
  633. hasFree = 2
  634. goto Loop
  635. } else {
  636. hasFree = 1
  637. var articlePermissionPermissionName string
  638. if detail.CategoryId > 0 {
  639. articlePermission, err := models.GetArticlePermission(detail.CategoryId)
  640. if err != nil {
  641. br.Msg = "获取信息失败"
  642. br.ErrMsg = "获取报告权限失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  643. return
  644. }
  645. if articlePermission == nil {
  646. br.Msg = "获取信息失败"
  647. br.ErrMsg = "报告权限不存在,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  648. return
  649. }
  650. articlePermissionPermissionName = articlePermission.PermissionName
  651. } else {
  652. articlePermissionPermissionName = detail.CategoryName
  653. }
  654. var hasPersion bool
  655. slice := strings.Split(articlePermissionPermissionName, ",")
  656. for _, v := range slice {
  657. if strings.Contains(companyPermission, v) {
  658. hasPersion = true
  659. }
  660. }
  661. if hasPersion {
  662. detailNew, err := models.GetNewArticleHistoryRecord(uid, articleId)
  663. if err == nil {
  664. hasPermission = 1
  665. historyRecord := new(models.AddStopTimeNewRep)
  666. historyRecord.StopTime = detailNew.StopTime + stopTime
  667. historyRecord.Id = detailNew.Id
  668. historyRecord.OutType = outType
  669. go models.UpdateArticleStopTime(historyRecord)
  670. }
  671. //不统计本公司的阅读记录、正常退出的不做时间差统计
  672. if user.CompanyId != 16 && stopTime > 3 {
  673. key := "CYGX_ARTICLE_PV" + strconv.Itoa(articleId) + "_" + strconv.Itoa(uid) + "_" + strconv.Itoa(user.CompanyId) + "_" + strconv.Itoa(outType)
  674. record := new(models.CygxArticleHistoryRecordNewpv)
  675. record.UserId = uid
  676. record.ArticleId = articleId
  677. record.CreateTime = time.Now().Add(-time.Second * time.Duration(stopTime))
  678. record.ModifyTime = time.Now()
  679. record.Mobile = user.Mobile
  680. record.Email = user.Email
  681. record.CompanyId = user.CompanyId
  682. record.CompanyName = user.CompanyName
  683. record.StopTime = stopTime
  684. record.OutType = outType
  685. record.Source = source
  686. if !utils.Rc.IsExist(key) || outType != 2 {
  687. //新增浏览记录
  688. go models.AddCygxArticleViewRecordNewpv(record)
  689. recordRedis := new(services.ReportViewRecord)
  690. recordRedis.UserId = user.UserId
  691. recordRedis.ReportId = articleId
  692. recordRedis.Mobile = user.Mobile
  693. recordRedis.Email = user.Email
  694. recordRedis.RealName = user.RealName
  695. recordRedis.CompanyName = user.CompanyName
  696. recordRedis.CreateTime = time.Now().Add(-time.Second * time.Duration(stopTime))
  697. go services.PushViewRecordNewRedisData(recordRedis, user.CompanyId)
  698. } else {
  699. go models.UpdateCygxArticleViewRecordNewpv(record, stopTime)
  700. }
  701. utils.Rc.Put(key, 1, 10*time.Minute)
  702. }
  703. models.ModifyReportLastViewTime(uid)
  704. } else { //无该行业权限
  705. hasPermission = 3
  706. }
  707. }
  708. } else { //潜在客户
  709. if applyCount > 0 {
  710. hasPermission = 5
  711. } else {
  712. hasPermission = 4
  713. }
  714. }
  715. Loop:
  716. resp := new(models.ArticleDetailAddStopTimeRep)
  717. resp.HasPermission = hasPermission
  718. resp.HasFree = hasFree
  719. br.Ret = 200
  720. br.Success = true
  721. br.Msg = "操作成功"
  722. br.Data = resp
  723. }
  724. // @Title 文章带问
  725. // @Description 新增文章带问接口
  726. // @Param request body models.AddArticleAskRep true "type json string"
  727. // @Success Ret=200 新增成功
  728. // @router /askAdd [post]
  729. func (this *ArticleController) AskAdd() {
  730. br := new(models.BaseResponse).Init()
  731. defer func() {
  732. this.Data["json"] = br
  733. this.ServeJSON()
  734. }()
  735. user := this.User
  736. if user == nil {
  737. br.Msg = "请登录"
  738. br.ErrMsg = "请登录,SysUser Is Empty"
  739. br.Ret = 408
  740. return
  741. }
  742. var req models.AddArticleAskRep
  743. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  744. if err != nil {
  745. br.Msg = "参数解析异常!"
  746. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  747. return
  748. }
  749. if req.Content == "" {
  750. br.Msg = "建议内容不可为空"
  751. return
  752. }
  753. content := req.Content
  754. itemToken, err := services.WxGetToken()
  755. if err != nil {
  756. br.Msg = "GetWxAccessToken Err:" + err.Error()
  757. return
  758. }
  759. if itemToken.AccessToken == "" {
  760. br.Msg = "accessToken is empty"
  761. return
  762. }
  763. commerr, err := weapp.MSGSecCheck(itemToken.AccessToken, content)
  764. if err != nil {
  765. br.Msg = "内容校验失败!"
  766. br.ErrMsg = "内容校验失败,Err:" + err.Error()
  767. return
  768. }
  769. if commerr.ErrCode != 0 {
  770. br.Msg = "内容违规,请重新提交!"
  771. br.ErrMsg = "颜文字内容违规,Err:" + commerr.ErrMSG
  772. return
  773. }
  774. articleId := req.ArticleId
  775. count, _ := models.GetArticleCountById(articleId)
  776. if count == 0 {
  777. br.Msg = "操作失败"
  778. br.ErrMsg = "文章ID错误,不存在 articleId:" + strconv.Itoa(articleId)
  779. return
  780. }
  781. companyDetail, err := models.GetCompanyDetailById(user.CompanyId)
  782. if err != nil {
  783. br.Msg = "提交失败!"
  784. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  785. return
  786. }
  787. if companyDetail == nil {
  788. br.Msg = "提交失败!"
  789. br.ErrMsg = "客户不存在,uid:" + strconv.Itoa(user.UserId)
  790. return
  791. }
  792. item := new(models.CygxArticleAsk)
  793. item.UserId = user.UserId
  794. item.ArticleId = req.ArticleId
  795. item.CompanyId = user.CompanyId
  796. item.CompanyName = companyDetail.CompanyName
  797. item.CreateTime = time.Now()
  798. item.Mobile = user.Mobile
  799. item.Email = user.Email
  800. item.Content = content
  801. _, err = models.AddArticleAsk(item)
  802. if err != nil {
  803. br.Msg = "提交失败"
  804. br.ErrMsg = "提交失败,Err:" + err.Error()
  805. return
  806. }
  807. companyItem, err := models.GetSellerDetailAllByCompanyId(user.CompanyId)
  808. if err != nil {
  809. br.Msg = "获取信息失败"
  810. br.ErrMsg = "获取所属销售信息失败,Err:" + err.Error()
  811. return
  812. }
  813. var mobile string
  814. if utils.RunMode == "release" {
  815. //mobile = utils.WxMsgTemplateIdAskMsgMobileAll + "," + companyItem.Mobile
  816. mobile = utils.WxMsgTemplateIdAskMsgMobileAll
  817. } else {
  818. mobile = utils.WxMsgTemplateIdAskMsgMobile
  819. }
  820. openIdList, err := models.GetWxOpenIdByMobileList(mobile)
  821. if err != nil {
  822. br.Msg = "提交失败"
  823. br.ErrMsg = "提交失败,Err:" + err.Error()
  824. return
  825. }
  826. detail, err := models.GetArticleDetailById(articleId)
  827. if err != nil {
  828. br.Msg = "获取信息失败"
  829. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  830. return
  831. }
  832. companyName := user.CompanyName + "-" + user.RealName + "(" + companyItem.SellerName + ")"
  833. go services.SendWxMsgWithAsk(companyName, time.Now().Format(utils.FormatDateTime), content, detail.Title, openIdList, req.ArticleId)
  834. br.Ret = 200
  835. br.Success = true
  836. br.Msg = "提交成功"
  837. }
  838. // @Title 下载PDF打水印
  839. // @Description 下载PDF打水印接口
  840. // @Param ArticleId query int true "报告ID"
  841. // @Success 200 {object} models.ArticleDetailFileLink
  842. // @router /pdfwatermark [get]
  843. func (this *ArticleController) Pdfwatermark() {
  844. br := new(models.BaseResponse).Init()
  845. defer func() {
  846. this.Data["json"] = br
  847. this.ServeJSON()
  848. }()
  849. user := this.User
  850. if user == nil {
  851. br.Msg = "请登录"
  852. br.ErrMsg = "请登录,用户信息为空"
  853. br.Ret = 408
  854. return
  855. }
  856. uid := user.UserId
  857. articleId, err := this.GetInt("ArticleId")
  858. if articleId <= 0 {
  859. br.Msg = "文章不存在"
  860. br.ErrMsg = "文章不存在,文章ID错误"
  861. return
  862. }
  863. //缓存校验
  864. cacheKey := fmt.Sprint("xygx:apply_record:add:", uid, "ArticleId_", articleId)
  865. ttlTime := utils.Rc.GetRedisTTL(cacheKey)
  866. if ttlTime > 0 && user.CompanyId != 16 {
  867. br.Msg = "下载失败,下载过于频繁"
  868. br.ErrMsg = "下载失败,下载过于频繁:mobile" + user.Mobile
  869. return
  870. }
  871. resp := new(models.ArticleDetailFileLink)
  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. resp.FileLink = fileLink
  942. br.Ret = 200
  943. br.Success = true
  944. br.Msg = "获取成功"
  945. br.Data = resp
  946. return
  947. }
  948. randStr := utils.GetRandStringNoSpecialChar(28)
  949. fileName := randStr + ".pdf"
  950. savePath := uploadDir + time.Now().Format("200601/20060102/")
  951. savePath += fileName
  952. //上传到阿里云
  953. err = services.UploadFileToAliyun(fileName, newFile, savePath)
  954. if err != nil {
  955. br.Msg = "下载失败"
  956. br.ErrMsg = "文件上传失败,Err:" + err.Error()
  957. return
  958. }
  959. fileHost := "https://hzstatic.hzinsights.com/"
  960. resourceUrl := fileHost + savePath
  961. defer func() {
  962. os.Remove(newFile)
  963. }()
  964. utils.Rc.SetNX(cacheKey, user.Mobile, time.Minute*5)
  965. resp.FileLink = resourceUrl
  966. br.Ret = 200
  967. br.Success = true
  968. br.Msg = "获取成功"
  969. br.Data = resp
  970. }
  971. // @Title 获取报告详情(无需token)
  972. // @Description 获取报告详情接口
  973. // @Param ArticleId query int true "报告ID"
  974. // @Param CompanyCode query string false "机构编号"
  975. // @Param CompanyName query string false "机构名称"
  976. // @Param Email query string false "邮箱"
  977. // @Param Sign query string false "加密签名"
  978. // @Success 200 {object} models.ArticleDetailHtgjResp
  979. // @router /detailPublic [get]
  980. func (this *ArticleCommonController) DetailPublic() {
  981. br := new(models.BaseResponse).Init()
  982. defer func() {
  983. this.Data["json"] = br
  984. this.ServeJSON()
  985. }()
  986. articleId, _ := this.GetInt("ArticleId")
  987. companyCode := this.GetString("CompanyCode")
  988. companyNameHt := this.GetString("CompanyName")
  989. email := this.GetString("Email")
  990. sign := this.GetString("Sign")
  991. resp := new(models.ArticleDetailHtgjResp)
  992. if companyCode == "" || email == "" {
  993. resp.HasPermission = 2
  994. br.Ret = 200
  995. br.Success = true
  996. br.Msg = "获取成功"
  997. br.Data = resp
  998. return
  999. }
  1000. if articleId <= 0 {
  1001. br.Msg = "文章不存在"
  1002. br.ErrMsg = "文章不存在,文章ID错误"
  1003. return
  1004. }
  1005. errMsg, err, wxUser, companyName := services.CheckHtgj(companyCode, companyNameHt, email, sign)
  1006. if errMsg != "" {
  1007. br.Msg = errMsg
  1008. return
  1009. }
  1010. companyPermission, err := models.GetCompanyPermission(wxUser.CompanyId)
  1011. if err != nil {
  1012. br.Msg = "获取信息失败"
  1013. br.ErrMsg = "获取用户权限失败,Err:" + err.Error() + ";articleId" + strconv.Itoa(articleId)
  1014. return
  1015. }
  1016. hasPermission := 0
  1017. detail, err := models.GetArticleDetailById(articleId)
  1018. if err != nil {
  1019. br.Msg = "获取信息失败"
  1020. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  1021. return
  1022. }
  1023. detail.Body = html.UnescapeString(detail.Body)
  1024. 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)
  1025. detail.Body = strings.Replace(detail.Body, "pre", "div", -1)
  1026. detail.Abstract, _ = services.GetReportContentTextSub(detail.Abstract)
  1027. var articlePermissionPermissionName string
  1028. if detail.CategoryId > 0 {
  1029. articlePermission, err := models.GetArticlePermission(detail.CategoryId)
  1030. if err != nil {
  1031. br.Msg = "获取信息失败"
  1032. br.ErrMsg = "获取报告权限失败,Err:" + err.Error() + strconv.Itoa(wxUser.UserId) + ";articleId" + strconv.Itoa(articleId)
  1033. return
  1034. }
  1035. if articlePermission == nil {
  1036. br.Msg = "获取信息失败"
  1037. br.ErrMsg = "报告权限不存在,Err:" + strconv.Itoa(wxUser.UserId) + ";articleId" + strconv.Itoa(articleId)
  1038. return
  1039. }
  1040. articlePermissionPermissionName = articlePermission.PermissionName
  1041. } else {
  1042. articlePermissionPermissionName = detail.CategoryName
  1043. }
  1044. var hasPersion bool
  1045. slice := strings.Split(articlePermissionPermissionName, ",")
  1046. for _, v := range slice {
  1047. if strings.Contains(companyPermission, v) {
  1048. hasPersion = true
  1049. }
  1050. }
  1051. if hasPersion {
  1052. hasPermission = 1
  1053. }
  1054. if strings.Contains(detail.CategoryName, "研选") {
  1055. detail.IsResearch = true
  1056. }
  1057. resp.HasPermission = hasPermission
  1058. if hasPermission == 1 {
  1059. //获取销售手机号
  1060. sellerItem, err := models.GetSellerByCompanyId(wxUser.CompanyId)
  1061. if err != nil {
  1062. br.Msg = "获取信息失败"
  1063. br.ErrMsg = "获取销售数据失败2,Err:" + strconv.Itoa(wxUser.UserId) + ";articleId" + strconv.Itoa(articleId)
  1064. return
  1065. }
  1066. if sellerItem != nil {
  1067. detail.SellerMobile = sellerItem.Mobile
  1068. detail.SellerName = sellerItem.RealName
  1069. }
  1070. sellerList, err := models.GetSellerList(articleId)
  1071. if err != nil {
  1072. br.Msg = "获取信息失败"
  1073. br.ErrMsg = "获取销售数据失败,Err:" + err.Error() + strconv.Itoa(wxUser.UserId) + ";articleId" + strconv.Itoa(articleId)
  1074. return
  1075. }
  1076. if detail.ArticleId >= utils.SummaryArticleId && strings.Contains(detail.SellerAndMobile, "-") {
  1077. strnum := strings.Index(detail.SellerAndMobile, "-")
  1078. detail.SellerAndMobile = detail.SellerAndMobile[0:strnum]
  1079. if strnum > 0 {
  1080. nickName := detail.SellerAndMobile[0:strnum]
  1081. sellerAndMobile := &models.SellerRep{
  1082. SellerMobile: "",
  1083. SellerName: nickName,
  1084. }
  1085. sellerList = append(sellerList, sellerAndMobile)
  1086. }
  1087. }
  1088. detail.SellerList = sellerList
  1089. resp.Detail = detail
  1090. historyRecord := new(models.CygxArticleHistoryRecord)
  1091. historyRecord.UserId = wxUser.UserId
  1092. historyRecord.ArticleId = articleId
  1093. historyRecord.CreateTime = time.Now()
  1094. historyRecord.Mobile = wxUser.Mobile
  1095. historyRecord.Email = wxUser.Email
  1096. historyRecord.CompanyId = wxUser.CompanyId
  1097. historyRecord.CompanyName = companyName
  1098. recordCount, _ := models.GetNoAddStoptimeArticleCount(wxUser.UserId, articleId)
  1099. if recordCount == 0 {
  1100. go models.AddCygxArticleHistoryRecord(historyRecord)
  1101. } else {
  1102. detailNew, err := models.GetNewArticleHistoryRecord(wxUser.UserId, articleId)
  1103. if err != nil {
  1104. br.Msg = "获取信息失败"
  1105. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  1106. return
  1107. }
  1108. if detailNew.StopTime > 0 {
  1109. go models.AddCygxArticleHistoryRecord(historyRecord)
  1110. }
  1111. }
  1112. key := "CYGX_ARTICLE_" + strconv.Itoa(articleId) + "_" + strconv.Itoa(wxUser.UserId)
  1113. if !utils.Rc.IsExist(key) {
  1114. //新增浏览记录
  1115. record := new(models.CygxArticleViewRecord)
  1116. record.UserId = wxUser.UserId
  1117. record.ArticleId = articleId
  1118. record.CreateTime = time.Now()
  1119. record.Mobile = wxUser.Mobile
  1120. record.Email = wxUser.Email
  1121. record.CompanyId = wxUser.CompanyId
  1122. record.CompanyName = companyName
  1123. go models.AddCygxArticleViewRecord(record)
  1124. utils.Rc.Put(key, 1, 5*time.Second)
  1125. models.ModifyReportLastViewTime(wxUser.UserId)
  1126. }
  1127. }
  1128. resp.CompanyName = companyName
  1129. br.Ret = 200
  1130. br.Success = true
  1131. br.Msg = "获取成功"
  1132. br.Data = resp
  1133. }
  1134. // @Title 上传文章阅读时间(无需token)
  1135. // @Description 上传文章阅读时间接口(无需token)
  1136. // @Param request body models.AddStopTimeHtgjRep true "type json string"
  1137. // @Success 200 {object} models.ArticleDetailResp
  1138. // @router /addStopTimePublic [post]
  1139. func (this *ArticleCommonController) AddStopTimePublic() {
  1140. br := new(models.BaseResponse).Init()
  1141. defer func() {
  1142. this.Data["json"] = br
  1143. this.ServeJSON()
  1144. }()
  1145. var req models.AddStopTimeHtgjRep
  1146. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1147. if err != nil {
  1148. br.Msg = "参数解析异常!"
  1149. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1150. return
  1151. }
  1152. articleId := req.ArticleId
  1153. stopTime := req.StopTime
  1154. outType := req.OutType
  1155. source := req.Source
  1156. companyCode := req.CompanyCode
  1157. companyName := req.CompanyName
  1158. wxuUserName := req.Email
  1159. sign := req.Sign
  1160. if companyCode == "" || companyName == "" || wxuUserName == "" || sign == "" {
  1161. br.Msg = "上传失败"
  1162. br.ErrMsg = "必填参数不能为空"
  1163. return
  1164. }
  1165. companyNameHt := companyCode + "_" + companyName
  1166. errMsg := services.CheckSign(companyCode+companyName+wxuUserName, sign)
  1167. if errMsg != "" {
  1168. br.Msg = errMsg
  1169. return
  1170. }
  1171. companyInfo, err := models.GetCompanyByThirdName(companyNameHt)
  1172. if err != nil {
  1173. br.Msg = "获取信息失败"
  1174. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  1175. return
  1176. }
  1177. user, err := models.GetUserByThirdName(companyInfo.CompanyId, wxuUserName)
  1178. if err != nil {
  1179. br.Msg = "获取信息失败"
  1180. br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
  1181. return
  1182. }
  1183. uid := user.UserId
  1184. if articleId <= 0 {
  1185. br.Msg = "文章ID不存在"
  1186. br.ErrMsg = "参数错误"
  1187. return
  1188. }
  1189. if stopTime == 0 {
  1190. stopTime = 1
  1191. }
  1192. if outType != 2 {
  1193. outType = 1
  1194. }
  1195. if source != "PC" {
  1196. source = "MOBILE"
  1197. }
  1198. detail := new(models.ArticleDetail)
  1199. hasPermission := 0
  1200. hasFree := 0
  1201. //判断是否已经申请过
  1202. applyCount, err := models.GetApplyRecordCount(uid)
  1203. if err != nil && err.Error() != utils.ErrNoRow() {
  1204. br.Msg = "获取信息失败"
  1205. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  1206. return
  1207. }
  1208. //`description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,4:潜在客户,未提交过申请,5:潜在客户,已提交过申请"`
  1209. if user.CompanyId > 1 {
  1210. companyPermission, err := models.GetCompanyPermission(user.CompanyId)
  1211. if err != nil {
  1212. br.Msg = "获取信息失败"
  1213. br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  1214. return
  1215. }
  1216. detail, err = models.GetArticleDetailById(articleId)
  1217. if err != nil {
  1218. br.Msg = "获取信息失败"
  1219. br.ErrMsg = "获取文章信息失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  1220. return
  1221. }
  1222. if companyPermission == "" {
  1223. if applyCount > 0 {
  1224. hasPermission = 5
  1225. } else {
  1226. hasPermission = 2
  1227. }
  1228. hasFree = 2
  1229. goto Loop
  1230. } else {
  1231. hasFree = 1
  1232. var articlePermissionPermissionName string
  1233. if detail.CategoryId > 0 {
  1234. articlePermission, err := models.GetArticlePermission(detail.CategoryId)
  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 articlePermission == nil {
  1241. br.Msg = "获取信息失败"
  1242. br.ErrMsg = "报告权限不存在,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  1243. return
  1244. }
  1245. articlePermissionPermissionName = articlePermission.PermissionName
  1246. } else {
  1247. articlePermissionPermissionName = detail.CategoryName
  1248. }
  1249. var hasPersion bool
  1250. slice := strings.Split(articlePermissionPermissionName, ",")
  1251. for _, v := range slice {
  1252. if strings.Contains(companyPermission, v) {
  1253. hasPersion = true
  1254. }
  1255. }
  1256. if hasPersion {
  1257. detailNew, err := models.GetNewArticleHistoryRecord(uid, articleId)
  1258. if err == nil {
  1259. hasPermission = 1
  1260. historyRecord := new(models.AddStopTimeNewRep)
  1261. historyRecord.StopTime = detailNew.StopTime + stopTime
  1262. historyRecord.Id = detailNew.Id
  1263. historyRecord.OutType = outType
  1264. go models.UpdateArticleStopTime(historyRecord)
  1265. }
  1266. //不统计本公司的阅读记录、正常退出的不做时间差统计
  1267. if user.CompanyId != 16 && stopTime > 3 {
  1268. key := "CYGX_ARTICLE_PV" + strconv.Itoa(articleId) + "_" + strconv.Itoa(uid) + "_" + strconv.Itoa(user.CompanyId) + "_" + strconv.Itoa(outType)
  1269. record := new(models.CygxArticleHistoryRecordNewpv)
  1270. record.UserId = uid
  1271. record.ArticleId = articleId
  1272. record.CreateTime = time.Now().Add(-time.Second * time.Duration(stopTime))
  1273. record.ModifyTime = time.Now()
  1274. record.Mobile = user.Mobile
  1275. record.Email = user.Email
  1276. record.CompanyId = user.CompanyId
  1277. record.CompanyName = companyInfo.CompanyName
  1278. record.StopTime = stopTime
  1279. record.OutType = outType
  1280. record.Source = source
  1281. if !utils.Rc.IsExist(key) || outType != 2 {
  1282. //新增浏览记录
  1283. go models.AddCygxArticleViewRecordNewpv(record)
  1284. recordRedis := new(services.ReportViewRecord)
  1285. recordRedis.UserId = user.UserId
  1286. recordRedis.ReportId = articleId
  1287. recordRedis.Mobile = user.Mobile
  1288. recordRedis.Email = user.Email
  1289. recordRedis.RealName = user.RealName
  1290. recordRedis.CompanyName = companyName
  1291. recordRedis.CreateTime = time.Now().Add(-time.Second * time.Duration(stopTime))
  1292. go services.PushViewRecordNewRedisData(recordRedis, user.CompanyId)
  1293. } else {
  1294. go models.UpdateCygxArticleViewRecordNewpv(record, stopTime)
  1295. }
  1296. utils.Rc.Put(key, 1, 10*time.Minute)
  1297. }
  1298. models.ModifyReportLastViewTime(uid)
  1299. } else { //无该行业权限
  1300. hasPermission = 3
  1301. }
  1302. }
  1303. } else { //潜在客户
  1304. if applyCount > 0 {
  1305. hasPermission = 5
  1306. } else {
  1307. hasPermission = 4
  1308. }
  1309. }
  1310. Loop:
  1311. resp := new(models.ArticleDetailAddStopTimeRep)
  1312. resp.HasPermission = hasPermission
  1313. resp.HasFree = hasFree
  1314. br.Ret = 200
  1315. br.Success = true
  1316. br.Msg = "操作成功"
  1317. br.Data = resp
  1318. }
  1319. // @Title 页面访问统计(无需token)
  1320. // @Description 上传页面访问统计(无需token)
  1321. // @Param request body models.CygxPageHistoryRecordHtgjRep true "type json string"
  1322. // @Success Ret=200 新增成功
  1323. // @router /pageHistoryPublic [post]
  1324. func (this *ArticleCommonController) PageHistoryPublic() {
  1325. br := new(models.BaseResponse).Init()
  1326. defer func() {
  1327. this.Data["json"] = br
  1328. this.ServeJSON()
  1329. }()
  1330. var req models.CygxPageHistoryRecordHtgjRep
  1331. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1332. if err != nil {
  1333. br.Msg = "参数解析异常!"
  1334. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1335. return
  1336. }
  1337. companyCode := req.CompanyCode
  1338. companyName := req.CompanyName
  1339. wxuUserName := req.Email
  1340. sign := req.Sign
  1341. if companyCode == "" || companyName == "" || wxuUserName == "" || sign == "" {
  1342. br.Msg = "上传失败"
  1343. br.ErrMsg = "必填参数不能为空"
  1344. return
  1345. }
  1346. companyNameHt := companyCode + "_" + companyName
  1347. errMsg := services.CheckSign(companyCode+companyName+wxuUserName, sign)
  1348. if errMsg != "" {
  1349. br.Msg = errMsg
  1350. return
  1351. }
  1352. companyInfo, err := models.GetCompanyByThirdName(companyNameHt)
  1353. if err != nil {
  1354. br.Msg = "获取信息失败"
  1355. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  1356. return
  1357. }
  1358. user, err := models.GetUserByThirdName(companyInfo.CompanyId, wxuUserName)
  1359. if err != nil {
  1360. br.Msg = "获取信息失败"
  1361. br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
  1362. return
  1363. }
  1364. item := new(models.CygxPageHistoryRecord)
  1365. item.UserId = user.UserId
  1366. item.CreateTime = time.Now()
  1367. item.Mobile = user.Mobile
  1368. item.Email = user.Email
  1369. item.CompanyId = user.CompanyId
  1370. item.CompanyName = companyName
  1371. item.DetailId = req.DetailId
  1372. item.ChartPermissionId = req.ChartPermissionId
  1373. item.IndustrialManagementId = req.IndustrialManagementId
  1374. item.PageType = "ArticleCopy"
  1375. _, err = models.AddCygxPageHistoryRecord(item)
  1376. if err != nil {
  1377. br.Msg = "记录信息失败"
  1378. br.ErrMsg = "新增访问记录失败,Err:" + err.Error()
  1379. return
  1380. }
  1381. br.Ret = 200
  1382. br.Success = true
  1383. br.Msg = "新增成功"
  1384. }