';
                    if (isset($v['update']) && is_array($v['update'])) {
                        $result[$k] = '
';
            } elseif (!$col && isset($v['class'])) {
                # 分割线
                $v['name'] = $this->value($v['name'], array('test' => 1));
                if (isset($v['right'])) {
                    $this->card_right = true;
                }
                $this->card = true;
                $result[$k] = Html::hr($v);
            }
        }
        if (Dever::input('ajax') == 1) {
            return implode('', $result);
        }
        //print_r($result);die;
        return $result;
    }
    public function card()
    {
        if (isset($this->card_right)) {
            return 'layui-col-md6';
        }
        return 'layui-col-md12';
    }
    public function layui_card()
    {
        if (isset($this->card)) {
            return false;
        }
        return true;
    }
    /**
     * update_class
     *
     * @return string
     */
    public function update_class($name, $param, $prefix = '', $data = array())
    {
        $class = '';
        $key = 'show';
        if (isset($param[$key]) && $param[$key]) {
            $parent = array();
            $child = array();
            if (is_string($param[$key])) {
                parse_str($param[$key], $param[$key]);
            }
            if (is_array($param[$key])) {
                foreach ($param[$key] as $k => $v) {
                    if ($k == 'no') {
                        $child[$k . '_' . $v] = $key . '_no';
                    } elseif (strpos($v, '/')) {
                        $parent[$k] = $key . '_' . $k;
                        $k = $k . '_ajax';
                        $value = '';
                        if (isset($data[$name])) {
                            $value = $data[$name];
                        }
                        $v = str_replace('?', '?key='.$name.'&value='.$value.'&source='.$this->name.'&', $v);
                        $child[$k] = $key . '_' . $k .'" dever-ajax="'.Dever::url($v).'"';
                    } else {
                        if (strpos($v, ',')) {
                            $temp = explode(',', $v);
                            foreach ($temp as $v1) {
                                $show = $k . '_' . $v1;
                                if ($prefix) {
                                    $k = str_replace($name, $k, $prefix);
                                    $show = str_replace($name, $show, $prefix);
                                }
                                $parent[$k] = $key . '_' . $k;
                                $child[$show] = $key . '_' . $show;
                            }
                        } else {
                            $show = $k . '_' . $v;
                            if ($prefix) {
                                $k = str_replace($name, $k, $prefix);
                                $show = str_replace($name, $show, $prefix);
                            }
                            $parent[$k] = $key . '_' . $k;
                            $child[$show] = $key . '_' . $show;
                        }
                    }
                }
            }
            $class = implode(' ', $parent) . ' ' . implode(' ', $child);
        } 
        if (isset($param['control'])) {
            $class .= ' ' . $key . '_input';
        }
        return $class;
    }
    /**
     * update_html
     *
     * @return string
     */
    public function create_update_html($key, $value, $data = array())
    {
        $result = '';
        $value['ext'] = $value['col'] = $key;
        $value['update'] = $value['update'] ? $value['update'] : 'text';
        if (isset($value['match']) && $value['match'] != 'option') {
            if (is_string($value['match']) && strpos($value['match'], '/') !== false) {
                if (strstr($value['match'], 'option||')) {
                    $value['valid'] = 'validate[custom[' . $key . ']]';
                } else {
                    $value['valid'] = 'validate[required,custom[' . $key . ']]';
                }
            } else {
                $value['valid'] = 'validate[required]';
            }
        }
        if (is_string($value['update']) && strpos($value['update'], 'copy.') !== false) {
            $value['value'] = $value['update'];
            $value['update'] = 'hidden';
        }
        $this->update_html($value, $key, $key, $data, $result);
        return $result;
    }
    /**
     * update_html
     *
     * @return string
     */
    public function update_html($param, $key, $index, $data, &$result)
    {
        if (isset($param['name']) && $param['update'] != 'hidden' && isset($param['update'])) {
            $result .= Html::pageLeft($param);
        }
        if ($param['update']) {
            # 名称带前缀
            $param['name'] = 'update_' . $param['ext'];
            $param['index'] = $index;
            //$param['value'] = '';
            # 得到当前的值
            if (isset($data[$index]) && !isset($param['value'])) {
                $param['value'] = $data[$index];
            }
            # 得到下级的值
            if (isset($param['child_value']) && isset($data['id'])) {
                $param['child_value'] = $this->value($param['child_value'], $data);
            }
            # 验证option是否是匿名函数
            if (isset($param['option'])) {
                $param['option'] = $this->option($param['option']);
            }
            if (isset($data[$index]) && !isset($param['value']) && isset($param['key']) && $param['update'] != 'editor') {
                $param['value'] = Dever::upload($data[$index]);
            }
            # 处理下级字段
            if (isset($param['child'])) {
                $param['child'] = $this->option($param['child']);
                if (isset($data[$key . '_parent'])) {
                    $param['parent_value'] = $data[$key . '_parent'];
                }
            }
            # 设置默认值
            if (isset($param['default'])) {
                $param['default'] = $this->option($param['default']);
            }
            # 处理同步
            if (isset($param['sync']) && isset($data[$param['sync'][0]]) && strpos($key, '-')) {
                $temp = explode('-', $key);
                $load = Dever::load($temp[0] . '/' . $temp[1] . '-one', array('option_' . $param['sync'][1] => $data[$param['sync'][0]]));
                $param['value'] = isset($load[$temp[2]]) ? $load[$temp[2]] : $param['default'];
            }
            $method = $param['update'];
            if (is_array($method)) {
                $c = '';
                if (layadmin()) {
                    $c = 'layui-tab-title';
                }
                $delete = true;
                if (isset($param['option'])) {
                    $delete = false;
                    $result .= '
';
                    $order = array
                    (
                        'col'       => $key,
                        'name'      => $param['desc'],
                        'default'   => '1',
                        'desc'      => $param['desc'],
                        'match'     => 'is_string',
                        'update'    => 'hidden',
                        'option'    => $param['option']
                    );
                    array_unshift($method, $order);
                    if (isset($param['value']) && $param['value']) {
                        $value = json_decode(base64_decode($param['value']), true);
                        $param['value'] = array();
                        foreach ($param['option'] as $k => $v) {
                            foreach ($value[$k-1] as $k1 => $v1) {
                                $param['value'][$v][$k1] = $v1;
                            }
                        }
                    } else {
                        $param['value'] = array();
                        foreach ($param['option'] as $k => $v) {
                            $param['value'][$v][$key] = $k;
                        }
                    }
                } else {
                    $result .= '
';
                    $order = array
                    (
                        'col'       => 'order',
                        'name'      => '排序-按照数字正序排列',
                        'default'   => '1',
                        'desc'      => '排序',
                        'match'     => 'is_string',
                        'update'    => 'text',
                    );
                    array_unshift($method, $order);
                }
                $tab = '';
                $this->update_child(array(), $method, $key, $result, -1, $delete);
                if (isset($param['value']) && $param['value']) {
                    if (!is_array($param['value'])) {
                        $param['value'] = json_decode(base64_decode($param['value']), true);
                    }
                    if (is_array($param['value'])) {
                        $i = 0;
                        foreach ($param['value'] as $k => $v) {
                            $n = $k;
                            if (is_string($k)) {
                                $k = $i;
                            }
                            $this->update_child($v, $method, $key, $result, $k, $delete);
                            $active = '';
                            if ($k == 0) {
                                $active = 'active';
                            }
                            if (layadmin() && $active) {
                                $active .= ' layui-this';
                            }
                            $k = $k + 1;
                            if (!is_string($n)) {
                                $n = '第' . $k . '条';
                            }
                            $tab .= '
'.$n.'';
                            $i++;
                        }
                    }
                    
                } else {
                    $this->update_child(array(), $method, $key, $result, 0, $delete);
                    $tab = '
第1条';
                }
                $result = str_replace('{tab}', $tab, $result);
            } else {
                if (isset($param['update_input']) && isset($data[$index . '_input'])) {
                    $param['update_input_data'] = explode(',', $data[$index . '_input']);
                }
                $result .= Html::$method($param);
            }
            if (isset($param['desc']) && ($param['update'] == 'text' || $param['update'] == 'password')) {
                $result .= Html::desc($param['desc']);
            }
        }
    }
    /**
     * update_action
     *
     * @return array
     */
    private function update_child($data, $param, $key, &$result, $index, $delete = true)
    {
        $style = '';
        if ($index != 0) {
            $style = 'style="display:none;"';
        }
        $result .= '
';
    }
    /**
     * update_action
     *
     * @return array
     */
    public function update_action_api()
    {
        $method = false;
        $config = $this->config();
        $input = Dever::preInput('update_');
        if ($this->id) {
            # 新增权限
            if (Dever::load('manage/auth.oper', 3) == false) {
                Dever::alert('你没有权限');
            }
            Dever::setInput('where_id', $this->id);
            //Dever::setInput('update_where_id', $this->id);
            $info = $this->load('one', $this->id);
            if ($info) {
                $method = 'update';
                $col = Dever::input('col');
                $value = Dever::input('value');
                if ($col && $value) {
                    $method = 'update_' . $col;
                    //Dever::setInput('set_' . $col, $value);
                    //Dever::setInput('update_' . $col, $value);
                    $param['where_id'] = $this->id;
                    $param['set_' . $col] = $value;
                    $this->load($method, $param);
                    $struct = $this->struct_data($config['struct'], array($col => $value));
                    Log::add($this->project, $this->table, array('method' => $method, 'input' => $struct, 'struct' => $config['struct']), $this->id);
                    Dever::out('yes');
                    return;
                }
                $prefix = 'set';
            } else {
                $method = 'insert';
                $prefix = 'add';
            }
        }
        if (!$method) {
            # 新增权限
            if (Dever::load('manage/auth.oper', 4) == false) {
                Dever::alert('你没有权限');
            }
            $method = 'insert';
            $prefix = 'add';
        }
        if ($method && $input) {
            $update = $order = array();
            $i = 0;
            $c = array();
            foreach ($input as $k => $v) {
                if ($v === '') {
                    $v = 'null';
                }
                if ($v && is_string($v) && strpos($v, 'copy.') !== false) {
                    $temp = str_replace('copy.', '', $v);
                    if (isset($input['update_' . $temp])) {
                        $v = $input['update_' . $temp];
                    }
                }
                if (strpos($k, '_c_') !== false) {
                    if ($v == 'null') {
                        $v = '';
                    }
                    $temp = explode('_c_', $k);
                    $k = str_replace('update_', $prefix . '_', $temp[0]);
                    if (!isset($c[$k])) {
                        $c[$k] = array();
                    }
                    if (strpos($temp[1], '_i_') !== false) {
                        $temp = explode('_i_', $temp[1]);
                        if (!isset($c[$k][$temp[1]])) {
                            $c[$k][$temp[1]] = 0;
                        } else {
                            $c[$k][$temp[1]]++;
                        }
                        $num = $c[$k][$temp[1]];
                        $update[$i][$k][$num][$temp[1]] = $v;
                        if ($temp[1] == 'order') {
                            $order[$i][$k][$num] = $v;
                        }
                    } else {
                        //$update[$i][$k][$c][$temp[1]] = $v;
                    }
                } elseif (strpos($k, '__') !== false) {
                    $temp1 = explode('__', $k);
                    $temp2 = explode('_', $temp1[0]);
                    $i = $temp2[1] - 1;
                    if (strpos($k, 'where_id') !== false) {
                        //$update[$i]['where_id'] = $v;
                    } else {
                        $update[$i]['add_' . $temp1[1]] = $v;
                    }
                } else {
                    $ki = str_replace('update_', $prefix . '_', $k);
                    if (strpos($ki, 'where_id') !== false) {
                        if ($method != 'insert') {
                            $update[$i]['where_id'] = $v;
                        }
                    } else {
                        if (strpos($k, '-')) {
                            $k = str_replace('update_', '', $k);
                            if (isset($config['struct'][$k]) && isset($config['struct'][$k]['sync'])) {
                                $s_col = $config['struct'][$k]['sync'][0];
                                $m_col = $config['struct'][$k]['sync'][1];
                                if ($s_col == 'id') {
                                    $s_value = $this->id;
                                } else {
                                    $s_one = $this->load('one', $this->id);
                                    $s_value = $s_one[$s_col];
                                }
                                $temp = explode('-', $k);
                                $index = $temp[0] . '/' . $temp[1];
                                $update_other_set[$index]['set_' . $temp[2]] = $v;
                                //$update_other_set[$index]['set_' . $m_col] = $s_value;
                                $update_other_add[$index]['add_' . $temp[2]] = $v;
                                $update_other_add[$index]['add_' . $m_col] = $s_value;
                                $update_other_id[$index]['option_' . $m_col] = $s_value;
                            }
                        } else {
                            if (is_array($v)) {
                                $k = str_replace('update_', '', $k);
                                $kd = $k . '_id';
                                if (isset($config['struct'][$kd])) {
                                    foreach ($v as $vk => $vt) {
                                        if ($vt == -1) {
                                            if ($vk != 0) {
                                                unset($v[$vk]);
                                            }
                                        }
                                    }
                                    if ($v) {
                                        $vd = end($v);
                                        $kdi = $prefix . '_' . $kd;
                                        $update[$i][$kdi] = $vd;
                                    }
                                }
                                if (isset($config['struct'][$k]) && strpos($config['struct'][$k]['type'], 'int') !== false) {
                                    $v = end($v);
                                }
                            }
                            $update[$i][$ki] = $v;
                        }
                    }
                }
            }
            //print_r($update_other_set);die;
            //print_r($input);
            //print_r($update_other);die;
            //print_r($config['struct']);die;
            # 增加复制的数量
            $copy_num = Dever::input('copy_num');
            if ($copy_num > 0) {
                $update[0]['where_id'] = 0;
                for ($i = 1; $i < $copy_num; $i++) {
                    $update[$i] = $update[0];
                    # 缓存处理
                    $update[$i]['rank'] = $i;
                }
            }
            if ($this->id && !$info) {
                $update[0]['add_id'] = $this->id;
            }
            //print_r($update);die;
            foreach ($update as $k => $v) {
                $method = 'insert';
                $old = array();
                if (isset($v['where_id']) && $v['where_id']) {
                    $method = 'update';
                    $old = $this->load('one', $v['where_id']);
                }
                if (isset($order[$k])) {
                    foreach ($order[$k] as $i => $j) {
                        array_multisort($j, SORT_ASC, $v[$i]);
                    }
                }
                if (isset($v['set_password']) && (!$v['set_password'] || $v['set_password'] == 'null')) {
                    unset($v['set_password']);
                }
                $id = $this->load($method, $v);
                if ($id) {
                    $struct = $this->struct_data($config['struct'], $v, $old);
                    Log::add($this->project, $this->table, array('method' => $method, 'input' => $struct), $this->id ? $this->id : $id);
                }
                if (isset($update_other_id) && $update_other_id) {
                    foreach ($update_other_set as $k => $v) {
                        $check = Dever::load($k . '-one', $update_other_id[$k]);
                        //print_r($check);die;
                        if ($check) {
                            $v['where_id'] = $check['id'];
                            Dever::load($k . '-update', $v);
                        } else {
                            Dever::load($k . '-insert', $update_other_add[$k]);
                        }
                    }
                }
            }
        }
        Dever::out('yes');
    }
    private function struct_data($struct, $data, $old = array())
    {
        $log = $tlog = array();
        foreach ($struct as $i => $j) {
            if (isset($j['list_name'])) {
                $j['name'] = $j['list_name'];
            } elseif (strpos($j['name'], '-')) {
                $temp = explode('-', $j['name']);
                $j['name'] = $temp[0];
            }
            if (isset($j['list_table'])) {
                $j['list'] = $j['list_table'];
                if ($j['list'] == false) {
                    $data[$i] = false;
                }
            }
            $list = (isset($j['list']) && is_string($j['list']) && $j['list'] != 'table');
            if (isset($data['where_' . $i]) && $data['where_' . $i]) {
                $log[$j['name']] = $data['where_' . $i];
            } elseif (isset($data['set_' . $i]) && $data['set_' . $i]) {
                $log[$j['name']] = $data['set_' . $i];
            } elseif (isset($data['add_' . $i]) && $data['add_' . $i]) {
                $log[$j['name']] = $data['add_' . $i];
            } elseif (isset($data[$i]) && $data[$i]) {
                $log[$j['name']] = $list ? $this->value($j['list'], $data) : $data[$i];
            }
            if (isset($log[$j['name']])) {
                $tlog[$j['name']] = $log[$j['name']];
                if (is_array($tlog[$j['name']])) {
                    if (isset($tlog[$j['name']][0]) && is_array($tlog[$j['name']][0])) {
                        $tlog[$j['name']] = json_encode($tlog[$j['name']]);
                        if (isset($old[$i]) && is_array($old[$i])) {
                            $old[$i] = json_encode($old[$i]);
                        }
                    } elseif (isset($tlog[$j['name']][0])) {
                        $tlog[$j['name']] = implode(',', $tlog[$j['name']]);
                        if (isset($old[$i]) && is_array($old[$i])) {
                            $old[$i] = implode(',', $old[$i]);
                        }
                    }
                } elseif (strpos($log[$j['name']], 'http://wx.qlogo.cn/') !== false || strpos($log[$j['name']], '.jpg') !== false || strpos($log[$j['name']], '.gif') !== false || strpos($log[$j['name']], '.png') !== false) {
                    $log[$j['name']] = '

';
                    if (isset($old[$i]) && $old[$i]) {
                        $old[$i] = '

';
                    }
                } elseif (is_numeric($log[$j['name']]) && (strpos($i, 'time') !== false || strpos($i, 'date') !== false)) {
                    $log[$j['name']] = date("Y-m-d H:i:s", $log[$j['name']]);
                    if (isset($old[$i]) && $old[$i]) {
                        $old[$i] = date("Y-m-d H:i:s", $old[$i]);
                    }
                } elseif (isset($j['decode'])) {
                    $log[$j['name']] = json_decode(base64_decode($log[$j['name']]), true);
                    if (isset($old[$i]) && $old[$i]) {
                        $old[$i] = json_decode(base64_decode($old[$i]), true);
                    }
                }
                if (isset($j['option']) && !$list) {
                    $name = array();
                    $option = $this->option($j['option']);
                    if (is_array($option)) {
                       foreach ($option as $a => $b) {
                            if (!is_array($log[$j['name']])) {
                                if ($a == $log[$j['name']]) {
                                    $name[] = (is_array($b) && isset($b['name'])) ? $b['name'] : $b;
                                }
                            } elseif (in_array($a, $log[$j['name']])) {
                                $name[] = (is_array($b) && isset($b['name'])) ? $b['name'] : $b;
                            }
                        }
                    }
                    
                    $log[$j['name']] = implode(',', $name);
                }
                if (isset($old[$i]) && $old[$i] != $tlog[$j['name']]) {
                    $log[$j['name']] = array('old' => $old[$i], 'new' => $log[$j['name']]);
                }
            }
        }
        return $log;
    }
    /**
     * delete_action
     *
     * @return array
     */
    public function delete_action_api()
    {
        if (Dever::load('manage/auth.oper', 5) == false) {
            Dever::alert('您没有权限');
        }
        $config = $this->config();
        if (isset($config['manage']['delete']) && $config['manage']['delete'] === 2) {
            $this->load('delete', array('where_id' => $this->id));
        } elseif (isset($config['struct']['state']) && (!isset($config['manage']['delete']) || (isset($config['manage']['delete']) && $config['manage']['delete']))) {
            $this->load('update', array('where_id' => $this->id, 'state' => 2));
        }
        return 'reload';
        return 'reloaderror';
    }
    /**
     * recovery_action
     *
     * @return array
     */
    public function recovery_action_api()
    {
        if (Dever::load('manage/auth.oper', 5) == false) {
            Dever::alert('您没有权限');
        }
        $this->load('update', array('where_id' => $this->id, 'state' => 1));
        return 'reload';
    }
    /**
     * stat 为主动统计提供相关数据
     *
     * @return array
     */
    public function stat()
    {
        //bundle 包依赖工具
        $config = $this->config();
        if (empty($config['manage']['stat'])) {
            Dever::alert('该项目主动统计功能未开放');
        }
        $data = $config['manage'];
        $data['table'] = '';
        $method = $this->project . '/' . $this->table . '-all';
        $gp = Dever::input('gp', 'month,day');
        $col = is_string($gp) ? explode(',', $gp) : $gp;
        $data['search'] = $this->stat_search($config['struct'], $gp, $config['manage']['stat'], $config['manage']['search']);
        foreach ($col as $k => $v) {
            $this->stat_data($data, $config['struct'], $v, $method);
        }
        return $data;
    }
    /**
     * stat 为主动统计提供导出数据 后续优化
     *
     * @return array
     */
    public function stat_excel()
    {
        Dever::$global['base']['excel'] = 1;
        //print_r($data['thead']);die;
        $data = $this->stat();
        if ($data && isset($data['list'])) {
            $xls = new \PHPExcel();
            $xls->getProperties()->setCreator("Maze Stat Excel")
                ->setLastModifiedBy("Maze Stat Excel")
                ->setTitle("Office 2007 XLSX Maze Document")
                ->setSubject("Office 2007 XLSX Maze Document")
                ->setDescription("Mazephp Stat Excel")
                ->setKeywords("Mazephp Stat Excel")
                ->setCategory("Mazephp Stat Excel");
            $info = $this->info();
            $name = $info['list_header'] . '的' . $info['stat_desc'] . '-' . $info['project_name'];
            $start = 65;
            $s = 0;
            foreach ($data['thead'] as $k => $v) {
                if ($s > 0) {
                    $xls->createSheet();
                }
                $act = $xls->setActiveSheetIndex($s);
                $act->setTitle($v[0]);
                $s++;
                $i = 0;
                foreach ($v as $kj => $vj) {
                    $num = 1;
                    $cell = $this->_getChr($start, $i);
                    $act->setCellValue($cell . '' . $num, $vj);
                    $act->getColumnDimension($cell)->setWidth(20);
                    $i++;
                    if (isset($data['list'][$k])) {
                        foreach ($data['list'][$k] as $ki => $vi) {
                            if (isset($vi[$kj])) {
                                $num += 1;
                                $act->setCellValue($cell . $num, $vi[$kj]);
                            }
                        }
                    }
                }
            }
            //$act->getStyle('A1:'.$k.'20')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);   // 垂直居中
            //$act->getStyle('A1:'.$k.'20')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);// 水平居中
            $xls->setActiveSheetIndex(0);
            $filename = $name . '.xlsx';
            header('Pragma: public');
            header('Expires: 0');
            header('Cache-Control:must-revalidate,post-check=0,pre-check=0');
            header('Content-Type:application/force-download');
            header('Content-Type:application/vnd.ms-execl');
            header('Content-Type:application/octet-stream');
            header('Content-Type:application/download');
            header("Content-Disposition:attachment;filename='" . $filename . "'");
            header('Content-Transfer-Encoding:binary');
            $write = \PHPExcel_IOFactory::createWriter($xls, 'Excel2007');
            $write->save('php://output');
        }
    }
    /**
     * stat_search
     *
     * @return mixed
     */
    private function stat_search($struct, $col, $stat, $search)
    {
        unset($struct['id']);
        unset($struct['cdate']);
        if ($stat) {
            $stat = explode(',', $stat);
            foreach ($stat as $k => $v) {
                if (isset($struct[$v])) {
                    unset($struct[$v]);
                }
            }
        }
        $struct['day']['name'] = '天';
        $struct['month']['name'] = '月';
        $struct['year']['name'] = '年';
        $param['update'] = 'checkbox';
        $param['name'] = 'gp';
        $param['value'] = $col;
        $param['option'] = $struct;
        $html = '
';
        return $html;
    }
    /**
     * stat_data
     *
     * @return mixed
     */
    private function stat_data(&$data, $struct, $col, $method)
    {
        Dever::setInput('group', $col);
        switch ($col) {
            case 'year':
                $name = '按年统计';
                break;
            case 'month':
                $name = '按月统计';
                break;
            case 'day':
                $name = '按天统计';
                break;
            default:
                $name = $struct[$col]['name'];
                break;
        }
        $list = Dever::load($method, array('group' => $col, 'col' => 'count(1) as total,id'));
        $data['table'] .= '
';
        $data['table'] .= '| ' . $name . ' | 统计数字 | 
|---|
';
        $data['thead'][$col] = array($name, '统计数字');
        if ($list) {
            $data['table'] .= '';
            $total = 0;
            foreach ($list as $k => $v) {
                if (isset($v[$col])) {
                    if (isset($struct[$col]['option'])) {
                        $option = $this->option($struct[$col]['option']);
                        if (isset($option[$v[$col]])) {
                            $v[$col] = $option[$v[$col]];
                            if (is_array($v[$col])) {
                                $v[$col] = $v[$col]['name'];
                            }
                        }
                    }
                    $data['table'] .= '| ' . $v[$col] . ' | ' . $v['total'] . ' | 
';
                    $total += $v['total'];
                    $data['list'][$col][] = array($v[$col], $v['total']);
                }
            }
            $data['table'] .= '';
            if ($total > 0 && $k > 0) {
                $data['table'] .= '| 汇总 | ' . $total . ' | 
';
                $data['list'][$col][] = array('汇总', $total);
            }
        }
        $data['table'] .= '
';
    }
    /**
     * load
     *
     * @return mixed
     */
    private function load($method = 'one', $param = array())
    {
        return Dever::load($this->project . '/' . $this->table . '-' . $method, $param);
    }
    /**
     * __call
     *
     * @return object
     */
    public function __call($method, $param)
    {
        if (strpos($method, 'html_') !== false) {
            return Html::text($param);
        }
        return $this;
    }
    /**
     * option
     *
     * @return string
     */
    private function option($option, $value = false)
    {
        if (is_object($option)) {
            $function = $option;
            $option = $function();
        }
        if ($value && is_array($value)) {
            $state = false;
            foreach ($value as $k => $v) {
                if ($v === true) {
                    $state = true;
                    break;
                }
            }
            if ($state) {
                $option = array_intersect_key($option, $value);
            } else {
                $option = $value;
            }
        }
        return $option;
    }
    /**
     * option
     *
     * @return string
     */
    public function manage()
    {
        $config = $this->config();
        return $config;
    }
    /**
     * valid
     *
     * @return string
     */
    public function valid()
    {
        //http://placehold.it/350x150
        $config = $this->config();
        if (isset($config['struct'])) {
            $rule = array();
            $rule['required']['regex'] = 'none';
            $rule['required']['alertText'] = '此项不能为空';
            $rule['required']['alertTextCheckboxMultiple'] = '请选择一个选项';
            $rule['required']['alertTextCheckboxe'] = '请选择一个选项';
            $rule['required']['alertTextDateRange'] = '日期范围不可空白';
            foreach ($config['struct'] as $k => $v) {
                if (isset($v['match']) && $v['match'] != 'option' && is_string($v['match']) && strpos($v['match'], '/') !== false) {
                    if (strstr($v['match'], 'option||')) {
                        $v['match'] = str_replace('option||', '', $v['match']);
                    }
                    $rule[$k]['regex'] = $v['match'];
                    $rule[$k]['alertText'] = $v['desc'];
                }
            }
        }
        $script = '';
        //print_r($script);die;
        return $script;
    }
    /**
     * save
     *
     * @return string
     */
    public function save()
    {
        $config = $this->config();
        if (isset($config['manage']['save'])) {
            return 'yes';
        }
        return 'no';
    }
}