<?php

$role = function()
{
	$array = array();
	$data = Dever::load('setting/role-state');
	if($data)
	{
		$array += $data;
	}
	return $array;
};
$mid = Dever::input('search_option_mid');
$button = array();
if ($mid) {
    $button['返回上一页'] = array('location', 'l=project/database/list&project=agent&table=member_area&page_type=1&mid=' . $mid . '&[refer]');
    if (Dever::load('manage/auth')->checkFunc('agent.member', 'edit2', '发放业绩')) {
        $button['发放业绩'] = array('fast', '', 'push_sell&search_option_mid=' . $mid);
    }
    // $button = array
    // (
    //     '返回上一页' => array('location', 'l=project/database/list&project=agent&table=member_area&page_type=1&mid=' . $mid),
    //     '发放业绩' => array('fast', '', 'push_sell&search_option_mid=' . $mid),
    // );
}
$type = array
(
    1 => '直推业绩',
    2 => '团队业绩',
);

$stype = array
(
    1 => '自动发放',
    2 => '手动发放',
    3 => '旧系统导入',
);

return array
(
    # 表名
    'name' => 'sell',
    # 显示给用户看的名称
    'lang' => '业绩流水',
    'order' => 90,
    'set' => array
    (
        'type' => $type,
        'stype' => $stype,
    ),
    # 数据结构
    'struct' => array
    (
    
        'id'        => array
        (
            'type'      => 'int-11',
            'name'      => 'ID',
            'default'   => '',
            'desc'      => '',
            'match'     => 'is_numeric',
            'search'    => 'order',
            //'list'        => true,
        ),

        'mid'      => array
        (
            'type'      => 'int-11',
            'name'      => '代理商姓名/手机号',
            'default'   => '-1',
            'desc'      => '代理商',
            'match'     => 'is_string',
            'update'    => 'text',
            'search'    => array
            (
                'api' => 'agent/member-getSearch',
                'col' => 'col',
                'result' => 'id',
                'search' => 'mid',
            ),
            'list_name' => '代理商信息',
            'list'      => 'Dever::load("agent/lib/member.getOne", {mid}, "agent/member", true)',
            'list_order' => 1,
        ),

        'child_mid'      => array
        (
            'type'      => 'int-11',
            'name'      => '下级直推的mid',
            'default'   => '-1',
            'desc'      => '下级直推的mid',
            'match'     => 'is_string',
            'update'    => 'text',
        ),

        'agent-member-name'=> array
        (
            'name'      => '姓名',
            'default'   => '',
            'desc'      => '姓名',
            'match'     => 'option',
            # 读取另外表的关联方式
            'sync'      => array('mid', 'id'),
            // 'search'    => 'fulltext',
            'searchs'    => array
            (
                'api' => 'agent/member-find',
                'col' => 'name',
                'result' => 'id',
                'search' => 'mid',
            ),
        ),

        'agent-member-role'=> array
        (
            'name'      => '代理角色',
            'default'   => '',
            'desc'      => '代理角色',
            'match'     => 'option',
            # 读取另外表的关联方式
            'sync'      => array('mid', 'id'),
            // 'list'      => 'Dever::load("setting/role-find#name", "{agent-member-role}")',
            // 'list_order' => 5,
        ),

        'order_num'      => array
        (
            'type'      => 'varchar-100',
            'name'      => '流水号',
            'default'   => '',
            'desc'      => '流水号',
            'match'     => 'is_string',
            'update'    => 'text',
            //'search'    => 'fulltext',
            //'list'      => true,
            //'list_order'  => 1,
        ),

        'type'      => array
        (
            'type'      => 'int-11',
            'name'      => '业绩类型',
            'default'   => '1',
            'desc'      => '业绩类型',
            'match'     => 'is_numeric',
            'search'    => 'select',
            'update'    => 'checkbox',
            'option'    => $type,
            'list'      => true,
            'list_order' => 7,
        ),

        'stype'      => array
        (
            'type'      => 'int-11',
            'name'      => '发放类型',
            'default'   => '1',
            'desc'      => '发放类型',
            'match'     => 'is_numeric',
            'search'    => 'select',
            'update'    => 'checkbox',
            'option'    => $stype,
            'list'      => true,
            'list_order' => 8,
        ),

        'type_id'      => array
        (
            'type'      => 'int-11',
            'name'      => '交易来源id',
            'default'   => '',
            'desc'      => '交易来源id',
            'match'     => 'is_string',
            'update'    => 'text',
        ),

        'role'      => array
        (
            'type'      => 'int-11',
            'name'      => '代理角色',
            'default'   => '',
            'desc'      => '代理角色',
            'match'     => 'is_numeric',
            //'search'	=> 'select',
            'update'    => 'checkbox',
            'option'    => $role,
            //'list'      => true,
        ),

        'num'      => array
        (
            'type'      => 'decimal-11,2',
            'name'      => '业绩金额',
            'default'   => '0',
            'desc'      => '业绩',
            'match'     => 'is_numeric',
            'update'    => 'text',
            'list'      => true,
        ),

        'desc'      => array
        (
            'type'      => 'varchar-600',
            'name'      => '业绩说明',
            'default'   => '',
            '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", {cdate})',
            'list_order'  => 20,
        ),
    ),

    'manage' => array
    (
        'insert' => false,
        'delete' => false,
        'edit' => false,
        'button' => $button,

        'list_button' => array
        (
            'list' => array('查看详情', '"push_sell&project=bill&id={id}&page_type=1"'),
        ),
    ),

    'request' => array
    (
        'getData' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'mid' => 'yes',
                'type' => 'yes',
                'state' => 1,
            ),
            'order' => array('id' => 'desc'),
            'page' => array(10, 'list'),
            'type' => 'all',
            'col' => '*',
        ),

        'getNumByTime' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'start' => array('yes-cdate', '>='),
                'end' => array('yes-cdate', '<='),
                'type' => 'yes',
                'state' => 1,
            ),
            'type' => 'all',
            'group' => 'mid,type',
            'col' => '*,sum(num) as num',
        ),

        'getNumByTimeOne' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                // 'start' => array('yes-cdate', '>='),
                'end' => array('yes-cdate', '<='),
                'mid' => 'yes',
                'stype' => 'yes',
                'type' => 'yes',
                'state' => 1,
            ),
            'type' => 'one',
            'col' => '*,sum(num) as num',
        ),

        'getNewParent' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'start' => array('yes-cdate','>='),
                'end' => array('yes-cdate','<='),
                'mid' => 'yes',
                'type' => 'yes',
                'state' => 1,
            ),
            'type' => 'one',
            'col' => 'sum(num) as total',
        ),

        'getChildData' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'child_mid' => -1,
                'state' => 1,
            ),
            'order' => array('id' => 'desc'),
            'type' => 'all',
            'limit' => '0,1000',
            'col' => '*',
        ),
    ),
);