<?php

$id = Dever::input('search_option_info_id');
$cate = array();
if ($id) {
    $journal = Dever::db('journal/info')->one($id);
    $cate = Dever::db('journal/cate')->one($journal['cate_id']);
}

$type_config = array
(
    # 默认类型
    3 => '图文内容',
    1 => '全屏图',
    
    # 2019-03-27 增加两个类型
    7 => '长图（文字）',
    8 => '横屏图',

    2 => '长图',
    9 => '无边框图片',
    10 => '四宫格图片',

    # 2018-12-11 增加3个类型
    4 => '全屏视频',
    5 => '留言视频',
    6 => '留言音频',

    # 2019-03-27 增加三个类型
    21 => '对话模板',

    # 关联类型 > 10
    11 => '关联图文',
    12 => '关联视频',
    13 => '关联直播',
);

$type_default = 3;

if ($cate) {
    $type = array();
    $cate_type = explode(',', $cate['type']);
    $i = 0;
    foreach ($cate_type as $k => $v) {
        if (isset($type_config[$v])) {
            if ($i == 0) {
                $type_default = $v;
            }
            $type[$v] = $type_config[$v];
            $i++;
        }
    }
} else {
    $type = $type_config;
}

$is_button = array
(
    1 => '显示',
    2 => '不显示',
);

$text = array
(
    1 => '上左',
    2 => '上中',
    3 => '上右',
    4 => '中左',
    5 => '正中',
    6 => '中右',
    7 => '下左',
    8 => '下中',
    9 => '下右',
    //10 => '自定义',
);


$palaces = array
(
    1 => '上左',
    2 => '上右',
    3 => '下左',
    4 => '下右',
);

$bgcolor_type = array
(
    1 => '设置背景颜色',
    2 => '不设置背景颜色',
);
$talk_type = array
(
    1 => '文字',
    2 => '图片',
    3 => '音频',
);

$talk_location = array
(
    1 => '显示在左侧',
    2 => '显示在右侧',
);

$author = function()
{
    $array = array();
    $info = Dever::db('content/author')->state();
    if($info)
    {
        $array += $info;
    }
    return $array;
};

