dever 6 years ago
parent
commit
989c9af55a

+ 8 - 2
service/src/Buy.php

@@ -17,9 +17,9 @@ class Buy extends Base
     # 列表页
     public function lists()
     {
-        # 记录渠道pv、uv数
+        # 记录列表页渠道pv、uv数
         if (Dever::project('source')) {
-            Dever::load('source/lib/core')->save($this->user['id'], $this->source);
+            Dever::load('source/lib/core')->save($this->user['id'], 'list', $this->source);
         }
         $where['cate_id'] = $this->cate;
         $where['buy'] = 1;
@@ -66,6 +66,12 @@ class Buy extends Base
     public function info()
     {
         $id = Dever::input('id');
+
+        # 记录购买页渠道pv、uv数
+        if (Dever::project('source')) {
+            Dever::load('source/lib/core')->save($this->user['id'], 'buy', $this->source, array('journal_id' => $id));
+        }
+
         $info = Dever::db('journal/info')->one($id);
 
         $info['buy'] = '正在购买《' . $info['name'] . '》';

+ 2 - 1
source/database/info.php

@@ -31,6 +31,7 @@ return array
 			'default' 	=> '',
 			'desc' 		=> '',
 			'match' 	=> 'is_numeric',
+			'list'		=> true,
 		),
 		
 		'name'		=> array
@@ -106,7 +107,7 @@ return array
 		# 列表
 		'list_buttons' => array
 		(
-			'list' => array('渠道统计', '"stat&search_option_info_id={id}&oper_parent=info"'),
+			//'list' => array('渠道统计', '"stat&search_option_info_id={id}&oper_parent=info"'),
 		),
 	),
 );

+ 2 - 1
source/database/link.php

@@ -3,7 +3,7 @@
 $type = array
 (
 	1 => 'H5',
-	2 => '小程序',
+	//2 => '小程序',
 );
 
 return array
@@ -23,6 +23,7 @@ return array
 			'default' 	=> '',
 			'desc' 		=> '',
 			'match' 	=> 'is_numeric',
+			'list'		=> true,
 		),
 		
 		'name'		=> array

+ 0 - 175
source/database/stat.php

