PageApi.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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())
  33. ->where('published_time', '>', 0)
  34. ->where(function (Query $query) use ($param) {
  35. if (!empty($param['keyword'])) {
  36. $query->where('post_title', 'like', "%{$param['keyword']}%");
  37. }
  38. })->select();
  39. }
  40. /**
  41. * 页面列表 用于导航选择
  42. * @return array
  43. */
  44. public function nav()
  45. {
  46. $portalPostModel = new PortalPostModel();
  47. $where = [
  48. 'post_type' => 2,
  49. 'post_status' => 1,
  50. 'delete_time' => 0
  51. ];
  52. $pages = $portalPostModel->field('id,post_title AS name')
  53. ->where('published_time', '<', time())
  54. ->where('published_time', '>', 0)
  55. ->where($where)->select();
  56. $return = [
  57. 'rule' => [
  58. 'action' => 'portal/Page/index',
  59. 'param' => [
  60. 'id' => 'id'
  61. ]
  62. ],//url规则
  63. 'items' => $pages //每个子项item里必须包括id,name,如果想表示层级关系请加上 parent_id
  64. ];
  65. return $return;
  66. }
  67. }