return array
(
    # 表名
    'name' => 'content',
    # 显示给用户看的名称
    'lang' => '内页管理',
    'menu' => false,
    'gettype' => $type,
    'text' => $text,
    'end' => array
    (
        'insert' => 'journal/lib/manage.addContent',
    ),
    # 数据结构
    'struct' => array
    (
    
        'id'        => array
        (
            'type'      => 'int-11',
            'name'      => 'ID',
            'default'   => '',
            'desc'      => '',
            'match'     => 'is_numeric',
            //'search'    => 'order',
            //'list'        => true,
        ),

        'info_id'      => array
        (
            'type'      => 'int-11',
            'name'      => '小刊',
            'default'   => '',
            'desc'      => '小刊',
            'match'     => 'is_numeric',
            'update'    => 'hidden',
            'value'     => Dever::input('search_option_info_id')
        ),

        'type'     => array
        (
            'type'      => 'int-11',
            'name'      => '类型',
            'default'   => $type_default,
            'desc'      => '类型',
            'match'     => 'is_numeric',
            'update'    => 'radio',
            'option'    => $type,
            'control'   => 'type',
        ),

        'name'      => array
        (
            'type'      => 'varchar-80',
            'name'      => '标题',
            'default'   => '',
            'desc'      => '标题',
            'match'     => 'is_string',
            'update'    => 'text',
            'list'      => true,
            //增加预览
            'preview'   => true,
            'show'      => 'type=3,5,6',      
        ),

        'video'     => array
        (
            'type'      => 'varchar-800',
            'name'      => '上传视频-视频格式mp4，上传大小不能超过4G',
            'default'   => '',
            'desc'      => '上传点播视频',
            'match'     => 'is_string',
            'update'    => 'upload',
            'key'       => '3',
            'place'     => '150',
            'upload'    => 'qiniu',
            'large'     => true,
            //不覆盖原文件，生成新文件
            'cover'     => 2,
            'show'      => 'type=4,5',      
        ),

        'video_info'        => array
        (
            'type'      => 'text-255',
            'name'      => '视频信息',
            'default'   => '',
            'desc'      => '视频信息',
            'match'     => 'is_string',
        ),

        'music'     => array
        (
            'type'      => 'varchar-800',
            'name'      => '上传音频-视频格式mp3，上传大小不能超过100M',
            'default'   => '',
            'desc'      => '上传音频',
            'match'     => 'is_string',
            'update'    => 'upload',
            'key'       => '2',
            'place'     => '150',
            'upload'    => 'qiniu',
            'large'     => true,
            //不覆盖原文件，生成新文件
            'cover'     => 2,
            'show'      => 'type=6',      
        ),

        'cover'     => array
        (
            'type'      => 'varchar-150',
            'name'      => '封面图-全屏视频的封面图图片尺寸750*1386px或等比尺寸，留言视频的封面图图片尺寸750*422px或等比尺寸，留言音频的封面图图片尺寸750*422px或等比尺寸，上传大小不能超过2M，支持JPG、PNG、GIF格式，建议上传JPG格式',
            'default'   => '',
            'desc'      => '封面图',
            'match'     => 'option',
            'update'    => 'image',
            'key'       => '1',
            'place'     => '150',
            'show'      => 'type=4,5,6',      
        ),

        'focus'     => array
        (
            'type'      => 'text-255',
            'name'      => '焦点图',
            'default'   => '',
            'desc'      => '焦点图',
            'match'     => 'option',
            'update'    => 'image',
            'key'       => '1',
            'place'     => '150',
            'show'      => 'type=3',      
        ),

        'author_id'     => array
        (
            'type'      => 'int-11',
            'name'      => '作者',
            'default'   => '1',
            'desc'      => '作者',
            'match'     => 'is_numeric',
            'update'    => 'select',
            'option'    => $author,
            //'search'    => 'select',
            'show'      => 'type=3',      
        ),

        'content'       => array
        (
            'type'      => 'text-255',
            'name'      => '内容',
            'default'   => '',
            'desc'      => '请输入内容',
            'match'     => 'is_string',
            'update'    => 'editor',
            'show'      => 'type=3',
            //自定义编辑器右侧按钮
            'editor'    => array
            (
                'name' => '选择插入模块',
                'button' => array
                (
                    array
                    (
                        # 名称
                        'name' => '图片',
                        # 资源库id
                        'key' => 1,
                        # 类型
                        'type' => 'image',
                    ),
                    array
                    (
                        'name' => '音频',
                        'key' => 2,
                        'type' => 'media',
                    ),
                    array
                    (
                        'name' => '视频',
                        'key' => 'video/lib/core.vod',
                    ),
                    array
                    (
                        'name' => '直播',
                        'key' => 'video/lib/core.live',
                    ),
                    array
                    (
                        'name' => '小程序',
                        'key' => 'content/lib/applet.update',
                        'type' => 'update',
                    ),
                ),
            ),
        ),

        'pic'     => array
        (
            'type'      => 'varchar-150',
            'name'      => '图片-全屏图图片尺寸750*1386px或等比尺寸，长屏图图片尺寸750*高度不限或等比尺寸，横屏图图片尺寸宽度不限*1386px或等比尺寸，长图图片尺寸750*高度不限或等比尺寸，无边框图片尺寸长和宽均没有限制，上传大小不能超过2M，支持JPG、PNG、GIF格式，建议上传JPG格式',
            'default'   => '',
            'desc'      => '图片',
            'match'     => 'option',
            'update'  => 'image',
            'key'       => '1',
            'place'     => '150',
            'show'      => 'type=1,2,7,8,9',      
        ),

        'pic_info'        => array
        (
            'type'      => 'varchar-500',
            'name'      => '图片信息',
            'default'   => '',
            'desc'      => '图片信息',
            'match'     => 'is_string',
            'update'    => 'hidden',
        ),

        'is_button'     => array
        (
            'type'      => 'int-11',
            'name'      => '是否显示保存按钮',
            'default'   => '1',
            'desc'      => '是否显示保存按钮',
            'match'     => 'is_numeric',
            'update'    => 'radio',
            'option'    => $is_button,
           // 'search'    => 'select',
            'show'      => 'type=1,7,8',      
            'control'   => 'is_button',
        ),

        'button_name'     => array
        (
            'type'      => 'varchar-80',
            'name'      => '保存按钮文字内容',
            'default'   => '保存图片',
            'desc'      => '保存按钮文字内容',
            'match'     => 'option',
            'update'    => 'textarea',
            'show'      => 'type=1,7,8',      
        ),

        'button_color'     => array
        (
            'type'      => 'varchar-10',
            'name'      => '保存按钮文字颜色',
            'default'   => '#000000',
            'desc'      => '保存按钮文字颜色',
            'match'     => 'option',
            'update'    => 'color',
            'show'      => 'type=1,7,8',      
        ),

        'article_id'     => array
        (
            'type'      => 'int-11',
            'name'      => '关联图文',
            'default'   => '',
            'desc'      => '关联图文',
            'match'     => 'option',
            'update'    => 'select',
            'show'      => 'type=11',
            'update_search' => 'journal/lib/manage.search_article',
        ),

        'vod_id'     => array
        (
            'type'      => 'int-11',
            'name'      => '关联视频',
            'default'   => '',
            'desc'      => '关联视频',
            'match'     => 'option',
            'update'    => 'select',
            'show'      => 'type=12',
            'update_search' => 'journal/lib/manage.search_vod',
        ),

        'live_id'     => array
        (
            'type'      => 'int-11',
            'name'      => '关联直播',
            'default'   => '',
            'desc'      => '关联直播',
            'match'     => 'option',
            'update'    => 'select',
            'show'      => 'type=13',
            'update_search' => 'journal/lib/manage.search_live',
        ),

        'text'       => array
        (
            'type'      => 'text-1000',
            'name'      => '文字设置',
            'default'   => '',
            'desc'      => '文字设置',
            'match'     => 'is_string',
            'option'    => $text,
            'show'      => 'type=1,7,8',
            'update'    => array
            (
                array
                (
                    'col'       => 'name',
                    'name'      => '文字内容',
                    'default'   => '',
                    'desc'      => '文字内容',
                    'match'     => 'is_string',
                    'update'    => 'textarea',
                ),

                array
                (
                    'col'       => 'color',
                    'name'      => '文字颜色',
                    'default'   => '#000000',
                    'desc'      => '文字颜色',
                    'match'     => 'is_string',
                    'update'    => 'color',
                ),

                array
                (
                    'col'       => 'bgcolor_type',
                    'name'      => '是否设置背景颜色',
                    'default'   => '2',
                    'desc'      => '是否设置背景颜色',
                    'match'     => 'is_string',
                    'update'    => 'radio',
                    'option'    => $bgcolor_type,
                    'control'   => 'bgcolor_type',
                ),

                array
                (
                    'col'       => 'bgcolor',
                    'name'      => '背景颜色',
                    'default'   => '#000000',
                    'desc'      => '背景颜色',
                    'match'     => 'is_string',
                    'update'    => 'color',
                    'show'      => 'bgcolor_type=1'
                ),

                array
                (
                    'col'       => 'size',
                    'name'      => '文字大小-直接输入像素数字',
                    'default'   => '16',
                    'desc'      => '结果描述',
                    'match'     => 'is_numeric',
                    'update'    => 'text',
                ),
            ),
        ),

        'palaces'       => array
        (
            'type'      => 'text-1000',
            'name'      => '四宫格图片',
            'default'   => '',
            'desc'      => '四宫格图片',
            'match'     => 'is_string',
            'option'    => $palaces,
            'show'      => 'type=10',
            'update'    => array
            (
                array
                (
                    'col'       => 'pic',
                    'name'      => '图片',
                    'default'   => '',
                    'desc'      => '图片',
                    'match'     => 'is_string',
                    'update'    => 'image',
                    'key'       => 1,
                ),
            ),
        ),

        'talk_pic'     => array
        (
            'type'      => 'varchar-150',
            'name'      => '置顶图片-图片尺寸750*1386px或等比尺寸，上传大小不能超过2M，支持JPG、PNG、GIF格式，建议上传JPG格式。为空则不显示',
            'default'   => '',
            'desc'      => '图片',
            'match'     => 'option',
            'update'    => 'image',
            'key'       => '1',
            'place'     => '150',
            'show'      => 'type=21',      
        ),

        'talk'       => array
        (
            'type'      => 'text-1000',
            'name'      => '对话设置',
            'default'   => '',
            'desc'      => '对话设置',
            'match'     => 'is_string',
            'show'      => 'type=21',
            'update'    => array
            (
                array
                (
                    'col'       => 'talk_location',
                    'name'      => '对话位置',
                    'default'   => '1',
                    'desc'      => '对话位置',
                    'match'     => 'is_string',
                    'update'    => 'radio',
                    'option'    => $talk_location,
                ),

                array
                (
                    'col'       => 'avatar',
                    'name'      => '头像-图片尺寸120*120px或等比尺寸，上传大小不能超过2M，支持JPG、PNG、GIF格式，建议上传JPG格式。',
                    'default'   => '',
                    'desc'      => '头像',
                    'match'     => 'option',
                    'update'    => 'image',
                    'key'       => 1,
                ),

                array
                (
                    'col'       => 'talk_type',
                    'name'      => '对话类型',
                    'default'   => '1',
                    'desc'      => '对话类型',
                    'match'     => 'is_string',
                    'update'    => 'radio',
                    'option'    => $talk_type,
                    'control'   => 'talk_type',
                ),

                array
                (
                    'col'       => 'text',
                    'name'      => '文字内容-为空则不显示',
                    'default'   => '',
                    'desc'      => '文字内容',
                    'match'     => 'option',
                    'update'    => 'textarea',
                    'show'      => 'talk_type=1'
                ),

                array
                (
                    'col'       => 'pic',
                    'name'      => '图片-图片尺寸750*1386px或等比尺寸，上传大小不能超过2M，支持JPG、PNG、GIF格式，建议上传JPG格式，可以上传GIF格式。为空则不显示',
                    'default'   => '',
                    'desc'      => '图片',
                    'match'     => 'option',
                    'update'    => 'image',
                    'key'       => 1,
                    'show'      => 'talk_type=2'
                ),

                array
                (
                    'col'       => 'audio',
                    'name'      => '音频-音频格式mp3，上传大小不能超过100M，为空则不显示',
                    'default'   => '',
                    'desc'      => '音频',
                    'match'     => 'option',
                    'update'    => 'upload',
                    'key'       => 2,
                    'show'      => 'talk_type=3'
                ),
            ),
        ),

        'reorder'       => array
        (
            'type'      => 'int-11',
            'name'      => '页号',
            'default'   => '1',
            'desc'      => '请输入排序',
            'match'     => 'option',
            //'update'    => 'text',
            'search'    => 'order',
            'list'      => true,
            'order'     => 'asc',
            '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'    => 'date',
            //'list'      => 'date("Y-m-d H:i:s", {cdate})',
        ),
    ),

    'manage' => array
    (
        'insert' => false,
        'edit' => false,
        //'delete' => false,
        'num' => false,
        'page_list_table' => 'journal',

        # 自定义快捷新增和编辑
        'button' => array
        (
            '新增内页' => array('location', 'add'),
            '预览' => array('fast', 'main/preview.get?type=4&id=' . Dever::input('search_option_info_id')),
        ),
    ),

    # request 请求接口定义
    'request' => array
    (
        'getAll' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'info_id' => 'yes',
                'state' => 1,
            ),
            'type' => 'all',
            'order' => array('reorder' => 'asc', 'id' => 'desc'),
            'page' => array(10, 'list'),
            'col' => '*',
        ),

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