@@ -1,175 +0,0 @@
-<?php
-
-$info = function()
-{
-	$array = array();
-	$info = Dever::db('source/info')->state();
-	if($info)
-	{
-		$array += $info;
-	}
-	return $array;
-};
-
-
-return array
-(
-	# 表名
-	'name' => 'stat',
-	# 显示给用户看的名称
-	'lang' => '渠道统计',
-	'order' => 10,
-	'menu' => false,
-	# 数据结构
-	'struct' => array
-	(
-		'id' 		=> array
-		(
-			'type' 		=> 'int-11',
-			'name' 		=> 'ID',
-			'default' 	=> '',
-			'desc' 		=> '',
-			'match' 	=> 'is_numeric',
-		),
-
-		'uid'		=> array
-		(
-			'type' 		=> 'int-11',
-			'name' 		=> '用户名',
-			'default' 	=> '0',
-			'desc' 		=> '请选择用户',
-			'match' 	=> 'is_numeric',
-			//'update'	=> 'select',
-			//'search'	=> 'select',
-			'search'    => array
-            (
-                'api' => 'passport/user-all',
-                'col' => 'username',
-                'result' => 'id',
-            ),
-			'list'		=> '{uid} > 0 ? Dever::load("passport/user-one#username", {uid}) : "匿名用户"',
-		),
-
-		'info_id'		=> array
-		(
-			'type' 		=> 'int-11',
-			'name' 		=> '渠道',
-			'default' 	=> '1',
-			'desc' 		=> '渠道',
-			'match' 	=> 'is_numeric',
-			'update'	=> 'select',
-			'option'	=> $info,
-			'search'	=> 'select',
-			'list'		=> true,
-		),
-		
-		'day'		=> array
-		(
-			'type' 		=> 'int-11',
-			'name' 		=> '统计时间',
-			'default' 	=> '',
-			'desc' 		=> '统计时间',
-			'match' 	=> 'is_numeric',
-			'update'	=> 'select',
-			'list'		=> true,
-		),
-
-		'pv'		=> array
-		(
-			'type' 		=> 'int-11',
-			'name' 		=> 'pv数',
-			'default' 	=> '',
-			'desc' 		=> 'pv数',
-			'match' 	=> 'option',
-			'update'	=> 'text',
-			'list'		=> true,
-		),
-
-		'uv'		=> array
-		(
-			'type' 		=> 'int-11',
-			'name' 		=> 'uv数',
-			'default' 	=> '',
-			'desc' 		=> 'uv数',
-			'match' 	=> 'option',
-			'update'	=> 'text',
-			//'list'		=> true,
-		),
-
-		'order'		=> array
-		(
-			'type' 		=> 'int-11',
-			'name' 		=> '下单数',
-			'default' 	=> '',
-			'desc' 		=> '下单数',
-			'match' 	=> 'option',
-			'update'	=> 'text',
-			'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
-	(
-		'getNew' => array
-		(
-			# 匹配的正则或函数 选填项
-			'option' => array
-			(
-				'config_id' => 'yes',
-				'action_id' => 'yes',
-				'uid' => 'yes',
-				'status' => 'yes',
-				'state' => 1,
-			),
-			'type' => 'one',
-			'order' => array('cdate' => 'desc'),
-			'col' => '*',
-		),
-
-		'getNewTotal' => array
-		(
-			# 匹配的正则或函数 选填项
-			'option' => array
-			(
-				'config_id' => 'yes',
-				'action_id' => 'yes',
-				'uid' => 'yes',
-				'status' => 'yes',
-				'state' => 1,
-				'start' => array('yes-cdate', '>='),
-				'end' => array('yes-cdate', '<='),
-			),
-			'type' => 'count',
-			'order' => array('cdate' => 'desc'),
-			'col' => 'count(1) as total',
-		),
-	)
-);

+ 133 - 0
source/database/user.php

@@ -0,0 +1,133 @@
+<?php
+
+$source = function()
+{
+	$info = Dever::db('source/info')->state();
+	if($info)
+	{
+		$array += $info;
+	}
+	return $array;
+};
+
+return array
+(
+	# 表名
+	'name' => 'user',
+	# 显示给用户看的名称
+	'lang' => '渠道用户',
+	'order' => 10,
+	'menu'	=> false,
+	# 数据结构
+	'struct' => array
+	(
+		'id' 		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> 'ID',
+			'default' 	=> '',
+			'desc' 		=> '',
+			'match' 	=> 'is_numeric',
+		),
+		
+		'vid'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '第三方id',
+			'default' 	=> '',
+			'desc' 		=> '第三方id',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+
+		'uid'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '用户id',
+			'default' 	=> '',
+			'desc' 		=> '用户id',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+
+		'source_id'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '渠道',
+			'default' 	=> '',
+			'desc' 		=> '渠道',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+			'option'	=> $source,
+			'search'	=> 'select',
+			'list'		=> true,
+		),
+
+		'account_type'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> 'account_type',
+			'default' 	=> '',
+			'desc' 		=> 'account_type',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+
+		'account_id'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> 'account_id',
+			'default' 	=> '',
+			'desc' 		=> 'account_id',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+			'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,
+		),
+	),
+
+	'manage' => array
+	(
+		'delete' => false,
+		'edit' => false,
+		//'insert' => false,
+	),
+
+	# request 请求接口定义
+	'request' => array
+	(
+		'getTotal' => array
+		(
+			# 匹配的正则或函数 选填项
+			'option' => array
+			(
+				'source_id' => 'yes',
+				'start' => array('yes-cdate', '>='),
+				'end' => array('yes-cdate', '<='),
+				'state' => 1,
+			),
+			'type' => 'count',
+		),
+	),
+);

+ 83 - 32
source/lib/Core.php

