<?php

$type = array
(
    1 => '普通发票',
    2 => '默认发票',
);

$title_type = array
(
    1 => '企业单位',
    2 => '个人/非企业',
);
$source_table = Dever::input('search_option_source_table');
$source_id = Dever::input('search_option_source_id');
return array
(
    # 表名
    'name' => 'invoice',
    # 显示给用户看的名称
    'lang' => '用户发票库',
    'menu' => false,
    'title_type' => $title_type,
    # 数据结构
    'struct' => array
    (
    
        'id'        => array
        (
            'type'      => 'int-11',
            'name'      => 'ID',
            'default'   => '',
            'desc'      => '',
            'match'     => 'is_numeric',
            'search'    => 'order',
            'update'    => 'hidden',
            //'list'        => true,
        ),

        'source_table'      => array
        (
            'type'      => 'varchar-100',
            'name'      => '来源表名',
            'default'   => '',
            'desc'      => '来源表名',
            'match'     => 'is_numeric',
            'update'    => 'hidden',
            'value'     => $source_table,
        ),

        'source_id'     => array
        (
            'type'      => 'int-11',
            'name'      => '用户名',
            'default'   => '0',
            'desc'      => '请选择用户',
            'match'     => 'is_numeric',
            'update'    => 'hidden',
            'search'    => $source_table ? array
            (
                'api' => $source_table . '-like',
                'col' => 'search',
                'result' => 'id',
            ) : false,
            'value'     => $source_id,
            'list'       => 'Dever::load("user/lib/invoice.getSource#name", "{source_table}", "{source_id}")',
        ),

        'type'      => array
        (
            'type'      => 'tinyint-1',
            'name'      => '类型',
            'default'   => '2',
            'desc'      => '类型',
            'match'     => 'is_numeric',
            'option'    => $type,
            'update'    => 'hidden',
            'value'     => Dever::input('type', 2),
            'list'      => true,
        ),

        'title_type'      => array
        (
            'type'      => 'tinyint-1',
            'name'      => '抬头类型',
            'default'   => '1',
            'desc'      => '抬头类型',
            'match'     => 'is_numeric',
            'option'    => $title_type,
            'update'    => 'radio',
            'list'      => true,
            'control'   => 'title_type',
        ),

        'title'       => array
        (
            'type'      => 'varchar-150',
            'name'      => '抬头名称-企业单位为公司名称',
            'default'   => '',
            'desc'      => '抬头名称',
            'match'     => 'option',
            'search'    => 'fulltext',
            'update'  => 'text',
            'list'        => true,
        ),

        'email'        => array
        (
            'type'      => 'varchar-150',
            'name'      => '电子邮箱',
            'default'   => '',
            'desc'      => '电子邮箱',
            'match'     => 'option',
            'search'    => 'fulltext',
            'update'    => 'text',
            'list'      => true,
        ),

        'mobile'        => array
        (
            'type'      => 'varchar-150',
            'name'      => '手机号',
            'default'   => '',
            'desc'      => '手机号',
            'match'     => 'option',
            'search'    => 'fulltext',
            'update'    => 'text',
            'list'      => true,
        ),

        'number'       => array
        (
            'type'      => 'varchar-150',
            'name'      => '公司税号',
            'default'   => '',
            'desc'      => '公司税号',
            'match'     => 'option',
            'update'    => 'text',
            'show'      => 1,
        ),

        'phone'       => array
        (
            'type'      => 'varchar-100',
            'name'      => '公司电话',
            'default'   => '',
            'desc'      => '公司电话',
            'match'     => 'option',
            'update'    => 'text',
            'show'      => 1,
        ),

        'address'       => array
        (
            'type'      => 'varchar-1000',
            'name'      => '注册地址',
            'default'   => '',
            'desc'      => '注册地址',
            'match'     => 'option',
            'update'    => 'text',
            'show'      => 1,
        ),

        'bank'       => array
        (
            'type'      => 'varchar-100',
            'name'      => '开户银行',
            'default'   => '',
            'desc'      => '开户银行',
            'match'     => 'option',
            'update'    => 'text',
            'show'      => 1,
        ),

        'bank_number'       => array
        (
            'type'      => 'varchar-100',
            'name'      => '银行账号',
            'default'   => '',
            'desc'      => '银行账号',
            'match'     => 'option',
            'update'    => 'text',
            'show'      => 1,
        ),

        '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})',
        ),
    ),

    'index' => array
    (
        1 => array
        (
            'source' => 'source_table,source_id,type',
        ),
        
        # 版本号 更改版本号会更新当前表的索引
        'version' => 1,
    ),

    'manage' => array
    (
        
    ),

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

        'updateType' => array
        (
            'set' => array
            (
                'type' => 'yes',
            ),
            'where' => array
            (
                'type' => 'yes',
            ),
            'type' => 'update',
        ),
    ),
);