<?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)
    {
        $array += $data;
    }
    return $array;
};
$priority = function()
{
    $array = array();
    $data = Dever::db('work/priority')->state();
    if($data)
    {
        foreach ($data as $k => $v) {
            $data[$k]['style'] = 'color:'.$v['color'];
        }
        $array += $data;
    }
    return $array;
};
$source = function()
{
    $array = array();
    $data = Dever::db('work/q_source')->state();
    if($data)
    {
        $array += $data;
    }
    return $array;
};
$question = function()
{
    $array = array();
    $data = Dever::db('work/question')->state();
    if($data)
    {
        $array += $data;
    }
    return $array;
};
$product = function()
{
    $array = array();
    $data = Dever::db('work/product')->state();
    if($data)
    {
        $array += $data;
    }
    return $array;
};
$status = array
(
    // 1 => '全部',
    1 => '待处理',
    2 => '处理中',
    3 => '完成关闭',
    4 => '取消关闭',
);
$email = array
(
    1 => '不发送',
    2 => '发送',
);
$admin = Dever::load("manage/auth.info");
$admin_id = '';
if ($admin) {
    $admin_id = $admin['id'];
}
#工单列表是1，我的工单列表2
$search_auth = Dever::input('search_option_dever_auth', 1);

$list_button = array();
$list_button['location'] = array('查看详情',Dever::url('lib/appoint.show','work'));
$list_button ['fast_add'] = array('指派工单','appoint&search_option_info_id={id}','{status}<3');
$data = array();
$insert = true;
// $company = Dever::load('manage/company.get');
if ($search_auth > 1) {
    $insert = false;
    if ($search_auth == 2) {
        $audit_admin = Dever::setInput('search_option_col', $admin_id);
    }
    if ($search_auth == 3) {
        $search_ids = Dever::load('work/lib/manage')->getMyTotal($admin_id,2);
        Dever::setInput('search_option_ids', $search_ids);
    }
    
    $data[]= array('待我处理',function() use ($admin_id) {return Dever::load('work/lib/manage')->getTotal($admin_id,'1,2');}, 'search_option_dever_auth=2&search_option_status=1,2&search_option_appoint_id=' . $admin_id);
    $data[]= array('处理完成',function() use($admin_id) {return Dever::load('work/lib/manage')->getTotal($admin_id,'3,4');}, 'search_option_dever_auth=2&search_option_status=3,4&search_option_fpeople=' . $admin_id);
    $data[]= array('我创建的',function() use($admin_id) {return Dever::load('work/lib/manage')->getTotal($admin_id,false);}, 'search_option_dever_auth=2&search_option_state=1&search_option_audit_admin=' . $admin_id);

    $data[]= array('和我相关的',function() use($admin_id) {
           return Dever::load('work/lib/manage')->getmyTotal($admin_id,1);
    }, 'search_option_dever_auth=3&search_option_state=1');

} 
$button = array();
if ($search_auth == 1) {
    $button['回调界面'] = array('location',Dever::url('lib/appoint.callback','work')); 
    // $button['电话回调界面'] = array('location',Dever::url('lib/appoint.callback','work')); 
}
$excel = false;
if (Dever::load('manage/auth')->checkFunc('work.info', 'infoedit', '数据导出')) {
    $excel[] = array('数据导出', '工单列表数据导出', 'work/lib/manage.out_info');
}
return array
(
    # 表名
    'name' => 'info',
    # 显示给用户看的名称
    'lang' => '发起新工单',
    # 后台菜单排序
    'order' => 100,
    // 'menu' => false,
    // 'auto' => 100000,
    'start' => array
    (
        'insert' => 'work/lib/manage.insertInfo',
        // 'update' => 'work/lib/manage.insertInfo',
    ),
    'end' => array
    (
        'insert' => 'work/lib/manage.updateInfo',
        'update' => 'work/lib/manage.updateInfo',
    ),
    'config_status' => $status,
    # 数据结构
    '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,
        ),

        'mobile'      => array
        (
            'type'      => 'bigint-11',
            'name'      => '手机号',
            'default'   => '',
            'desc'      => '请输入手机号',
            'match'     => Dever::rule('mobile'),
            // 'is_numeric',
            'update'    => 'text',
           
            'value'     => Dever::input('search_option_mobile'),
            # 绑定js脚本，更新时使用，第一个参数是执行的方式，第二个参数执行的方法，第三个参数是传值。
            'bind'        => array('onblur', 'loading', array('url' => Dever::url("lib/manage.search","work"))),
            'list_name' => '客户信息',
            'list'      => 'Dever::load("work/lib/manage.getUser#user",{id})',#true,
            // '"Dever::load("work/lib/manage.getUser",{mobile})"',
        ),

        'name'      => array
        (
            'type'      => 'varchar-200',
            'name'      => '用户姓名（或微信名）',
            'default'   => '',
            'desc'      => '用户姓名（或微信名）',
            'match'     => 'option',
            'update'    => 'text',
            // 'search'    => 'fulltext',
            // 'list'      => true,
        ),

        'work_num'      => array
        (
            'type'      => 'varchar-100',
            'name'      => '姓名/手机号',
            'default'   => '',
            'desc'      => '工单号',
            'match'     => 'is_string',
            'update'    => 'hidden',
             'search'    => array
            (
                'api' => 'work/info-getSearch',
                'col' => 'col',
                'result' => 'id',
                'search' => 'id',
            ),
            // 'search'    => 'fulltext',
            // 'list'      => true,
        ),

        'source'      => array
        (
            'type'      => 'int-11',
            'name'      => '问题来源',
            'default'   => '1',
            'desc'      => '问题来源',
            'match'     => 'is_string',
            'option'    => $source,
            'update'    => 'radio',
            'search'    => $search_auth == 1 ? 'select' : false,
            // 'list'      => true,
        ),

        'cate_id'      => array
        (
            'type'      => 'varchar-30',
            'name'      => '问题类型',
            'default'   => '-1',
            'desc'      => '问题类型',
            'match'     => 'is_string',
            'search'    => $search_auth == 1 ? 'linkage' : false,
            'update'    => 'linkage',
            'option'    => Dever::url('lib/appoint.getCate?level_total=2', 'work'),
            'list'      => 'Dever::load("work/lib/manage.getUser#cate_name",{id})',
        ),

        'priority_id'      => array
        (
            'type'      => 'int-11',
            'name'      => '优先级',
            'default'   => '1',
            'desc'      => '优先级',
            'match'     => 'is_string',
            'option'    => $priority,
            'update'    => 'radio',
            'search'    => $search_auth == 1 ? 'select' : false,
            'list'      => true,
        ),

        'appoint_id'      => array
        (
            'type'      => 'int-11',
            'name'      => '指派人',
            'default'   => '-1',
            'desc'      => '指派人',
            'match'     => 'is_string',
            // 'option'    => $priority,
            // 'update'    => 'select',
            // 'search'    => 'select',
            // 'list'      => true,
        ),

        'desc'       => array
        (
            'type'      => 'text-255',
            'name'      => '问题描述',
            'default'   => '',
            'desc'      => '问题描述',
            'match'     => 'is_string',
            'update'    => 'textarea',
            'list'      => true,
        ),

        'pic'        => array
        (
            'type'      => 'varchar-500',
            'name'      => '相关截图',
            'default'   => '',
            'desc'      => '请选择相关截图',
            'match'     => 'option',
            'update'    => 'images',
            'key'       => '1',
            //'place'       => '150',
        ),

        'video'        => array
        (
            'type'      => 'varchar-500',
            'name'      => '相关视频',
            'default'   => '',
            'desc'      => '请选择相关视频',
            'match'     => 'option',
            'update'    => 'video',
            'key'       => '3',
            'place'     => '150',
            'upload'    => 'yun',
            'large'     => true,
        ),

         'group'       => array
        (
            'type'      => 'int-11',
            'name'      => '部门',
            'default'   => '',
            'desc'      => '部门',
            'match'     => 'option',
            // 'search'    => 'linkage',
            'update'    => 'hidden',
            // 'option'    => Dever::url('lib/appoint.get?level_total=2', 'work'),
        ),

        'question'       => array
        (
            'type'      => 'int-11',
            'name'      => '问题',
            'default'   => '',
            'desc'      => '问题',
            'match'     => 'option',
            // 'search'    => 'linkage',
            'update'    => 'hidden',
            // 'option'    => Dever::url('lib/appoint.get?level_total=2', 'work'),
        ),

        'cate'       => array
        (
            'type'      => 'int-11',
            'name'      => '分类',
            'default'   => '',
            'desc'      => '分类',
            'match'     => 'option',
            // 'search'    => 'linkage',
            'update'    => 'hidden',
            // 'option'    => Dever::url('lib/appoint.get?level_total=2', 'work'),
        ),

        'product'       => array
        (
            'type'      => 'int-11',
            'name'      => '系统产品',
            'default'   => '',
            'desc'      => '系统产品',
            'match'     => 'option',
            'search'    => 'select',
            'update'    => 'hidden',
            'option'    => $product,
            'list'      => true,
        ),

        'branch_id'       => array
        (
            'type'      => 'varchar-500',
            'name'      => '协助部门',
            'default'   => '',
            'desc'      => '协助部门',
            'match'     => 'option',
            // 'search'    => 'linkage',
            'update'    => 'linkage',
            'option'    => Dever::url('lib/appoint.get?level_total=2', 'work'),
        ),

        'email'       => array
        (
            'type'      => 'int-11',
            'name'      => '是否发送邮件',
            'default'   => '1',
            'desc'      => '是否发送邮件',
            'match'     => 'option',
            'option'    => $email,
            // 'search'    => 'linkage',
            'update'    => 'radio',
            // 'option'    => Dever::url('lib/appoint.get?level_total=2', 'work'),
        ),

        'status'      => array
        (
            'type'      => 'int-11',
            'name'      => '处理结果',
            'default'   => '1',
            'desc'      => '处理结果',
            'match'     => 'is_string',
            'option'    => $status,
            'update'    => 'radio',
            'search'    => 'select',
            'list'      => true,
        ),
        'fdate'     => array
        (
            'type'      => 'int-11',
            'name'      => '完成时间',
            'default'   => '',
            'match'     => 'is_numeric',
            // 'search'    => 'date',
            'list_name' => '时间/完成时间',
            // 'desc'      => '',
            'list'      => 'Dever::load("work/lib/manage.getUSer#time",{id})',
            'list_order' => 1,
        ),

        'fpeople'       => array
        (
            'type'      => 'int-11',
            'name'      => '完成人',
            'default'   => '',
            'desc'      => '完成人',
            'match'     => 'option',
            // 'search'    => 'select',
            'update'    => 'hidden',
            // 'option'    => $product,
            // 'list'      => true,
        ),

        'zdate'     => array
        (
            'type'      => 'int-11',
            'name'      => '指派时间',
            'default'   => '',
            'match'     => 'is_numeric',
            // 'search'    => 'date',
        ),

        'chdate'     => array
        (
            'type'      => 'int-11',
            'name'      => '处理时间',
            'default'   => '',
            'match'     => 'is_numeric',
            // 'search'    => 'date',
            // 'desc'      => '',
        ),

        'audit_admin'     => array
        (
            'type'      => 'int-11',
            'name'      => '工单创建人',
            'default'   => '',
            'match'     => 'is_numeric',
            'desc'      => '工单创建人',
            'update'    => 'hidden',
            'insert'    => true,
            'value'     => $admin_id,
            'search'    => 
            // 'Dever::load("work/lib/manage.getUSer#chuangjian",{id})',
            array
            (
                'api' => 'manage/admin-getSearch',
                'col' => 'col',
                'result' => 'id',
                'search' => 'audit_admin',
            ),
            'list'      => 'Dever::load("work/lib/manage.getUSer#chuangjian",{id})',
        ),

         'dever_auth'      => array
        (
            'name'      => '搜索',
            'default'   => '',
            'desc'      => '类型',
            'match'     => 'is_string',
            'search'    => 'hidden',
        ),

        '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,
            'search'    => 'date',

            // 'list'      => 'date("Y-m-d H:i:s", {cdate})',
        ),
    ),
    'alter' => array
    (
        
        4 => array
        (
            array('update', 'product','product','int-11  系统产品'),
        ),
        'version' => 4,
    ),
    'manage' => array
    (
    	'insert' => $insert,
        'delete' => false,
        'edit' => false,
        'list_button' => $list_button,
        'data' => $data,
        'button' => $button,
        'excel'  => $excel,
        # 设置公司权限
        'company' => 'company_id',
    ),

    'request' => array
    (
        'list_option' => array
        (
         'col' => 'yes-appoint_id,audit_admin,fpeople',
         'ids' => array('yes-id', 'in'),
         'status' => array('yes', 'in'),
         'state'=>1,
        ),
        'getSearch' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'col' => array('yes-mobile,name', 'like'),
            ),
            'type' => 'all',
            'col' => '*|id',
        ),
        'getTotal' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'audit_admin' => 'yes',
                'appoint_id' => 'yes',
                'fpeople' => 'yes',
                'state' => 1,
                'status'=> array('yes','in'),
                'company_id'=>'yes',
            ),
            'type' => 'count',
            // 'order' => array('reorder' => 'desc', 'id' => 'asc'),
            'col' => '*',
        ),
        'getCount' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'group' => 'yes',
                'state' => 1,
                'id' => array('yes','in'),
                'question' => array('yes','in'),
                'start' => array('yes-cdate','>='),
                'end' => array('yes-cdate','<='),
                'status'=> array('yes','in'),
                'fpeople' => array('yes','in'),
            ),
            'type' => 'count',
            // 'order' => array('reorder' => 'desc', 'id' => 'asc'),
            'col' => '*',
        ),
        'getAll' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'group' => 'yes',
                'question' => 'yes',
                'state' => 1,
                'start' => array('yes-cdate','>='),
                'end' => array('yes-cdate','<='),
                'status'=> array('yes','in'),
            ),
            'type' => 'all',
            'order' => array('reorder' => 'desc', 'id' => 'desc'),
            'col' => '*',
        ),

        'getHAll' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'mobile' =>'yes',
                'state' => 1,
            ),
            'type' => 'all',
            'order' => array('reorder' => 'desc', 'id' => 'desc'),
            'page' => array(5,'list'),
            'col' => '*',
        ),

        'getquestTotal' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'group' => 'yes',
                'state' => 1,
            ),
            'type' => 'count',
            // 'order' => array('id' => 'desc'),
            'col' => '*',
        ),
        'getNum' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'start' => array('yes-cdate','>='),
                'end' => array('yes-cdate','<='),
                'priority_id' =>'yes',
                'cate' => 'yes',
                'state' => 1,
            ),
            'type' => 'count',
            // 'order' => array('id' => 'desc'),
            'col' => '*',
        ),
        'getmyAll' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'audit_admin' =>'yes',
                'cate' => 'yes',
                'state' => 1,
            ),
            'type' => 'all',
            // 'order' => array('id' => 'desc'),
            'col' => 'id as info_id',
        ),
    ),
);
