Common.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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\index\controller\Home;
  11. use think\Db;
  12. use util\Tree;
  13. /**
  14. * 前台公共控制器
  15. * @package app\cms\admin
  16. */
  17. class Common extends Home
  18. {
  19. /**
  20. * 初始化方法
  21. * @author 蔡伟明 <314013107@qq.com>
  22. */
  23. protected function initialize()
  24. {
  25. parent::initialize();
  26. // 获取菜单
  27. $this->getNav();
  28. // 获取滚动图片
  29. $this->assign('slider', $this->getSlider());
  30. // 获取客服
  31. $this->assign('support', $this->getSupport());
  32. }
  33. /**
  34. * 获取导航
  35. * @author 蔡伟明 <314013107@qq.com>
  36. */
  37. private function getNav()
  38. {
  39. $list_nav = Db::name('cms_nav')->where('status', 1)->column('id,tag');
  40. foreach ($list_nav as $id => $tag) {
  41. $data_list = Db::view('cms_menu', true)
  42. ->view('cms_column', ['name' => 'column_name'], 'cms_menu.column=cms_column.id', 'left')
  43. ->view('cms_page', ['title' => 'page_title'], 'cms_menu.page=cms_page.id', 'left')
  44. ->where('cms_menu.nid', $id)
  45. ->where('cms_menu.status', 1)
  46. ->order('cms_menu.sort,cms_menu.pid,cms_menu.id')
  47. ->select();
  48. foreach ($data_list as &$item) {
  49. if ($item['type'] == 0) { // 栏目链接
  50. $item['title'] = $item['column_name'];
  51. $item['url'] = url('cms/column/index', ['id' => $item['column']]);
  52. } elseif ($item['type'] == 1) { // 单页链接
  53. $item['title'] = $item['page_title'];
  54. $item['url'] = url('cms/page/detail', ['id' => $item['page']]);
  55. } else {
  56. if ($item['url'] != '#' && substr($item['url'], 0, 4) != 'http') {
  57. $item['url'] = url($item['url']);
  58. }
  59. }
  60. }
  61. $this->assign($tag, Tree::toLayer($data_list));
  62. }
  63. }
  64. /**
  65. * 获取滚动图片
  66. * @author 蔡伟明 <314013107@qq.com>
  67. */
  68. private function getSlider()
  69. {
  70. return Db::name('cms_slider')->where('status', 1)->select();
  71. }
  72. /**
  73. * 获取在线客服
  74. * @author 蔡伟明 <314013107@qq.com>
  75. */
  76. private function getSupport()
  77. {
  78. return Db::name('cms_support')->where('status', 1)->order('sort')->select();
  79. }
  80. }