<?php

$role = function()
{
	$array = array();
	$data = Dever::load('setting/role-state');
	if($data)
	{
		$array += $data;
	}
	return $array;
};

$source_id = function()
{
    $array = array
    (
        -1 => array
        (
            'id' => '-1',
            'name' => '无来源',
        ),
    );
    $data = Dever::load('setting/source-state');
    if($data)
    {
        $array += $data;
    }
    return $array;
};


$status = array
(
    1 => '待业务初审',
    2 => '待财务终审',
    3 => '待权益发放',
    4 => '已完成',
    5 => '已作废',
);

$pay_status = array
(
    1 => '待支付',
    2 => '已支付',
    3 => '已退款',
);

$goods_status = array
(
    1 => '未发放',
    2 => '无权益',
    3 => '已发放',
);

$type = array
(
    1 => '个人',
    2 => '公司',
);

$pay_type = array
(
	1 => '在线支付',
    2 => '汇款',
    3 => '个人转账',
);

$get_type = array
(
    1 => '购买',
    2 => '赠送',
);

$level = function()
{
	$array = array
	(
		-1 => array
		(
			'id' => -1,
			'name' => '普通',
		),
	);
	$data = Dever::load('setting/level-state');
	if($data)
	{
		$array += $data;
	}
	return $array;
};

$order_type = array
(
    1 => '新购',
    2 => '升级',
);
$button = array();
$parent_mid = Dever::input('search_option_parent_mid');
$mid = Dever::input('search_option_mid');
$pmid = '';
if ($parent_mid) {
    $pmid = $parent_mid;
}
if ($mid) {
   $pmid = $mid; 
}

