<?php

$status = array
(
    1 => '未激活',
    2 => '正常',
    3 => '停用',
);

$audit_manage = array
(
    //1 => '未开始审核',
    //2 => '待审核',
    3 => '审核通过',
    4 => '审核未通过',
);

$audit_search = array
(
    //1 => '未开始审核',
    2 => '待审核',
    3 => '审核通过',
    4 => '审核未通过',
);

$audit = array
(
    1 => '未开始审核',
    2 => '待审核',
    3 => '审核通过',
    4 => '审核未通过',
);

$is_email = array
(
    1 => '邮箱已验证',
    2 => '邮箱未验证',
);

$send_email = array
(
    1 => '不发送邮件',
    2 => '发送邮件',
);

$is_idcard = array
(
    1 => '已上传',
    2 => '未上传',
);

$agreement_status = array
(
    0 => '合同审核状态',
    'no' => '未签署',
    2 => '待审核',
    3 => '审核通过',
    4 => '审核未通过',
);

$col = Dever::input('col');

# 权限设置 1是审核列表、2是账户列表、3是展示列表
$search_auth = Dever::input('search_option_dever_auth', 1);

$button = $list_button = array();

if ($search_auth <= 2) {
    $list_button = array
    (
        'list' => array('查看详情', '"cash&mid={mid}&page_type=1&search_auth='.$search_auth.'"'),
    );
}

if ($search_auth == 1) {
    $list_button['edit'] = array('审核', 'audit,audit_desc', '{audit} == 2');
} elseif ($search_auth == 2) {
    $button = array
    (
        '创建账户' => array('fast', '', 'member'),
    );
    $list_button['list1'] = array('账户列表', '"member&search_option_aid={id}&search_option_dever_auth='.$search_auth.'"');
   
} elseif ($search_auth == 3) {
    $list_button['list1'] = array('账户列表', '"member&search_option_aid={id}&search_option_dever_auth='.$search_auth.'"');
}

// if (Dever::load('manage/auth')->checkFunc('menu_279.menu_290','setmessage','发送短信')) {
//         $list_button['fast'] = array('发送短信','Dever::load("option/lib/account.send_sms",{mid})');
// }

