<?php
$cate = function()
{
    $array = array();
    $data = Dever::db('work/q_cate')->state();
    if($data)
    {
        $array += $data;
    }
    return $array;
};
return array
(
    # 表名
    'name' => 'info_stat',
    # 显示给用户看的名称
    'lang' => '工单统计',
    'order' => -100,
    'menu'	=> true,
    # 数据结构
    'struct' => array
    (
    
        'id'        => array
        (
            'type'      => 'int-11',
            'name'      => 'ID',
            'default'   => '',
            'desc'      => '',
            'match'     => 'is_numeric',
            'search'    => 'order',
            //'list'      => true,
        ), 

        'cate'      => array
        (
            'type'      => 'int-11',
            'name'      => '问题分类',
            'default'   => '0',
            'desc'      => '问题分类',
            'match'     => 'option',
            'option'    => $cate,
            'search'    => 'select',
            'update'    => 'text',
            // 'list'      => true,
        ),

        'day'     => array
        (
            'type'      => 'int-11',
            'name'      => '日期',
            'default'   => '',
            'match'     => 'is_numeric',
            'desc'      => '',
            'search'    => 'day',
            'search_button' => array
            (
            	'sum' => 'question,super,urgent,yb,pt',
            	'option' => array(
            		'day' => '按天',
	            	'week' => '按周',
	            	'month' => '按月',
            	),
                // 'group' => 'cate',
            ),
            'order'     => 'desc',
            'list'      => 'Dever::showDay("{day}")',
        ),

        'question'      => array
        (
            'type'      => 'int-11',
            'name'      => '工单总量',
            'default'   => '0',
            'desc'      => '工单总量',
            'match'     => 'option',
            'update'    => 'text',
            'list'      => true,
        ),

        'super'      => array
        (
            'type'      => 'int-11',
            'name'      => '超级紧急',
            'default'   => '0',
            'desc'      => '超级紧急',
            'match'     => 'option',
            'update'    => 'text',
            'list'      => true,
        ),

        'urgent'      => array
        (
            'type'      => 'int-11',
            'name'      => '紧急',
            'default'   => '0',
            'desc'      => '紧急',
            'match'     => 'option',
            'update'    => 'text',
            'list'      => true,
        ),

        'yb'      => array
        (
            'type'      => 'int-11',
            'name'      => '一般',
            'default'   => '0',
            'desc'      => '一般',
            'match'     => 'option',
            'update'    => 'text',
            'list'      => true,
        ),

        'pt'      => array
        (
            'type'      => 'int-11',
            'name'      => '普通',
            'default'   => '0',
            'desc'      => '普通',
            'match'     => 'option',
            'update'    => 'text',
            'list'      => 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})',
            //'list'      => 'Dever::load("service/lib/manage.showOrderTime", "{id}")',
        ),
    ),

    'manage' => array
    (
        'delete' => false,
        'edit' => false,
        'insert' => false,
        'chart' => array
        (
        	'x' => 'day',
        	'data' => array('question','super','urgent','yb','pt'),
        ),
        'data' => array
        (
        	array('工单总量', function() {return Dever::db('work/info')->total(array('state'=>1));}),
        	array('今日新增', function() {list($start, $end) = Dever::day(); return Dever::db('work/info')->total(array('start' => $start, 'end' => $end, 'state'=>1));}),
        	array('本月新增', function() {list($start, $end) = Dever::month();return Dever::db('work/info')->total(array('start' => $start, 'end' => $end, 'state'=>1));}),
        	array('待处理', function() {return Dever::db('work/info')->total(array('status'=>1, 'state'=>1));}),
        	array('处理中', function() {return Dever::db('work/info')->total(array('status' => 2,'state'=>1));}),
        	array('完成关闭', function() {return Dever::db('work/info')->total(array('status' => 3, 'state'=>1));}),
        	array('取消关闭', function() {return Dever::db('work/info')->total(array('status' => 4,'state'=>1));}),
        ),
    ),

    'request' => array
    (
        'list' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'cate' => 'yes',
               
                'start' => array('yes-day', '>='),
                'end' => array('yes-day', '<='),
                'state' => 1,
            ),
            'type' => 'all',
            'order' => array('day' => 'desc', 'cdate' => 'desc'),
            'page' => array(20, 'list'),
            'group' => 'day',
            'col' => '*,sum(question) as question, sum(super) as super, sum(urgent) as urgent, sum(yb) as yb, sum(pt) as pt',
        ),
    ),
);