dever 6 years ago
parent
commit
ac13199c0f

+ 218 - 0
applet/database/total_base.php

@@ -0,0 +1,218 @@
+<?php
+
+return array
+(
+	# 表名
+	'name' => 'total_base',
+	# 显示给用户看的名称
+	'lang' => '统计概览',
+	'order' => 20,
+	'desc' => '请将total.cron加入到cron中',
+	# 数据结构
+	'struct' => array
+	(
+		'id' 		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> 'ID',
+			'default' 	=> '',
+			'desc' 		=> '',
+			'match' 	=> 'is_numeric',
+			//'search'	=> 'order',
+			'order'		=> 'desc',
+			//'list'		=> true,
+		),
+
+		'project_id'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '项目',
+			'default' 	=> '',
+			'desc' 		=> '请输入项目',
+			'match' 	=> 'is_numeric',
+			'list'		=> 'Dever::load("main/project-one#name", {project_id})',
+		),
+		
+		'day'		=> array
+		(
+			'type' 		=> 'varchar-60',
+			'name' 		=> '统计日期',
+			'default' 	=> '',
+			'desc' 		=> '统计日期',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'search'	=> 'fulltext',
+			'list'		=> true,
+		),
+
+		'daynum'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '统计日期',
+			'default' 	=> '',
+			'desc' 		=> '统计日期',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+			//'search'	=> 'time',
+			//'list'		=> true,
+		),
+
+		'session_cnt'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '打开次数',
+			'default' 	=> '0',
+			'match' 	=> '打开次数',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+
+		'visit_pv'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '访问次数',
+			'default' 	=> '0',
+			'match' 	=> '访问次数',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+
+		'visit_uv'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '访问人数',
+			'default' 	=> '0',
+			'match' 	=> '访问人数',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+
+		'visit_uv_new'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '新用户数',
+			'default' 	=> '0',
+			'match' 	=> '新用户数',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+
+		'stay_time_uv'		=> array
+		(
+			'type' 		=> 'varchar-30',
+			'name' 		=> '人均停留时长',
+			'default' 	=> '0',
+			'match' 	=> '人均停留时长',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+
+		'stay_time_session'		=> array
+		(
+			'type' 		=> 'varchar-30',
+			'name' 		=> '次均停留时长',
+			'default' 	=> '0',
+			'match' 	=> '次均停留时长',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+
+		'visit_depth'		=> array
+		(
+			'type' 		=> 'varchar-30',
+			'name' 		=> '平均访问深度',
+			'default' 	=> '0',
+			'match' 	=> '平均访问深度',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+
+		'visit_total'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '累计用户数',
+			'default' 	=> '0',
+			'match' 	=> '累计用户数',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+
+		'share_pv'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '转发次数',
+			'default' 	=> '0',
+			'match' 	=> '转发次数',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+
+		'share_uv'		=> 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,
+			//'list'		=> 'date("Y-m-d H:i:s", {cdate})',
+		),
+	),
+	
+	'manage' => array
+	(
+		'insert' => false,
+		'edit' => false,
+		'delete' => false,
+		'excel' => true,
+		'button' => array
+		(
+			'下载昨日统计报表' => array('location', 'applet/total.out'),
+		),
+	),
+
+	'request' => array
+	(
+		'getData' => array
+		(
+			# 匹配的正则或函数 选填项
+			'option' => array
+			(
+				'day' => 'yes',
+				'project_id' => array('yes', 'in'),
+				'state' => 1,
+			),
+			'type' => 'all',
+			'col' => '*',
+		),
+	),
+);

+ 1 - 1
applet/src/Total.php

@@ -72,7 +72,7 @@ class Total
         $update['day'] = $day;
         $update['daynum'] = Dever::maketime($day);
         $update['project_id'] = $project;
