article.go 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "hongze/hongze_cygx/models"
  6. "hongze/hongze_cygx/services"
  7. "hongze/hongze_cygx/utils"
  8. "html"
  9. "os"
  10. "rdluck_tools/http"
  11. "regexp"
  12. "strconv"
  13. "strings"
  14. "time"
  15. )
  16. type ArticleController struct {
  17. BaseAuthController
  18. }
  19. type ArticleCommonController struct {
  20. BaseCommonController
  21. }
  22. // @Title 获取报告详情
  23. // @Description 获取报告详情接口
  24. // @Param ArticleId query int true "报告ID"
  25. // @Success 200 {object} models.ArticleDetailResp
  26. // @router /detail [get]
  27. func (this *ArticleController) Detail() {
  28. br := new(models.BaseResponse).Init()
  29. defer func() {
  30. this.Data["json"] = br
  31. this.ServeJSON()
  32. }()
  33. user := this.User
  34. if user == nil {
  35. br.Msg = "请登录"
  36. br.ErrMsg = "请登录,用户信息为空"
  37. br.Ret = 408
  38. return
  39. }
  40. uid := user.UserId
  41. articleId, err := this.GetInt("ArticleId")
  42. if articleId <= 0 {
  43. br.Msg = "文章不存在"
  44. br.ErrMsg = "文章不存在,文章ID错误"
  45. return
  46. }
  47. detail := new(models.ArticleDetail)
  48. hasPermission := 0
  49. hasFree := 0
  50. //判断是否已经申请过
  51. applyCount, err := models.GetApplyRecordCount(uid)
  52. if err != nil && err.Error() != utils.ErrNoRow() {
  53. br.Msg = "获取信息失败"
  54. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  55. return
  56. }
  57. //`description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,4:潜在客户,未提交过申请,5:潜在客户,已提交过申请"`
  58. if user.CompanyId > 1 {
  59. companyPermission, err := models.GetCompanyPermission(user.CompanyId)
  60. if err != nil {
  61. br.Msg = "获取信息失败"
  62. br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  63. return
  64. }
  65. detail, err = models.GetArticleDetailById(articleId)
  66. if err != nil {
  67. br.Msg = "获取信息失败"
  68. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  69. return
  70. }
  71. detail.Body = html.UnescapeString(detail.Body)
  72. //detail.Abstract = html.UnescapeString(detail.Abstract)
  73. detail.Abstract, _ = services.GetReportContentTextSub(detail.Abstract)
  74. if companyPermission == "" {
  75. if applyCount > 0 {
  76. hasPermission = 5
  77. } else {
  78. hasPermission = 2
  79. }
  80. hasFree = 2
  81. goto Loop
  82. } else {
  83. hasFree = 1
  84. var articlePermissionPermissionName string
  85. if detail.CategoryId > 0 {
  86. articlePermission, err := models.GetArticlePermission(detail.CategoryId)
  87. if err != nil {
  88. br.Msg = "获取信息失败"
  89. br.ErrMsg = "获取报告权限失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  90. return
  91. }
  92. if articlePermission == nil {
  93. br.Msg = "获取信息失败"
  94. br.ErrMsg = "报告权限不存在,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  95. return
  96. }
  97. articlePermissionPermissionName = articlePermission.PermissionName
  98. } else {
  99. articlePermissionPermissionName = detail.CategoryName
  100. }
  101. var hasPersion bool
  102. slice := strings.Split(articlePermissionPermissionName, ",")
  103. for _, v := range slice {
  104. if strings.Contains(companyPermission, v) {
  105. hasPersion = true
  106. }
  107. }
  108. if hasPersion {
  109. hasPermission = 1
  110. historyRecord := new(models.CygxArticleHistoryRecord)
  111. historyRecord.UserId = uid
  112. historyRecord.ArticleId = articleId
  113. historyRecord.CreateTime = time.Now()
  114. historyRecord.Mobile = user.Mobile
  115. historyRecord.Email = user.Email
  116. historyRecord.CompanyId = user.CompanyId
  117. historyRecord.CompanyName = user.CompanyName
  118. recordCount, _ := models.GetNoAddStoptimeArticleCount(uid, articleId)
  119. if recordCount == 0 {
  120. go models.AddCygxArticleHistoryRecord(historyRecord)
  121. } else {
  122. detailNew, err := models.GetNewArticleHistoryRecord(uid, articleId)
  123. if err != nil {
  124. br.Msg = "获取信息失败"
  125. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  126. return
  127. }
  128. if detailNew.StopTime > 0 {
  129. go models.AddCygxArticleHistoryRecord(historyRecord)
  130. }
  131. }
  132. } else { //无该行业权限
  133. hasPermission = 3
  134. }
  135. if hasPermission == 1 {
  136. key := "CYGX_ARTICLE_" + strconv.Itoa(articleId) + "_" + strconv.Itoa(uid)
  137. if !utils.Rc.IsExist(key) {
  138. //新增浏览记录
  139. record := new(models.CygxArticleViewRecord)
  140. record.UserId = uid
  141. record.ArticleId = articleId
  142. record.CreateTime = time.Now()
  143. record.Mobile = user.Mobile
  144. record.Email = user.Email
  145. record.CompanyId = user.CompanyId
  146. record.CompanyName = user.CompanyName
  147. go models.AddCygxArticleViewRecord(record)
  148. utils.Rc.Put(key, 1, 5*time.Second)
  149. models.ModifyReportLastViewTime(uid)
  150. }
  151. }
  152. }
  153. if strings.Contains(detail.CategoryName, "研选") {
  154. detail.IsResearch = true
  155. }
  156. collectCount, err := models.GetArticleCollectCount(uid, articleId)
  157. if err != nil && err.Error() != utils.ErrNoRow() {
  158. br.Msg = "获取信息失败"
  159. br.ErrMsg = "判断是否已收藏失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  160. return
  161. }
  162. if collectCount > 0 {
  163. detail.IsCollect = true
  164. }
  165. interviewApplyItem, err := models.GetArticleInterviewApply(uid, articleId)
  166. if err != nil && err.Error() != utils.ErrNoRow() {
  167. br.Msg = "获取信息失败"
  168. br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  169. return
  170. }
  171. if interviewApplyItem != nil && interviewApplyItem.InterviewApplyId > 0 {
  172. detail.IsInterviewApply = true
  173. detail.InterviewApplyStatus = interviewApplyItem.Status
  174. }
  175. //获取销售手机号
  176. sellerItem, err := models.GetSellerByCompanyId(user.CompanyId)
  177. if err != nil {
  178. br.Msg = "获取信息失败"
  179. br.ErrMsg = "获取销售数据失败2,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  180. return
  181. }
  182. if sellerItem != nil {
  183. detail.SellerMobile = sellerItem.Mobile
  184. detail.SellerName = sellerItem.RealName
  185. }
  186. sellerList, err := models.GetSellerList(articleId)
  187. if err != nil {
  188. br.Msg = "获取信息失败"
  189. br.ErrMsg = "获取销售数据失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  190. return
  191. }
  192. if detail.ArticleId >= utils.SummaryArticleId {
  193. //var hrefRegexp = regexp.MustCompile("[0-9]\\d*")
  194. //match := hrefRegexp.FindAllString(detail.SellerAndMobile, -1)
  195. //if match != nil {
  196. // for _, v := range match {
  197. // sellerAndMobile := &models.SellerRep{
  198. // SellerMobile: v,
  199. // SellerName: strings.Replace(detail.SellerAndMobile, v, "", -1),
  200. // }
  201. // sellerList = append(sellerList, sellerAndMobile)
  202. // }
  203. //}
  204. strnum := strings.Index(detail.SellerAndMobile, "-")
  205. detail.SellerAndMobile = detail.SellerAndMobile[0:strnum]
  206. if strnum > 0 {
  207. nickName := detail.SellerAndMobile[0:strnum]
  208. sellerAndMobile := &models.SellerRep{
  209. SellerMobile: "",
  210. SellerName: nickName,
  211. }
  212. sellerList = append(sellerList, sellerAndMobile)
  213. }
  214. }
  215. detail.SellerList = sellerList
  216. } else { //潜在客户
  217. if applyCount > 0 {
  218. hasPermission = 5
  219. } else {
  220. hasPermission = 4
  221. }
  222. }
  223. Loop:
  224. if hasPermission != 1 {
  225. detail.Body = ""
  226. detail.BodyText = ""
  227. } else {
  228. articleFollowdetail, err := models.GetArticleFollowDetail(articleId, uid)
  229. if err != nil {
  230. br.Msg = "获取信息失败"
  231. br.ErrMsg = "获取关注信息失败,Err:" + err.Error()
  232. return
  233. }
  234. detail.FollowNum = articleFollowdetail.DNum
  235. detail.CollectionNum = articleFollowdetail.AcNum
  236. if articleFollowdetail.MdNum > 0 {
  237. detail.IsFollow = true
  238. }
  239. if detail.IsSummary == 1 {
  240. detail.IsBelongSummary = true
  241. }
  242. if detail.IsReport == 1 {
  243. detail.IsBelongReport = true
  244. }
  245. }
  246. fmt.Println(uid)
  247. resp := new(models.ArticleDetailResp)
  248. resp.HasPermission = hasPermission
  249. resp.HasFree = hasFree
  250. resp.Detail = detail
  251. br.Ret = 200
  252. br.Success = true
  253. br.Msg = "获取成功"
  254. br.Data = resp
  255. }
  256. // @Title 收藏
  257. // @Description 收藏
  258. // @Param request body models.ArticleCollectReq true "type json string"
  259. // @Success 200 {object} models.FontsCollectResp
  260. // @router /collect [post]
  261. func (this *ArticleController) ArticleCollect() {
  262. br := new(models.BaseResponse).Init()
  263. defer func() {
  264. this.Data["json"] = br
  265. this.ServeJSON()
  266. }()
  267. user := this.User
  268. if user == nil {
  269. br.Msg = "请重新登录"
  270. br.Ret = 408
  271. return
  272. }
  273. uid := user.UserId
  274. var req models.ArticleCollectReq
  275. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  276. if err != nil {
  277. br.Msg = "参数解析异常!"
  278. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  279. return
  280. }
  281. count, err := models.GetArticleCollectCount(uid, req.ArticleId)
  282. if err != nil {
  283. br.Msg = "获取数据失败!"
  284. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  285. return
  286. }
  287. resp := new(models.ArticleCollectResp)
  288. if count <= 0 {
  289. item := new(models.CygxArticleCollect)
  290. item.ArticleId = req.ArticleId
  291. item.UserId = uid
  292. item.CreateTime = time.Now()
  293. _, err = models.AddCygxArticleCollect(item)
  294. if err != nil {
  295. br.Msg = "收藏失败"
  296. br.ErrMsg = "收藏失败,Err:" + err.Error()
  297. return
  298. }
  299. br.Msg = "收藏成功"
  300. resp.Status = 1
  301. } else {
  302. err = models.RemoveArticleCollect(uid, req.ArticleId)
  303. if err != nil {
  304. br.Msg = "取消收藏失败"
  305. br.ErrMsg = "取消收藏失败,Err:" + err.Error()
  306. return
  307. }
  308. br.Msg = "已取消收藏"
  309. resp.Status = 2
  310. }
  311. collectTotal, err := models.GetArticleCollectUsersCount(req.ArticleId)
  312. if err != nil {
  313. br.Msg = "获取数据失败"
  314. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  315. return
  316. }
  317. resp.CollectCount = collectTotal
  318. br.Ret = 200
  319. br.Success = true
  320. br.Data = resp
  321. }
  322. // @Title 访谈申请
  323. // @Description 访谈申请
  324. // @Param request body models.ArticleInterviewApplyReq true "type json string"
  325. // @Success 200 {object} models.FontsCollectResp
  326. // @router /interview/apply [post]
  327. func (this *ArticleController) InterviewApply() {
  328. br := new(models.BaseResponse).Init()
  329. defer func() {
  330. this.Data["json"] = br
  331. this.ServeJSON()
  332. }()
  333. user := this.User
  334. if user == nil {
  335. br.Msg = "请重新登录"
  336. br.Ret = 408
  337. return
  338. }
  339. uid := user.UserId
  340. var req models.ArticleInterviewApplyReq
  341. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  342. if err != nil {
  343. br.Msg = "参数解析异常!"
  344. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  345. return
  346. }
  347. article, err := models.GetArticleDetailById(req.ArticleId)
  348. if err != nil {
  349. br.Msg = "获取纪要失败!"
  350. br.ErrMsg = "获取纪要失败,Err:" + err.Error()
  351. return
  352. }
  353. count, err := models.GetArticleInterviewApplyCount(uid, req.ArticleId)
  354. if err != nil {
  355. br.Msg = "获取数据失败!"
  356. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  357. return
  358. }
  359. resp := new(models.ArticleInterviewApplyResp)
  360. if count <= 0 {
  361. item := new(models.CygxInterviewApply)
  362. item.ArticleId = req.ArticleId
  363. item.UserId = uid
  364. item.CompanyId = user.CompanyId
  365. item.Status = "待邀请"
  366. item.Sort = 1
  367. item.ArticleTitle = article.Title
  368. item.CreateTime = time.Now()
  369. item.ModifyTime = time.Now()
  370. item.ArticleIdMd5 = article.ArticleIdMd5
  371. _, err = models.AddCygxInterviewApply(item)
  372. if err != nil {
  373. br.Msg = "申请失败"
  374. br.ErrMsg = "申请失败,Err:" + err.Error()
  375. return
  376. }
  377. br.Msg = "申请成功"
  378. resp.Status = 1
  379. //发送模板消息
  380. if user.CompanyId > 1 {
  381. mobile := user.Mobile
  382. if mobile == "" {
  383. mobile = user.Email
  384. }
  385. sellerItem, _ := models.GetSellerByCompanyId(user.CompanyId)
  386. if sellerItem != nil && sellerItem.AdminId > 0 && user.Mobile != "" {
  387. openIpItem, _ := models.GetUserRecordByUserId(sellerItem.UserId, 1)
  388. if openIpItem != nil && openIpItem.OpenId != "" {
  389. go services.SendInterviewApplyTemplateMsg(user.RealName, sellerItem.CompanyName, mobile, article.Title, openIpItem.OpenId)
  390. }
  391. }
  392. }
  393. } else {
  394. err = models.RemoveArticleInterviewApply(uid, req.ArticleId)
  395. if err != nil {
  396. br.Msg = "取消申请失败"
  397. br.ErrMsg = "取消申请失败,Err:" + err.Error()
  398. return
  399. }
  400. br.Msg = "已取消申请"
  401. resp.Status = 2
  402. if user.CompanyId > 1 {
  403. mobile := user.Mobile
  404. if mobile == "" {
  405. mobile = user.Email
  406. }
  407. sellerItem, _ := models.GetSellerByCompanyId(user.CompanyId)
  408. if sellerItem != nil && sellerItem.AdminId > 0 && user.Mobile != "" {
  409. openIpItem, _ := models.GetUserRecordByUserId(sellerItem.UserId, 1)
  410. if openIpItem != nil && openIpItem.OpenId != "" {
  411. go services.SendInterviewApplyCancelTemplateMsg(user.RealName, sellerItem.CompanyName, mobile, article.Title, openIpItem.OpenId)
  412. }
  413. }
  414. }
  415. }
  416. br.Ret = 200
  417. br.Success = true
  418. br.Data = resp
  419. }
  420. // @Title 获取报告详情
  421. // @Description 获取报告详情接口
  422. // @Param ArticleIdMd5 query int true "报告ID"
  423. // @Success 200 {object} models.ArticleDetailResp
  424. // @router /look/detail [get]
  425. func (this *ArticleCommonController) Detail() {
  426. br := new(models.BaseResponse).Init()
  427. defer func() {
  428. this.Data["json"] = br
  429. this.ServeJSON()
  430. }()
  431. articleIdMd5 := this.GetString("ArticleIdMd5")
  432. if articleIdMd5 == "" {
  433. br.Msg = "参数错误"
  434. br.ErrMsg = "参数错误"
  435. return
  436. }
  437. resp := new(models.ArticleDetailResp)
  438. detail, err := models.GetArticleDetailByIdMd5(articleIdMd5)
  439. if err != nil && err.Error() != utils.ErrNoRow() {
  440. br.Msg = "获取信息失败"
  441. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  442. return
  443. }
  444. if detail == nil {
  445. resp.HasPermission = 2
  446. } else {
  447. resp.HasPermission = 1
  448. }
  449. if detail != nil {
  450. detail.Body = html.UnescapeString(detail.Body)
  451. detail.Abstract = html.UnescapeString(detail.Abstract)
  452. }
  453. sellerList, err := models.GetSellerList(detail.ArticleId)
  454. if err != nil {
  455. br.Msg = "获取信息失败"
  456. br.ErrMsg = "获取销售数据失败,Err:" + err.Error() + ";articleId" + strconv.Itoa(detail.ArticleId)
  457. return
  458. }
  459. if detail.ArticleId > 1000000 {
  460. var hrefRegexp = regexp.MustCompile("[0-9]\\d*")
  461. match := hrefRegexp.FindAllString(detail.SellerAndMobile, -1)
  462. if match != nil {
  463. for _, v := range match {
  464. sellerAndMobile := &models.SellerRep{
  465. SellerMobile: v,
  466. SellerName: strings.Replace(detail.SellerAndMobile, v, "", -1),
  467. }
  468. sellerList = append(sellerList, sellerAndMobile)
  469. }
  470. }
  471. }
  472. detail.Abstract, _ = services.GetReportContentTextSub(detail.Abstract)
  473. detail.SellerList = sellerList
  474. resp.Detail = detail
  475. br.Ret = 200
  476. br.Success = true
  477. br.Msg = "获取成功"
  478. br.Data = resp
  479. }
  480. // @Title 上传文章阅读时间
  481. // @Description 上传文章阅读时间接口
  482. // @Param request body models.AddStopTimeRep true "type json string"
  483. // @Success 200 {object} models.ArticleDetailResp
  484. // @router /addStopTime [post]
  485. func (this *ArticleController) AddStopTime() {
  486. br := new(models.BaseResponse).Init()
  487. defer func() {
  488. this.Data["json"] = br
  489. this.ServeJSON()
  490. }()
  491. user := this.User
  492. if user == nil {
  493. br.Msg = "请登录"
  494. br.ErrMsg = "请登录,用户信息为空"
  495. br.Ret = 408
  496. return
  497. }
  498. var req models.AddStopTimeRep
  499. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  500. if err != nil {
  501. br.Msg = "参数解析异常!"
  502. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  503. return
  504. }
  505. uid := user.UserId
  506. articleId := req.ArticleId
  507. stopTime := req.StopTime
  508. if articleId <= 0 {
  509. br.Msg = "参数错误"
  510. br.ErrMsg = "参数错误"
  511. return
  512. }
  513. if stopTime == 0 {
  514. stopTime = 1
  515. //br.Msg = "时间格式错误"
  516. //br.ErrMsg = "时间错误"
  517. //return
  518. }
  519. detail := new(models.ArticleDetail)
  520. hasPermission := 0
  521. hasFree := 0
  522. //判断是否已经申请过
  523. applyCount, err := models.GetApplyRecordCount(uid)
  524. if err != nil && err.Error() != utils.ErrNoRow() {
  525. br.Msg = "获取信息失败"
  526. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  527. return
  528. }
  529. //`description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,4:潜在客户,未提交过申请,5:潜在客户,已提交过申请"`
  530. if user.CompanyId > 1 {
  531. companyPermission, err := models.GetCompanyPermission(user.CompanyId)
  532. if err != nil {
  533. br.Msg = "获取信息失败"
  534. br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  535. return
  536. }
  537. detail, err = models.GetArticleDetailById(articleId)
  538. if err != nil {
  539. br.Msg = "获取信息失败"
  540. br.ErrMsg = "获取文章信息失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  541. return
  542. }
  543. if companyPermission == "" {
  544. if applyCount > 0 {
  545. hasPermission = 5
  546. } else {
  547. hasPermission = 2
  548. }
  549. hasFree = 2
  550. goto Loop
  551. } else {
  552. hasFree = 1
  553. var articlePermissionPermissionName string
  554. if detail.CategoryId > 0 {
  555. articlePermission, err := models.GetArticlePermission(detail.CategoryId)
  556. if err != nil {
  557. br.Msg = "获取信息失败"
  558. br.ErrMsg = "获取报告权限失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  559. return
  560. }
  561. if articlePermission == nil {
  562. br.Msg = "获取信息失败"
  563. br.ErrMsg = "报告权限不存在,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  564. return
  565. }
  566. articlePermissionPermissionName = articlePermission.PermissionName
  567. } else {
  568. articlePermissionPermissionName = detail.CategoryName
  569. }
  570. if strings.Contains(companyPermission, articlePermissionPermissionName) {
  571. detailNew, err := models.GetNewArticleHistoryRecord(uid, articleId)
  572. if err == nil {
  573. //br.Msg = "获取信息失败"
  574. //br.ErrMsg = "获取最新阅读信息失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  575. //return
  576. hasPermission = 1
  577. historyRecord := new(models.AddStopTimeNewRep)
  578. historyRecord.StopTime = detailNew.StopTime + stopTime
  579. historyRecord.Id = detailNew.Id
  580. go models.AddArticleStopTime(historyRecord)
  581. }
  582. } else { //无该行业权限
  583. hasPermission = 3
  584. }
  585. }
  586. } else { //潜在客户
  587. if applyCount > 0 {
  588. hasPermission = 5
  589. } else {
  590. hasPermission = 4
  591. }
  592. }
  593. Loop:
  594. resp := new(models.ArticleDetailAddStopTimeRep)
  595. resp.HasPermission = hasPermission
  596. resp.HasFree = hasFree
  597. br.Ret = 200
  598. br.Success = true
  599. br.Msg = "操作成功"
  600. br.Data = resp
  601. }
  602. // @Title 文章带问
  603. // @Description 新增文章带问接口
  604. // @Param request body models.AddArticleAskRep true "type json string"
  605. // @Success Ret=200 新增成功
  606. // @router /askAdd [post]
  607. func (this *ArticleController) AskAdd() {
  608. br := new(models.BaseResponse).Init()
  609. defer func() {
  610. this.Data["json"] = br
  611. this.ServeJSON()
  612. }()
  613. user := this.User
  614. if user == nil {
  615. br.Msg = "请登录"
  616. br.ErrMsg = "请登录,SysUser Is Empty"
  617. br.Ret = 408
  618. return
  619. }
  620. var req models.AddArticleAskRep
  621. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  622. if err != nil {
  623. br.Msg = "参数解析异常!"
  624. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  625. return
  626. }
  627. if req.Content == "" {
  628. br.Msg = "建议内容不可为空"
  629. return
  630. }
  631. articleId := req.ArticleId
  632. content := req.Content
  633. count, _ := models.GetArticleCountById(articleId)
  634. if count == 0 {
  635. br.Msg = "操作失败"
  636. br.ErrMsg = "文章ID错误,不存在 articleId:" + strconv.Itoa(articleId)
  637. return
  638. }
  639. companyDetail, err := models.GetCompanyDetailById(user.CompanyId)
  640. if err != nil {
  641. br.Msg = "提交失败!"
  642. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  643. return
  644. }
  645. if companyDetail == nil {
  646. br.Msg = "提交失败!"
  647. br.ErrMsg = "客户不存在,uid:" + strconv.Itoa(user.UserId)
  648. return
  649. }
  650. item := new(models.CygxArticleAsk)
  651. item.UserId = user.UserId
  652. item.ArticleId = req.ArticleId
  653. item.CompanyId = user.CompanyId
  654. item.CompanyName = companyDetail.CompanyName
  655. item.CreateTime = time.Now()
  656. item.Mobile = user.Mobile
  657. item.Email = user.Email
  658. item.Content = content
  659. _, err = models.AddArticleAsk(item)
  660. if err != nil {
  661. br.Msg = "提交失败"
  662. br.ErrMsg = "提交失败,Err:" + err.Error()
  663. return
  664. }
  665. openIdList, err := models.GetWxOpenIdByMobileList()
  666. if err != nil {
  667. br.Msg = "提交失败"
  668. br.ErrMsg = "提交失败,Err:" + err.Error()
  669. return
  670. }
  671. detail, err := models.GetArticleDetailById(articleId)
  672. if err != nil {
  673. br.Msg = "获取信息失败"
  674. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  675. return
  676. }
  677. companyName := user.CompanyName + "-" + user.RealName + "(王芳)"
  678. go services.SendWxMsgWithAsk(companyName, time.Now().Format(utils.FormatDateTime), content, detail.Title, openIdList, req.ArticleId)
  679. br.Ret = 200
  680. br.Success = true
  681. br.Msg = "提交成功"
  682. }
  683. // @Title 下载PDF打水印
  684. // @Description 下载PDF打水印接口
  685. // @Param ArticleId query int true "报告ID"
  686. // @Success 200 {object} models.ArticleDetailFileLink
  687. // @router /pdfwatermark [get]
  688. func (this *ArticleController) Pdfwatermark() {
  689. br := new(models.BaseResponse).Init()
  690. defer func() {
  691. this.Data["json"] = br
  692. this.ServeJSON()
  693. }()
  694. user := this.User
  695. if user == nil {
  696. br.Msg = "请登录"
  697. br.ErrMsg = "请登录,用户信息为空"
  698. br.Ret = 408
  699. return
  700. }
  701. articleId, err := this.GetInt("ArticleId")
  702. if articleId <= 0 {
  703. br.Msg = "文章不存在"
  704. br.ErrMsg = "文章不存在,文章ID错误"
  705. return
  706. }
  707. detail := new(models.ArticleDetail)
  708. detail, err = models.GetArticleDetailById(articleId)
  709. if err != nil {
  710. br.Msg = "获取信息失败"
  711. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  712. return
  713. }
  714. fileLink := detail.FileLink
  715. if fileLink == "" {
  716. br.Msg = "下载失败"
  717. br.ErrMsg = "下载失败,报告链接不存在"
  718. return
  719. }
  720. mobile := user.Mobile
  721. if mobile == "" {
  722. mobile = user.Email
  723. }
  724. dataMap := make(map[string]interface{})
  725. dataMap["Mobile"] = mobile
  726. //dataMap["Name"] = user.RealName
  727. dataMap["Name"] = ""
  728. dataMap["FileLink"] = fileLink
  729. postUrl := "http://127.0.0.1:5007/pdfwatermark/" //
  730. fmt.Println("postUrl:", postUrl)
  731. postData, err := json.Marshal(dataMap)
  732. if err != nil {
  733. br.Msg = "获取postData数据失败"
  734. br.ErrMsg = "解析,Marshal,Err:" + err.Error()
  735. return
  736. }
  737. fmt.Println("publish ppt param:", string(postData))
  738. result, err := http.Post(postUrl, string(postData))
  739. if err != nil {
  740. br.Msg = "发布失败"
  741. br.ErrMsg = "Marshal,Err:" + err.Error()
  742. return
  743. }
  744. fmt.Println("publish pdf result:", string(result))
  745. var pdfResult PublishPdfResult
  746. err = json.Unmarshal(result, &pdfResult)
  747. if err != nil {
  748. br.Msg = "获取数据失败"
  749. br.ErrMsg = "Unmarshal,Err:" + err.Error()
  750. return
  751. }
  752. resp := new(models.ArticleDetailFileLink)
  753. filePathName := strings.TrimLeft(pdfResult.FilePath, ".")
  754. filePathOldName := strings.TrimLeft(pdfResult.FileOldPath, ".")
  755. filePath := pdfResult.Pdfpath + filePathName
  756. filePathOld := pdfResult.Pdfpath + filePathOldName
  757. fmt.Println(filePath)
  758. fmt.Println(filePathOld)
  759. randStr := utils.GetRandStringNoSpecialChar(28)
  760. fileName := randStr + ".pdf"
  761. hzUploadDir := "static/pdf/"
  762. savePath := hzUploadDir + time.Now().Format("200601/20060102/")
  763. savePath += fileName
  764. //上传到阿里云
  765. err = services.UploadFileToAliyun(fileName, filePath, savePath)
  766. if err != nil {
  767. br.Msg = "文件上传失败"
  768. br.ErrMsg = "文件上传失败,Err:" + err.Error()
  769. return
  770. }
  771. utils.FileLog.Info("%s:", time.Now().Format(utils.FormatDateTime))
  772. utils.FileLog.Info("end update oss ")
  773. fileHost := "https://hzstatic.hzinsights.com/"
  774. resourceUrl := fileHost + savePath
  775. defer func() {
  776. os.Remove(filePath)
  777. os.Remove(filePathOld)
  778. }()
  779. resp.FileLink = resourceUrl
  780. br.Ret = 200
  781. br.Success = true
  782. br.Msg = "获取成功"
  783. br.Data = resp
  784. }
  785. type PublishPdfResult struct {
  786. Result string `json:"result"`
  787. FilePath string `json:"file_path"`
  788. FileOldPath string `json:"file_old_path"`
  789. Pdfpath string `json:"pdfpath"`
  790. }