article.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  1. package advisory
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "hongze/hz_crm_api/controllers"
  7. "hongze/hz_crm_api/models"
  8. "hongze/hz_crm_api/models/advisory"
  9. "hongze/hz_crm_api/utils"
  10. "strconv"
  11. "time"
  12. )
  13. type AdminBaseArticleController struct {
  14. controllers.BaseCommonController
  15. }
  16. // 管理端——资讯文章模块
  17. type AdminArticleController struct {
  18. controllers.BaseAuthController
  19. }
  20. // @Title 新增资讯接口 发布与定时发布
  21. // @Description 发布
  22. // @Param request body advisory.ArticleAddReq true "type json string"
  23. // @Success 200 新增成功
  24. // @router /article/firstadd [post]
  25. func (this *AdminArticleController) FirstAdd() {
  26. br := new(models.BaseResponse).Init()
  27. defer func() {
  28. this.Data["json"] = br
  29. this.ServeJSON()
  30. }()
  31. AdminUser := this.SysUser
  32. if AdminUser == nil {
  33. br.Msg = "请登录"
  34. br.ErrMsg = "请登录,用户信息为空"
  35. br.Ret = 408
  36. return
  37. }
  38. var req advisory.ArticleAddReq
  39. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  40. if err != nil {
  41. br.Msg = "参数解析异常!"
  42. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  43. return
  44. }
  45. //userFllowInfo, _ := advisory.GetUserFllowInfo(AdminUser.AdminId)
  46. //if userFllowInfo == nil {
  47. // br.Msg = "请先关注品种"
  48. // br.ErrMsg = "用户未关注品种,Err:" + err.Error()
  49. // return
  50. //} else {
  51. // fllowList := strings.Split(userFllowInfo.ChartPermissionId, ",")
  52. // isHaveFllow := advisory.CheckIsFllow(fllowList, strconv.Itoa(req.ChartPermissionId))
  53. // if isHaveFllow == false {
  54. // br.Msg = "没有关注该品种"
  55. // br.ErrMsg = "用户未关注品种,ChartPermissionId为" + strconv.Itoa(req.ChartPermissionId) + ":的品种你暂未关注"
  56. // return
  57. // }
  58. //}
  59. if req.Title == "" {
  60. br.Msg = "标题不可为空"
  61. br.ErrMsg = "标题不可为空"
  62. return
  63. }
  64. if req.Body == "" {
  65. br.Msg = "内容不可为空"
  66. br.ErrMsg = "内容不可为空"
  67. return
  68. }
  69. charInfo, err := advisory.GetCategoryInfoById(req.ChartPermissionId)
  70. if err != nil {
  71. br.Msg = "获取品种信息失败"
  72. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  73. return
  74. }
  75. item := new(advisory.AdvisoryArticle)
  76. item.Title = req.Title
  77. item.Body = req.Body
  78. item.ChartPermissionId = req.ChartPermissionId
  79. item.ChartPermissionName = charInfo.PermissionName
  80. item.AdminId = AdminUser.AdminId
  81. fmt.Println(req.TimingPublishTime)
  82. //判断是否定时发布
  83. if req.TimingPublishTime != "" {
  84. resultTime := utils.StrTimeToTime(req.TimingPublishTime) //时间字符串格式转时间格式
  85. //fmt.Println(resultTime.Format("20060102"))
  86. //fmt.Println(time.Now().Format("20060102"))
  87. if time.Now().Format("20060102") == resultTime.Format("20060102") {
  88. item.PublishStatus = 1
  89. item.ActualPublishTime = time.Now()
  90. } else {
  91. res := time.Now().Before(resultTime)
  92. if res == false {
  93. br.Msg = "定时时间错误"
  94. br.ErrMsg = "定时时间请大于当前时间"
  95. return
  96. }
  97. var pars []interface{}
  98. var condition string
  99. condition += ` AND chart_permission_id = ` + strconv.Itoa(req.ChartPermissionId) + ` AND admin_id = ` + strconv.Itoa(AdminUser.AdminId) + ` AND DATE_FORMAT(timing_publish_time,'%Y%m%d') = ` + resultTime.Format("20060102")
  100. count, _ := advisory.GetThisDayTimingPublishTimeCount(condition, pars)
  101. if count > 0 {
  102. br.Msg = "该时间已被占用,请选择其他时间"
  103. br.ErrMsg = "该时间已被占用,请选择其他时间"
  104. return
  105. }
  106. item.TimingPublishTime = resultTime
  107. item.IsTiming = 1
  108. fmt.Println(item.TimingPublishTime)
  109. }
  110. } else {
  111. item.ActualPublishTime = time.Now()
  112. item.PublishStatus = 1
  113. }
  114. item.LinkName = req.LinkName
  115. item.LinkAddress = req.LinkAddress
  116. item.CreateTime = time.Now()
  117. item.LastUpdateTime = time.Now()
  118. if req.ArticleId < 1 {
  119. item.Code = utils.MD5("advisory" + utils.GetRandDigit(6))
  120. _, err = advisory.AddArticle(item)
  121. if err != nil {
  122. br.Msg = "发布失败"
  123. br.ErrMsg = "发布失败,Err:" + err.Error()
  124. return
  125. }
  126. } else {
  127. item.ArticleId = req.ArticleId
  128. err = advisory.EditArticle(item)
  129. }
  130. if err != nil {
  131. br.Msg = "发布失败"
  132. br.ErrMsg = "发布失败,Err:" + err.Error()
  133. return
  134. }
  135. br.Ret = 200
  136. br.Success = true
  137. br.Msg = "发布成功"
  138. }
  139. // @Title 保存资讯接口
  140. // @Description 保存资讯
  141. // @Param request body advisory.ArticleAddReq true "type json string"
  142. // @Success 200 保存成功
  143. // @router /article/preservation [post]
  144. func (this *AdminArticleController) FirstPreservation() {
  145. br := new(models.BaseResponse).Init()
  146. defer func() {
  147. this.Data["json"] = br
  148. this.ServeJSON()
  149. }()
  150. AdminUser := this.SysUser
  151. if AdminUser == nil {
  152. br.Msg = "请登录"
  153. br.ErrMsg = "请登录,用户信息为空"
  154. br.Ret = 408
  155. return
  156. }
  157. var req advisory.ArticleAddReq
  158. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  159. if err != nil {
  160. br.Msg = "参数解析异常!"
  161. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  162. return
  163. }
  164. //userFllowInfo, _ := advisory.GetUserFllowInfo(AdminUser.AdminId)
  165. //if userFllowInfo == nil {
  166. // br.Msg = "请先关注品种"
  167. // br.ErrMsg = "用户未关注品种,Err:" + err.Error()
  168. // return
  169. //} else {
  170. // fllowList := strings.Split(userFllowInfo.ChartPermissionId, ",")
  171. // isHaveFllow := advisory.CheckIsFllow(fllowList, strconv.Itoa(req.ChartPermissionId))
  172. // if isHaveFllow == false {
  173. // br.Msg = "没有关注该品种"
  174. // br.ErrMsg = "用户未关注品种,ChartPermissionId为" + strconv.Itoa(req.ChartPermissionId) + ":的品种你暂未关注"
  175. // return
  176. // }
  177. //}
  178. if req.Title == "" {
  179. br.Msg = "标题不可为空"
  180. br.ErrMsg = "标题不可为空"
  181. return
  182. }
  183. charInfo, err := advisory.GetCategoryInfoById(req.ChartPermissionId)
  184. if err != nil {
  185. br.Msg = "获取品种信息失败"
  186. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  187. return
  188. }
  189. item := new(advisory.AdvisoryArticle)
  190. item.Title = req.Title
  191. item.Body = req.Body
  192. item.ChartPermissionId = req.ChartPermissionId
  193. item.ChartPermissionName = charInfo.PermissionName
  194. item.AdminId = AdminUser.AdminId
  195. item.LinkName = req.LinkName
  196. item.LinkAddress = req.LinkAddress
  197. item.CreateTime = time.Now()
  198. item.ActualPublishTime = time.Now()
  199. item.LastUpdateTime = time.Now()
  200. resp := new(advisory.ArticleDeleteReq)
  201. itemLog := new(advisory.AdvisoryArticleLog)
  202. if req.ArticleId < 1 {
  203. item.Code = utils.MD5("advisory" + utils.GetRandDigit(6))
  204. newId, err := advisory.AddArticle(item)
  205. if err != nil {
  206. br.Msg = "保存失败"
  207. br.ErrMsg = "保存失败,Err:" + err.Error()
  208. return
  209. }
  210. resp.ArticleId = newId
  211. itemLog.ArticleId = int(newId)
  212. } else {
  213. item.ArticleId = req.ArticleId
  214. resp.ArticleId = int64(req.ArticleId)
  215. itemLog.ArticleId = req.ArticleId
  216. err = advisory.EditArticle(item)
  217. if err != nil {
  218. br.Msg = "保存失败"
  219. br.ErrMsg = "保存失败,Err:" + err.Error()
  220. return
  221. }
  222. }
  223. itemLog.Title = req.Title
  224. itemLog.Body = req.Body
  225. itemLog.ChartPermissionId = req.ChartPermissionId
  226. itemLog.ChartPermissionName = charInfo.PermissionName
  227. itemLog.AdminId = AdminUser.AdminId
  228. itemLog.LinkName = req.LinkName
  229. itemLog.LinkAddress = req.LinkAddress
  230. itemLog.CreateTime = time.Now()
  231. itemLog.LastUpdateTime = time.Now()
  232. go advisory.AddArticleLog(itemLog)
  233. br.Ret = 200
  234. br.Success = true
  235. br.Msg = "保存成功"
  236. br.Data = resp
  237. }
  238. // @Title 资讯接口 文章修改
  239. // @Description 文章修改
  240. // @Param ArticleId query int true "文章ID"
  241. // @Param Title query string true "标题"
  242. // @Param Body query string true "内容"
  243. // @Param ChartPermissionId query int true "所属分类ID"
  244. // @Param TimingPublishTime query string true "定时发布时间"
  245. // @Param LinkName query string true "链接名称"
  246. // @Param LinkAddress query string true "链接地址"
  247. // @Param ArticleId query string true "文章ID"
  248. // @Success 200 修改成功
  249. // @router /edit [post]
  250. func (this *AdminArticleController) Edit() {
  251. br := new(models.BaseResponse).Init()
  252. defer func() {
  253. this.Data["json"] = br
  254. this.ServeJSON()
  255. }()
  256. AdminUser := this.SysUser
  257. if AdminUser == nil {
  258. br.Msg = "请登录"
  259. br.ErrMsg = "请登录,用户信息为空"
  260. br.Ret = 408
  261. return
  262. }
  263. var req advisory.PreservationArticle
  264. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  265. if err != nil {
  266. br.Msg = "参数解析异常!"
  267. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  268. return
  269. }
  270. //userFllowInfo, _ := advisory.GetUserFllowInfo(AdminUser.AdminId)
  271. //if userFllowInfo == nil {
  272. // br.Msg = "请先关注品种"
  273. // br.ErrMsg = "用户未关注品种,Err:" + err.Error()
  274. // return
  275. //} else {
  276. // fllowList := strings.Split(userFllowInfo.ChartPermissionId, ",")
  277. // isHaveFllow := advisory.CheckIsFllow(fllowList, strconv.Itoa(req.ChartPermissionId))
  278. // if isHaveFllow == false {
  279. // br.Msg = "没有关注该品种"
  280. // br.ErrMsg = "用户未关注品种,ChartPermissionId为" + strconv.Itoa(req.ChartPermissionId) + ":的品种你暂未关注"
  281. // return
  282. // }
  283. //}
  284. if req.ArticleId < 1 {
  285. br.Msg = "请传入文章ID"
  286. br.ErrMsg = "ArticleId不可为空"
  287. return
  288. }
  289. fmt.Println(strconv.Itoa(req.ArticleId))
  290. if req.Title == "" {
  291. br.Msg = "标题不可为空"
  292. br.ErrMsg = "标题不可为空"
  293. return
  294. }
  295. if req.Body == "" {
  296. br.Msg = "内容不可为空"
  297. br.ErrMsg = "内容不可为空"
  298. return
  299. }
  300. charInfo, err := advisory.GetCategoryInfoById(req.ChartPermissionId)
  301. if err != nil {
  302. br.Msg = "获取品种信息失败"
  303. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  304. return
  305. }
  306. userArticleInfo, err := advisory.GetUserArticleInfo(AdminUser.AdminId, int64(req.ArticleId))
  307. if userArticleInfo == nil {
  308. br.Msg = "文章不存在"
  309. br.ErrMsg = "文章ID错误,Err:" + err.Error()
  310. return
  311. }
  312. item := new(advisory.AdvisoryArticle)
  313. item.ArticleId = req.ArticleId
  314. item.Title = req.Title
  315. item.Body = req.Body
  316. item.ChartPermissionId = req.ChartPermissionId
  317. item.ChartPermissionName = charInfo.PermissionName
  318. //判断是否定时发布
  319. if req.TimingPublishTime != "" {
  320. resultTime := utils.StrTimeToTime(req.TimingPublishTime) //时间字符串格式转时间格式
  321. res := time.Now().Before(resultTime)
  322. if res == false {
  323. br.Msg = "定时时间错误"
  324. br.ErrMsg = "定时时间请大于当前时间"
  325. return
  326. }
  327. item.TimingPublishTime = resultTime
  328. }
  329. item.PublishStatus = 0
  330. item.LinkName = req.LinkName
  331. item.LinkAddress = req.LinkAddress
  332. item.CreateTime = time.Now()
  333. item.LastUpdateTime = time.Now()
  334. err = advisory.EditArticle(item)
  335. if err != nil {
  336. br.Msg = "修改失败"
  337. br.ErrMsg = "修改失败,Err:" + err.Error()
  338. return
  339. }
  340. br.Ret = 200
  341. br.Success = true
  342. br.Msg = "修改成功"
  343. }
  344. // @Title 资讯接口 文章详情
  345. // @Description 文章详情
  346. // @Param ArticleId query int true "文章ID"
  347. // @Success Ret=200 {object} advisory.AdvisoryArticle
  348. // @router /article/detail [get]
  349. func (this *AdminArticleController) Detail() {
  350. br := new(models.BaseResponse).Init()
  351. defer func() {
  352. this.Data["json"] = br
  353. this.ServeJSON()
  354. }()
  355. AdminUser := this.SysUser
  356. if AdminUser == nil {
  357. br.Msg = "请登录"
  358. br.ErrMsg = "请登录,用户信息为空"
  359. br.Ret = 408
  360. return
  361. }
  362. ArticleId, _ := this.GetInt("ArticleId")
  363. if ArticleId < 1 {
  364. br.Msg = "请输入文章ID"
  365. return
  366. }
  367. userArticleInfo, err := advisory.GetUserArticleInfo(AdminUser.AdminId, int64(ArticleId))
  368. if userArticleInfo == nil {
  369. br.Msg = "文章不存在"
  370. br.ErrMsg = "文章ID错误,Err:" + err.Error()
  371. return
  372. }
  373. br.Ret = 200
  374. br.Success = true
  375. br.Msg = "获取成功"
  376. br.Data = userArticleInfo
  377. }
  378. // @Title 删除文章
  379. // @Description 删除文章
  380. // @Param ArticleId query int true "文章ID"
  381. // @Success 200 删除成功
  382. // @router /article/delete [post]
  383. func (this *AdminArticleController) Delete() {
  384. br := new(models.BaseResponse).Init()
  385. defer func() {
  386. this.Data["json"] = br
  387. this.ServeJSON()
  388. }()
  389. AdminUser := this.SysUser
  390. if AdminUser == nil {
  391. br.Msg = "请登录"
  392. br.ErrMsg = "请登录,用户信息为空"
  393. br.Ret = 408
  394. return
  395. }
  396. var req advisory.ArticleDeleteReq
  397. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  398. if err != nil {
  399. br.Msg = "参数解析异常!"
  400. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  401. return
  402. }
  403. userArticleInfo, err := advisory.GetUserArticleInfo(AdminUser.AdminId, req.ArticleId)
  404. if userArticleInfo == nil {
  405. br.Msg = "文章不存在"
  406. br.ErrMsg = "文章ID错误,Err:" + err.Error()
  407. return
  408. }
  409. err = advisory.DeleteArticle(req.ArticleId)
  410. if err != nil {
  411. br.Msg = "删除失败"
  412. br.ErrMsg = "删除失败,Err:" + err.Error()
  413. return
  414. }
  415. br.Ret = 200
  416. br.Success = true
  417. br.Msg = "删除成功"
  418. }
  419. // @Title 取消发布
  420. // @Description 取消发布
  421. // @Param ArticleId query int true "文章ID"
  422. // @Success 200 取消成功
  423. // @router /article/unpublish [post]
  424. func (this *AdminArticleController) Unpublish() {
  425. br := new(models.BaseResponse).Init()
  426. defer func() {
  427. this.Data["json"] = br
  428. this.ServeJSON()
  429. }()
  430. AdminUser := this.SysUser
  431. if AdminUser == nil {
  432. br.Msg = "请登录"
  433. br.ErrMsg = "请登录,用户信息为空"
  434. br.Ret = 408
  435. return
  436. }
  437. var req advisory.ArticleDeleteReq
  438. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  439. if err != nil {
  440. br.Msg = "参数解析异常!"
  441. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  442. return
  443. }
  444. userArticleInfo, err := advisory.GetUserArticleInfo(AdminUser.AdminId, req.ArticleId)
  445. if userArticleInfo == nil {
  446. br.Msg = "文章不存在"
  447. br.ErrMsg = "文章ID错误,Err:" + err.Error()
  448. return
  449. }
  450. if userArticleInfo.PublishStatus == 0 {
  451. br.Msg = "已经取消发布请勿重复操作"
  452. return
  453. }
  454. err = advisory.UnpublishArticle(int(req.ArticleId))
  455. if err != nil {
  456. br.Msg = "取消失败"
  457. br.ErrMsg = "取消失败,Err:" + err.Error()
  458. return
  459. }
  460. br.Ret = 200
  461. br.Success = true
  462. br.Msg = "取消成功"
  463. }
  464. // @Title 资讯接口
  465. // @Description 列表
  466. // @Param PageSize query int true "每页数据条数"
  467. // @Param CurrentIndex query int true "当前页页码,从1开始"
  468. // @Param KeyWord query string false "关键词搜索"
  469. // @Param Status query string false "发布状态,1,已发布,0未发布"
  470. // @Param ChartPermissionIds query string false "关注分类ID,多个用英文逗号隔开"
  471. // @Param PublishSort query string true "desc:降序,asc 升序(预留)"
  472. // @Success Ret=200 {object} advisory.ArticleListResp
  473. // @router /article/list [get]
  474. func (this *AdminArticleController) List() {
  475. br := new(models.BaseResponse).Init()
  476. defer func() {
  477. this.Data["json"] = br
  478. this.ServeJSON()
  479. }()
  480. AdminUser := this.SysUser
  481. if AdminUser == nil {
  482. br.Msg = "请登录"
  483. br.ErrMsg = "请登录,用户信息为空"
  484. br.Ret = 408
  485. return
  486. }
  487. pageSize, _ := this.GetInt("PageSize")
  488. currentIndex, _ := this.GetInt("CurrentIndex")
  489. keyWord := this.GetString("KeyWord")
  490. status := this.GetString("Status")
  491. chartPermissionIds := this.GetString("ChartPermissionIds")
  492. var startSize int
  493. var condition string
  494. var pars []interface{}
  495. //condition += ` AND admin_id = ` + strconv.Itoa(AdminUser.AdminId) + ` `
  496. if status != "" {
  497. condition += ` AND publish_status = ` + status + ` `
  498. }
  499. if keyWord != "" {
  500. condition += ` AND ( title LIKE '%` + keyWord + `%' OR body LIKE '%` + keyWord + `%')`
  501. }
  502. if chartPermissionIds != "" {
  503. condition += ` AND chart_permission_id in (` + chartPermissionIds + `) `
  504. }
  505. //else {
  506. // userFllowInfo, _ := advisory.GetUserFllowInfo(AdminUser.AdminId)
  507. // if userFllowInfo != nil {
  508. // condition += ` AND chart_permission_id in (` + userFllowInfo.ChartPermissionId + `) `
  509. // }
  510. //}
  511. if pageSize <= 0 {
  512. pageSize = utils.PageSize20
  513. }
  514. if currentIndex <= 0 {
  515. currentIndex = 1
  516. }
  517. startSize = utils.StartIndex(currentIndex, pageSize)
  518. total, err := advisory.GetArticleListCount(condition, pars)
  519. if err != nil {
  520. br.Msg = "获取失败"
  521. br.ErrMsg = "获取失败,Err:" + err.Error()
  522. return
  523. }
  524. condition += ` ORDER BY last_update_time DESC `
  525. //if status == "0" {
  526. // condition += ` ORDER BY last_update_time DESC `
  527. //}
  528. list, err := advisory.GetArticlerList(condition, pars, startSize, pageSize)
  529. if err != nil {
  530. br.Msg = "获取失败"
  531. br.ErrMsg = "获取失败,Err:" + err.Error()
  532. return
  533. }
  534. for key, value := range list {
  535. LastUpdateTime := value.LastUpdateTime
  536. list[key].WhatWeek = utils.StrDateTimeToWeek(LastUpdateTime)
  537. list[key].LastUpdateTime = LastUpdateTime
  538. list[key].ActualPublishTime = utils.TimeRemoveHms(LastUpdateTime)
  539. }
  540. page := paging.GetPaging(currentIndex, pageSize, total)
  541. resp := new(advisory.ArticleListResp)
  542. resp.Paging = page
  543. resp.List = list
  544. br.Ret = 200
  545. br.Success = true
  546. br.Msg = "获取成功"
  547. br.Data = resp
  548. }
  549. // @Title 资讯接口 文章详情
  550. // @Description 通过Code获取文章详情
  551. // @Param Code query string true "文章code"
  552. // @Success Ret=200 {object} advisory.AdvisoryArticle
  553. // @router /articleCode [get]
  554. func (this *AdminArticleController) ArticleCode() {
  555. br := new(models.BaseResponse).Init()
  556. defer func() {
  557. this.Data["json"] = br
  558. this.ServeJSON()
  559. }()
  560. AdminUser := this.SysUser
  561. if AdminUser == nil {
  562. br.Msg = "请登录"
  563. br.ErrMsg = "请登录,用户信息为空"
  564. br.Ret = 408
  565. return
  566. }
  567. code := this.GetString("Code")
  568. if code == "" {
  569. br.Msg = "请输入文章Code"
  570. return
  571. }
  572. userArticleInfo, err := advisory.GetUserArticleInfoByCode(code)
  573. if userArticleInfo == nil {
  574. br.Msg = "文章不存在"
  575. br.ErrMsg = "文章Code错误,Err:" + err.Error()
  576. return
  577. }
  578. br.Ret = 200
  579. br.Success = true
  580. br.Msg = "获取成功"
  581. br.Data = userArticleInfo
  582. }
  583. // @Title 资讯接口 获取网站PV,Uv
  584. // @Description 获取网站PV,Uv
  585. // @Success Ret=200 {object} advisory.PvAndUvResp
  586. // @router /getPVAndUv [get]
  587. func (this *AdminArticleController) GetPVAndUv() {
  588. br := new(models.BaseResponse).Init()
  589. defer func() {
  590. this.Data["json"] = br
  591. this.ServeJSON()
  592. }()
  593. AdminUser := this.SysUser
  594. if AdminUser == nil {
  595. br.Msg = "请登录"
  596. br.ErrMsg = "请登录,用户信息为空"
  597. br.Ret = 408
  598. return
  599. }
  600. resp, err := advisory.GetPVAndUv()
  601. if err != nil {
  602. br.Msg = "获取失败"
  603. br.ErrMsg = "获取失败,Err:" + err.Error()
  604. return
  605. }
  606. br.Ret = 200
  607. br.Success = true
  608. br.Msg = "获取成功"
  609. br.Data = resp
  610. }