<?php
$cate = function()
{
    $array = array();
    $data = Dever::db('work/q_cate')->state();
    if($data)
    {
        $array += $data;
    }
    return $array;
};
$branch = function()
{
    $array = array();
    $data = Dever::db('work/branch')->state();
    if($data)
    {
        foreach ($data as $k => $v) {
            $group = Dever::db('manage/group')->find($v['group_id']);
            $data[$k]['id'] = $v['group_id'];
            $data[$k]['name'] = $group['name'];
        }
        $array += $data;
    }
    return $array;
};
$product = function()
{
    $array = array();
    $data = Dever::db('work/product')->state();
    if($data)
    {
        $array += $data;
    }
    return $array;
};
$type = array
(
    1 => '上架',
    2 => '下架',
);
$button = false;
if (Dever::load('manage/auth')->checkFunc('work.question', 'qcate', '问题分类设置'))
{
    $button['问题分类设置'] = array('location', 'l=project/database/list&project=work&table=q_cate&&oper_table=question');
}
if (Dever::load('manage/auth')->checkFunc('work.question', 'qsource', '问题来源设置'))
{
    $button['问题来源设置'] = array('location', 'l=project/database/list&project=work&table=q_source&&oper_table=question');
}
if (Dever::load('manage/auth')->checkFunc('work.question', 'qpriority', '优先级设置'))
{
    $button['优先级设置'] = array('location', 'l=project/database/list&project=work&table=priority&&oper_table=question');
}

return array
(
    # 表名
    'name' => 'question',
    # 显示给用户看的名称
    'lang' => '问题设置',
    # 后台菜单排序
    'order' => 98,
    // 'menu' => false,
    // 'auto' => 100000,
    # 数据结构
    'struct' => array
    (
        'id'        => array
        (
            'type'      => 'int-11',
            'name'      => 'ID',
            'default'   => '',
            'desc'      => '',
            'match'     => 'is_numeric',
            'search'    => 'order',
            'list'      => true,
            'order'     => 'desc',
        ),

        'company_id'       => array
        (
            'type'      => 'int-11',
            'name'      => '所属公司',
            'default'   => '1',
            'desc'      => '所属公司',
            'match'     => 'is_numeric',
            'update'    => 'hidden',
            //'search'    => $company ? 'select' : false,
            //'list'      => true,
        ),

        'name'      => array
        (
            'type'      => 'varchar-200',
            'name'      => '名称',
            'default'   => '',
            'desc'      => '名称',
            'match'     => 'is_string',
            'update'    => 'text',
            'search'    => 'fulltext',
            'list'      => true,
        ),

        'cate_id'      => array
        (
            'type'      => 'int-11',
            'name'      => '选择所属分类',
            'default'   => '-1',
            'desc'      => '选择所属分类',
            'match'     => 'is_string',
            'option'    => $cate,
            'update'    => 'select',
            'search'    => 'select',
            'list'      => true,
        ),

        'branch_id'      => array
        (
            'type'      => 'int-11',
            'name'      => '关联部门',
            'default'   => '-1',
            'desc'      => '关联部门',
            'match'     => 'is_string',
            'search'    => 'select',
            'update'    => 'select',
            'option'    => $branch,
            // Dever::url('lib/appoint.get?level_total=1', 'work'),
            'list'      => 'Dever::load("work/lib/manage.branch",{branch_id})',
        ),

        'product_id'      => array
        (
            'type'      => 'int-11',
            'name'      => '相关系统产品',
            'default'   => '-1',
            'desc'      => '相关系统产品',
            'match'     => 'is_string',
            'option'    => $product,
            'update'    => 'select',
            'list'      => true,
        ),

        'type'        => array
        (
            'type'      => 'tinyint-1',
            'name'      => '上下架状态',
            'default'   => '1',
            'desc'      => '上下架状态',
            'match'     => 'is_numeric',
            'update'    => 'radio',
            'option'    => $type,
            'search'    => 'select',
            'list'      => true,
        ),

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

    'manage' => array
    (
    	//'insert' => false,
        'delete' => false,
        // 'edit' => false,
        'button' => $button,
        
        # 设置公司权限
        'company' => 'company_id',
    ),

    'request' => array
    (
        // 'getData' => array
        // (
        //     # 匹配的正则或函数 选填项
        //     'option' => array
        //     (
        //         //'id' => array('yes', '!='),
        //         'state' => 1,
        //     ),
        //     'type' => 'all',
        //     'order' => array('id' => 'desc'),
        //     'col' => '*|id',
        // ),
        'getAll' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'branch_id' => 'yes',
                // 'id' => array('yes','>'),
                'state' => 1,
            ),
            'type' => 'all',
            'order' => array('reorder' => 'desc', 'id' => 'asc'),
            'col' => '*',
        ),
        'getSearchAll' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'cate_id'=>'yes',
                'state' => 1,
                'type' => 1,
            ),
            'type' => 'all',
            'order' => array('reorder' => 'desc', 'id' => 'asc'),
            'col' => 'id as value, name',
        ),
        'getTotal' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'branch_id'=>'yes',
                'state' => 1,
                'type' => 1,
            ),
            'type' => 'count',
            // 'order' => array('reorder' => 'desc', 'id' => 'asc'),
            'col' => '*',
        ),
    ),
);
