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