@@ -6,38 +6,89 @@ use Dever;
 
 class Core
 {
-	/**
-	 * 日志记录
-	 *
-	 * @return mixed
-	 */
-	public function save($uid, $id)
-	{
-		$input = Dever::json_encode(Dever::input());
+    private $key = 'source';
+
+    /**
+     * 记录用户信息
+     *
+     * @return mixed
+     */
+    public function saveUser($vid, $uid, $source_id, $account_type, $account_id)
+    {
+    	$data['vid'] = $vid;
+    	$data['uid'] = $uid;
+    	$data['source_id'] = $source_id;
+    	$data['account_type'] = $account_type;
+    	$data['account_id'] = $account_id;
+
+    	$info = Dever::db('source/user')->one($data);
+
+    	if (!$info) {
+    		Dever::db('source/user')->insert($data);
+    	}
+
+        return true;
+    }
+
+    /**
+     * 日志记录
+     *
+     * @return mixed
+     */
+    public function save($uid, $type, $source_id, $log = array())
+    {
+    	$log += Dever::input();
         $url = Dever::url();
 
-		$log = array
-		(
-			'uid' => $uid,
-			'source_id' => $id,
-			'input' => $input,
-			'url' => $url,
-		);
-		Dever::log($log, 'source');
-
-		$data = array();
-		$data['info_id'] = $id;
-		$data['day'] = Dever::maketime(date('Y-m-d', time()));
-		$info = Dever::db('source/stat')->one($data);
-
-		if ($info) {
-			$data['pv'] = $info['pv'] + 1;
-			Dever::db('source/stat')->update($data);
-		} else {
-			$data['pv'] = 1;
-			Dever::db('source/stat')->insert($data);
-		}
-
-		return true;
-	}
+        $log['uid'] = $uid;
+        $log['source_id'] = $source_id;
+        $log['url'] = $url;
+        $log['ip'] = Dever::ip();
+
+        Dever::log($log, $this->key . '/' . $source_id . '/' . $type);
+
+        return true;
+    }
+
+    public function get($day, $type, $source_id, $start = 0, $end = 0)
+    {
+        $log = Dever::getLog($day, $this->key . '/' . $source_id . '/' . $type);
+        $source = array();
+        $source['pv'] = 0;
+    	$source['uv'] = 0;
+    	$source['user_num'] = 0;
+    	$source['user_yes_num'] = 0;
+        if ($log) {
+        	$result = array();
+        	$pv = $uv = 0;
+        	$user = array();
+        	foreach ($log 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);
+
+        	if ($start && $end) {
+        		$where['source_id'] = $source_id;
+	        	$where['start'] = $start;
+	        	$where['end'] = $end;
+	        	$source['user_num'] = Dever::db('source/user')->getTotal($where);
+	        	$source['user_yes_num'] = $source['user_num'];
+        	}
+        }
+        return $source;
+    }
 }

+ 3 - 3
stat/database/journal.php

