rabin 5 éve
szülő
commit
0606fd2c67
13 módosított fájl, 453 hozzáadás és 107 törlés
  1. 11 0
      README.md
  2. 15 0
      config/base.php
  3. 9 0
      config/env/localhost/default.php
  4. 16 11
      database/col.php
  5. 91 0
      database/data.php
  6. 8 3
      database/project.php
  7. 96 0
      database/source.php
  8. 1 1
      index.php
  9. 52 0
      lib/Core.php
  10. 68 0
      lib/Cron.php
  11. 45 0
      lib/Manage.php
  12. 41 0
      src/Api.php
  13. 0 92
      src/Data.php

+ 11 - 0
README.md

@@ -0,0 +1,11 @@
+# 日志组件
+
+接口:
+
+1、attr/api.getInfo 根据属性ID获取属性详细信息
+
+传入参数
+
+a、ids:属性ID,多个用半角逗号隔开
+
+b、value:属性的值

+ 15 - 0
config/base.php

@@ -0,0 +1,15 @@
+<?php
+
+$config['base'] = array
+(
+	'system' => array
+	(
+		-1 => '未知',
+		1 => 'H5',
+		2 => '安卓',
+		3 => '苹果',
+		4 => '微信小程序',
+	),
+);
+
+return $config;

+ 9 - 0
config/env/localhost/default.php

@@ -0,0 +1,9 @@
+<?php
+
+$config['debug'] = array
+(
+	'log' => array('type' => 'file','host' => 'host', 'port' => 'port'),
+);
+
+
+return $config;

+ 16 - 11
database/col.php

@@ -1,5 +1,6 @@
 <?php
 
