<?php

$time = time();
$status = array
(
    1 => '已发布',
    2 => '未发布',
);


$top = array
(
    1 => '不推荐',
    2 => '首页推荐',
);

$type = array
(
    1 => '资讯',
    2 => '专题',
    3 => '视频',
    4 => '活动',
);

$type_value = Dever::input('search_option_type', 1);

if ($type_value == 2) {
    # 专题
    $small_pic_name = '首页专题封面图';
    $small_pic_size = '700*460';
    $small_pic_update = 'image';
    $small_pic_match = 'is_string';
} elseif ($type_value == 4) {
    # 活动
    $small_pic_name = '活动封面小图';
    $small_pic_size = '288*384';
    $small_pic_update = 'image';
    $small_pic_match = 'is_string';
} else {
    $small_pic_name = '活动封面小图';
    $small_pic_size = '288*384';
    $small_pic_update = 'hidden';
    $small_pic_match = 'option';
}

$name = $type[$type_value];

return array
(
    # 表名
    'name' => 'news',
    # 显示给用户看的名称
    'lang' => $name . '管理',
    'order' => 98,

    'end' => array
    (
        //'insert' => 'tag/api.update',
        //'update' => 'tag/api.update',
    ),

    # 数据结构
    'struct' => array
    (
        'id'        => array
        (
            'type'      => 'int-11',
            'name'      => 'ID',
            'default'   => '',
            'desc'      => '',
            'match'     => 'is_numeric',
            'list'      => true,
        ),

        'type'        => array
        (
            'type'      => 'int-11',
            'name'      => '类型',
            'default'   => '1',
            'desc'      => '类型',
            'match'     => 'is_numeric',
            'update'    => 'hidden',
            'value'    => $type_value,
            'search'    => 'hidden',
        ),
        
        'name'      => array
        (
            'type'      => 'varchar-80',
            'name'      => '主标题-最大长度50个字符',
            'default'   => '',
            'desc'      => '主标题',
            'match'     => 'is_string',
            'update'    => 'text',
            'list'      => true,
            'search'    => 'fulltext',
        ),

        'desc'      => array
        (
            'type'      => 'varchar-50',
            'name'      => '副标题-最大长度50个字符',
            'default'   => '',
            'desc'      => '副标题',
            'match'     => 'option',
            'update'    => 'text',
            'list'      => true,
            'search'    => 'fulltext',
        ),

        'info'      => array
        (
            'type'      => 'varchar-500',
            'name'      => '简介-最大长度100个字符',
            'default'   => '',
            'desc'      => '简介',
            'match'     => 'is_string',
            'update'    => 'textarea',
        ),

        'author'      => array
        (
            'type'      => 'varchar-50',
            'name'      => '作者-最大长度20个字符',
            'default'   => '',
            'desc'      => '作者',
            'match'     => 'is_string',
            'update'    => 'text',
            'list'      => true,
            'search'    => 'fulltext',
        ),

        'pic'       => array
        (
            'type'      => 'varchar-150',
            'name'      => '封面图-图片尺寸'.($type_value == 3 ? '1200*670' : '1200*530').'px或等比尺寸,上传大小不能超过2M,支持JPG、PNG、GIF格式,建议上传JPG格式',
            'default'   => '',
            'desc'      => '封面图',
            'match'     => 'is_string',
            'update'    => 'image',
            'key'       => '1',
            'place'     => $type_value == 3 ? '1200*670' : '1200*530',
        ),

        'small_pic'       => array
        (
            'type'      => 'varchar-150',
            'name'      => $small_pic_name . '-图片尺寸'.$small_pic_size.'px或等比尺寸,上传大小不能超过2M,支持JPG、PNG、GIF格式,建议上传JPG格式',
            'default'   => '',
            'desc'      => '封面图',
            'match'     => $small_pic_match,
            'update'    => $small_pic_update,
            'key'       => '1',
            'place'     => $small_pic_size,
        ),

        'video'     => array
        (
            'type'      => 'varchar-800',
            'name'      => '上传视频-视频格式为MP4,上传大小不能超过4M。如需添加腾讯视频,请将腾讯视频分享链接添加至【上传视频】按钮下方地址输入框中',
            'default'   => '',
            'desc'      => '上传推荐视频',
            'match'     => $type_value == 3 ? 'is_string' : 'option',
            'update'    => $type_value == 3 ? 'upload' : 'hidden',
            'key'       => '3',
            'place'     => '150',
            'upload'    => 'yun',
            'large'     => true,
        ),

        'tag_name'       => array
        (
            'type'      => 'varchar-100',
            'name'      => '标签标题',
            'default'   => '',
            'desc'      => '标签标题',
            'match'     => 'option',
            'update'    => 'text',
        ),

        'tag'       => array
        (
            'type'      => 'varchar-1000',
            'name'      => '标签-多个用半角逗号,隔开',
            'default'   => '',
            'desc'      => '标签',
            'match'     => 'option',
            'update'    => 'text',
            //如果要输入带有自动提示的,就打开这个,update=>'text'即可
            //'autocomplete' => array('tag/manage.getByName', 'id', 'tag/info-one#name'),
            //'list'        => true,
            //显示
            //'show'  => 'cate=tag/manage.getByCate?cate=',
        ),

        'share_title'       => array
        (
            'type'      => 'varchar-100',
            'name'      => '分享标题',
            'default'   => '',
            'desc'      => '分享标题',
            'match'     => 'option',
            //'update'    => 'text',
        ),

        'share_pic'     => array
        (
            'type'      => 'varchar-150',
            'name'      => '分享图片-图片尺寸200*200px或等比尺寸,上传大小不能超过2M,支持JPG、PNG、GIF格式,建议上传JPG格式',
            'default'   => '',
            'desc'      => '分享图片',
            'match'     => 'option',
            //'update'    => 'image',
            'key'       => '1',
            'place'     => '200*200',
            //'upload'  => 'qiniu',
            //'large'   => true,
        ),

        'share_content'     => array
        (
            'type'      => 'varchar-200',
            'name'      => '分享内容',
            'default'   => '',
            'desc'      => '分享内容',
            'match'     => 'option',
            //'update'    => 'textarea',
        ),

        'content'       => array
        (
            'type'      => 'text-255',
            'name'      => '内容',
            'default'   => '',
            'desc'      => '请输入内容',
            'match'     => 'is_string',
            'update'    => 'editor',
            'key'       => '1',
        ),

        'content_video'     => array
        (
            'type'      => 'varchar-800',
            'name'      => '上传内容视频-视频格式为MP4,上传大小不能超过4M。如需添加腾讯视频,请将腾讯视频分享链接添加至【上传视频】按钮下方地址输入框中',
            'default'   => '',
            'desc'      => '上传推荐视频',
            'match'     => $type_value != 3 ? 'option' : 'option',
            'update'    => $type_value != 3 ? 'upload' : 'hidden',
            'key'       => '3',
            'place'     => '150',
            'upload'    => 'yun',
            'large'     => true,
        ),

        'content_video_pic'       => array
        (
            'type'      => 'varchar-150',
            'name'      => '内容视频封面图-图片尺寸1200*670px或等比尺寸,上传大小不能超过2M,支持JPG、PNG、GIF格式,建议上传JPG格式',
            'default'   => '',
            'desc'      => '封面图',
            'match'     => $type_value != 3 ? 'option' : 'option',
            'update'    => $type_value != 3 ? 'image' : 'hidden',
            'key'       => '1',
            'place'     => '1200*670',
        ),

        'beizhu'      => array
        (
            'type'      => 'varchar-500',
            'name'      => '备注',
            'default'   => '',
            'desc'      => '备注',
            'match'     => 'option',
            'update'    => 'textarea',
        ),

        'pdate'     => array
        (
            'type'      => 'int-11',
            'name'      => '发布时间-选择未来时间将不会显示',
            'match'     => 'option',
            'default'   => '',
            'desc'      => '',
            'update'    => 'date',
            'callback'  => 'maketime',
            //'list'        => 'date("Y-m-d H:i:s", {pdate})',
        ),

        'reorder'       => array
        (
            'type'      => 'int-11',
            'name'      => '排序(数值越大越靠前)',
            'default'   => '1',
            'desc'      => '请输入排序',
            'match'     => 'option',
            //'update'  => 'text',
            'search'    => 'order',
            'list'      => true,
            'order'     => 'desc',
            'edit'      => true,
        ),

        'top'        => array
        (
            'type'      => 'int-11',
            'name'      => '是否推荐到首页',
            'default'   => '1',
            'desc'      => '是否推荐到首页',
            'match'     => 'is_numeric',
            'update'  => 'select',
            'option'    => $top,
            'search'    => 'select',
            'list'      => true,
            'edit'      => true,
        ),

        'status'        => array
        (
            'type'      => 'int-11',
            'name'      => '发布状态',
            'default'   => '1',
            'desc'      => '发布状态',
            'match'     => 'is_numeric',
            'update'  => 'select',
            'option'    => $status,
            'search'    => 'select',
            'list'      => true,
            'edit'      => true,
        ),

        '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'    => 'time',
        ),
    ),
    
    # 管理功能
    'manage' => array
    (

    ),

    # request 请求接口定义
    'request' => array
    (
        'search' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'ids' => array('yes-id', 'in'),
                'name' => array('yes', 'like'),
                'id' => 'yes',
                'type' => 'yes',
                'status' => 1,
                'state' => 1,
            ),
            'type' => 'all',
            'order' => array('reorder' => 'desc', 'cdate' => 'desc'),
            'limit' => '0,1000',
            'col' => 'name as name, id, id as value, "" as selected, "" as disabled|id',
        ),

        'getHome' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'ids' => array('yes-id', 'in'),
                'name' => array('yes', 'like'),
                'pdate' => array($time, '<='),
                'id' => 'yes',
                'type' => 'yes',
                'status' => 1,
                'state' => 1,
            ),
            'type' => 'all',
            'order' => array('top' => 'desc', 'reorder' => 'desc', 'cdate' => 'desc'),
            'limit' => '0,10',
            'col' => '*',
        ),

        'getOne' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'ids' => array('yes-id', 'in'),
                'name' => array('yes', 'like'),
                'pdate' => array($time, '<='),
                'id' => 'yes',
                'type' => 'yes',
                'status' => 1,
                'state' => 1,
            ),
            'type' => 'one',
            'col' => '*',
        ),

        'getAll' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'type' => 'yes',
                'name' => array('yes', 'like', 'and('),
                'tag' => array('yes', 'like', 'or)'),
                'pdate' => array($time, '<='),
                'status' => 1,
                'state' => 1,
            ),
            'type' => 'all',
            'order' => array('reorder' => 'desc', 'id' => 'desc'),
            'page' => array(5, 'list'),
            'col' => '*',
        ),

        'getAllVideo' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'type' => 'yes',
                'name' => array('yes', 'like', 'and('),
                'tag' => array('yes', 'like', 'or)'),
                'pdate' => array($time, '<='),
                'status' => 1,
                'state' => 1,
            ),
            'type' => 'all',
            'order' => array('reorder' => 'desc', 'id' => 'desc'),
            'page' => array(12, 'list'),
            'col' => '*',
        ),
    ),
);