@@ -96,7 +96,7 @@ return array
         'order_num'       => array
         (
             'type'      => 'int-11',
-            'name'      => '总订单',
+            'name'      => '总订单',
             'default'   => '0',
             'match'     => '总订单数',
             'match'     => 'is_numeric',
@@ -107,7 +107,7 @@ return array
         'order_yes_num'       => array
         (
             'type'      => 'int-11',
-            'name'      => '支付订单',
+            'name'      => '支付订单',
             'default'   => '0',
             'match'     => '支付订单数',
             'match'     => 'is_numeric',
@@ -118,7 +118,7 @@ return array
         'order_no_num'       => array
         (
             'type'      => 'int-11',
-            'name'      => '未支付订单',
+            'name'      => '未支付订单',
             'default'   => '0',
             'match'     => '未支付订单数',
             'match'     => 'is_numeric',

+ 277 - 0
stat/database/source.php

@@ -0,0 +1,277 @@
+<?php
+$journal = function()
+{
+    $array = array();
+    $info = Dever::db('journal/info')->state(array('buy' => 1));
+    if($info)
+    {
+        $array += $info;
+    }
+    return $array;
+};
+$source = function()
+{
+    $array = array();
+    $info = Dever::db('source/info')->state();
+    if($info)
+    {
+        $array += $info;
+    }
+    return $array;
+};
+
+$list = array
+(
+    # 匹配的正则或函数 选填项
+    'option' => array
+    (
+
+        'start_day_int' => array('yes-day_int', '>='),
+        'end_day_int' => array('yes-day_int', '<='),
+        'source_id' => 'yes',
+        'journal_id' => 'yes',
+        'state' => 1,
+    ),
+    'type' => 'all',
+    'order' => array('day_int' => 'desc', 'id' => 'desc'),
+    'group' => 'day_int',
+    'page' => array(20, 'list'),
+    'col' => 'id,pv,uv,user_num,user_yes_num,sum(order_num) as order_num,sum(order_yes_num) as order_yes_num,sum(order_no_num) as order_no_num,sum(buy_num) as buy_num,sum(buy_cash) as buy_cash,cdate,journal_id,source_id,day_int,day_string',
+);
+
+$search = Dever::input('search_option_journal_id');
+if ($search && $search > 0) {
+    unset($list['group']);
+    $list['col'] = 'id,order_num,order_yes_num,order_no_num,buy_num,buy_cash,cdate,journal_id,source_id,day_int,day_string';
+}
+
+$config = array
+(
+    # 表名
+    'name' => 'source',
+    # 显示给用户看的名称
+    'lang' => '渠道订单',
+    'order' => '9',
+    # 数据结构
+    'struct' => array
+    (
+    
+        'id'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => 'ID',
+            'default'   => '',
+            'desc'      => '',
+            'match'     => 'is_numeric',
+            //'list'        => true,
+        ),
+
+        'day_string'       => array
+        (
+            'type'      => 'varchar-60',
+            'name'      => '统计日期',
+            'default'   => '',
+            'desc'      => '统计日期',
+            'match'     => 'is_string',
+            'update'    => 'text',
+            //'search'    => 'fulltext',
+            'list'      => true,
+        ),
+
+        'day_int'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => '统计日期',
+            'default'   => '',
+            'desc'      => '统计日期',
+            'match'     => 'is_numeric',
+            'update'    => 'text',
+            'search'    => 'time',
+            'order'     => 'desc',
+            //'list'        => true,
+        ),
+
+        'source_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '渠道',
+            'default'   => '',
+            'desc'      => '渠道',
+            'match'     => 'is_numeric',
+            'update'    => 'select',
+            'search'    => 'select',
+            'option'    => $source,
+            'list'      => true,
+        ),
+
+        'journal_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '小刊',
+            'default'   => '',
+            'desc'      => '小刊',
+            'match'     => 'is_numeric',
+            'update'    => 'select',
+            'search'    => 'select',
+            'option'    => $journal,
+            'list'      => 'Dever::load("stat/lib/manage.info", {journal_id})',
+        ),
+
+        'pv'       => array
+        (
+            'type'      => 'int-11',
+            'name'      => 'PV',
+            'default'   => '0',
+            'match'     => '落地页PV',
+            'match'     => 'is_numeric',
+            'update'    => 'text',
+            'list'      => true,
+        ),
+
+        'uv'       => array
+        (
+            'type'      => 'int-11',
+            'name'      => 'UV',
+            'default'   => '0',
+            'match'     => '落地页UV',
+            'match'     => 'is_numeric',
+            'update'    => 'text',
+            'list'      => true,
+        ),
+
+        'user_num'       => array
+        (
+            'type'      => 'int-11',
+            'name'      => '用户量',
+            'default'   => '0',
+            'match'     => '用户量',
+            'match'     => 'is_numeric',
+            'update'    => 'text',
+            //'list'      => true,
+        ),
+
+        'user_yes_num'       => array
+        (
+            'type'      => 'int-11',
+            'name'      => '用户量',
+            'default'   => '0',
+            'match'     => '用户授权量',
+            'match'     => 'is_numeric',
+            'update'    => 'text',
+            'list'      => true,
+        ),
+
+        'order_num'       => array
+        (
+            'type'      => 'int-11',
+            'name'      => '总订单',
+            'default'   => '0',
+            'match'     => '总订单数',
+            'match'     => 'is_numeric',
+            'update'    => 'text',
+            'list'      => true,
+        ),
+
+        'order_yes_num'       => array
+        (
+            'type'      => 'int-11',
+            'name'      => '支付订单',
+            'default'   => '0',
+            'match'     => '支付订单数',
+            'match'     => 'is_numeric',
+            'update'    => 'text',
+            'list'      => true,
+        ),
+
+        'order_no_num'       => array
+        (
+            'type'      => 'int-11',
+            'name'      => '未支付订单',
+            'default'   => '0',
+            'match'     => '未支付订单数',
+            'match'     => 'is_numeric',
+            'update'    => 'text',
+            'list'      => true,
+        ),
+
+        'buy_num'       => array
+        (
+            'type'      => 'int-11',
+            'name'      => '售出本数',
+            'default'   => '0',
+            'match'     => '售出本数',
+            'match'     => 'is_numeric',
+            'update'    => 'text',
+            'list'      => true,
+        ),
+
+        'buy_cash'       => array
+        (
+            'type'      => 'int-11',
+            'name'      => '售出金额',
+            'default'   => '0',
+            'match'     => '售出金额',
+            'match'     => 'is_numeric',
+            'update'    => 'text',
+            '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,
+            //'search'    => 'date',
+            'list'      => 'date("Y-m-d H:i", {cdate})',
+        ),
+    ),
+
+    'manage' => array
+    (
+        'insert' => false,
+        'edit' => false,
+        'delete' => false,
+        'num' => false,
+        'excel' => true,
+
+        //'page_list' => 'journal',
+    ),
+
+    'request' => array
+    (
+        'list' => $list,
+
+        'getData' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'start' => array('yes-day_int', '>='),
+                'end' => array('yes-day_int', '<='),
+                'state' => 1,
+            ),
+            'type' => 'all',
+            'order' => array('day_int' => 'desc'),
+            //'group' => 'day_int',
+            'col' => '*',
+        ),
+    ),
+);
+
+
+if ($search && $search > 0) {
+	$config['struct']['pv']['list'] = $config['struct']['uv']['list'] = $config['struct']['user_num']['list'] = $config['struct']['user_yes_num']['list'] = false;
+}
+return $config;

