<?php

# 定义几个常用的选项
$option = array
(
	1 => '生效',
	2 => '失效',
);

return array
(
	# 表名
	'name' => 'top',
	# 显示给用户看的名称
	'lang' => '头部菜单设置',
	'menu' => false,
	# 数据结构
	'struct' => array
	(
		'id' 		=> array
		(
			'type' 		=> 'int-11',
			'name' 		=> 'ID',
			'default' 	=> '',
			'desc' 		=> '',
			'match' 	=> 'is_numeric',
			'order'		=> 'desc',
		),
		
		'name'		=> array
		(
			'type' 		=> 'varchar-50',
			'name' 		=> '权限名',
			'default' 	=> '',
			'desc' 		=> '请输入权限名',
			'match' 	=> 'is_string',
			'update'	=> 'text',
			'search'	=> 'order,fulltext',
			'list'		=> true,
		),
		
		'top_id'		=> array
		(
			'type' 		=> 'int-11',
			'name' 		=> '上级权限',
			'default' 	=> -1,
			'desc' 		=> '请选择上级权限',
			'match' 	=> 'is_numeric',
			'update'	=> 'select',
			'search'	=> 'order,select',
			'list'		=> '{top_id} > 0 ? Dever::load("manage/top-one#name", {top_id}) : "父级权限"',
		),
		
		'key'		=> array
		(
			'type' 		=> 'varchar-100',
			'name' 		=> '权限key',
			'default' 	=> '',
			'desc' 		=> '请输入权限key',
			'match' 	=> 'is_string',
			'update'	=> 'text',
			'search'	=> 'fulltext',
			'list'		=> true,
		),

		'value'		=> array
		(
			'type' 		=> 'varchar-30',
			'name' 		=> '对应的值',
			'default' 	=> '',
			'desc' 		=> '请输入对应的值',
			'match' 	=> 'is_string',
			'update'	=> 'text',
			'search'	=> 'fulltext',
			'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})',
		),
	),
	
	# request 请求接口定义
	'request' => array
	(
		'key' => array
		(
			'where' => array
			(
				'key' => 'yes',
			),
			'type' => 'one',
		),

		'getOne' => array
		(
			'where' => array
			(
				'top_id' => 'yes',
			),
			'type' => 'one',
			'order' => array('id', 'desc'),
		),
		
		'keyId' => array
		(
			'where' => array
			(
				'key' => 'yes',
				'id' => array('yes', '!='),
			),
			'type' => 'one',
		),

		# main 取所有子权限
		'child' => array
		(
			'where' => array
			(
				'state' => 1,
				'top_id' => array(1, '>='),
			),
			'type' => 'all',
			'order' => array('id', 'desc'),
			'col' => '*|top_id|key|',
		),
		
		# main 取所有一级权限
		'main' => array
		(
			'where' => array
			(
				'state' => 1,
				'top_id' => -1,
			),
			'type' => 'all',
			'order' => array('id', 'desc'),
			'col' => '*|key',
		),
	),
);