<?php

$status = array
(
    1 => '待签署',
    2 => '有效',
    3 => '作废',
);
$audit = array
(
    //1 => '未提交审核',
    2 => '待审核',
    3 => '审核通过',
    4 => '审核未通过',
);

$audit_manage = array
(
    //1 => '未提交审核',
    //2 => '待审核',
    3 => '审核通过',
    4 => '审核未通过',
);
$col = Dever::input('col');

$aid = Dever::input('search_option_aid');
$button = array();
if ($aid) {
    $option_aid = $aid;
    $search_auth = Dever::input('search_auth');
    if ($search_auth) {
        $option_aid .= '&search_auth=' . $search_auth;
    }
    $button = array
    (
        // '返回上一页' => array('location', 'l=project/database/list&project=option&table=cash&page_type=1&aid=' . $option_aid),
    );
}

$mul = '{audit} == 2';
return array
(
    # 表名
    'name' => 'agreement',
    # 显示给用户看的名称
    'lang' => '期权合同管理',
    'order' => 10,
    'status' => $status,
    'audit' => $audit,
    'start' => array
    (
        'update' => 'option/lib/manage.setAudit',
    ),
    'end' => array
    (
        'update' => 'option/lib/manage.setAgreement',
        'updatemul' => 'option/lib/manage.setAgreement',
    ),
    # 数据结构
    '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',
            'searchs'    => 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_date'      => array
        (
            'type'      => 'int-11',
            'name'      => '交付时间',
            'match'     => 'is_numeric',
            'desc'      => '交付时间',
        ),

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

        'jiaofu_qiquan'      => array
        (
            'type'      => 'decimal-11,2',
            'name'      => '交付的期权价值',
            'default'   => '',
            'desc'      => '交付的期权价值',
            'match'     => 'is_numeric',
        ),

        'jiaofu_yuanshi'      => array
        (
            'type'      => 'decimal-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',
            'search'    => $aid ? 'hidden' : 'fulltext',
        ),

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

        'audit'        => array
        (
            'type'      => 'tinyint-1',
            'name'      => '审核状态',
            'default'   => $col ? '3' : '1',
            'desc'      => '审核',
            'match'     => 'is_numeric',
            'option'    => $col ? $audit_manage : $audit,
            'update'    => 'radio',
            'search'    => 'select',
            'control'   => 'audit',
            'value'     => $col ? '3' : '1',
            'list'      => true,
            'mul'       => true,
            'mul_option' => $audit_manage,
            'list_order' => 7,
            'control'   => 'audit',
        ),

        'audit_desc'        => array
        (
            'type'      => 'varchar-500',
            'name'      => '审核备注',
            'default'   => '',
            'desc'      => '备注',
            'match'     => 'option',
            'update'    => 'textarea',
            'value'     => '',
            'list'      => '"{audit_desc}" ? "{audit_desc}" : "-"',
            'list_order'  => 9,
            'show'      => 'audit=4',
        ),

        'audit_date'     => array
        (
            'type'      => 'int-11',
            'name'      => '审核时间',
            'match'     => 'is_numeric',
            'desc'      => '审核时间',
            'default'   => '',
        ),

        'audit_admin'     => array
        (
            'type'      => 'int-11',
            'name'      => '操作人',
            'default'   => '',
            'match'     => 'is_numeric',
            'desc'      => '操作人',
            'list'      => '"{audit_admin}" > 0 ? Dever::load("manage/admin-find#username", {audit_admin}) : "-"',
            'list_order'  => 6,
        ),

        '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'      => 'Dever::load("option/lib/manage.getDate", {id})',
            'list_order' => 4,
        ),
    ),

    'alter' => array
    (
        5 => array
        (
            array('update', 'jiaofu_total', 'jiaofu_total', 'decimal-11,2 0 交付的总额'),
            array('update', 'jiaofu_qiquan', 'jiaofu_qiquan', 'decimal-11,2 0 交付的期权价值'),
            array('update', 'jiaofu_yuanshi', 'jiaofu_yuanshi', 'decimal-11,2 0 交付的原始期权价值'),
        ),
        'version' => 5,
    ),

    'manage' => array
    (
        'list_table' => 'html',
        'insert' => false,
        'delete' => false,
        'edit' => false,
        'button' => $button,
        'mul' => $mul,
        '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"),
            'edit' => array('审核', 'audit,audit_desc', '{audit} == 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',
                'audit' => array('yes', 'in'),
                'state' => 1,
            ),
            'type' => 'all',
            'order' => array('id' => 'desc'),
            'page' => array(10, 'list'),
            'col' => 'id,aid,agreement_id,status,qdate,name,agreement_name',
        ),
    ),
);