+ 9 - 10
stat/lib/Journal.php

@@ -40,26 +40,26 @@ class Journal
         $journal = Dever::db('journal/info')->state(array('buy' => 1));
 
         if ($journal) {
-            foreach ($journal as $k => $v) {
-                for ($i = 0; $i < $num; $i++) {
-                    $where['start'] = strtotime("$start -$i day");
-                    $where['end'] = $where['start'] + 86399;
-                    $this->total($v, $where, $day);
+            for ($i = 0; $i < $num; $i++) {
+                $where['start'] = strtotime("$start -$i day");
+                $where['end'] = $where['start'] + 86399;
+                foreach ($journal as $k => $v) {
+                    $this->total($v, $where);
                 }
             }
         }
         return true;
     }
 
-    private function total($info, $where, $day)
+    private function total($info, $where)
     {
         # 这里就是为了做下sql的实现方式,其实用dever自带的功能完全可以实现。
         $day = date('Y-m-d', $where['start']);
         $sql = 'select * from wonderful_journal_order where type = 1 and product_id = '.$info['id'].' and state = 1 and cdate >= '.$where['start'].' and cdate <= '.$where['end'];
         $order = Dever::db('journal/order')->fetchAll($sql);
-
+        $order_num = $order_yes_num = $order_no_num = $buy_num = $buy_cash = 0;
         if ($order) {
-            $order_num = $order_yes_num = $order_no_num = $buy_num = $buy_cash = 0;
+            
             foreach ($order as $k => $v) {
                 $order_num++;
                 if ($v['status'] == 1) {
@@ -81,9 +81,8 @@ class Journal
                     }
                 }
             }
-
-            $this->update($info['id'], $day, $order_num, $order_yes_num, $order_no_num, $buy_num, $buy_cash);
         }
+        $this->update($info['id'], $day, $order_num, $order_yes_num, $order_no_num, $buy_num, $buy_cash);
     }
 
     public function update($info_id, $day, $order_num, $order_yes_num, $order_no_num, $buy_num, $buy_cash)

+ 124 - 0
stat/lib/Source.php