-        $update['session_cnt'] = isset($data['session_cnt'] ? $data['session_cnt'] : 0;
+        $update['session_cnt'] = isset($data['session_cnt']) ? $data['session_cnt'] : 0;
         $update['visit_pv'] = isset($data['visit_pv']) ? $data['visit_pv'] : 0;
         $update['visit_uv'] = isset($data['visit_uv']) ? $data['visit_uv'] : 0;
         $update['visit_uv_new'] = isset($data['visit_uv_new']) ? $data['visit_uv_new'] : 0;

+ 1 - 1
component/applet/database/auditing.php

@@ -152,7 +152,7 @@ return array
 
 		'statusDesc'		=> array
 		(
-			'type' 		=> 'varchar-40',
+			'type' 		=> 'varchar-140',
 			'name' 		=> '审核说明',
 			'default' 	=> '',
 			'desc' 		=> '审核说明',

+ 1 - 1
main/database/log.php

@@ -63,7 +63,7 @@ return array
 
 		'result'		=> array
 		(
-			'type' 		=> 'text-255',
+			'type' 		=> 'longtext',
 			'name' 		=> '微信返回信息',
 			'default' 	=> '',
 			'desc' 		=> '微信返回信息',

+ 16 - 1
main/lib/Wechat.php

@@ -23,6 +23,13 @@ class Wechat
 	 * @var string
 	 */
 	private $project;
+
+	/**
+	 * alert
+	 *
+	 * @var int
+	 */
+	private $alert;
 	
 	/**
 	 * 构造函数 初始化
@@ -277,6 +284,14 @@ class Wechat
 	 */
 	public function curl($method, $param = array(), $alert = true, $type = false)
 	{
+		if (!$this->alert) {
+			if (!$alert) {
+				$this->alert = 1;
+			} else {
+				$this->alert = 2;
+			}
+		}
+		
 		//return array();
 		if (is_string($param)) {
 			$result = json_decode(Dever::curl($param), true);
@@ -297,7 +312,7 @@ class Wechat
 			*/
 			$result = $param + $result;
 			Dever::log($result);
-			if ($alert) {
+			if ($alert && $this->alert == 2) {
 				Dever::alert(json_encode($result, JSON_UNESCAPED_UNICODE));
 			}
 		}

+ 114 - 0
service/config/wechat.php

@@ -41,4 +41,118 @@ $config['ticket'] = array
 	),
 );
 
+$config['batchget_material'] = array
+(
+	'name' => '获取素材列表',
+	'method' => 'post',
+	'json' => true,
+	'url' => 'https://api.weixin.qq.com/cgi-bin/material/batchget_material?',
+	'param' => array
+	(
+		'access_token' => 'token',
+		'type' => 'news',
+		'offset' => 'offset',
+		'count' => 'count',
+	),
+	//针对一些返回的名称,做转换
+	'response' => array
+	(
+		
+	),
+);
+
+$config['get_material'] = array
+(
+	'name' => '获取永久素材',
+	'method' => 'post',
+	'json' => true,
+	'url' => 'https://api.weixin.qq.com/cgi-bin/material/get_material?',
+	'param' => array
+	(
+		'access_token' => 'token',
+		'media_id' => 'media_id',
+	),
+	//针对一些返回的名称,做转换
+	'response' => array
+	(
+		
+	),
+);
+
+$config['getusersummary'] = array
+(
+	'name' => '获取用户增减数据',
+	'method' => 'post',
+	'json' => true,
+	'url' => 'https://api.weixin.qq.com/datacube/getusersummary?',
+	'param' => array
+	(
+		'access_token' => 'token',
+		'end_date' => 'end_date',
+		'begin_date' => 'begin_date',
+	),
+	//针对一些返回的名称,做转换
+	'response' => array
+	(
+		
+	),
+);
+
+$config['getusercumulate'] = array
+(
+	'name' => '获取累计用户数据',
+	'method' => 'post',
+	'json' => true,
+	'url' => 'https://api.weixin.qq.com/datacube/getusercumulate?',
+	'param' => array
+	(
+		'access_token' => 'token',
+		'end_date' => 'end_date',
+		'begin_date' => 'begin_date',
+	),
+	//针对一些返回的名称,做转换
+	'response' => array
+	(
+		
+	),
+);
+
+$config['getarticlesummary'] = array
+(
+	'name' => '获取图文群发每日数据',
+	'method' => 'post',
+	'json' => true,
+	'url' => 'https://api.weixin.qq.com/datacube/getarticlesummary?',
+	'param' => array
+	(
+		'access_token' => 'token',
+		'end_date' => 'end_date',
+		'begin_date' => 'begin_date',
+	),
+	//针对一些返回的名称,做转换
+	'response' => array
+	(
+		
+	),
+);
+
+$config['getuserread'] = array
+(
+	'name' => '获取图文统计数据',
+	'method' => 'post',
+	'json' => true,
+	'url' => 'https://api.weixin.qq.com/datacube/getuserread?',
+	'param' => array
+	(
+		'access_token' => 'token',
+		'end_date' => 'end_date',
+		'begin_date' => 'begin_date',
+	),
+	//针对一些返回的名称,做转换
+	'response' => array
+	(
+		
+	),
+);
+
 return $config;

+ 221 - 0
service/database/material.php

@@ -0,0 +1,221 @@
+<?php
+
+$type = array
+(
+	1 => '图文',
+);
+
+return array
+(
+	# 表名
+	'name' => 'material',
+	# 显示给用户看的名称
+	'lang' => '素材列表',
+	'order' => 100,
+	'desc' => '请将material.cron放到cron中,项目选择公众号',
+
+	# 数据结构
+	'struct' => array
+	(
+		'id' 		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> 'ID',
+			'default' 	=> '',
+			'desc' 		=> '',
+			'match' 	=> 'is_numeric',
+			'search'	=> 'order',
+			//'list'		=> true,
+		),
+
+		'project_id'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '项目',
+			'default' 	=> '',
+			'desc' 		=> '请输入项目',
+			'match' 	=> 'is_numeric',
+			'list'		=> 'Dever::load("main/project-one#name", {project_id})',
+		),
+
+		'type'		=> array
+		(
+			'type' 		=> 'tinyint-1',
+			'name' 		=> '类型',
+			'default' 	=> '1',
+			'desc' 		=> '类型',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'select',
+			'search'	=> 'select',
+			'option'	=> $type,
+			'list'		=> true,
+		),
+
+
+		'media_id'		=> array
+		(
+			'type' 		=> 'varchar-50',
+			'name' 		=> '素材id-相同素材id为一组',
+			'default' 	=> '',
+			'desc' 		=> '素材id',
+			'match' 	=> 'is_string',
+			//'update'	=> 'text',
+			//'list'		=> true,
+		),
+
+		'index'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '同组素材的key',
+			'default' 	=> '',
+			'desc' 		=> '同组素材的key',
+			'match' 	=> 'is_string',
+			//'update'	=> 'text',
+			//'list'		=> true,
+		),
+		
+		'name'		=> array
+		(
+			'type' 		=> 'varchar-120',
+			'name' 		=> '标题-对应微信的title',
+			'default' 	=> '',
+			'desc' 		=> '标题',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'search'	=> 'fulltext',
+			'list'		=> '"{name}:{index}"',
+			//'modal'		=> '"{name}"',
+		),
+
+		'author'		=> array
+		(
+			'type' 		=> 'varchar-120',
+			'name' 		=> '作者',
+			'default' 	=> '',
+			'desc' 		=> '作者',
+			'match' 	=> 'option',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+
+		'desc'		=> array
+		(
+			'type' 		=> 'varchar-500',
+			'name' 		=> '摘要-对应微信的digest',
+			'default' 	=> '',
+			'desc' 		=> '摘要',
+			'match' 	=> 'option',
+			'update'	=> 'textarea',
+			//'list'		=> true,
+		),
+
+		'url'		=> array
+		(
+			'type' 		=> 'varchar-500',
+			'name' 		=> '链接-微信链接',
+			'default' 	=> '',
+			'desc' 		=> '链接',
+			'match' 	=> 'option',
+			'update'	=> 'text',
+			//'list'		=> true,
+		),
+
+		'content_source_url'		=> array
+		(
+			'type' 		=> 'varchar-500',
+			'name' 		=> '原文页链接',
+			'default' 	=> '',
+			'desc' 		=> '原文页链接',
+			'match' 	=> 'option',
+			'update'	=> 'text',
+			//'list'		=> true,
+		),
+
+		'thumb_media_id'		=> array
+		(
+			'type' 		=> 'varchar-50',
+			'name' 		=> '封面图片素材id',
+			'default' 	=> '',
+			'desc' 		=> '封面图片素材id',
+			'match' 	=> 'is_string',
+			//'update'	=> 'text',
+			//'list'		=> true,
+		),
+
+		'thumb_url'		=> array
+		(
+			'type' 		=> 'varchar-150',
+			'name' 		=> '封面',
+			'default' 	=> '',
+			'desc' 		=> '请选择封面',
+			'match' 	=> 'option',
+			'update'	=> 'image',
+			'key' 		=> '1',
+			'place'		=> '150',
+		),
+
+		'content'		=> array
+		(
+			'type' 		=> 'longtext',
+			'name' 		=> '内容',
+			'default' 	=> '',
+			'desc' 		=> '内容',
+			'match' 	=> 'option',
+			'update'	=> 'editor',
+			//'list'		=> true,
+		),
+
+		'update_time'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '更新时间',
+			'match' 	=> 'is_numeric',
+			'desc' 		=> '',
+			'default' 	=> '',
+			'list'		=> 'date("Y-m-d H:i:s", {update_time})',
+		),
+
+		'create_time'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '创建时间',
+			'match' 	=> 'is_numeric',
+			'desc' 		=> '',
+			'default' 	=> '',
+			//'list'		=> 'date("Y-m-d H:i:s", {create_time})',
+		),
+		
+		'state'		=> array
+		(
+			'type' 		=> 'tinyint-1',
+			'name' 		=> '状态',
+			'default' 	=> '1',
+			'desc' 		=> '请选择状态',
+			'match' 	=> 'is_numeric',
+		),
+		
+		'cdate'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '更新时间',
+			'match' 	=> array('is_numeric', time()),
+			'desc' 		=> '',
+			'default' 	=> '',
+			# 只有insert时才生效
+			'insert'	=> true,
+			//'list'		=> 'date("Y-m-d H:i:s", {cdate})',
+		),
+	),
+
+	'manage' => array
+	(
+		//'delete' => false,
+		//'insert' => false,
+		//'edit' => false,
+
+		'button' => array
+		(
+			'获取最新图文' => 'service/material.get',
+		),
+	),
+);

