rabin 5 yıl önce
ebeveyn
işleme
3c3897b50c
2 değiştirilmiş dosya ile 290 ekleme ve 0 silme
  1. 217 0
      database/stat.php
  2. 73 0
      lib/Cron.php

+ 217 - 0
database/stat.php

@@ -0,0 +1,217 @@
+<?php
+$project = function()
+{
+    $array = array();
+    $info = Dever::db('log/project')->state();
+    if($info)
+    {
+        $array += $info;
+    }
+    return $array;
+};
+return array
+(
+	# 表名
+	'name' => 'stat',
+	# 显示给用户看的名称
+	'lang' => '广告数据统计',
+	'order' => 1,
+	'menu' => false,
+	# 数据结构
+	'struct' => array
+	(
+		'id' 		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> 'ID',
+			'default' 	=> '',
+			'desc' 		=> '',
+			'match' 	=> 'is_numeric',
+			//'search'	=> 'order',
+			'order'		=> 'desc',
+			//'list'		=> true,
+		),
+		
+		'page_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '广告页面id',
+            'default'   => '1',
+            'desc'      => '广告页面id',
+            'match'     => 'is_numeric',
+            'update'    => 'select',
+            //'search'    => 'select',
+            //'list'        => true,
+        ),
+
+        'info_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '广告位id',
+            'default'   => '1',
+            'desc'      => '广告位id',
+            'match'     => 'is_numeric',
+            'update'    => 'select',
+            //'search'    => 'select',
+            //'list'        => true,
+        ),
+
+        'data_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '广告投放id',
+            'default'   => '1',
+            'desc'      => '广告投放id',
+            'match'     => 'is_numeric',
+            'update'    => 'select',
+            //'search'    => 'select',
+            //'list'        => true,
+        ),
+
+        'year'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '时间',
+			'default' 	=> '',
+			'desc' 		=> '年',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+			'list'        => '"{year}年{month}月{day}日{hour}时"',
+		),
+
+		'month'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '月',
+			'default' 	=> '',
+			'desc' 		=> '月',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+		),
+
+		'day'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '日',
+			'default' 	=> '',
+			'desc' 		=> '日',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+		),
+
+		'hour'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '小时',
+			'default' 	=> '',
+			'desc' 		=> '小时',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+		),
+
+		'time'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '时间',
+			'default' 	=> '',
+			'desc' 		=> '时间',
+			'match' 	=> 'is_numeric',
+			'search'	=> 'time',
+			'update'	=> 'text',
+		),
+
+		'pv_view'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '广告访问量',
+			'default' 	=> '',
+			'desc' 		=> '广告访问量',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+			//'search'	=> 'order',
+			'list_name'		=> '数据统计',
+			'list'      => 'Dever::load("ad/lib/manage.getNum", {id})',
+		),
+
+		'uv_view'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '广告访问量(UV)',
+			'default' 	=> '',
+			'desc' 		=> '广告访问量',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+			//'search'	=> 'order',
+			//'list'		=> true,
+		),
+
+		'pv_click'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '广告点击量',
+			'default' 	=> '',
+			'desc' 		=> '广告点击量',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+			//'search'	=> 'order',
+			//'list'		=> true,
+		),
+
+		'uv_click'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '广告点击量(UV)',
+			'default' 	=> '',
+			'desc' 		=> '广告点击量',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+			//'search'	=> 'order',
+			//'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
+	(
+		'delete' => false,
+		'edit' => false,
+		'insert' => false,
+	),
+	
+	# request 请求接口定义
+	'request' => array
+	(
+		'sum' => array
+		(
+			# 匹配的正则或函数 选填项
+		    'option' => array
+		    (
+		        'data_id' => 'yes',
+		        'state' => 1,
+		    ),
+		    'type' => 'one',
+		    'order' => array('id' => 'desc'),
+		    //'group' => 'data_id',
+		    'col' => 'id,sum(pv_view) as pv_view,sum(pv_click) as pv_click,sum(uv_view) as uv_view,sum(uv_click) as uv_click,cdate,data_id,info_id,page_id,time',
+		),
+	),
+);

+ 73 - 0
lib/Cron.php

@@ -0,0 +1,73 @@
+<?php
+
+namespace Ad\Lib;
+
+use Dever;
+
+class Cron
+{
+	public function run($data)
+	{
+		$source = $data[0];
+		$desc = $data[1];
+		$up = $data[2];
+
+		if ($desc) {
+			$update = array();
+			foreach ($desc as $k => $v) {
+				if (!isset($v['param']['ad_data_id'])) {
+					continue;
+				}
+				$key = 'key_' . $up['time'] . '_' . $v['param']['ad_data_id'];
+				if (!isset($update[$key])) {
+					$update[$key] = array();
+					$update[$key]['time'] = $up['time'];
+					$update[$key]['data_id'] = $v['param']['ad_data_id'];
+					if (isset($v['param']['ad_info_id'])) {
+						$update[$key]['info_id'] = $v['param']['ad_info_id'];
+					}
+					if (isset($v['param']['ad_page_id'])) {
+						$update[$key]['page_id'] = $v['param']['ad_page_id'];
+					}
+
+					$update[$key]['year'] = $up['year'];
+					$update[$key]['month'] = $up['month'];
+					$update[$key]['day'] = $up['day'];
+					$update[$key]['hour'] = $up['hour'];
+
+					$update[$key]['pv_click'] = 0;
+					$update[$key]['uv_click'] = 0;
+					$update[$key]['pv_view'] = 0;
+					$update[$key]['uv_view'] = 0;
+				}
+				if ($v['param']['project'] == 'ad_click') {
+					$update[$key]['pv_click']++;
+					$update[$key]['uv_click']++;
+				} else {
+					$update[$key]['pv_view']++;
+					$update[$key]['uv_view']++;
+				}
+			}
+
+			if ($update) {
+				foreach ($update as $k => $v) {
+					$this->update($v);
+				}
+			}
+		}
+	}
+
+	private function update($data)
+	{
+		$where = array();
+		$where['data_id'] = $data['data_id'];
+		$where['time'] = $data['time'];
+		$info = Dever::db('ad/stat')->one($where);
+		if (!$info) {
+			Dever::db('ad/stat')->insert($data);
+		} else {
+			$data['where_id'] = $info['id'];
+			Dever::db('ad/stat')->update($data);
+		}
+	}
+}