<?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',
			'option'	=> $action,
			'search'	=> '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',
		),
	)
);