+ 266 - 0
service/database/total_base.php

@@ -0,0 +1,266 @@
+<?php
+
+$source = array
+(
+	0 => '其他合计',
+	1 => '公众号搜索',
+	17 => '名片分享',
+	30 => '扫描二维码',
+	43 => '图文页右上角菜单',
+	51 => '支付后关注',
+	57 => '图文页内公众号名称',
+	75 => '公众号文章广告',
+	78 => '朋友圈广告',
+);
+return array
+(
+	# 表名
+	'name' => 'total_base',
+	# 显示给用户看的名称
+	'lang' => '统计概览',
+	'order' => 20,
+	'desc' => '请将total.cron加入到cron中',
+	# 数据结构
+	'struct' => array
+	(
+		'id' 		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> 'ID',
+			'default' 	=> '',
+			'desc' 		=> '',
+			'match' 	=> 'is_numeric',
+			//'search'	=> 'order',
+			'order'		=> 'desc',
+			//'list'		=> true,
+		),
+
+		'project_id'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '项目',
+			'default' 	=> '',
+			'desc' 		=> '请输入项目',
+			'match' 	=> 'is_numeric',
+			'list'		=> 'Dever::load("main/project-one#name", {project_id})',
+		),
+		
+		'day'		=> array
+		(
+			'type' 		=> 'varchar-60',
+			'name' 		=> '统计日期',
+			'default' 	=> '',
+			'desc' 		=> '统计日期',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'search'	=> 'fulltext',
+			'list'		=> true,
+		),
+
+		'daynum'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '统计日期',
+			'default' 	=> '',
+			'desc' 		=> '统计日期',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+			//'search'	=> 'time',
+			//'list'		=> true,
+		),
+
+		/*
+		'user_source'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '用户的渠道',
+			'default' 	=> '0',
+			'match' 	=> '用户的渠道',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'select',
+			'option'	=> $source,
+			'list'		=> true,
+		),
+		*/
+
+		'new_user'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '新增的用户数量',
+			'default' 	=> '0',
+			'match' 	=> '新增的用户数量',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+
+		'cancel_user'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '取消关注的用户数量',
+			'default' 	=> '0',
+			'match' 	=> '取消关注的用户数量',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+
+		'user'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '净增用户数量',
+			'default' 	=> '0',
+			'match' 	=> '净增用户数量',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+
+		'cumulate_user'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '总用户量',
+			'default' 	=> '0',
+			'match' 	=> '总用户量',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+
+		'int_page_read_user'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '图文页的阅读人数',
+			'default' 	=> '0',
+			'match' 	=> '图文页的阅读人数',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+
+		'int_page_read_count'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '图文页的阅读次数',
+			'default' 	=> '0',
+			'match' 	=> '图文页的阅读次数',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+
+		'ori_page_read_user'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '原文页的阅读人数',
+			'default' 	=> '0',
+			'match' 	=> '原文页的阅读人数',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+
+		'ori_page_read_count'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '原文页的阅读次数',
+			'default' 	=> '0',
+			'match' 	=> '原文页的阅读次数',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+
+		'share_user'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '分享的人数',
+			'default' 	=> '0',
+			'match' 	=> '分享的人数',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+
+		'share_count'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '分享的次数',
+			'default' 	=> '0',
+			'match' 	=> '分享的次数',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+
+		'add_to_fav_user'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '收藏的人数',
+			'default' 	=> '0',
+			'match' 	=> '收藏的人数',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+
+		'add_to_fav_count'		=> 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,
+			//'list'		=> 'date("Y-m-d H:i:s", {cdate})',
+		),
+	),
+	
+	'manage' => array
+	(
+		'insert' => false,
+		'edit' => false,
+		'delete' => false,
+		'excel' => true,
+		'button' => array
+		(
+			'下载昨日统计报表' => array('location', 'service/total.out'),
+		),
+	),
+
+	'request' => array
+	(
+		'getData' => array
+		(
+			# 匹配的正则或函数 选填项
+			'option' => array
+			(
+				'day' => 'yes',
+				'project_id' => array('yes', 'in'),
+				'state' => 1,
+			),
+			'type' => 'all',
+			'col' => '*',
+		),
+	),
+);

