Browse Source

上传文件至 ''

鬼彝 4 months ago
parent
commit
149815f888
1 changed files with 102 additions and 0 deletions
  1. 102 0
      Base.php

+ 102 - 0
Base.php

@@ -0,0 +1,102 @@
1
+<?php
2
+/**
3
+ * Created by PhpStorm.
4
+ * User: 庞涛
5
+ * Date: 2018/8/28
6
+ * Time: 10:30
7
+ */
8
+namespace app\mobile\controller;
9
+class Base extends \think\Controller
10
+{
11
+    protected $site;
12
+    private $controller;
13
+    private $seo;
14
+    protected $menuSeo = true;
15
+    public function _initialize(){
16
+        parent::_initialize();
17
+        if(request()->isMobile()){
18
+        }
19
+        $site = cache('site');
20
+        if($site['status'] == 0){
21
+            die($site['reson']);
22
+        }
23
+        $this->site = $site;
24
+        $this->seo = [
25
+            'title'     => $site['title'],
26
+            'seo_title' => $site['seo_title'],
27
+            'seo_keys'  => $site['seo_keys'],
28
+            'seo_desc'  => $site['seo_desc']
29
+        ];
30
+        $qq = str_replace(',',',',$site['qq']);
31
+        $qq = explode(',',$qq);
32
+        $this->controller = strtolower(request()->controller());
33
+        $this->getMenu();
34
+        $this->setSeo();
35
+        $this->getCate();//单页分类
36
+        $this->assign('site',$site);
37
+        $this->assign('qq',$qq);
38
+        $this->assign('controller',$this->controller);
39
+    }
40
+
41
+    //设置站点优化
42
+    protected function setSeo($info='',$field='title',$q=''){
43
+        if(!empty($info)){
44
+            $info['title'] = isset($info['title']) ? $info['title'] : $info[$field];
45
+            $seo['title'] = empty($info['seo_title']) ? $info[$field].'_'.$this->seo['title'] : $info['seo_title'].'_'.$this->seo['title'];
46
+            $seo['keys']  = empty($info['seo_keys']) ? (empty($info['seo_title']) ? $info['title']:$info['seo_title']) : $info['seo_keys'];//$seoarr[$key]['keys'];
47
+            $seo['desc']  = empty($info['seo_desc']) ? '' : $info['seo_desc'];//$seoarr[$key]['desc'];
48
+        }else{
49
+            $site['title'] = empty($q) ? $this->seo['seo_title'].'_'.$this->seo['title'] : $q .'_'.$this->seo['title'];
50
+            $site['keys']  = empty($this->seo['seo_keys']) ? $this->seo['seo_title'] : $this->seo['seo_keys'];
51
+            $site['desc']  = empty($this->seo['seo_desc']) ? '' : $this->seo['seo_desc'];
52
+            $seo = $site;
53
+        }
54
+        $this->assign('seo',$seo);
55
+    }
56
+    /**
57
+     * 读取站点导航
58
+     */
59
+    private function getMenu(){
60
+        $menu = cache('nav');
61
+        if(!$menu){
62
+            $map['status'] = 1;
63
+            $lists = model('nav')->where($map)->order('ordid asc')->select();
64
+            if($lists){
65
+                $cate = objToArray($lists);//普通列表
66
+                $temp = [];
67
+                foreach($cate as $v){
68
+                    if(!empty($v['alias'])){
69
+                        $temp[$v['alias']] = $v;
70
+                    }else{
71
+                        $temp[$v['model']] = $v;
72
+                    }
73
+                }
74
+                $menu = $temp;
75
+                cache('nav',$temp);
76
+            }
77
+
78
+        }
79
+        if(isset($menu[$this->controller]) && $this->menuSeo){
80
+            $this->seo = [
81
+                'title'     =>$this->site['title'],
82
+                'seo_title' => empty($menu[$this->controller]['seo_title']) ? $menu[$this->controller]['title'] : $menu[$this->controller]['seo_title'],
83
+                'seo_keys'  => $menu[$this->controller]['seo_keys'],
84
+                'seo_desc'  => $menu[$this->controller]['seo_desc']
85
+            ];
86
+        }
87
+        $this->assign('menu',$menu);
88
+    }
89
+    /**
90
+     * @return mixed
91
+     * 空操作 找不到操作方法时执行
92
+     */
93
+    public function _empty(){
94
+        return $this->fetch('public/404');
95
+    }
96
+    private function getCate(){
97
+        $cate = cache('oneCate');
98
+        $articleCate = cache('articleCate');
99
+        $this->assign('articleCate',$articleCate);
100
+        $this->assign('oneCate',$cate);
101
+    }
102
+}