PageApi.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2013-2019 http://www.thinkcmf.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: 老猫 <thinkcmf@126.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\portal\api;
  12. use app\portal\model\PortalPostModel;
  13. use think\db\Query;
  14. class PageApi
  15. {
  16. /**
  17. * 页面列表 用于模板设计
  18. * @param array $param
  19. * @return false|\PDOStatement|string|\think\Collection
  20. */
  21. public function index($param = [])
  22. {
  23. $portalPostModel = new PortalPostModel();
  24. $where = [
  25. 'post_type' => 2,
  26. 'post_status' => 1,
  27. 'delete_time' => 0
  28. ];
  29. //返回的数据必须是数据集或数组,item里必须包括id,name,如果想表示层级关系请加上 parent_id
  30. return $portalPostModel->field('id,post_title AS name')
  31. ->where($where)
  32. ->where('published_time',['<', time()], ['> time', 0],'and')
  33. ->where(function (Query $query) use ($param) {
  34. if (!empty($param['keyword'])) {
  35. $query->where('post_title', 'like', "%{$param['keyword']}%");
  36. }
  37. })->select();
  38. }
  39. /**
  40. * 页面列表 用于导航选择
  41. * @return array
  42. */
  43. public function nav()
  44. {
  45. $portalPostModel = new PortalPostModel();
  46. $where = [
  47. 'post_type' => 2,
  48. 'post_status' => 1,
  49. 'delete_time' => 0
  50. ];
  51. $pages = $portalPostModel->field('id,post_title AS name')
  52. ->where('published_time',['<', time()], ['> time', 0],'and')
  53. ->where($where)->select();
  54. $return = [
  55. 'rule' => [
  56. 'action' => 'portal/Page/index',
  57. 'param' => [
  58. 'id' => 'id'
  59. ]
  60. ],//url规则
  61. 'items' => $pages //每个子项item里必须包括id,name,如果想表示层级关系请加上 parent_id
  62. ];
  63. return $return;
  64. }
  65. }