<?php
$group = function()
{
    $array = array();
    $data = Dever::load('manage/group-state');
    if($data)
    {
        $array += $data;
    }
    return $array;
};
$cadre = function()
{
    // $array = array();
    $array = array
    (
        -1 => array('id' => '-1', 'name' => '请选择'),
    );
    $data = Dever::load('manage/admin-state');
    if($data)
    {
        foreach ($data as $k => $v) {
            $data[$k]['name'] = $v['username']; 
        }
        $array += $data;
    }
    return $array;
};
$type = array
(
    1 => '发送',
    2 => '不发送',
);
return array
(
    # 表名
    'name' => 'branch',
    # 显示给用户看的名称
    'lang' => '相关部门设置',
    # 后台菜单排序
    'order' => 94,
    // 'menu' => false,
    // 'auto' => 100000,
    // 'check' => 'group_id',
    'start' => array
    (
        'insert' => 'work/lib/appoint.startBranch',
        'update' => 'work/lib/appoint.startBranch',
    ),
    'end' => array
    (
        'insert' => 'work/lib/appoint.updateBranch',
        'update' => 'work/lib/appoint.updateBranch',
    ),
    # 数据结构
    '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,
        ),

        'group'      => array
        (
            'type'      => 'varchar-100',
            'name'      => '部门和负责人',
            'default'   => '-1',
            'desc'      => '部门名称',
            'match'     => 'is_string',
            // 'option'    => $group,
            'update'    => 'linkage',
            'option'    => Dever::url('lib/appoint.get?level_total=2&type=1', 'work'),
            'list'      => 'Dever::load("work/lib/manage.xietiao#group",{id})',
            'load'      => 'coor',
        ),

        'group_id'      => array
        (
            'type'      => 'int-11',
            'name'      => '部门',
            'default'   => '-1',
            'desc'      => '部门id',
            'match'     => 'is_string',
            'option'    => $group,
            'update'    => 'hidden',
        ),

        'coor'          => array
        (
            'type'      => 'varchar-2000',
            'name'      => '协调人',
            'default'   => '',
            'desc'      => '请先选择协调人',
            'match'     => 'option',
            'update'    => 'load',
            'update_load' => array('work/lib/manage.getCoor', 'group'),
        ),

        'type'        => array
        (
            'type'      => 'tinyint-1',
            'name'      => '是否发送每日汇总邮件通知',
            'default'   => '2',
            'desc'      => '是否发送每日汇总邮件通知',
            'match'     => 'is_numeric',
            'update'    => 'radio',
            'option'    => $type,
            // 'search'    => 'select',
            // 'list'      => true,
        ),
        #弃用，实时查询
        'num'        => array
        (
            'type'      => 'int-11',
            'name'      => '关联问题数',
            'default'   => '0',
            'desc'      => '数量',
            'match'     => 'option',
            'update'    => 'hidden',
            'list'      => 'Dever::load("work/lib/manage.xietiao#num",{id})',
        ),

        '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,
        'list_button' => array
        (
            'list' => array('关联问题列表', '"question&search_option_branch_id={group_id}&oper_table=branch"')
        ),
        # 设置公司权限
        'company' => 'company_id',
    ),

    'request' => array
    (
        'getAll' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                // 'id' => array('yes','>'),
                'state' => 1,
            ),
            'type' => 'all',
            'order' => array('reorder' => 'desc', 'id' => 'asc'),
            'col' => '*',
        ),
    ),
);
