article.go 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811
  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. if strnum > 0 {
  206. nickName := detail.SellerAndMobile[0:strnum]
  207. sellerAndMobile := &models.SellerRep{
  208. SellerMobile: "",
  209. SellerName: nickName,
  210. }
  211. sellerList = append(sellerList, sellerAndMobile)
  212. }
  213. }
  214. detail.SellerList = sellerList
  215. } else { //潜在客户
  216. if applyCount > 0 {
  217. hasPermission = 5
  218. } else {
  219. hasPermission = 4
  220. }
  221. }
  222. Loop:
  223. if hasPermission != 1 {
  224. detail.Body = ""
  225. detail.BodyText = ""
  226. } else {
  227. articleFollowdetail, err := models.GetArticleFollowDetail(articleId, uid)
  228. if err != nil {
  229. br.Msg = "获取信息失败"
  230. br.ErrMsg = "获取关注信息失败,Err:" + err.Error()
  231. return
  232. }
  233. detail.FollowNum = articleFollowdetail.DNum
  234. detail.CollectionNum = articleFollowdetail.AcNum
  235. if articleFollowdetail.MdNum > 0 {
  236. detail.IsFollow = true
  237. }
  238. if detail.IsSummary == 1 {
  239. detail.IsBelongSummary = true
  240. }
  241. if detail.IsReport == 1 {
  242. detail.IsBelongReport = true
  243. }
  244. }
  245. fmt.Println(uid)
  246. resp := new(models.ArticleDetailResp)
  247. resp.HasPermission = hasPermission
  248. resp.HasFree = hasFree
  249. resp.Detail = detail
  250. br.Ret = 200
  251. br.Success = true
  252. br.Msg = "获取成功"
  253. br.Data = resp
  254. }
  255. // @Title 收藏
  256. // @Description 收藏
  257. // @Param request body models.ArticleCollectReq true "type json string"
  258. // @Success 200 {object} models.FontsCollectResp
  259. // @router /collect [post]
  260. func (this *ArticleController) ArticleCollect() {
  261. br := new(models.BaseResponse).Init()
  262. defer func() {
  263. this.Data["json"] = br
  264. this.ServeJSON()
  265. }()
  266. user := this.User
  267. if user == nil {
  268. br.Msg = "请重新登录"
  269. br.Ret = 408
  270. return
  271. }
  272. uid := user.UserId
  273. var req models.ArticleCollectReq
  274. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  275. if err != nil {
  276. br.Msg = "参数解析异常!"
  277. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  278. return
  279. }
  280. count, err := models.GetArticleCollectCount(uid, req.ArticleId)
  281. if err != nil {
  282. br.Msg = "获取数据失败!"
  283. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  284. return
  285. }
  286. resp := new(models.ArticleCollectResp)
  287. if count <= 0 {
  288. item := new(models.CygxArticleCollect)
  289. item.ArticleId = req.ArticleId
  290. item.UserId = uid
  291. item.CreateTime = time.Now()
  292. _, err = models.AddCygxArticleCollect(item)
  293. if err != nil {
  294. br.Msg = "收藏失败"
  295. br.ErrMsg = "收藏失败,Err:" + err.Error()
  296. return
  297. }
  298. br.Msg = "收藏成功"
  299. resp.Status = 1
  300. } else {
  301. err = models.RemoveArticleCollect(uid, req.ArticleId)
  302. if err != nil {
  303. br.Msg = "取消收藏失败"
  304. br.ErrMsg = "取消收藏失败,Err:" + err.Error()
  305. return
  306. }
  307. br.Msg = "已取消收藏"
  308. resp.Status = 2
  309. }
  310. collectTotal, err := models.GetArticleCollectUsersCount(req.ArticleId)
  311. if err != nil {
  312. br.Msg = "获取数据失败"
  313. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  314. return
  315. }
  316. resp.CollectCount = collectTotal
  317. br.Ret = 200
  318. br.Success = true
  319. br.Data = resp
  320. }
  321. // @Title 访谈申请
  322. // @Description 访谈申请
  323. // @Param request body models.ArticleInterviewApplyReq true "type json string"
  324. // @Success 200 {object} models.FontsCollectResp
  325. // @router /interview/apply [post]
  326. func (this *ArticleController) InterviewApply() {
  327. br := new(models.BaseResponse).Init()
  328. defer func() {
  329. this.Data["json"] = br
  330. this.ServeJSON()
  331. }()
  332. user := this.User
  333. if user == nil {
  334. br.Msg = "请重新登录"
  335. br.Ret = 408
  336. return
  337. }
  338. uid := user.UserId
  339. var req models.ArticleInterviewApplyReq
  340. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  341. if err != nil {
  342. br.Msg = "参数解析异常!"
  343. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  344. return
  345. }
  346. article, err := models.GetArticleDetailById(req.ArticleId)
  347. if err != nil {
  348. br.Msg = "获取纪要失败!"
  349. br.ErrMsg = "获取纪要失败,Err:" + err.Error()
  350. return
  351. }
  352. count, err := models.GetArticleInterviewApplyCount(uid, req.ArticleId)
  353. if err != nil {
  354. br.Msg = "获取数据失败!"
  355. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  356. return
  357. }
  358. resp := new(models.ArticleInterviewApplyResp)
  359. if count <= 0 {
  360. item := new(models.CygxInterviewApply)
  361. item.ArticleId = req.ArticleId
  362. item.UserId = uid
  363. item.CompanyId = user.CompanyId
  364. item.Status = "待邀请"
  365. item.Sort = 1
  366. item.ArticleTitle = article.Title
  367. item.CreateTime = time.Now()
  368. item.ModifyTime = time.Now()
  369. item.ArticleIdMd5 = article.ArticleIdMd5
  370. _, err = models.AddCygxInterviewApply(item)
  371. if err != nil {
  372. br.Msg = "申请失败"
  373. br.ErrMsg = "申请失败,Err:" + err.Error()
  374. return
  375. }
  376. br.Msg = "申请成功"
  377. resp.Status = 1
  378. //发送模板消息
  379. if user.CompanyId > 1 {
  380. mobile := user.Mobile
  381. if mobile == "" {
  382. mobile = user.Email
  383. }
  384. sellerItem, _ := models.GetSellerByCompanyId(user.CompanyId)
  385. if sellerItem != nil && sellerItem.AdminId > 0 && user.Mobile != "" {
  386. openIpItem, _ := models.GetUserRecordByUserId(sellerItem.UserId, 1)
  387. if openIpItem != nil && openIpItem.OpenId != "" {
  388. go services.SendInterviewApplyTemplateMsg(user.RealName, sellerItem.CompanyName, mobile, article.Title, openIpItem.OpenId)
  389. }
  390. }
  391. }
  392. } else {
  393. err = models.RemoveArticleInterviewApply(uid, req.ArticleId)
  394. if err != nil {
  395. br.Msg = "取消申请失败"
  396. br.ErrMsg = "取消申请失败,Err:" + err.Error()
  397. return
  398. }
  399. br.Msg = "已取消申请"
  400. resp.Status = 2
  401. if user.CompanyId > 1 {
  402. mobile := user.Mobile
  403. if mobile == "" {
  404. mobile = user.Email
  405. }
  406. sellerItem, _ := models.GetSellerByCompanyId(user.CompanyId)
  407. if sellerItem != nil && sellerItem.AdminId > 0 && user.Mobile != "" {
  408. openIpItem, _ := models.GetUserRecordByUserId(sellerItem.UserId, 1)
  409. if openIpItem != nil && openIpItem.OpenId != "" {
  410. go services.SendInterviewApplyCancelTemplateMsg(user.RealName, sellerItem.CompanyName, mobile, article.Title, openIpItem.OpenId)
  411. }
  412. }
  413. }
  414. }
  415. br.Ret = 200
  416. br.Success = true
  417. br.Data = resp
  418. }
  419. // @Title 获取报告详情
  420. // @Description 获取报告详情接口
  421. // @Param ArticleIdMd5 query int true "报告ID"
  422. // @Success 200 {object} models.ArticleDetailResp
  423. // @router /look/detail [get]
  424. func (this *ArticleCommonController) Detail() {
  425. br := new(models.BaseResponse).Init()
  426. defer func() {
  427. this.Data["json"] = br
  428. this.ServeJSON()
  429. }()
  430. articleIdMd5 := this.GetString("ArticleIdMd5")
  431. if articleIdMd5 == "" {
  432. br.Msg = "参数错误"
  433. br.ErrMsg = "参数错误"
  434. return
  435. }
  436. resp := new(models.ArticleDetailResp)
  437. detail, err := models.GetArticleDetailByIdMd5(articleIdMd5)
  438. if err != nil && err.Error() != utils.ErrNoRow() {
  439. br.Msg = "获取信息失败"
  440. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  441. return
  442. }
  443. if detail == nil {
  444. resp.HasPermission = 2
  445. } else {
  446. resp.HasPermission = 1
  447. }
  448. if detail != nil {
  449. detail.Body = html.UnescapeString(detail.Body)
  450. detail.Abstract = html.UnescapeString(detail.Abstract)
  451. }
  452. sellerList, err := models.GetSellerList(detail.ArticleId)
  453. if err != nil {
  454. br.Msg = "获取信息失败"
  455. br.ErrMsg = "获取销售数据失败,Err:" + err.Error() + ";articleId" + strconv.Itoa(detail.ArticleId)
  456. return
  457. }
  458. if detail.ArticleId > 1000000 {
  459. var hrefRegexp = regexp.MustCompile("[0-9]\\d*")
  460. match := hrefRegexp.FindAllString(detail.SellerAndMobile, -1)
  461. if match != nil {
  462. for _, v := range match {
  463. sellerAndMobile := &models.SellerRep{
  464. SellerMobile: v,
  465. SellerName: strings.Replace(detail.SellerAndMobile, v, "", -1),
  466. }
  467. sellerList = append(sellerList, sellerAndMobile)
  468. }
  469. }
  470. }
  471. detail.Abstract, _ = services.GetReportContentTextSub(detail.Abstract)
  472. detail.SellerList = sellerList
  473. resp.Detail = detail
  474. br.Ret = 200
  475. br.Success = true
  476. br.Msg = "获取成功"
  477. br.Data = resp
  478. }
  479. // @Title 上传文章阅读时间
  480. // @Description 上传文章阅读时间接口
  481. // @Param request body models.AddStopTimeRep true "type json string"
  482. // @Success 200 {object} models.ArticleDetailResp
  483. // @router /addStopTime [post]
  484. func (this *ArticleController) AddStopTime() {
  485. br := new(models.BaseResponse).Init()
  486. defer func() {
  487. this.Data["json"] = br
  488. this.ServeJSON()
  489. }()
  490. user := this.User
  491. if user == nil {
  492. br.Msg = "请登录"
  493. br.ErrMsg = "请登录,用户信息为空"
  494. br.Ret = 408
  495. return
  496. }
  497. var req models.AddStopTimeRep
  498. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  499. if err != nil {
  500. br.Msg = "参数解析异常!"
  501. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  502. return
  503. }
  504. uid := user.UserId
  505. articleId := req.ArticleId
  506. stopTime := req.StopTime
  507. if articleId <= 0 {
  508. br.Msg = "参数错误"
  509. br.ErrMsg = "参数错误"
  510. return
  511. }
  512. if stopTime == 0 {
  513. stopTime = 1
  514. //br.Msg = "时间格式错误"
  515. //br.ErrMsg = "时间错误"
  516. //return
  517. }
  518. detail := new(models.ArticleDetail)
  519. hasPermission := 0
  520. hasFree := 0
  521. //判断是否已经申请过
  522. applyCount, err := models.GetApplyRecordCount(uid)
  523. if err != nil && err.Error() != utils.ErrNoRow() {
  524. br.Msg = "获取信息失败"
  525. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  526. return
  527. }
  528. //`description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,4:潜在客户,未提交过申请,5:潜在客户,已提交过申请"`
  529. if user.CompanyId > 1 {
  530. companyPermission, err := models.GetCompanyPermission(user.CompanyId)
  531. if err != nil {
  532. br.Msg = "获取信息失败"
  533. br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  534. return
  535. }
  536. detail, err = models.GetArticleDetailById(articleId)
  537. if err != nil {
  538. br.Msg = "获取信息失败"
  539. br.ErrMsg = "获取文章信息失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  540. return
  541. }
  542. if companyPermission == "" {
  543. if applyCount > 0 {
  544. hasPermission = 5
  545. } else {
  546. hasPermission = 2
  547. }
  548. hasFree = 2
  549. goto Loop
  550. } else {
  551. hasFree = 1
  552. var articlePermissionPermissionName string
  553. if detail.CategoryId > 0 {
  554. articlePermission, err := models.GetArticlePermission(detail.CategoryId)
  555. if err != nil {
  556. br.Msg = "获取信息失败"
  557. br.ErrMsg = "获取报告权限失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  558. return
  559. }
  560. if articlePermission == nil {
  561. br.Msg = "获取信息失败"
  562. br.ErrMsg = "报告权限不存在,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  563. return
  564. }
  565. articlePermissionPermissionName = articlePermission.PermissionName
  566. } else {
  567. articlePermissionPermissionName = detail.CategoryName
  568. }
  569. if strings.Contains(companyPermission, articlePermissionPermissionName) {
  570. detailNew, err := models.GetNewArticleHistoryRecord(uid, articleId)
  571. if err == nil {
  572. //br.Msg = "获取信息失败"
  573. //br.ErrMsg = "获取最新阅读信息失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  574. //return
  575. hasPermission = 1
  576. historyRecord := new(models.AddStopTimeNewRep)
  577. historyRecord.StopTime = detailNew.StopTime + stopTime
  578. historyRecord.Id = detailNew.Id
  579. go models.AddArticleStopTime(historyRecord)
  580. }
  581. } else { //无该行业权限
  582. hasPermission = 3
  583. }
  584. }
  585. } else { //潜在客户
  586. if applyCount > 0 {
  587. hasPermission = 5
  588. } else {
  589. hasPermission = 4
  590. }
  591. }
  592. Loop:
  593. resp := new(models.ArticleDetailAddStopTimeRep)
  594. resp.HasPermission = hasPermission
  595. resp.HasFree = hasFree
  596. br.Ret = 200
  597. br.Success = true
  598. br.Msg = "操作成功"
  599. br.Data = resp
  600. }
  601. // @Title 文章带问
  602. // @Description 新增文章带问接口
  603. // @Param request body models.AddArticleAskRep true "type json string"
  604. // @Success Ret=200 新增成功
  605. // @router /askAdd [post]
  606. func (this *ArticleController) AskAdd() {
  607. br := new(models.BaseResponse).Init()
  608. defer func() {
  609. this.Data["json"] = br
  610. this.ServeJSON()
  611. }()
  612. user := this.User
  613. if user == nil {
  614. br.Msg = "请登录"
  615. br.ErrMsg = "请登录,SysUser Is Empty"
  616. br.Ret = 408
  617. return
  618. }
  619. var req models.AddArticleAskRep
  620. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  621. if err != nil {
  622. br.Msg = "参数解析异常!"
  623. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  624. return
  625. }
  626. if req.Content == "" {
  627. br.Msg = "建议内容不可为空"
  628. return
  629. }
  630. articleId := req.ArticleId
  631. content := req.Content
  632. count, _ := models.GetArticleCountById(articleId)
  633. if count == 0 {
  634. br.Msg = "操作失败"
  635. br.ErrMsg = "文章ID错误,不存在 articleId:" + strconv.Itoa(articleId)
  636. return
  637. }
  638. companyDetail, err := models.GetCompanyDetailById(user.CompanyId)
  639. if err != nil {
  640. br.Msg = "提交失败!"
  641. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  642. return
  643. }
  644. if companyDetail == nil {
  645. br.Msg = "提交失败!"
  646. br.ErrMsg = "客户不存在,uid:" + strconv.Itoa(user.UserId)
  647. return
  648. }
  649. item := new(models.CygxArticleAsk)
  650. item.UserId = user.UserId
  651. item.ArticleId = req.ArticleId
  652. item.CompanyId = user.CompanyId
  653. item.CompanyName = companyDetail.CompanyName
  654. item.CreateTime = time.Now()
  655. item.Mobile = user.Mobile
  656. item.Email = user.Email
  657. item.Content = content
  658. _, err = models.AddArticleAsk(item)
  659. if err != nil {
  660. br.Msg = "提交失败"
  661. br.ErrMsg = "提交失败,Err:" + err.Error()
  662. return
  663. }
  664. openIdList, err := models.GetWxOpenIdByMobileList()
  665. if err != nil {
  666. br.Msg = "提交失败"
  667. br.ErrMsg = "提交失败,Err:" + err.Error()
  668. return
  669. }
  670. detail, err := models.GetArticleDetailById(articleId)
  671. if err != nil {
  672. br.Msg = "获取信息失败"
  673. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  674. return
  675. }
  676. companyName := user.CompanyName + "-" + user.RealName + "(王芳)"
  677. go services.SendWxMsgWithAsk(companyName, time.Now().Format(utils.FormatDateTime), content, detail.Title, openIdList, req.ArticleId)
  678. br.Ret = 200
  679. br.Success = true
  680. br.Msg = "提交成功"
  681. }
  682. // @Title 下载PDF打水印
  683. // @Description 下载PDF打水印接口
  684. // @Param ArticleId query int true "报告ID"
  685. // @Success 200 {object} models.ArticleDetailFileLink
  686. // @router /pdfwatermark [get]
  687. func (this *ArticleController) Pdfwatermark() {
  688. br := new(models.BaseResponse).Init()
  689. defer func() {
  690. this.Data["json"] = br
  691. this.ServeJSON()
  692. }()
  693. user := this.User
  694. if user == nil {
  695. br.Msg = "请登录"
  696. br.ErrMsg = "请登录,用户信息为空"
  697. br.Ret = 408
  698. return
  699. }
  700. articleId, err := this.GetInt("ArticleId")
  701. if articleId <= 0 {
  702. br.Msg = "文章不存在"
  703. br.ErrMsg = "文章不存在,文章ID错误"
  704. return
  705. }
  706. detail := new(models.ArticleDetail)
  707. detail, err = models.GetArticleDetailById(articleId)
  708. if err != nil {
  709. br.Msg = "获取信息失败"
  710. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  711. return
  712. }
  713. fileLink := detail.FileLink
  714. if fileLink == "" {
  715. br.Msg = "下载失败"
  716. br.ErrMsg = "下载失败,报告链接不存在"
  717. return
  718. }
  719. mobile := user.Mobile
  720. if mobile == "" {
  721. mobile = user.Email
  722. }
  723. dataMap := make(map[string]interface{})
  724. dataMap["Mobile"] = mobile
  725. //dataMap["Name"] = user.RealName
  726. dataMap["Name"] = ""
  727. dataMap["FileLink"] = fileLink
  728. postUrl := "http://127.0.0.1:5000/pdfwatermark/" //
  729. fmt.Println("postUrl:", postUrl)
  730. postData, err := json.Marshal(dataMap)
  731. if err != nil {
  732. br.Msg = "获取postData数据失败"
  733. br.ErrMsg = "解析,Marshal,Err:" + err.Error()
  734. return
  735. }
  736. fmt.Println("publish ppt param:", string(postData))
  737. result, err := http.Post(postUrl, string(postData))
  738. if err != nil {
  739. br.Msg = "发布失败"
  740. br.ErrMsg = "Marshal,Err:" + err.Error()
  741. return
  742. }
  743. fmt.Println("publish pdf result:", string(result))
  744. var pdfResult PublishPdfResult
  745. err = json.Unmarshal(result, &pdfResult)
  746. if err != nil {
  747. br.Msg = "获取数据失败"
  748. br.ErrMsg = "Unmarshal,Err:" + err.Error()
  749. return
  750. }
  751. resp := new(models.ArticleDetailFileLink)
  752. filePathName := strings.TrimLeft(pdfResult.FilePath, ".")
  753. filePathOldName := strings.TrimLeft(pdfResult.FileOldPath, ".")
  754. filePath := pdfResult.Pdfpath + filePathName
  755. filePathOld := pdfResult.Pdfpath + filePathOldName
  756. fmt.Println(filePath)
  757. fmt.Println(filePathOld)
  758. randStr := utils.GetRandStringNoSpecialChar(28)
  759. fileName := randStr + ".pdf"
  760. hzUploadDir := "static/pdf/"
  761. savePath := hzUploadDir + time.Now().Format("200601/20060102/")
  762. savePath += fileName
  763. //上传到阿里云
  764. err = services.UploadFileToAliyun(fileName, filePath, savePath)
  765. if err != nil {
  766. br.Msg = "文件上传失败"
  767. br.ErrMsg = "文件上传失败,Err:" + err.Error()
  768. return
  769. }
  770. utils.FileLog.Info("%s:", time.Now().Format(utils.FormatDateTime))
  771. utils.FileLog.Info("end update oss ")
  772. fileHost := "https://hzstatic.hzinsights.com/"
  773. resourceUrl := fileHost + savePath
  774. defer func() {
  775. os.Remove(filePath)
  776. os.Remove(filePathOld)
  777. }()
  778. resp.FileLink = resourceUrl
  779. br.Ret = 200
  780. br.Success = true
  781. br.Msg = "获取成功"
  782. br.Data = resp
  783. }
  784. type PublishPdfResult struct {
  785. Result string `json:"result"`
  786. FilePath string `json:"file_path"`
  787. FileOldPath string `json:"file_old_path"`
  788. Pdfpath string `json:"pdfpath"`
  789. }