+ 217 - 0
service/database/total_news.php

@@ -0,0 +1,217 @@
+<?php
+
+return array
+(
+	# 表名
+	'name' => 'total_news',
+	# 显示给用户看的名称
+	'lang' => '统计图文',
+	'order' => 19,
+	# 数据结构
+	'struct' => array
+	(
+		'id' 		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> 'ID',
+			'default' 	=> '',
+			'desc' 		=> '',
+			'match' 	=> 'is_numeric',
+			//'search'	=> 'order',
+			'order'		=> 'desc',
+			//'list'		=> true,
+		),
+
+		'project_id'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '项目',
+			'default' 	=> '',
+			'desc' 		=> '请输入项目',
+			'match' 	=> 'is_numeric',
+			'list'		=> 'Dever::load("main/project-one#name", {project_id})',
+		),
+		
+		'day'		=> array
+		(
+			'type' 		=> 'varchar-60',
+			'name' 		=> '日期',
+			'default' 	=> '',
+			'desc' 		=> '日期',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'search'	=> 'fulltext',
+			'list'		=> true,
+		),
+
+		'daynum'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '日期',
+			'default' 	=> '',
+			'desc' 		=> '日期',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+			//'search'	=> 'time',
+			//'list'		=> true,
+		),
+
+		'msgid'		=> array
+		(
+			'type' 		=> 'varchar-60',
+			'name' 		=> '图文消息id',
+			'default' 	=> '0',
+			'match' 	=> '图文消息id',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			//'list'		=> true,
+		),
+
+		'title'		=> array
+		(
+			'type' 		=> 'varchar-120',
+			'name' 		=> '标题',
+			'default' 	=> '0',
+			'match' 	=> '标题',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+
+		'int_page_read_user'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '阅读人数',
+			'default' 	=> '0',
+			'match' 	=> '图文页的阅读人数',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+
+		'int_page_read_count'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '阅读次数',
+			'default' 	=> '0',
+			'match' 	=> '阅读次数',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+
+		'ori_page_read_user'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '原文阅读人数',
+			'default' 	=> '0',
+			'match' 	=> '原文阅读人数',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+
+		'ori_page_read_count'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '原文阅读次数',
+			'default' 	=> '0',
+			'match' 	=> '原文阅读次数',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+
+		'share_user'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '分享人数',
+			'default' 	=> '0',
+			'match' 	=> '分享人数',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+
+		'share_count'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '分享次数',
+			'default' 	=> '0',
+			'match' 	=> '分享次数',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+
+		'add_to_fav_user'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '收藏人数',
+			'default' 	=> '0',
+			'match' 	=> '收藏人数',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+
+		'add_to_fav_count'		=> 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,
+			//'list'		=> 'date("Y-m-d H:i:s", {cdate})',
+		),
+	),
+	
+	'manage' => array
+	(
+		'insert' => false,
+		'edit' => false,
+		'delete' => false,
+		'excel' => true,
+		'button' => array
+		(
+			'下载昨日统计报表' => array('location', 'service/total.news_out'),
+		),
+	),
+
+	'request' => array
+	(
+		'getData' => array
+		(
+			# 匹配的正则或函数 选填项
+			'option' => array
+			(
+				'day' => 'yes',
+				'project_id' => array('yes', 'in'),
+				'state' => 1,
+			),
+			'type' => 'all',
+			'col' => '*',
+		),
+	),
+);

