Column.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 海豚PHP框架 [ DolphinPHP ]
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2016~2019 广东卓锐软件有限公司 [ http://www.zrthink.com ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://dolphinphp.com
  8. // +----------------------------------------------------------------------
  9. namespace app\cms\home;
  10. use app\cms\model\Column as ColumnModel;
  11. use think\Db;
  12. use util\Tree;
  13. /**
  14. * 前台栏目文档列表控制器
  15. * @package app\cms\admin
  16. */
  17. class Column extends Common
  18. {
  19. /**
  20. * 栏目文章列表
  21. * @param null $id 栏目id
  22. * @author 蔡伟明 <314013107@qq.com>
  23. * @return mixed
  24. * @throws \think\db\exception\DataNotFoundException
  25. * @throws \think\db\exception\ModelNotFoundException
  26. * @throws \think\exception\DbException
  27. */
  28. public function index($id = null)
  29. {
  30. if ($id === null) $this->error('缺少参数');
  31. $map = [
  32. 'status' => 1,
  33. 'id' => $id
  34. ];
  35. $column = Db::name('cms_column')->where($map)->find();
  36. if (!$column) $this->error('该栏目不存在');
  37. $model = Db::name('cms_model')->where('id', $column['model'])->find();
  38. if ($model['type'] == 2) {
  39. $cid_all = ColumnModel::getChildsId($id);
  40. $cid_all[] = (int)$id;
  41. $map = [
  42. [$model['table'].'.trash', '=', 0],
  43. [$model['table'].'.status', '=', 1],
  44. [$model['table'].'.cid', 'in', $cid_all],
  45. ];
  46. $data_list = Db::view($model['table'], true)
  47. ->view('admin_user', 'username', $model['table'].'.uid=admin_user.id', 'left')
  48. ->where($map)
  49. ->order('create_time desc')
  50. ->paginate(config('list_rows'));
  51. $this->assign('model', $column['model']);
  52. } else {
  53. $cid_all = ColumnModel::getChildsId($id);
  54. $cid_all[] = (int)$id;
  55. $map = [
  56. ['cms_document.trash', '=', 0],
  57. ['cms_document.status', '=', 1],
  58. ['cms_document.cid', 'in', $cid_all],
  59. ];
  60. $data_list = Db::view('cms_document', true)
  61. ->view('admin_user', 'username', 'cms_document.uid=admin_user.id', 'left')
  62. ->view($model['table'], '*', 'cms_document.id='. $model['table'] . '.aid', 'left')
  63. ->where($map)
  64. ->order('create_time desc')
  65. ->paginate(config('list_rows'));
  66. $this->assign('model', '');
  67. }
  68. $this->assign('lists', $data_list);
  69. $this->assign('pages', $data_list->render());
  70. $this->assign('breadcrumb', $this->getBreadcrumb($id));
  71. $this->assign('column_info', $column);
  72. $template = $column['list_template'] == '' ? 'list' : substr($column['list_template'], 0, strpos($column['list_template'], '.'));
  73. return $this->fetch($template);
  74. }
  75. /**
  76. * 获取栏目面包屑导航
  77. * @param $id
  78. * @author 蔡伟明 <314013107@qq.com>
  79. * @return mixed
  80. */
  81. public function getBreadcrumb($id)
  82. {
  83. $columns = ColumnModel::where('status', 1)->column('id,pid,name,url,target,type');
  84. foreach ($columns as &$column) {
  85. if ($column['type'] == 0) {
  86. $column['url'] = url('cms/column/index', ['id' => $column['id']]);
  87. }
  88. }
  89. return Tree::config(['title' => 'name'])->getParents($columns, $id);
  90. }
  91. }