$v) {
$k = explode('.', $k);
$time = $v['time'];
unset($v['time']);
$this->update($k[0], $k[1], implode(',', $v), false, $time);
}
}
return 1;
}
public function get($id)
{
$opt = is_array($id) ? $id : Dever::db('manage/opt')->one($id);
$db = Dever::db($opt['project'] . '/' . $opt['table']);
if (empty($db->config['lang'])) {
return;
}
$result['table'] = $db->config['lang'] . '
' . $opt['table'];
$result['total'] = Dever::load($opt['project'] . '/' . $opt['table'] . '-total');
$table = '[表结构]:';
if ($result['total'] > 0) {
$table .= '数据总数('.$result['total'].')';
}
$table .= '
';
$table .= Dever::tbody(array('字段', '类型-长度', '名称'));
foreach ($db->config['struct'] as $k => $v) {
if (isset($v['type'])) {
$temp = Html::cue(array('name' => $v['name']));
$v['name'] = $temp['name'];
$table .= Dever::tbody(array($k, $v['type'], $v['name']));
}
}
$table .= '
';
$table .= '
[常用字段]:';
$table .= Dever::tbody(array('字段', '说明'));
$col = explode(',', $opt['col']);
$index = array();
foreach ($col as $k => $v) {
if (isset($db->config['struct'][$v])) {
$struct = $db->config['struct'][$v];
if ($v == 'id') {
$struct['name'] = '主键,无需索引';
} elseif ((isset($struct['option']) && is_array($struct['option']) && count($struct['option']) <= 2) || strpos($struct['type'], 'tinyint') !== false) {
$struct['name'] = '不同值较少,无需索引';
} else {
$index[$v] = $v;
}
$table .= Dever::tbody(array($v, $struct['name']));
}
}
$table .= '
';
if ($opt['col_index']) {
$table .= '
已为('.$opt['col_index'].')建立索引,版本号:';
} else {
$table .= '';
}
if ($index) {
$index = implode(',', $index);
$result['index'] = $index;
$table .= '
建议索引:'.self::INDEX.'-';
$url = Dever::url('opt.index?id=' . $opt['id']);
$table .= ' 点此更新索引';
}
$result['text'] = $table;
return $result;
}
public function index_api()
{
$id = Dever::input('id');
$config = Dever::load('manage/opt-one', $id);
if ($config) {
$info = $this->get($config);
if (isset($info['index'])) {
$index = array();
$info['index'] = Dever::input('index', $info['index']);
$index['version'] = Dever::input('version', 0);
$index['version'] += 1;
$index[$index['version']] = array
(
self::INDEX => $info['index']
);
Dever::load($config['project'] . '/' . $config['table'] . '-index', $index);
Dever::load('manage/opt-update', array('set_status' => 2, 'set_version' => $index['version'], 'set_col_index' => $info['index'], 'where_id' => $id));
}
}
Dever::out('yes');
}
private function update($project, $table, $col, $method = false, $time = 0)
{
if ($project == 'manage') {
return;
}
$param['option_project'] = $project;
$param['option_table'] = $table;
if ($method) $param['option_method'] = $method;
$id = -1;
if ($col) {
$info = Dever::db('manage/opt')->one($param);
if ($info) {
$param['where_id'] = $info['id'];
$param['set_col'] = array();
$col = explode(',', $col);
$info['col'] = explode(',', $info['col']);
foreach ($info['col'] as $v) {
$param['set_col'][$v] = $v;
}
foreach ($col as $v) {
$param['set_col'][$v] = $v;
}
$param['set_col'] = implode(',', $param['set_col']);
$param['set_time'] = $time;
$param['set_num'] = 1;
Dever::db('manage/opt')->updateNum($param);
$id = $info['id'];
} else {
$param['add_project'] = $param['option_project'];
$param['add_table'] = $param['option_table'];
if($method) $param['add_method'] = $param['option_method'];
$param['add_col'] = $col;
$param['add_time'] = $time;
$param['add_num'] = 1;
$param['add_status'] = 1;
$id = Dever::db('manage/opt')->insert($param);
}
}
return $id;
}
}