if ($pmid) {
    $button = array
    (
        '返回上一页' => array('location', 'l=project/database/list&project=agent&table=member_area&page_type=1&mid=' . $pmid),
    );
}
return array
(
    # 表名
    'name' => 'order',
    # 显示给用户看的名称
    'lang' => '代理商订单',
    'set' => array
    (
    	'status' => $status,
    	'pay_status' => $pay_status,
    	'goods_status' => $goods_status,
    	'type' => $type,
    	'pay_type' => $pay_type,
        'order_type' => $order_type,
    ),
    'order' => 99,
    # 数据结构
    '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',
            'searchs'    => array
            (
                'api' => 'agent/member-find',
                'col' => 'mobile',
                'result' => 'id',
            ),
            //'list'      => 'Dever::load("agent/member-find#name", {mid})',
        ),

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

        'order_type'        => array
        (
            'type'      => 'tinyint-1',
            'name'      => '订单类型',
            'default'   => '1',
            'desc'      => '订单类型',
            'match'     => 'is_numeric',
            'option'    => $order_type,
        ),

        'mobile'      => array
        (
            'type'      => 'bigint-11',
            'name'      => '手机号',
            'default'   => '',
            'desc'      => '请输入手机号',
            'match'     => Dever::rule('mobile'),
            'update'    => 'text',
            'search'    => 'fulltext',
            //'list'      => true,
        ),

        'parent_mid'      => array
        (
            'type'      => 'int-11',
            'name'      => '邀请人手机号',
            'default'   => '-1',
            'desc'      => '邀请人',
            'match'     => 'is_string',
            'update'    => 'text',
            'search'    => $parent_mid ? 'hidden' : array
            (
                'api' => 'agent/member-find',
                'col' => 'mobile',
                'result' => 'id',
            ),
            'list_name'      => '邀请人',
            'list'      => 'Dever::load("agent/lib/member.getOne", {parent_mid})',
            'list_order' => 4,
        ),

        'source_id'      => array
        (
            'type'      => 'int-11',
            'name'      => '注册来源',
            'default'   => '-1',
            'desc'      => '注册来源',
            'match'     => 'is_numeric',
            'search'    => 'select',
            'update'    => 'checkbox',
            'option'    => $source_id,
            'list'      => true,
            'list_order' => 5,
        ),

        'name'      => array
        (
            'type'      => 'varchar-100',
            'name'      => '姓名',
            'default'   => '',
            'desc'      => '姓名',
            'match'     => 'is_string',
            'update'    => 'text',
            'search'    => 'fulltext',
            'list'      => 'Dever::load("agent/lib/member.getOne", {id}, "agent/order")',
            'list_order' => 3,
        ),

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

        'area'       => array
        (
            'type'      => 'varchar-500',
            'name'      => '区域',
            'default'   => '',
            'desc'      => '区域',
            'match'     => 'option',
            'search'    => 'linkage',
            'update'    => 'linkage',
            'option'    => Dever::url('api.get?level_total=4', 'area'),
            'list'      => 'Dever::load("area/api.string", "{area}")',
        ),

        'desc'      => array
        (
            'type'      => 'varchar-600',
            'name'      => '付款备注',
            'default'   => '',
            'desc'      => '付款备注',
            'match'     => 'is_string',
            'update'    => 'text',
        ),

        'f_price'      => array
        (
            'type'      => 'float-11,2',
            'name'      => '原价',
            'default'   => '0',
            'desc'      => '原价',
            'match'     => 'option',
            'update'    => 'text',
        ),

        'price'      => array
        (
            'type'      => 'float-11,2',
            'name'      => '实付金额',
            'default'   => '0',
            'desc'      => '金额',
            'match'     => 'option',
            'update'    => 'text',
            'list'		=> true,
            'list_order' => 6,
        ),

        'pay_type'		=> array
		(
			'type' 		=> 'tinyint-1',
			'name' 		=> '支付方式',
			'default' 	=> '1',
			'desc' 		=> '支付方式',
			'match' 	=> 'is_numeric',
			'search'	=> 'select',
			'update'	=> 'select',
			'option'	=> $pay_type,
			'list'		=> true,
            'list_order' => 7,
		),

		'pay_pic'		=> array
		(
			'type' 		=> 'varchar-150',
			'name' 		=> '打款凭证',
			'default' 	=> '',
			'desc' 		=> '打款凭证',
			'match' 	=> 'option',
			'update'	=> 'image',
			'key' 		=> '1',
			'place'		=> '150',
		),

        'pay_price'      => array
        (
            'type'      => 'float-11,2',
            'name'      => '交款金额',
            'default'   => '0',
            'desc'      => '交款金额',
            'match'     => 'option',
            'update'    => 'text',
        ),

		'bank_id'		=> array
		(
			'type' 		=> 'int-11',
			'name' 		=> '所属银行',
			'default' 	=> '',
			'desc' 		=> '所属银行',
			'match' 	=> 'is_numeric',
		),

		'bank_card'		=> array
		(
			'type' 		=> 'int-11',
			'name' 		=> '银行卡号',
			'default' 	=> '',
			'desc' 		=> '银行卡号',
			'match' 	=> 'is_numeric',
		),

        'type'        => array
        (
            'type'      => 'tinyint-1',
            'name'      => '类型',
            'default'   => '1',
            'desc'      => '类型',
            'match'     => 'is_numeric',
            'option'    => $type,
        ),

        'sign'     => array
        (
            'type'      => 'varchar-150',
            'name'      => '手写签名',
            'default'   => '',
            'desc'      => '手写签名',
            'match'     => 'option',
            'update'    => 'image',
            'key'       => '7',
        ),

        'idcard'      => array
        (
            'type'      => 'varchar-100',
            'name'      => '身份证号码',
            'default'   => '',
            'desc'      => '身份证号码',
            'match'     => 'is_string',
            'update'    => 'text',
            'search'	=> 'fulltext',
        ),

        'idcard_front'     => array
        (
            'type'      => 'varchar-150',
            'name'      => '身份证正面',
            'default'   => '',
            'desc'      => '身份证正面',
            'match'     => 'option',
            'update'    => 'image',
            'key'       => '8',
            'place'     => '660*660',
        ),

        'idcard_back'     => array
        (
            'type'      => 'varchar-150',
            'name'      => '身份证背面',
            'default'   => '',
            'desc'      => '身份证背面',
            'match'     => 'option',
            'update'    => 'image',
            'key'       => '8',
            'place'     => '660*660',
        ),

        'company_name'      => array
        (
            'type'      => 'varchar-100',
            'name'      => '公司名称',
            'default'   => '',
            'desc'      => '公司名称',
            'match'     => 'is_string',
            'update'    => 'text',
            //'search'    => 'fulltext',
            //'list'      => true,
        ),

        'company_pic'      => array
        (
            'type'      => 'varchar-150',
            'name'      => '营业执照',
            'default'   => '',
            'desc'      => '营业执照',
            'match'     => 'option',
            'update'    => 'image',
            'key'       => '8',
            'place'     => '660*660',
        ),

        'company_number'      => array
        (
            'type'      => 'varchar-80',
            'name'      => '营业执照号码',
            'default'   => '',
            'desc'      => '营业执照号码',
            'match'     => 'is_string',
            'update'    => 'text',
        ),

        'address'      => array
        (
            'type'      => 'varchar-800',
            'name'      => '地址',
            'default'   => '',
            'desc'      => '地址',
            'match'     => 'is_string',
            'update'    => 'text',
        ),

        'status'        => array
        (
            'type'      => 'tinyint-1',
            'name'      => '订单状态',
            'default'   => '1',
            'desc'      => '状态',
            'match'     => 'is_numeric',
            'option'    => $status,
            'search'    => 'select',
            'list'      => true,
            'list_order' => 8,
        ),

        'goods_status'        => array
        (
            'type'      => 'tinyint-1',
            'name'      => '权益状态',
            'default'   => '1',
            'desc'      => '权益状态',
            'match'     => 'is_numeric',
            'option'    => $goods_status,
            'search'    => 'select',
            'list'      => true,
            'list_order' => 9,
        ),

        'pay_status'        => array
        (
            'type'      => 'tinyint-1',
            'name'      => '支付状态',
            'default'   => '1',
            'desc'      => '状态',
            'match'     => 'is_numeric',
            'option'    => $pay_status,
        ),

        'get_type'        => array
        (
            'type'      => 'tinyint-1',
            'name'      => '获取方式',
            'default'   => '1',
            'desc'      => '获取方式',
            'match'     => 'is_numeric',
            'update'    => 'radio',
            'option'    => $get_type,
        ),

        'agent_cash'      => array
        (
            'type'      => 'float-11,2',
            'name'      => '代理费',
            'default'   => '0',
            'desc'      => '代理费',
            'match'     => 'option',
            'update'    => 'text',
        ),

        'soft_cash'      => array
        (
            'type'      => 'float-11,2',
            'name'      => '软件服务费',
            'default'   => '0',
            'desc'      => '软件服务费',
            'match'     => 'option',
            'update'    => 'text',
        ),

        'state'     => array
        (
            'type'      => 'tinyint-1',
            'name'      => '状态',
            'default'   => '1',
            'desc'      => '请选择状态',
            'match'     => 'is_numeric',
        ),

        'fdate'     => array
        (
            'type'      => 'int-11',
            'name'      => '完成时间',
            'default'   => '',
            'match'     => 'is_numeric',
            'desc'      => '',
        ),
        
        '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})',
            'list_order' => 2,
        ),
    ),

    'manage' => array
    (
        'insert' => false,
        'delete' => false,
        'edit' => false,
        'button' => $button,
        'list_button' => array
        (
            //fast_list
            'list' => array('查看详情', '"order_process&project=agent&order_id={id}&page_type=1"'),

            //'edit' => array('退款', 'status,tk_time,tk_pic,tk_desc,tk_admin,tk_status', '{status} == 6'),
            //'delete' => array('删除', '', '{status} == 1'),
        ),
    ),

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