<?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
    (
        '返回上一页' => 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 => '团队业绩',
);

$ftype = array
(
    1 => '自动发放',
    2 => '手动发放',
);

return array
(
    # 表名
    'name' => 'sell',
    # 显示给用户看的名称
    'lang' => '业绩流水',
    'order' => 90,
    'set' => array
    (
        'type' => $type,
    ),
    # 数据结构
    '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'    => $mid ? 'hidden' : array
            (
                'api' => 'agent/member-find',
                'col' => 'mobile',
                'result' => 'id',
            ),
            'list_name' => '手机号',
            'list'      => 'Dever::load("agent/member-find#mobile", {mid})',
            'list_order' => 4,
        ),

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

        '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'      => 'float-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'  => 2,
        ),
    ),

    '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' => array('yes', 'in'),
                'state' => 1,
            ),
            'type' => 'all',
            'group' => 'mid',
            'col' => '*,sum(num) as num',
        ),

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