+ 42 - 42
service/src/Auth.php

@@ -11,65 +11,65 @@ use Main\Lib\Wechat;
 
 class Auth
 {
-	/**
-	 * wechat
-	 *
-	 * @var Wechat
-	 */
-	private $wechat;
-	
-	/**
-	 * result
-	 *
-	 * @var array
-	 */
-	private $result;
-	
-	/**
-	 * output
-	 *
-	 * @var string
-	 */
-	private $output;
-	
-	/**
+    /**
+     * wechat
+     *
+     * @var Wechat
+     */
+    private $wechat;
+    
+    /**
+     * result
+     *
+     * @var array
+     */
+    private $result;
+    
+    /**
+     * output
+     *
+     * @var string
+     */
+    private $output;
+    
+    /**
      * 构造函数 初始化
      * 
      * @return mixed
      */
-	public function __construct()
-	{
-		$this->wechat = new Wechat(false, 'service');
-	}
+    public function __construct()
+    {
+        $this->wechat = new Wechat(false, 'service');
+    }
 
-	/**
+    /**
      * 获取签名数据,主要用于jssdk
      * 
      * @return mixed
      */
-	public function sign()
-	{
-		$url = Dever::input('url');
-		return $this->wechat->sign($url);
-	}
+    public function sign()
+    {
+        $url = Dever::input('url');
+        return $this->wechat->sign($url);
+    }
 
-	/**
+    /**
      * 获取ticket
      * 
      * @return mixed
      */
-	public function ticket()
-	{
-		return $this->wechat->ticket(false, false, 2000, true);
-	}
+    public function ticket()
+    {
+        return $this->wechat->ticket(false, false, 2000, true);
+    }
 
-	/**
+    /**
      * 获取token 一般为系统token
      * 
      * @return mixed
      */
-	public function token()
-	{
-		return $this->wechat->token(false, false, 2000, true);
-	}
+    public function token()
+    {
+        return $this->wechat->token(false, false, 2000, true);
+    }
 }