+$time = time();
 return array
 (
 	# 表名
@@ -10,8 +11,8 @@ return array
 	'check' => 'key',
 	'end' => array
 	(
-		'insert' => 'stat/data.create',
-		'update' => 'stat/data.create',
+		'insert' => 'log/lib/manage.create',
+		'update' => 'log/lib/manage.create',
 	),
 	# 数据结构
 	'struct' => array
@@ -43,9 +44,9 @@ return array
 		'key'		=> array
 		(
 			'type' 		=> 'varchar-60',
-			'name' 		=> '维度key',
+			'name' 		=> '维度标识',
 			'default' 	=> '',
-			'desc' 		=> '请输入维度key',
+			'desc' 		=> '请输入维度标识',
 			'match' 	=> 'is_string',
 			'update'	=> 'text',
 			'search'	=> 'fulltext',
@@ -81,15 +82,19 @@ return array
 	# 默认值
 	'default' => array
 	(
-		'col' => 'name,key,state,cdate',
+		'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(),
+			'"项目ID","project",1,' . $time,
+			'"来源","source",1,' . $time,
+			'"系统","system",1,' . $time,
+			'"用户ID","uid",1,' . $time,
+			'"UA信息","ua",1,' . $time,
+			'"是否微信","ck_wechat",1,' . $time,
+			'"是否手机","ck_mobile",1,' . $time,
+			'"ip地址","ip",1,' . $time,
+			'"操作系统","os",1,' . $time,
+			'"浏览器","browser",1,' . $time,
 		),
 	),
 	

+ 91 - 0
database/data.php

@@ -0,0 +1,91 @@
+<?php
+
+return array
+(
+	# 表名
+	'name' => 'data',
+	# 显示给用户看的名称
+	'lang' => '数据统计',
+	'order' => 1,
+	'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' 		=> '项目标识',
+			'default' 	=> '',
+			'desc' 		=> '请输入项目标识',
+			'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 - 3
database/project.php

@@ -8,6 +8,11 @@ return array
 	'lang' => '项目管理',
 	'order' => -10,
 	'check' => 'key',
+	'end' => array
+	(
+		'insert' => 'log/lib/manage.create',
+		'update' => 'log/lib/manage.create',
+	),
 	# 数据结构
 	'struct' => array
 	(
@@ -38,9 +43,9 @@ return array
 		'key'		=> array
 		(
 			'type' 		=> 'varchar-60',
-			'name' 		=> '项目key',
+			'name' 		=> '项目标识',
 			'default' 	=> '',
-			'desc' 		=> '请输入项目key',
+			'desc' 		=> '请输入项目标识',
 			'match' 	=> 'is_string',
 			'update'	=> 'text',
 			'search'	=> 'fulltext',
@@ -76,7 +81,7 @@ return array
 	# 默认值
 	'default' => array
 	(
-		'col' => 'name,key,state,cdate',
+		'col' => 'name,`key`,state,cdate',
 		'value' => array
 		(
 			'"默认项目","default",1,' . time(),

+ 96 - 0
database/source.php

@@ -0,0 +1,96 @@
+<?php
+
+return array
+(
+	# 表名
+	'name' => 'source',
+	# 显示给用户看的名称
+	'lang' => '来源管理',
+	'order' => -12,
+	'check' => 'key',
+	'end' => array
+	(
+		'insert' => 'log/lib/manage.create',
+		'update' => 'log/lib/manage.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' 		=> '来源标识',
+			'default' 	=> '',
+			'desc' 		=> '请输入来源标识',
+			'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
+		(
+			'"默认来源","dever",1,' . time(),
+		),
+	),
+	
+	# request 请求接口定义
+	'request' => array
+	(
+		
+	),
+);

+ 1 - 1
index.php

@@ -1,6 +1,6 @@
 <?php
 
-define('DEVER_APP_NAME', 'stat');
+define('DEVER_APP_NAME', 'log');
 define('DEVER_APP_LANG', '日志设置');
 define('DEVER_APP_PATH', dirname(__FILE__) . DIRECTORY_SEPARATOR);
 define('DEVER_MANAGE_ORDER', 1);

+ 52 - 0
lib/Core.php

@@ -0,0 +1,52 @@
+<?php
+
+namespace Log\Lib;
+
+use Dever;
+
+class Core
+{
+    protected function file()
+    {
+        return Dever::data() . 'log.php';
+    }
+
+    protected function config()
+    {
+        $config = include($this->file());
+        return $config;
+    }
+
+    protected function input($input)
+    {
+        if (!is_array($input)) {
+            $input = Dever::json_decode($input);
+        }
+        //$system = Dever::config('base', 'log')->system;
+
+        $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();
+
+        if (!isset($input['source'])) {
+        	$input['source'] = -1;
+        }
+
+        if (!isset($input['uid'])) {
+        	$input['uid'] = -1;
+        }
+
+        if (!isset($input['project'])) {
+        	$input['project'] = -1;
+        }
+
+        if (!isset($input['system'])) {
+        	$input['system'] = -1;
+        }
+
+        return $input;
+    }
+}

+ 68 - 0
lib/Cron.php

@@ -0,0 +1,68 @@
+<?php
+
+namespace Log\Lib;
+
+use Dever;
+
+class Cron extends Core
+{
+	public function get()
+	{
+		# 获取所有项目
+		$config = $this->config();
+		$day = array();
+		$day[0] = date('Y-m-d-H');
+		$day[1] = date('Y-m-d-H', strtotime("-1 hour"));
+		if (isset($config['project'])) {
+			foreach ($config['project'] as $k => $v) {
+				foreach ($day as $i => $j) {
+					$data = $this->getDataByProject($j, $v['id'], $v['key']);
+					$this->write($data);
+				}
+			}
+		}
+	}
+
+	private function write($data)
+	{
+		//$data[0]写入到data表中,data[1]写入到es中
+		
+	}
+
+	private function getDataByProject($day, $id, $key)
+	{
+		$data = Dever::getLog($day, $key . '/');
+		$source = array();
+		$source['project_id'] = $id;
+		$source['time'] = $day;
+		$source['pv'] = 0;
+		$source['uv'] = 0;
+		if ($data) {
+			$result = array();
+			$pv = $uv = 0;
+			$user = array();
+			foreach ($data as $k => $v) {
+				if ($v) {
+					$temp = explode('dever&', $v);
+					$info = explode(' ', $temp[0]);
+					$result[$k]['time'] = $info[0];
+					$result[$k]['project'] = $info[1];
+					$result[$k]['app'] = $info[2];
+					parse_str($temp[1], $result[$k]['param']);
+					$pv++;
+					if (isset($result[$k]['param']['uid']) && $result[$k]['param']['uid'] > 0) {
+						$user[$result[$k]['param']['uid']] = 1;
+					} else {
+						$user[$result[$k]['param']['ip']] = 1;
+					}
+				}
+			}
+			$source['pv'] = $pv;
+			$source['uv'] = count($user);
+		}
+
+		return array($source, $result);
+	}
+
+	public function get_api(){}
+}

+ 45 - 0
lib/Manage.php

@@ -0,0 +1,45 @@
+<?php
+
+namespace Log\Lib;
+
+use Dever;
+
+class Manage extends Core
+{
+    # 从数据库生成维度和项目的配置文件
+    public function create()
+    {
+        
+        
+        $config = array();
+
+        $project = Dever::db('log/project')->state();
+
+        if ($project) {
+            foreach ($project as $k => $v) {
+                $config['project'][$v['key']] = $v;
+            }
+        }
+
+        $source = Dever::db('log/source')->state();
+
+        if ($project) {
+            foreach ($project as $k => $v) {
+                $config['source'][$v['key']] = $v;
+            }
+        }
+
+        $col = Dever::db('log/col')->state();
+
+        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;
+    }
+}

+ 41 - 0
src/Api.php

@@ -0,0 +1,41 @@
+<?php
+
+namespace Log\Src;
+
+use Dever;
+use Log\Lib\Core;
+
+class Api extends Core
+{
+    public function push()
+    {
+        $project = Dever::input('project');
+        $input = Dever::input();
+        return $this->add($project, $input);
+    }
+
+    private function add($project, $input)
+    {
+        $config = $this->config();
+        if (!isset($config['project'][$project])) {
+            return true;
+        }
+
+        $project = $config['project'][$project];
+
+        $msg['project'] = $project['id'];
+        $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, $project['key'] . '/');
+        }
+
+        return true;
+    }
+}

+ 0 - 92
src/Data.php

@@ -1,92 +0,0 @@
-<?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;
-    }
-}