PagesController.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Author: pl125 <xskjs888@163.com>
  8. // +----------------------------------------------------------------------
  9. namespace api\portal\controller;
  10. use api\portal\service\PortalPostService;
  11. use cmf\controller\RestBaseController;
  12. use api\portal\model\PortalPostModel;
  13. class PagesController extends RestBaseController
  14. {
  15. /**
  16. * 页面列表
  17. * @throws \think\db\exception\DataNotFoundException
  18. * @throws \think\db\exception\ModelNotFoundException
  19. * @throws \think\exception\DbException
  20. */
  21. public function index()
  22. {
  23. $params = $this->request->get();
  24. $postService = new PortalPostService();
  25. $data = $postService->postArticles($params, true);
  26. if (empty($this->apiVersion) || $this->apiVersion == '1.0.0') {
  27. $response = $data;
  28. } else {
  29. $response = ['list' => $data,];
  30. }
  31. $this->success('请求成功!', $response);
  32. }
  33. /**
  34. * 获取页面
  35. * @param $id
  36. * @throws \think\db\exception\DataNotFoundException
  37. * @throws \think\db\exception\ModelNotFoundException
  38. * @throws \think\exception\DbException
  39. */
  40. public function read($id)
  41. {
  42. $params = $this->request->get();
  43. $field = empty($params['field']) ? '*' : $params['field'];
  44. $postModel = new PortalPostModel();
  45. $data = $postModel
  46. ->field($field)
  47. ->where('id', $id)
  48. ->where('delete_time', 0)
  49. ->where('post_status', 1)
  50. ->where('post_type', 2)
  51. ->find();
  52. if ($data){
  53. $this->success('请求成功!', $data);
  54. }else{
  55. $this->error('文章不存在!');
  56. }
  57. }
  58. }