+ 51 - 0
service/src/Base.php

@@ -0,0 +1,51 @@
+<?php
+/*
+|--------------------------------------------------------------------------
+| material.php 素材管理
+|--------------------------------------------------------------------------
+*/
+namespace Service\Src;
+
+use Dever;
+use Main\Lib\Wechat;
+
+class Base
+{
+    /**
+     * wechat
+     *
+     * @var Wechat
+     */
+    private $wechat;
+    
+    /**
+     * result
+     *
+     * @var array
+     */
+    private $result;
+    
+    /**
+     * output
+     *
+     * @var string
+     */
+    private $output;
+    
+    /**
+     * 构造函数 初始化
+     * 
+     * @return mixed
+     */
+    public function __construct()
+    {
+        
+    }
+
+    protected function getProject()
+    {
+        $where['type'] = Dever::config('wechat', 'service')->type;
+        $project = Dever::db('main/project')->state($where);
+        return $project;
+    }
+}

+ 166 - 0
service/src/Material.php

@@ -0,0 +1,166 @@
+<?php
+/*
+|--------------------------------------------------------------------------
+| material.php 素材管理
+|--------------------------------------------------------------------------
+*/
+namespace Service\Src;
+
+use Dever;
+use Main\Lib\Wechat;
+
+class Material extends Base
+{
+    # 计划任务
+    public function cron()
+    {
+        $project = $this->getProject();
+        if ($project) {
+            foreach ($project as $k => $v) {
+                if ($v) {
+                    $base = $this->getList($v);
+                }
+            }
+        }
+    }
+
+    /**
+     * 获取素材列表
+     * 
+     * @return mixed
+     */
+    public function getList($project)
+    {
+        $day = Dever::input('day', date('Y-m-d', time()-86400));
+
+        $wechat = new Wechat($project, 'service');
+
+        $this->get($day, $wechat);
+        
+        return 'yes';
+    }
+
+    /**
+     * 更新素材到数据库中
+     * 
+     * @return mixed
+     */
+    private function get($day, $wechat, $offset = 0)
+    {
+        $param['news'] = 'news';
+        $param['offset'] = $offset;
+        $param['count'] = 20;
+
+        $data = $wechat->curl('batchget_material', $param, false);
+
+        if ($data && isset($data['item'][0])) {
+            $project = $wechat->project();
+            foreach ($data['item'] as $k => $v) {
+                $this->update($v, $project['id']);
+            }
+
+            $this->get($day, $wechat, $offset + $param['count']);
+        }
+    }
+
+    /**
+     * 更新素材到数据库中
+     * 
+     * @return mixed
+     */
+    private function update($data, $project)
+    {
+        if (isset($data['media_id']) && isset($data['content']['news_item'])) {
+            $media_id = $data['media_id'];
+            $content = $data['content']['news_item'];
+            foreach ($content as $k => $v) {
+                $this->updateOne($media_id, $project, $k, $v, $data['content']['create_time'], $data['content']['update_time']);
+            }
+        }
+    }
+
+    /**
+     * 更新素材到数据库中
+     * 
+     * @return mixed
+     */
+    private function updateOne($media_id, $project, $index, $data, $create_time, $update_time)
+    {
+        $update['media_id'] = $media_id;
+        $update['project_id'] = $project;
+        $update['index'] = $index;
+        $update['name'] = $data['title'];
+
+        $db = Dever::db('service/material');
+
+        $info = $db->one($update);
+
+        $update['type'] = 1;
+        $update['author'] = $data['author'];
+        $update['desc'] = $data['digest'];
+        $update['content'] = $this->content($data['content']);
+        $update['url'] = $data['url'];
+        $update['content_source_url'] = $data['content_source_url'];
+        $update['thumb_media_id'] = $data['thumb_media_id'];
+        $update['thumb_url'] = $this->pic($data['thumb_url']);
+        $update['update_time'] = $update_time;
+        $update['create_time'] = $create_time;
+
+        if ($info) {
+            $update['where_id'] = $info['id'];
+            $db->update($update);
+        } else {
+            $db->insert($update);
+        }
+    }
+
+    /**
+     * 图片本地化
+     * 
+     * @return mixed
+     */
+    private function pic($pic)
+    {
+        $pic = Dever::load('upload/save')->copy($pic);
+
+        return $pic['url'];
+    }
+
+    /**
+     * 内容中的图片本地化
+     * 
+     * @return mixed
+     */
+    private function content($content)
+    {
+        return preg_replace_callback('/<img(.*?) data-src="(.*?)"/i', array($this, 'replace'), $content);
+    }
+
+    /**
+     * 内容中的图片本地化
+     * 
+     * @return mixed
+     */
+    private function replace($matches)
+    {
+        $result = '';
+        if (isset($matches[1])) {
+            $data = str_replace(array('"', ' '), array('', '&'), trim($matches[1]));
+            parse_str($data, $config);
+            $attr = $matches[1];
+            if (isset($config['data-w'])) {
+                $attr .= ' width="'.$config['data-w'].'"';
+            }
+            if (isset($config['data-h'])) {
+                $attr .= ' height="'.$config['data-h'].'"';
+            }
+            
+            $result = '<img'.$attr.' src="';
+        }
+        if (isset($matches[2]) && $matches[2]) {
+            $result .= $this->pic($matches[2]) . '"';
+        }
+
+        return $result;
+    }
+}

