article.go 23 KB

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