dever 7 rokov pred
commit
e7548229fb
4 zmenil súbory, kde vykonal 292 pridanie a 0 odobranie
  1. 101 0
      database/col.php
  2. 91 0
      database/project.php
  3. 8 0
      index.php
  4. 92 0
      src/Data.php

+ 101 - 0
database/col.php

@@ -0,0 +1,101 @@
+<?php
+
+return array
+(
+	# 表名
+	'name' => 'col',
+	# 显示给用户看的名称
+	'lang' => '维度管理',
+	'order' => -10,
+	'check' => 'key',
+	'end' => array
+	(
+		'insert' => 'stat/data.create',
+		'update' => 'stat/data.create',
+	),
+	# 数据结构
+	'struct' => array
+	(
+		'id' 		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> 'ID',
+			'default' 	=> '',
+			'desc' 		=> '',
+			'match' 	=> 'is_numeric',
+			//'search'	=> 'order',
+			'order'		=> 'desc',
+			'list'		=> true,
+		),
+		
+		'name'		=> array
+		(
+			'type' 		=> 'varchar-60',
+			'name' 		=> '维度名称',
+			'default' 	=> '',
+			'desc' 		=> '请输入维度名称',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'search'	=> 'fulltext',
+			'list'		=> true,
+		),
+
+		'key'		=> array
+		(
+			'type' 		=> 'varchar-60',
+			'name' 		=> '维度key',
+			'default' 	=> '',
+			'desc' 		=> '请输入维度key',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'search'	=> 'fulltext',
+			'list'		=> true,
+		),
+
+		'state'		=> array
+		(
+			'type' 		=> 'tinyint-1',
+			'name' 		=> '状态',
+			'default' 	=> '1',
+			'desc' 		=> '请选择状态',
+			'match' 	=> 'is_numeric',
+		),
+		
+		'cdate'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '录入时间',
+			'match' 	=> array('is_numeric', time()),
+			'desc' 		=> '',
+			# 只有insert时才生效
+			'insert'	=> true,
+			'list'		=> 'date("Y-m-d H:i:s", {cdate})',
+		),
+	),
+	
+	'manage' => array
+	(
+
+	),
+
+	# 默认值
+	'default' => array
+	(
+		'col' => 'name,key,state,cdate',
+		'value' => array
+		(
+			'"用户信息","ua",1,' . time(),
+			'"是否微信","ck_wechat",1,' . time(),
+			'"是否手机","ck_mobile",1,' . time(),
+			'"ip地址","ip",1,' . time(),
+			'"操作系统","os",1,' . time(),
+			'"浏览器","browser",1,' . time(),
+		),
+	),
+	
+	# request 请求接口定义
+	'request' => array
+	(
+		
+	),
+);

+ 91 - 0
database/project.php

@@ -0,0 +1,91 @@
+<?php
+
+return array
+(
+	# 表名
+	'name' => 'project',
+	# 显示给用户看的名称
+	'lang' => '项目管理',
+	'order' => -10,
+	'check' => 'key',
+	# 数据结构
+	'struct' => array
+	(
+		'id' 		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> 'ID',
+			'default' 	=> '',
+			'desc' 		=> '',
+			'match' 	=> 'is_numeric',
+			//'search'	=> 'order',
+			'order'		=> 'desc',
+			'list'		=> true,
+		),
+		
+		'name'		=> array
+		(
+			'type' 		=> 'varchar-60',
+			'name' 		=> '项目名称',
+			'default' 	=> '',
+			'desc' 		=> '请输入项目名称',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'search'	=> 'fulltext',
+			'list'		=> true,
+		),
+
+		'key'		=> array
+		(
+			'type' 		=> 'varchar-60',
+			'name' 		=> '项目key',
+			'default' 	=> '',
+			'desc' 		=> '请输入项目key',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'search'	=> 'fulltext',
+			'list'		=> true,
+		),
+
+		'state'		=> array
+		(
+			'type' 		=> 'tinyint-1',
+			'name' 		=> '状态',
+			'default' 	=> '1',
+			'desc' 		=> '请选择状态',
+			'match' 	=> 'is_numeric',
+		),
+		
+		'cdate'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '录入时间',
+			'match' 	=> array('is_numeric', time()),
+			'desc' 		=> '',
+			# 只有insert时才生效
+			'insert'	=> true,
+			'list'		=> 'date("Y-m-d H:i:s", {cdate})',
+		),
+	),
+	
+	'manage' => array
+	(
+
+	),
+
+	# 默认值
+	'default' => array
+	(
+		'col' => 'name,key,state,cdate',
+		'value' => array
+		(
+			'"默认项目","default",1,' . time(),
+		),
+	),
+	
+	# request 请求接口定义
+	'request' => array
+	(
+		
+	),
+);

+ 8 - 0
index.php

@@ -0,0 +1,8 @@
+<?php
+
+define('DEVER_APP_NAME', 'stat');
+define('DEVER_APP_LANG', '日志设置');
+define('DEVER_APP_PATH', dirname(__FILE__) . DIRECTORY_SEPARATOR);
+define('DEVER_MANAGE_ORDER', 1);
+define('DEVER_MANAGE_ICON', 'glyphicon glyphicon-credit-card');
+include(DEVER_APP_PATH . '../boot.php');

+ 92 - 0
src/Data.php

@@ -0,0 +1,92 @@
+<?php
+
+namespace Main\Src;
+
+use Dever;
+
+class Data
+{
+    private function file()
+    {
+        return Dever::data() . 'log.php';
+    }
+
+    private function config()
+    {
+        $config = include($this->file());
+        return $config;
+    }
+
+    # 从数据库生成维度和项目的配置文件
+    public function create()
+    {
+        $project = Dever::db('main/project')->all();
+        
+        $config = array();
+
+        if ($project) {
+            foreach ($project as $k => $v) {
+                $config['project'][$v['key']] = $v;
+            }
+        }
+
+        $col = Dever::db('main/col')->all();
+
+        if ($col) {
+            foreach ($col as $k => $v) {
+                $config['col'][$v['key']] = $v;
+            }
+        }
+
+        $data = '<?php return ' . var_export($config, true) . ';';
+        file_put_contents($this->file(), $data);
+
+        return true;
+    }
+
+    public function push_api()
+    {
+        $project = Dever::input('project');
+        $input = Dever::input();
+        return $this->add($project, $input);
+    }
+
+    public function add($project, $input)
+    {
+        $config = $this->config();
+        if (!isset($config['project'][$project])) {
+            return true;
+        }
+
+        $msg['project'] = $project;
+        $input = $this->input($input);
+        if (isset($config['col'])) {
+            foreach ($config['col'] as $k => $v) {
+                if (isset($input[$k])) {
+                    $msg[$k] = $input[$k];
+                }
+            }
+        }
+        if ($msg) {
+            Dever::log($msg, 3);
+        }
+
+        return true;
+    }
+
+    private function input($input)
+    {
+        if (!is_array($input)) {
+            $input = Dever::json_decode($input);
+        }
+
+        $input['ua'] = Dever::ua();
+        $input['ck_wechat'] = Dever::weixin();
+        $input['ck_mobile'] = Dever::mobile();
+        $input['ip'] = Dever::ip();
+        $input['os'] = Dever::os();
+        $input['browser'] = Dever::browser();
+
+        return $input;
+    }
+}