+ 227 - 0
service/src/Total.php

@@ -0,0 +1,227 @@
+<?php
+/*
+|--------------------------------------------------------------------------
+| 统计信息
+|--------------------------------------------------------------------------
+*/
+namespace Service\Src;
+
+use Dever;
+use Main\Lib\Wechat;
+use Main\Lib\Core;
+
+class Total extends Base
+{
+    # 计划任务
+    public function cron()
+    {
+        $project = $this->getProject();
+        if ($project) {
+            foreach ($project as $k => $v) {
+                if ($v) {
+                    $base = $this->base($v);
+                }
+            }
+        }
+    }
+
+    # 获取基本统计信息
+    public function base($project)
+    {
+        $day = Dever::input('day', date('Y-m-d', time()-86400));
+
+        $wechat = new Wechat($project, 'service');
+
+        $id = $project;
+        if (is_array($project)) {
+            $id = $project['id'];
+        }
+
+        $param['begin_date'] = $param['end_date'] = $day;
+
+        $result = array();
+
+        $data = $wechat->curl('getusersummary', $param, false);
+
+        $source = array();
+        if (isset($data['list'][0])) {
+            $result['new_user'] = $result['cancel_user'] = 0;
+            foreach ($data['list'] as $k => $v) {
+                $source[$v['user_source']] = $v;
+                $result['new_user'] += $v['new_user'];
+                $result['cancel_user'] += $v['cancel_user'];
+            }
+        }
+
+        if (isset($result['new_user'])) {
+            $data = $wechat->curl('getusercumulate', $param, false);
+            if (isset($data['list'][0])) {
+                $result['cumulate_user'] = 0;
+                foreach ($data['list'] as $k => $v) {
+                    $source[$v['user_source']]['cumulate_user'] = $v['cumulate_user'];
+                    $result['cumulate_user'] += $v['cumulate_user'];
+                }
+            }
+            //$this->update_source($id, $day, $source);
+
+            $data = $wechat->curl('getarticlesummary', $param, false);
+            if (isset($data['list'][0])) {
+                $result += $this->news($id, $day, $data['list']);
+            }
+
+            $this->update_base($id, $day, $result);
+        }
+        
+        return $result;
+    }
+
+    private function update_base($project, $day, $data)
+    {
+        $update = array();
+        $update['day'] = $day;
+        $update['daynum'] = Dever::maketime($day);
+        $update['project_id'] = $project;
+        //$update['user_source'] = isset($data['user_source']) ? $data['user_source'] : 0;
+        $update['new_user'] = isset($data['new_user']) ? $data['new_user'] : 0;
+        $update['cancel_user'] = isset($data['cancel_user']) ? $data['cancel_user'] : 0;
+        $update['user'] = $update['new_user'] - $update['cancel_user'];
+        $update['cumulate_user'] = isset($data['cumulate_user']) ? $data['cumulate_user'] : 0;
+
+
+        $update['int_page_read_user'] = isset($data['int_page_read_user']) ? $data['int_page_read_user'] : 0;
+        $update['int_page_read_count'] = isset($data['int_page_read_count']) ? $data['int_page_read_count'] : 0;
+        $update['ori_page_read_user'] = isset($data['ori_page_read_user']) ? $data['ori_page_read_user'] : 0;
+        $update['ori_page_read_count'] = isset($data['ori_page_read_count']) ? $data['ori_page_read_count'] : 0;
+        $update['share_user'] = isset($data['share_user']) ? $data['share_user'] : 0;
+        $update['share_count'] = isset($data['share_count']) ? $data['share_count'] : 0;
+        $update['add_to_fav_user'] = isset($data['add_to_fav_user']) ? $data['add_to_fav_user'] : 0;
+        $update['add_to_fav_count'] = isset($data['add_to_fav_count']) ? $data['add_to_fav_count'] : 0;
+
+        $where = array();
+        $where['day'] = $update['day'];
+        $where['project_id'] = $update['project_id'];
+
+        $info = Dever::db('service/total_base')->one($where);
+        if (!$info) {
+            $id = Dever::db('service/total_base')->insert($update);
+        } else {
+            $id = $info['id'];
+            $update['where_id'] = $id;
+            Dever::db('service/total_base')->update($update);
+        }
+    }
+
+    # 获取图文统计数据
+    private function news($project, $day, $data)
+    {
+        $result = array();
+        $result['int_page_read_user'] = 0;
+        $result['int_page_read_count'] = 0;
+        $result['ori_page_read_user'] = 0;
+        $result['ori_page_read_count'] = 0;
+        $result['share_user'] = 0;
+        $result['share_count'] = 0;
+        $result['add_to_fav_user'] = 0;
+        $result['add_to_fav_count'] = 0;
+
+
+        foreach ($data as $k => $v) {
+            $this->update_news($project, $day, $v);
+
+            foreach ($result as $k1 => $v1) {
+                if (isset($v[$k1]) && $v[$k1] > 0) {
+                    $result[$k1] += $v[$k1];
+                }
+            }
+        }
+
+        return $result;
+    }
+
+    private function update_news($project, $day, $data)
+    {
+        $update = array();
+        $update['day'] = $day;
+        $update['daynum'] = Dever::maketime($day);
+        $update['project_id'] = $project;
+        $update['msgid'] = $data['msgid'];
+        $update['title'] = $data['title'];
+
+        $update['int_page_read_user'] = isset($data['int_page_read_user']) ? $data['int_page_read_user'] : 0;
+        $update['int_page_read_count'] = isset($data['int_page_read_count']) ? $data['int_page_read_count'] : 0;
+        $update['ori_page_read_user'] = isset($data['ori_page_read_user']) ? $data['ori_page_read_user'] : 0;
+        $update['ori_page_read_count'] = isset($data['ori_page_read_count']) ? $data['ori_page_read_count'] : 0;
+        $update['share_user'] = isset($data['share_user']) ? $data['share_user'] : 0;
+        $update['share_count'] = isset($data['share_count']) ? $data['share_count'] : 0;
+        $update['add_to_fav_user'] = isset($data['add_to_fav_user']) ? $data['add_to_fav_user'] : 0;
+        $update['add_to_fav_count'] = isset($data['add_to_fav_count']) ? $data['add_to_fav_count'] : 0;
+
+        $where = array();
+        $where['day'] = $update['day'];
+        $where['project_id'] = $update['project_id'];
+        $where['msgid'] = $update['msgid'];
+
+        $info = Dever::db('service/total_news')->one($where);
+        if (!$info) {
+            $id = Dever::db('service/total_news')->insert($update);
+        } else {
+            $id = $info['id'];
+            $update['where_id'] = $id;
+            Dever::db('service/total_news')->update($update);
+        }
+    }
+
+    /**
+     * 导出
+     *
+     * @return mixed
+     */
+    public function out()
+    {
+        $service = $this->getProject();
+
+        $day = Dever::input('day');
+        if (!$day) {
+            $day = date('Y-m-d', time()-3600*24);
+        }
+        $data = Dever::db('service/total_base')->state(array('day' => $day));
+
+        $i = 0;
+        foreach ($data as $k => $v) {
+            $data[$k]['service'] = $service[$data[$k]['project_id']]['name'];
+
+            if ($data[$k]['service']) {
+                $body[$i] = array
+                (
+                    $data[$k]['service'],
+                    $data[$k]['new_user'],
+                    $data[$k]['cancel_user'],
+                    $data[$k]['user'],
+                    $data[$k]['cumulate_user'],
+                    $data[$k]['int_page_read_user'],
+                    $data[$k]['int_page_read_count'],
+                    $data[$k]['ori_page_read_user'],
+                    $data[$k]['ori_page_read_count'],
+                    $data[$k]['share_user'],
+                    $data[$k]['share_count'],
+                    $data[$k]['add_to_fav_user'],
+                    $data[$k]['add_to_fav_count'],
+                );
+                $i++;
+            }
+        }
+        $header = array
+        (
+            '公众号名称', '新增的用户数量', '取消关注的用户数量', '净增用户数量', '总用户量', '图文页的阅读人数', '图文页的阅读次数', '原文页的阅读人数', '原文页的阅读次数', '分享的人数', '分享的次数', '收藏的人数', '收藏的次数'
+        );
+
+        $file = $day . '_公众号每日概览';
+        if (Dever::input('test')) {
+            print_r($header);
+            print_r($body);die;
+        }
+        
+        Dever::excelExport($body, $header, $file, $sheet = 0, $sheetName = $day);
+        return;
+    }
+}