<?php

$status = array
(
    1 => array('name' => '待签署', 'style' => 'font-weight:bold;color:#436EEE'),
    2 => array('name' => '有效', 'style' => 'font-weight:bold;color:green'),
    3 => array('name' => '作废', 'style' => 'font-weight:bold;color:#CD3700'),
);
$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),
    );
}
$list_button = array();
$list_button['new'] = array('查看', '"lib/agreement.location?id={id}"', 'agent');
 if (Dever::load('manage/auth')->checkFunc('agent.member_agreement', 'edit', '作废并生成')) {
    $list_button['oper'] = array('作废并生成', '"agent/lib/manage.dropAgreement?id={id}"', "{status} == 2");
    }
if (Dever::load('manage/auth')->checkFunc('agent.member_agreement', 'edit1', '更新')) {
     $list_button['oper1'] = array('更新', '"agent/lib/manage.upAgreement?id={id}"', "{status} <= 2");
}

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

return array
(
    # 表名
    'name' => 'member_agreement',
    # 显示给用户看的名称
    'lang' => '合同管理',
    'order' => 10,
    'status' => $status,
    # 数据结构
    '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'    => array
            (
                'api' => 'agent/member-getSearch',
                'col' => 'col',
                'result' => 'id',
                'search' => 'mid',
            ),
            'list_name' => '代理商信息',
            'list'      => 'Dever::load("agent/lib/member.getOne", {mid}, "agent/member", true)',
            'list_order' => 3,
        ),

        'agent-member-name'=> array
        (
            'name'      => '姓名',
            'default'   => '',
            'desc'      => '姓名',
            'match'     => 'option',
            # 读取另外表的关联方式
            'sync'      => array('mid', 'id'),
            //'list'      => $mid ? false : true,
            //'list_order' => 1,
        ),

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

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

        'order_id'      => array
        (
            'type'      => 'int-11',
            'name'      => '关联订单表id',
            'default'   => '',
            'desc'      => '关联订单表id',
            'match'     => 'is_numeric',
        ),

        'agreement_id'      => array
        (
            'type'      => 'int-11',
            'name'      => '合同模板',
            'default'   => '',
            'desc'      => '合同模板',
            'match'     => 'is_numeric',
            'option'    => $agreement,
            'search'    => 'select',
        ),

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

        'type'        => array
        (
            'type'      => 'tinyint-1',
            'name'      => '类型',
            'default'   => '1',
            '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'    => $mid ? 'hidden' : 'fulltext',
            //'list'      => $mid ? false : true,
            //'list_order' => 2,
        ),

        'role'      => array
        (
            'type'      => 'int-11',
            'name'      => '代理角色',
            'default'   => '',
            'desc'      => '代理角色',
            'match'     => 'is_numeric',
        ),

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

        'area'       => array
        (
            'type'      => 'varchar-500',
            'name'      => '区域',
            'default'   => '',
            'desc'      => '区域',
            'match'     => 'option',
        ),

        'idcard'      => array
        (
            'type'      => 'varchar-32',
            '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',
        ),

        'qdate'     => array
        (
            'type'      => 'int-11',
            'name'      => '协议签订时间',
            'match'     => 'is_numeric',
            'desc'      => '协议签订时间',
            'search'    => 'date',
            '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_name' => '创建时间<br/>更新时间<br/>签署时间',
            'list'      => 'Dever::load("agent/lib/agreement.data",{id})',
            '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,
        ),
    ),

    'alter' => array
    (
        5 => array
        (
            array('update', 'price', 'price', 'decimal-11,2 0 实付金额'),
        ),
        'version' => 5,
    ),

    'manage' => array
    (
        'list_table' => 'html',
        'insert' => false,
        //'delete' => false,
        'edit' => false,
        'button' => $button,
        'list_button' => $list_button,
        
    ),

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

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

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

        'getAll' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'mid' => 'yes',
                'status' => array('yes', 'in'),
                'state' => 1,
            ),
            'type' => 'all',
            'order' => array('id' => 'desc'),
            'page' => array(10, 'list'),
            'col' => 'id,mid,agreement_id,status,qdate,role,name,area,agreement_name',
        ),
        'getNum' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'fstart' => array('yes-qdate', '>='),
                'fend' => array('yes-qdate', '<='),
                'agreement_id' => 6,
                'status' => array('yes','='),
                'state' => 1,
            ),
            'type' => 'count',
            'col' => '*',
        ),
        'getNoNum' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'fstart' => array('yes-cdate', '>='),
                'fend' => array('yes-cdate', '<='),
                'status' => 'yes',
                'agreement_id' => 6,
                'state' => 1,
            ),
            'type' => 'count',
            'col' => '*',
        ),
        'getPrice' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'fstart' => array('yes-qdate', '>='),
                'fend' => array('yes-qdate', '<='),
                'status' => array('yes', '='),
                'agreement_id' => 6,
                'state' => 1,
            ),
            'type' => 'one',
            'col' => 'sum(price) as total',
        ),
        'getNoPrice' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'fstart' => array('yes-qdate', '>='),
                'fend' => array('yes-qdate', '<='),
                'status' => 'yes',
                'agreement_id' => 6,
                'state' => 1,
            ),
            'type' => 'one',
            'col' => 'sum(price) as total',
        ),
    ),
);