<?php

$action = function()
{
	$array = array();
	$info = Dever::db('score/action')->state();
	if($info)
	{
		$array += $info;
	}
	return $array;
};

$score_type = array
(
	1 => '未加积分',
	2 => '已加积分',
	3 => '达到积分上限',
);

$cron_type = array
(
	1 => '未开始',
	2 => '进行中',
	3 => '已完成',
);

return array
(
	# 表名
	'name' => 'action_log',
	# 显示给用户看的名称
	'lang' => '积分行为日志',
	'order' => 10,
	'menu' => false,
	# 数据结构
	'struct' => array
	(
		'id' 		=> array
		(
			'type' 		=> 'int-11',
			'name' 		=> 'ID',
			'default' 	=> '',
			'desc' 		=> '',
			'match' 	=> 'is_numeric',
			'list'		=> true,
		),

		'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}) : "匿名用户"',
		),
		
		'action_id'		=> array
		(
			'type' 		=> 'int-11',
			'name' 		=> '所属行为',
			'default' 	=> '1',
			'desc' 		=> '所属行为',
			'match' 	=> 'is_numeric',
			'update'	=> 'select',
			'option'	=> $action,
			'search'	=> 'select',
			'list'		=> true,
		),

		'score_type'		=> array
		(
			'type' 		=> 'int-11',
			'name' 		=> '是否增加积分',
			'default' 	=> '1',
			'desc' 		=> '是否增加积分',
			'match' 	=> 'is_numeric',
			'update'	=> 'select',
			'option'	=> $score_type,
			'search'	=> 'select',
			'list'		=> true,
		),

		'cron_type'		=> array
		(
			'type' 		=> 'int-11',
			'name' 		=> '是否增加积分',
			'default' 	=> '3',
			'desc' 		=> '是否增加积分',
			'match' 	=> 'is_numeric',
			'update'	=> 'select',
			'option'	=> $cron_type,
			'search'	=> 'select',
			'list'		=> true,
		),

		'score'		=> array
		(
			'type' 		=> 'varchar-30',
			'name' 		=> '增加积分数',
			'default' 	=> '0',
			'desc' 		=> '积分数',
			'match' 	=> 'is_string',
			'list'		=> true,
		),

		'num'		=> array
		(
			'type' 		=> 'varchar-30',
			'name' 		=> '增加的积分将乘以该数量',
			'default' 	=> '0',
			'desc' 		=> '积分数',
			'match' 	=> 'is_string',
		),

		'mscore'		=> array
		(
			'type' 		=> 'varchar-30',
			'name' 		=> '手动增加积分数',
			'default' 	=> '0',
			'desc' 		=> '积分数',
			'match' 	=> 'is_string',
		),

		'callback'		=> array
		(
			'type' 		=> 'varchar-800',
			'name' 		=> '行为回调方法',
			'default' 	=> '',
			'desc' 		=> '行为回调方法',
			'match' 	=> 'option',
			'update'	=> 'textarea',
			//'list'		=> true,
		),

		'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
	(
		'getDataByDate' => array
		(
			# 匹配的正则或函数 选填项
			'option' => array
			(
				'start' => array('yes-cdate', '>='),
				'end' => array('yes-cdate', '<='),
				'score_type' => 'yes',
				'action_id' => 'yes',
			),
			'type' => 'all',
			'order' => array('id' => 'desc'),
			'col' => 'id',
		),
	)
);
