<?php

$role = function()
{
    $info = Dever::db('setting/role')->select();
    return $info;
};

$value_type = array
(
    1 => '百分比',
    2 => '数值',
);

$is_give = array
(
	1 => '是',
	2 => '否',
);

$prize = function()
{
    $info = Dever::db('setting/prize')->select();
    return $info;
};

$role_id = Dever::input('search_option_role_id');

$update = false;
$value = '3,4';
if ($role_id) {
    $role_info = Dever::db('setting/role')->find($role_id);
    if ($role_info && $role_info['type'] == 2 && $role_info['area'] < 3) {
        if ($role_info['area'] == 2) {
            $value = '4';
        }
        $update = 'text';
    }
}



return array
(
    # 表名
    'name' => 'role_reward',
    # 显示给用户看的名称
    'lang' => '直推奖励管理',
    'menu' => false,
    # 数据结构
    'struct' => array
    (
    
        'id'        => array
        (
            'type'      => 'int-11',
            'name'      => 'ID',
            'default'   => '',
            'desc'      => '',
            'match'     => 'is_numeric',
            'search'    => 'order',
            'update'    => 'hidden',
            //'list'        => true,
        ),

        'role_id'      => array
        (
            'type'      => 'int-11',
            'name'      => '代理商角色',
            'default'   => '',
            'desc'      => '代理商角色',
            'match'     => 'is_numeric',
            'update'    => 'hidden',
            'search'    => 'hidden',
            'value'     => $role_id,
            'list'      => 'Dever::load("setting/role-one#name", {role_id})',
        ),

        't_role_id'      => array
        (
            'type'      => 'int-11',
            'name'      => '推荐角色',
            'default'   => '',
            'desc'      => '推荐角色',
            'match'     => 'is_numeric',
            'update'    => 'radio',
            'search'    => 'select',
            'option'	=> $role,
            'list'      => 'Dever::load("setting/role-one#name", {t_role_id})',
            'control'   => 't_role_id',
        ),

        'num'      => array
        (
            'type'      => 'int-11',
            'name'      => '推荐个数-每推荐多少个，奖励多少数值，这里填写推荐个数',
            'default'   => '1',
            'desc'      => '推荐个数',
            'match'     => 'is_numeric',
            'update'    => 'text',
            'list'      => true,
        ),

        'value'      => array
        (
            'type'      => 'varchar-32',
            'name'      => '推荐奖励数值-如果是百分比，这里输入10，就是奖励10%，如果是数值，这里以元为单位',
            'default'   => '0',
            'desc'      => '推荐奖励数值',
            'match'     => 'is_string',
            'update'    => 'text',
            'search'    => 'fulltext',
            'list'      => true,
        ),

        'zt_qn_value'      => array
        (
            'type'      => 'varchar-32',
            'name'      => '直推区内数值-规则同上，仅限区县和城市代理有效',
            'default'   => '0',
            'desc'      => '直推区内数值',
            'match'     => 'is_string',
            'update'    => $update,
            'show'      => 't_role_id=' . $value,
            //'search'    => 'fulltext',
            //'list'      => true,
        ),

        'zt_qw_value'      => array
        (
            'type'      => 'varchar-32',
            'name'      => '直推区外数值-规则同上，仅限区县和城市代理有效',
            'default'   => '0',
            'desc'      => '直推区外数值',
            'match'     => 'is_string',
            'update'    => $update,
            'show'      => 't_role_id=' . $value,
            //'search'    => 'fulltext',
            //'list'      => true,
        ),

        'fzt_qn_value'      => array
        (
            'type'      => 'varchar-32',
            'name'      => '非直推区内数值-规则同上，仅限区县和城市代理有效，如果是城市代理，这里可以填写两个数值，用半角逗号隔开，第一个是区县数值，第二个是街道数值',
            'default'   => '0',
            'desc'      => '非直推区内数值',
            'match'     => 'is_string',
            'update'    => $update,
            'show'      => 't_role_id=' . $value,
            //'search'    => 'fulltext',
            //'list'      => true,
        ),

        'value_type'        => array
        (
            'type'      => 'tinyint-1',
            'name'      => '奖励数值类型',
            'default'   => '1',
            'desc'      => '奖励数值类型',
            'match'     => 'is_numeric',
            'update'  	=> 'radio',
            'option'    => $value_type,
            'search'    => 'select',
            'list'      => true,
            'control'	=> 'type',
        ),

        'is_give'        => array
        (
            'type'      => 'tinyint-1',
            'name'      => '是否有额外奖励',
            'default'   => '2',
            'desc'      => '是否有额外奖励',
            'match'     => 'is_numeric',
            //'update'  	=> 'radio',
            'option'    => $is_give,
            'control'	=> 'is_give',
        ),

        'give'      => array
        (
            'type'      => 'text-1000',
            'name'      => '额外奖励',
            'default'   => '',
            'desc'      => '额外奖励',
            'match'     => 'is_string',
            'show'		=> 'is_give=1',
            'updates'    => array
            (
                array
                (
                    'col'       => 'num',
                    'name'      => '推荐个数',
                    'default'   => '0',
                    'desc'      => '推荐个数',
                    'match'     => 'is_string',
                    'update'    => 'text',
                ),

                array
                (
                    'col'       => 'type',
                    'name'      => '奖励类型',
                    'default'   => '1',
                    'desc'      => '奖励类型',
                    'match'     => 'is_string',
                    'update'  	=> 'select',
            		'option'    => $prize,
                ),

                array
                (
                    'col'       => 'value',
                    'name'      => '奖励数值',
                    'default'   => '0',
                    'desc'      => '奖励数值',
                    'match'     => 'is_string',
                    'update'    => 'text',
                ),
            ),
        ),

        '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,
            'search'    => 'date',
            'list'      => 'date("Y-m-d H:i:s", {cdate})',
        ),
    ),

    'manage' => array
    (
        'list_button' => array
        (
            //'location1' => array('权益设置', Dever::url('lib/reward_set.home', 'agent')),
            'list' => array('额外奖励', '"role_reward_give&search_option_reward_id={id}&search_option_role_id={role_id}&oper_table=role_reward&oper_parent=role_reward&top_table=role"'),
        )
    ),

    'request' => array
    (
        
    ),
);
