<?php
$status = array
(
    1 => '待核销',
    2 => '已核销',
    3 => '已作废',
);
$type = array
(
    1 => '分享领取',
    2 => '手动添加',
);
$act_status = array
(
    1 => '未开始',
    2 => '报名中',
    3 => '报名结束',
    4 => '活动开始',
    5 => '活动结束',
);
$active = function()
{
    $array = array();
    $data = Dever::db('active/info')->state();
    if($data)
    {
        $array += $data;
    }
    return $array;
};
$excel = false;
if (Dever::load('manage/auth')->checkFunc('active.code', 'editExcelCode', '数据导出')) {
    $excel[] = array('数据导出','数据导出','active/lib/excel.out_active_code');
}
$button = array();
$button['导入订单'] = array('fast', '', 'import&project=upload&call=active/lib/excel.import');
$list_button = array();
$list_button['fast'] = array('添加座位号', '"code&where_id={id}&col=seat_num&oper_save_jump=code&oper_table=code&oper_parent=code"');
if (Dever::load('manage/auth')->checkFunc('active.code', 'edithexiaocode', '核销')) {
    $list_button['oper1'] = array('核销', '"active/lib/manage.upCode?id={id}"', "{status} == 1");
}
            
return array
(
    # 表名
    'name' => 'code',
    # 显示给用户看的名称
    'lang' => '活动核销码',
    # 后台菜单排序
    'order' => 2,
    // 'menu' => false,
    # 数据结构
    'struct' => array
    (
        'id'        => array
        (
            'type'      => 'int-11',
            'name'      => 'ID',
            'default'   => '',
            'desc'      => '',
            'match'     => 'is_numeric',
            'search'    => 'order',
            'list'      => true,
            'order'     => 'desc',
        ),

        'active_id'      => array
        (
            'type'      => 'int-11',
            'name'      => '活动名称',
            'default'   => '-1',
            'desc'      => '活动名称',
            'match'     => 'is_string',
            'update'    => 'hidden',
            'value'     => Dever::input('search_option_active_id'),
            'option'    => $active,
            'search'    => 'select',
            //  'search'    => array
            // (
            //     'api' => 'active/info-getSearch',
            //     'col' => 'col',
            //     'result' => 'id',
            //     'search' => 'active_id',
            // ),
            'list'      => "Dever::load('active/lib/manage.active#active_name',{active_id})",
        ),

        'order_id'      => array
        (
            'type'      => 'int-11',
            'name'      => '订单名称',
            'default'   => '-1',
            'desc'      => '订单名称',
            'match'     => 'is_string',
            'update'    => 'hidden',
            // 'search'    => 'text',
            // 'list'      => true,
        ),

        'join_uid'      => array
        (
            'type'      => 'int-11',
            'name'      => '参加人名称/手机号',
            'default'   => '-1',
            'desc'      => '用户名称',
            'match'     => 'is_string',
            // 'option'    => $user,
            // 'update'    => 'text',
            'search'    => array
            (
                'api' => 'active/user-getSearch',
                'col' => 'col',
                'result' => 'id',
                'search' => 'join_uid',
            ),
            'list_name' => '参加人信息',
            'list'      => "Dever::load('active/lib/manage.user',{join_uid})",
        ),

        'buy_uid'      => array
        (
            'type'      => 'int-11',
            'name'      => '购买人姓名/手机号',
            'default'   => '-1',
            'desc'      => '用户名称',
            'match'     => 'is_string',
            // 'option'    => $user,
            // 'update'    => 'text',
            'search'    => array
            (
                'api' => 'active/user-getSearch',
                'col' => 'col',
                'result' => 'id',
                'search' => 'buy_uid',
            ),
            'list_name' => '购买人信息',
            'list'      => "Dever::load('active/lib/manage.user',{buy_uid})",
        ),

        'write_code'      => array
        (
            'type'      => 'varchar-200',
            'name'      => '核销码',
            'default'   => '',
            'desc'      => '核销码',
            'match'     => 'is_string',
            // 'update'    => 'text',
            'search'    => 'fulltext',
            'list'      => true,
        ),

        'seat_num'      => array
        (
            'type'      => 'varchar-200',
            'name'      => '座位号',
            'default'   => '',
            'desc'      => '座位号',
            'match'     => 'option',
            'update'    => 'text',
            'search'    => 'fulltext',
            'list'      => true,
        ),

        'act_status'        => array
        (
            'type'      => 'tinyint-1',
            'name'      => '活动状态',
            'default'   => '1',
            'desc'      => '活动状态',
            'match'     => 'is_numeric',
            // 'update'    => 'radio',
            'option'    => $act_status,
            // 'search'    => 'select',
            // 'list'      => true,
        ),

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

        'type'        => array
        (
            'type'      => 'tinyint-1',
            'name'      => '核销码来自哪的状态',
            'default'   => '1',
            'desc'      => '核销码来自哪的状态',
            'match'     => 'is_numeric',
            'option'    => $type,
            // 'search'    => 'select',
            // 'list'      => true,
        ),

        'pic'       => array
        (
            'type'      => 'text-255',
            'name'      => '二维码',
            'default'   => '',
            'desc'      => '二维码',
            'match'     => 'option',
            // 'update'    => 'image',
            'key'       => '1',
            // 'place'     => '759*562',
        ),

        'offdate'     => array
        (
            'type'      => 'int-11',
            'name'      => '核销时间',
            'default'   => '',
            'match'     => 'is_numeric',
            // 'search'    => 'date',
            // 'desc'      => '',
            // 'list'      => 'date("Y-m-d H:i:s", {zdate})',
        ),

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

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

        'content'       => array
        (
            'type'      => 'text-255',
            'name'      => '填写手机号-多个换行隔开，如手机号重复将不会录入到库中',
            'default'   => '',
            'desc'      => '填写手机号',
            'match'     => 'is_string',
            'update'    => 'textarea',
            'value'     => '',
            // 'show'      => 'type=2',
        ),

        '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'    => 'day',
            'list'      => 'date("Y-m-d H:i:s", {cdate})',
            'list_order' => 5,
        ),
    ),

    'manage' => array
    (
    	'insert' => false,
        'delete' => false,
        'edit' => false,
        'excel' => $excel,
        'button' => $button,
        'list_button' => $list_button,
        // array
        // (
        //     'fast' => array('添加座位号', '"code&where_id={id}&col=seat_num&oper_save_jump=code&oper_table=code&oper_parent=code"'),
        //     'oper1' => array('手动核销', '"active/lib/manage.upCode?id={id}"', "{status} == 1"),
        // ),
    ),

    'request' => array
    (
        'getAll' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'join_uid' => 'yes',
                'state' => 1,
            ),
            'type' => 'all',
            'order' => array('cdate' => 'desc'),
            'col' => '*',
        ),
        'getOne' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'join_uid' => 'yes',
                'active_id' =>'yes',
                'status' => array('yes','in'),
                'state' => 1,
            ),
            'type' => 'one',
            // 'order' => array('cdate' => 'desc'),
            'col' => '*',
        ),
        'getCode' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'order_id' => 'yes',
                'status' => array('yes','in'),
                'state' => 1,
            ),
            'type' => 'all',
            'order' => array('cdate' => 'desc'),
            'col' => '*',
        ),
        'getNum' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'active_id' => 'yes',
                'buy_uid' => 'yes',
                'status' => array('yes','in'),
                'state' => 1,
            ),
            'type' => 'count',
            // 'order' => array('cdate' => 'desc'),
            'col' => '*',
        ),
        'getExcel' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'order_id' => 'yes',
                'status' => 'yes',
                'state' => 1,
            ),
            'type' => 'count',
            // 'order' => array('cdate' => 'desc'),
            'col' => '*',
        ),
    ),
);
