<?php

$button = array();
$list_button = array
(
	'list' => array('认证', '"auth&search_option_uid={id}&oper_table=info"'),

	'list1' => array('地址', '"address&search_option_source_table=user/info&search_option_source_id={id}&oper_table=info"'),
	'list2' => array('发票', '"invoice&search_option_source_table=user/info&search_option_source_id={id}&oper_table=info"'),
);
if (Dever::project('account')) {
	$list_button += array
	(
		'list99' => array('钱包', '"info_log&project=account&config_key=qianbao&search_option_uid={id}&parent=user/info"'),
	);
}
if (Dever::project('score')) {
	$list_button += array
	(
		'list100' => array('积分', '"user&project=score&search_option_uid={id}&parent=user/info"'),
		'list101' => array('等级', '"user_level&project=score&search_option_uid={id}&parent=user/info"'),
	);
}

$project = function()
{
	return Dever::db('user/project')->state();
};

$sex = array
(
	1 => '男',
	2 => '女',
	3 => '未知',
);

$system_source = Dever::config('base')->system_source;

return array
(
	# 表名
	'name' => 'info',
	# 显示给用户看的名称
	'lang' => '用户管理',
	'order' => 10,
	# 用户id从100w开始
	'auto' => 100000000,
	'set' => array
	(
		'system_source' => $system_source,
		'sex' => $sex,
	),
	# 数据结构
	'struct' => array
	(
	
		'id' 		=> array
		(
			'type' 		=> 'int-11',
			'name' 		=> '用户ID',
			'default' 	=> '',
			'desc' 		=> '',
			'match' 	=> 'is_numeric',
			'search'	=> 'order,fulltext',
			'list'		=> true,
		),
		
		'name'		=> array
		(
			'type' 		=> 'varchar-50',
			'name' 		=> '用户名',
			'default' 	=> '',
			'desc' 		=> '请输入用户名',
			'match' 	=> 'is_string',
			'update'	=> 'text',
			'search'	=> 'fulltext',
			'list'		=> true,
		),

		'mobile'		=> array
		(
			'type' 		=> 'varchar-32',
			'name' 		=> '手机号',
			'default' 	=> '',
			'desc' 		=> '请输入用户手机号',
			'match' 	=> Dever::rule('mobile'),
			'update'	=> 'text',
			'search'	=> 'fulltext',
			'list'		=> true,
		),

		'email'		=> array
		(
			'type' 		=> 'varchar-150',
			'name' 		=> '邮箱',
			'default' 	=> '',
			'desc' 		=> '请输入邮箱',
			'match' 	=> 'option',
			'update'	=> 'text',
			//'search'	=> 'fulltext',
			//'list'		=> true,
		),
		
		'password'		=> array
		(
			'type' 		=> 'varchar-50',
			'name' 		=> '密码',
			'default' 	=> '',
			'desc' 		=> '请输入密码',
			'match' 	=> 'option',
			'update'	=> 'password',
			'callback'	=> 'sha1',
		),

		'project_id'		=> array
		(
			'type' 		=> 'int-11',
			'name' 		=> '所属项目',
			'default' 	=> '1',
			'desc' 		=> '所属项目',
			'match' 	=> 'is_numeric',
			'option' 	=> $project,
			'update'	=> 'radio',
			'search'	=> 'select',
			'list'		=> true,
		),

		'system_source'		=> array
		(
			'type' 		=> 'tinyint-1',
			'name' 		=> '用户来源',
			'default' 	=> '100',
			'desc' 		=> '用户来源',
			'match' 	=> 'is_numeric',
			'option' 	=> $system_source,
			'update'	=> 'radio',
			'search'	=> 'select',
			'list'		=> true,
		),

		'avatar_id'		=> array
		(
			'type' 		=> 'int-11',
			'name' 		=> '头像',
			'default' 	=> '1',
			'desc' 		=> '头像',
			'match' 	=> 'is_numeric',
		),

		'avatar'		=> array
		(
			'type' 		=> 'varchar-150',
			'name' 		=> '头像',
			'default' 	=> '',
			'desc' 		=> '请选择头像',
			'match' 	=> 'option',
			'update'	=> 'image',
			'key' 		=> '1',
			'place'		=> '150',
		),

		'sex'		=> array
		(
			'type' 		=> 'tinyint-1',
			'name' 		=> '性别',
			'default' 	=> '3',
			'desc' 		=> '性别',
			'match' 	=> 'is_numeric',
			'option' 	=> $sex,
			'update'	=> 'radio',
			'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
	(
		'excel' => true,
		'button' => $button,
		'list_button' => $list_button,
	),

	# 更新表结构
	/*
	'alter' => array
	(
		1 => array
		(
			array('add', 'bind', 'bind', 'tinyint-1 2 是否绑定手机'),
		),
		'version' => 1,
	),
	*/
	# 索引
	'index' => array
	(
		1 => array
		(
			'mobile' => 'mobile',
		),
		
		# 版本号 更改版本号会更新当前表的索引
		'version' => 1,
	),
	
	# request 请求接口定义
	'request' => array
	(
		# 此处定义是为跳出auth
		'login' => array
		(
			'option' => array
			(
				'username' => 'yes',
				'mobile' => 'yes',
				'email' => 'yes',
				'password' => 'yes',
			),
			'type' => 'one',
		),

		# 验证手机号是否被使用 
		'checkMobile' => array
		(
			# 匹配的正则或函数 选填项
			'where' => array
			(
				'mobile' => 'yes',
				'id' => array('yes', '!='),
			),
			'type' => 'one',
		),

		# 后台搜索用到
		'search' => array
		(
			# 匹配的正则或函数 选填项
			'option' => array
			(
				'ids' => array('yes-id', 'in'),
				'search' => array('yes-mobile,name', 'like'),
				'id' => 'yes',
				'state' => 1,
			),
			'type' => 'all',
			'order' => array('id' => 'desc'),
			'limit' => '0,1000',
			'col' => 'concat(name, "-", mobile) as name, id, id as value, "" as selected, "" as disabled|id',
		),

		'getNum' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'start' => array('yes-cdate', '>='),
                'end' => array('yes-cdate', '<='),
                'state' => 1,
            ),
            'type' => 'count',
            'col' => '*',
        ),

        'like' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
            	'search' => array('yes-mobile,name', 'like'),
            	'mobile' => array('yes', 'like'),
                'name' => array('yes', 'like'),
                'id' => 'yes',
                'state' => 1,
            ),
            'type' => 'all',
            'order' => array('id' => 'desc'),
            'col' => '*|id',
        ),
	),
);