return array
(
    # 表名
    'name' => 'account',
    # 显示给用户看的名称
    'lang' => '期权登录账户',
    'order' => 100,
    'set' => array
    (
        'status' => $status,
        'audit' => $audit,
        'is_email' => $is_email,
        'is_idcard' => $is_idcard,
    ),
    'end' => array
    (
        'update' => 'option/lib/manage.updateAccount',
    ),
    'check' => 'mid',
    # 数据结构
    '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'   => '',
            'desc'      => '期权账户',
            'match'     => 'is_numeric',
            'update'    => 'text',
            'search'    => array
            (
                'api' => 'option/member-getOne',
                'col' => 'name',
                'result' => 'id',
                'search' => 'mid',//本表的字段，默认为当前的字段
            ),
            'list_name' => '期权账户',
            'list'      => 'Dever::load("option/lib/member.getInfo", {mid})',
            'list_order' => 1,
        ),

        'option-member-mobile'=> array
        (
            'name'      => '手机号',
            'default'   => '',
            'desc'      => '手机号',
            'match'     => 'option',
            'search'    => array
            (
                'api' => 'option/member-getOne',
                'col' => 'mobile',
                'result' => 'id',
                'search' => 'mid',
            ),
            # 读取另外表的关联方式
            'sync'      => array('mid', 'id'),
        ),

        'option-member-key'=> array
        (
            'name'      => '索引号',
            'default'   => '',
            'desc'      => '索引号',
            'match'     => 'option',
            'search'    => array
            (
                'api' => 'option/member-getOne',
                'col' => 'key',
                'result' => 'id',
                'search' => 'mid',
            ),
            # 读取另外表的关联方式
            'sync'      => array('mid', 'id'),
        ),

        'is_email'        => array
        (
            'type'      => 'tinyint-1',
            'name'      => '邮箱认证',
            'default'   => '2',
            'desc'      => '邮箱是否验证',
            'match'     => 'is_numeric',
            'search'    => 'select',
            'option'    => $is_email,
            'list'      => 'Dever::load("option/lib/account.getEmail", {id})',
            'list_order' => 3,
        ),

        'send_email'        => array
        (
            'type'      => 'tinyint-1',
            'name'      => '是否发送邮件',
            'default'   => '2',
            'desc'      => '是否发送邮件',
            'match'     => 'is_numeric',
            'update'    => 'radio',
            'option'    => $send_email,
        ),

        'email'     => array
        (
            'type'      => 'varchar-150',
            'name'      => '邮箱',
            'default'   => '',
            'desc'      => '请输入邮箱',
            'search'    => 'fulltext',
            'match'     => 'option||' . Dever::rule('email'),
            'update'    => 'text',
        ),

        'is_idcard'        => array
        (
            'type'      => 'tinyint-1',
            'name'      => '身份证资料',
            'default'   => '2',
            'desc'      => '身份证资料',
            'match'     => 'is_numeric',
            'option'    => $is_idcard,
            'search'    => 'select',
            //'order'     => 'asc',
            //'update'    => 'radio',
            'list'      => $search_auth == 1 ? 'Dever::load("option/lib/account.getIdcard", {id})' : false,
            'list_order' => 3,
            'list_header'  => array('width' => '30%'),
        ),

        'option-member-idcard'=> array
        (
            'name'      => '身份证号码',
            'default'   => '',
            'desc'      => '身份证号码',
            'match'     => 'option',
            'search'    => array
            (
                'api' => 'option/member-getOne',
                'col' => 'idcard',
                'result' => 'id',
                'search' => 'mid',
            ),
            # 读取另外表的关联方式
            'sync'      => array('mid', 'id'),
            'list'      => $search_auth == 2 ? 'Dever::load("option/lib/account.getCash#daijiaofu", {id})' : false,
            'list_name' => '待交付',
            'list_order' => 4,
        ),

        'idcard_front'     => array
        (
            'type'      => 'varchar-150',
            'name'      => '身份证正面',
            'default'   => '',
            'desc'      => '身份证正面',
            'match'     => 'option',
            'update'    => $col ? 'image' : false,
            'key'       => '8',
            //'place'     => '660*660',
            'list'      => $search_auth == 2 ? 'Dever::load("option/lib/account.getCash#qiquan", {id})' : false,
            'list_name' => '期权',
            'list_order' => 5,
        ),

        'idcard_back'     => array
        (
            'type'      => 'varchar-150',
            'name'      => '身份证背面',
            'default'   => '',
            'desc'      => '身份证背面',
            'match'     => 'option',
            'update'    => $col ? 'image' : false,
            'key'       => '8',
            //'place'     => '660*660',
            'list'      => $search_auth == 2 ? 'Dever::load("option/lib/account.getCash#yuanshiqiquan", {id})' : false,
            'list_name' => '原始期权',
            'list_order' => 6,
        ),

        'idcard_path'      => array
        (
            'type'      => 'varchar-800',
            'name'      => '身份证信息',
            'default'   => '',
            'desc'      => '身份证信息',
            'match'     => 'is_string',
            'update'    => 'text',
        ),

        'audit'        => array
        (
            'type'      => 'tinyint-1',
            'name'      => $search_auth == 1 ? '审核状况' : '账户认证',
            'default'   => $col ? '3' : '1',
            'desc'      => '审核状况',
            'match'     => 'is_numeric',
            'option'    => $col ? $audit_manage : $audit_search,
            'search'    => 'select',
            'update'    => $col ? 'radio' : false,
            'list'      => 'Dever::load("option/lib/account.getAudit", {id})',
            'list_order' => $search_auth == 1 ? 5 : 3,
            'value'     => $col ? '3' : '1',
            'control'   => 'audit',
        ),

        'audit_desc'        => array
        (
            'type'      => 'varchar-500',
            'name'      => '审核备注',
            'default'   => '',
            'desc'      => '审核备注',
            'match'     => 'option',
            'update'    => $col ? 'textarea' : false,
            'show'      => 'audit=4',
        ),

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

        'up_date'     => array
        (
            'type'      => 'int-11',
            'name'      => '上传时间',
            'default'   => '',
            'match'     => 'is_numeric',
            'order'     => 'desc',
            'desc'      => '上传时间',
            'search'    => 'date,order',
            'list'      => '("{up_date}" ? date("Y-m-d H:i", {up_date}) : "-") . "<br />" . (date("Y-m-d H:i", {cdate}))',
            'list_order' => 2,
        ),

        'option-agreement-status'=> array
        (
            'name'      => '名称',
            'default'   => '',
            'desc'      => '手机号',
            'match'     => 'option',
            'search'    => $search_auth == 3 ? array
            (
                'api' => 'option/agreement-select',
                'col' => 'audit',
                'result' => 'aid',
                'search' => 'id',
                'option' => $agreement_status,
                'no' => '(select aid from churen_option_agreement)',
            ) : 'hidden',
            # 读取另外表的关联方式
            'sync'      => array('id', 'aid'),
            'list_name' => '合同审核状态',
            'list'      => $search_auth == 3 ? 'Dever::load("option/lib/account.getAgreementStatus", {id})' : false,
            'list_order' => 10,
        ),

        'status'        => array
        (
            'type'      => 'tinyint-1',
            'name'      => '状态',
            'default'   => '1',
            'desc'      => '状态',
            'match'     => 'is_numeric',
            'option'    => $status,
            'search'    => 'select',
            'list'      => $search_auth == 1 ? false : true,
            'list_order' => 100,
        ),

        'stype'      => array
        (
            'type'      => 'int-11',
            'name'      => '类型-仅用于展示类型',
            'default'   => '-1',
            'desc'      => '类型',
            'match'     => 'is_string',
            'update'    => 'text',
            'search'    => 'hidden',
        ),

        'dever_auth'      => array
        (
            'name'      => '权限',
            'default'   => '',
            'desc'      => '类型',
            'match'     => 'is_string',
            'search'    => 'hidden',
        ),

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

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

    'request' => array
    (
        'list' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'id' => array('yes', 'in'),
                'mid' => 'yes',
                'is_email' => 'yes',
                'is_idcard' => 'yes',
                'email' => array('yes', 'like'),
                'audit' => array('yes', 'in'),
                'start_cdate' => array('yes-cdate', '>='),
                'end_cdate' => array('yes-cdate', '<='),
                //'no' => 'yes-NOT EXISTS (select * from churen_option_agreement as a where a.aid = churen_option_account.id)',
                /*
                'not' => array
                (
                    'table' => 'option/agreement',
                    'on' => array('aid','id'),
                ),
                */
                'no' => array('yes-id', 'not in'),
                'status' => 'yes',
                'state' => 1,
            ),

            'type' => 'all',
            'order' => array('id' => 'desc'),
            'page' => array(20, 'list'),
            'col' => '*',
        ),

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

        'getData' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'idcard' => 'yes',
                'id' => array('yes', '!='),
                'status' => 2,
                'state' => 1,
            ),
            'order' => array('id' => 'desc'),
            'type' => 'all',
            'page' => array(20, 'list'),
            'col' => '*',
        ),

        'upCash' => array
        (
            'type' => 'update',
            'where' => array
            (
                'id' => 'yes',
            ),
            'set' => array
            (
                'cash' => array('yes', '+='),
            ),
        ),

        'upSell' => array
        (
            'type' => 'update',
            'where' => array
            (
                'id' => 'yes',
            ),
            'set' => array
            (
                'cash' => array('yes', '+='),
                'upcol' => array('yes-sell', '+='),
                'level_id' => 'yes',
            ),
        ),

        'upGroupSell' => array
        (
            'type' => 'update',
            'where' => array
            (
                'id' => 'yes',
            ),
            'set' => array
            (
                'cash' => array('yes', '+='),
                'upcol' => array('yes-group_sell', '+='),
                'level_id' => 'yes',
            ),
        ),

        'upGroupSellOne' => array
        (
            'type' => 'update',
            'where' => array
            (
                'id' => 'yes',
            ),
            'set' => array
            (
                'group_sell' => array('yes', '+='),
            ),
        ),

        # 获取订单数量
        'getNum' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'start' => array('yes-cdate', '>='),
                'end' => array('yes-cdate', '<='),
                'status' => 'yes',
                'role' => 'yes',
                'state' => 1,
            ),
            'type' => 'count',
            'col' => '*',
        ),
        #获取所有数据
        'getCount' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'status' => 'yes',
                'state' => 1,
                'audit' => 'yes',
            ),
            // 'order' => array('id' => 'desc'),
            'type' => 'count',
            'col' => '*',
        ),
    ),
);