@@ -0,0 +1,124 @@
+<?php
+
+namespace Stat\Lib;
+
+use Dever;
+
+class Source
+{
+    const NUM = 2;
+
+    public function data_api()
+    {
+
+    }
+    /**
+     * 获取数据-可以放到cron里
+     *
+     * @return mixed
+     */
+    public function data()
+    {
+        # 获取最近self::NUM天的数据
+        $num = Dever::input('num', self::NUM);
+
+        $day = Dever::input('day');
+        if ($day) {
+            $day = Dever::maketime($day);
+        } else {
+            $day = time();
+        }
+        $start = date('Y-m-d 00:00:00', $day);
+        $option = array
+        (
+            'state' => 1,
+            'start' => array('yes-cdate', '>'),
+            'end' => array('yes-cdate', '<'),
+        );
+        $where['option'] = $option;
+
+        $source = Dever::db('source/info')->state();
+        $journal = Dever::db('journal/info')->state(array('buy' => 1));
+
+        if ($source && $journal) {
+        	foreach ($source as $sk => $sv) {
+        		for ($i = 0; $i < $num; $i++) {
+        			$where['start'] = strtotime("$start -$i day");
+	                $where['end'] = $where['start'] + 86399;
+	                $log = Dever::load('source/lib/core')->get(date('Y_m_d', $where['start']), 'list', $sv['id'], $where['start'], $where['end']);
+        			foreach ($journal as $k => $v) {
+	                    $this->total($sv, $v, $where, $log['pv'], $log['uv'], $log['user_num'], $log['user_yes_num']);
+		            }
+                }
+            }
+        }
+        return true;
+    }
+
+    private function total($source, $info, $where, $pv, $uv, $user_num, $user_yes_num)
+    {
+        $day = date('Y-m-d', $where['start']);
+        $sql = 'select * from wonderful_journal_order where type = 1 and source = '.$source['id'].' and product_id = '.$info['id'].' and state = 1 and cdate >= '.$where['start'].' and cdate <= '.$where['end'];
+        $order = Dever::db('journal/order')->fetchAll($sql);
+
+        $order_num = $order_yes_num = $order_no_num = $buy_num = $buy_cash = 0;
+
+        if ($order) {
+            foreach ($order as $k => $v) {
+                $order_num++;
+                if ($v['status'] == 1) {
+                    # 待支付
+                    $order_no_num++;
+                } elseif ($v['status'] == 2) {
+                    # 已支付
+                    $order_yes_num++;
+
+                    if ($v['buy_id']) {
+                        $buy = Dever::db('journal/buy_num')->one($v['buy_id']);
+                        if ($buy['num']) {
+                            $buy_num += $buy['num'];
+                        }
+                    }
+
+                    if ($v['cash']) {
+                        $buy_cash += $v['cash'];
+                    }
+                }
+            }
+        }
+
+        $this->update($source['id'], $info['id'], $day, $pv, $uv, $user_num, $user_yes_num, $order_num, $order_yes_num, $order_no_num, $buy_num, $buy_cash);
+    }
+
+    public function update($source_id, $info_id, $day, $pv, $uv, $user_num, $user_yes_num, $order_num, $order_yes_num, $order_no_num, $buy_num, $buy_cash)
+    {
+        $update = array();
+        $update['day_string'] = $day;
+        $update['day_int'] = Dever::maketime($day);
+        $update['pv'] = $pv;
+        $update['uv'] = $uv;
+        $update['user_num'] = $user_num;
+        $update['user_yes_num'] = $user_yes_num;
+        $update['order_num'] = $order_num;
+        $update['order_yes_num'] = $order_yes_num;
+        $update['order_no_num'] = $order_no_num;
+        $update['buy_num'] = $buy_num;
+        $update['buy_cash'] = $buy_cash;
+        $update['source_id'] = $source_id;
+        $update['journal_id'] = $info_id;
+        $update['cdate'] = time();
+
+        $where = array();
+        $where['day_int'] = $update['day_int'];
+        $where['journal_id'] = $update['journal_id'];
+
+        $info = Dever::db('stat/source')->one($where);
+        if (!$info) {
+            $id = Dever::db('stat/source')->insert($update);
+        } else {
+            $id = $info['id'];
+            $update['where_id'] = $id;
+            Dever::db('stat/source')->update($update);
+        }
+    }
+}