<?php

/*
$status = array
(
    1 => '待签署',
    2 => '有效',
    3 => '作废',
);
*/
$status = array
(
    1 => '有效',
    2 => '有效',
    3 => '作废',
);
$aid = Dever::input('search_option_aid');
$button = array();
if ($aid) {
    $option_aid = $aid;
    $search_type = Dever::input('search_type');
    if ($search_type) {
        $option_aid .= '&search_type=' . $search_type;
    }
    $button = array
    (
        '返回上一页' => array('location', 'l=project/database/list&project=option&table=cash&page_type=1&aid=' . $option_aid),
    );
}
return array
(
    # 表名
    'name' => 'agreement',
    # 显示给用户看的名称
    'lang' => '期权合同管理',
    'order' => 10,
    'status' => $status,
    # 数据结构
    'struct' => array
    (
    
        'id'        => array
        (
            'type'      => 'int-11',
            'name'      => 'ID',
            'default'   => '',
            'desc'      => '',
            'match'     => 'is_numeric',
            'search'    => 'order',
            //'list'        => true,
        ),

        'aid'      => array
        (
            'type'      => 'int-11',
            'name'      => '手机号',
            'default'   => '-1',
            'desc'      => '代理商',
            'match'     => 'is_string',
            'update'    => 'text',
            'search'    => array
            (
                'api' => 'option/account-find',
                'col' => 'mobile',
                'result' => 'id',
            ),
            'list_name' => '期权账户',
            'list'      => 'Dever::load("option/lib/account.getInfo", {aid})',
            'list_order' => 3,
        ),

        'order_num'      => array
        (
            'type'      => 'varchar-100',
            'name'      => '合同编号',
            'default'   => '',
            'desc'      => '合同编号',
            'match'     => 'is_string',
            'update'    => 'text',
        ),

        'agreement_id'      => array
        (
            'type'      => 'int-11',
            'name'      => '合同模板id',
            'default'   => '',
            'desc'      => '合同模板id',
            'match'     => 'is_numeric',
        ),

        'agreement_name'      => array
        (
            'type'      => 'varchar-500',
            'name'      => '合同名称',
            'default'   => '',
            'desc'      => '合同名称',
            'match'     => 'is_string',
            'update'    => 'text',
            'search'    => 'fulltext',
            'list'      => true,
            'list_order' => 6,
        ),

        'jiaofu_id'      => array
        (
            'type'      => 'varchar-100',
            'name'      => '交付的id',
            'default'   => '',
            'desc'      => '交付的id',
            'match'     => 'is_string',
        ),

        'jiaofu_total'      => array
        (
            'type'      => 'float-11,2',
            'name'      => '交付的总额',
            'default'   => '',
            'desc'      => '交付的总额',
            'match'     => 'is_numeric',
        ),

        'sign'     => array
        (
            'type'      => 'varchar-150',
            'name'      => '合同签名',
            'default'   => '',
            'desc'      => '合同签名',
            'match'     => 'option',
            'update'    => 'image',
            'key'       => '7',
            'list'      => '"<img src=\'{sign}\' width=\'150\'>"',
            'list_order' => 7,
        ),

        'name'      => array
        (
            'type'      => 'varchar-100',
            'name'      => '姓名',
            'default'   => '',
            'desc'      => '姓名',
            'match'     => 'is_string',
            'update'    => 'text',
        ),

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

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

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

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

        'qdate'     => array
        (
            'type'      => 'int-11',
            'name'      => '协议签订时间',
            'match'     => 'is_numeric',
            'desc'      => '协议签订时间',
            'update'    => 'text',
        ),

        'sdate'     => array
        (
            'type'      => 'int-11',
            'name'      => '有效期开始时间',
            'match'     => 'is_numeric',
            'desc'      => '有效期开始时间',
            'update'    => 'text',
        ),

        'edate'     => array
        (
            'type'      => 'int-11',
            'name'      => '有效期结束时间',
            'match'     => 'is_numeric',
            'desc'      => '有效期结束时间',
            'update'    => 'text',
        ),

        'udate'     => array
        (
            'type'      => 'int-11',
            'name'      => '更新时间',
            'match'     => 'is_numeric',
            'desc'      => '更新时间',
            'search'    => 'date',
            'list'      => 'date("Y-m-d H:i", {udate})',
            'list_order' => 5,
        ),

        'content'       => array
        (
            'type'      => 'text-255',
            'name'      => '合同内容',
            'default'   => '',
            'desc'      => '请输入内容',
            'match'     => 'is_string',
        ),

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

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

    'manage' => array
    (
        'insert' => false,
        'delete' => false,
        'edit' => false,
        'button' => $button,
        'list_button' => array
        (
            'new' => array('查看', '"lib/agreement.location?id={id}"', 'option'),
            'oper' => array('作废并生成', '"option/lib/manage.dropAgreement?id={id}"', "{status} == 2"),
            'oper1' => array('更新', '"option/lib/manage.upAgreement?id={id}"', "{status} == 2"),
        ),
    ),

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

        'getOld' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'aid' => 'yes',
                'agreement_id' => 'yes',
                'state' => 1,
            ),
            'type' => 'one',
            'order' => array('id' => 'desc'),
            'col' => '*',
        ),

        'getOne' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'aid' => 'yes',
                'type' => 'yes',
                'state' => 1,
            ),
            'type' => 'one',
            'order' => array('id' => 'desc'),
            'col' => '*',
        ),

        'getAll' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'aid' => 'yes',
                'state' => 1,
            ),
            'type' => 'all',
            'order' => array('id' => 'desc'),
            'page' => array(10, 'list'),
            'col' => 'id,aid,agreement_id,status,qdate,name,agreement_name',
        ),
    ),
);