重新定义模型
This commit is contained in:
@@ -46,19 +46,7 @@ class Attribute extends Admin {
|
|||||||
* @author colin <colin@tensent.cn>
|
* @author colin <colin@tensent.cn>
|
||||||
*/
|
*/
|
||||||
public function index($model_id = null) {
|
public function index($model_id = null) {
|
||||||
$map['model_id'] = $model_id;
|
$this->getAttributeList($model_id);
|
||||||
if (!$model_id) {
|
|
||||||
return $this->error("非法操作!");
|
|
||||||
}
|
|
||||||
|
|
||||||
$list = model('Attribute')->where($map)->order('id desc')->paginate(25);
|
|
||||||
|
|
||||||
$data = array(
|
|
||||||
'list' => $list,
|
|
||||||
'model_id' => $model_id,
|
|
||||||
'page' => $list->render(),
|
|
||||||
);
|
|
||||||
$this->assign($data);
|
|
||||||
$this->setMeta('字段管理');
|
$this->setMeta('字段管理');
|
||||||
return $this->fetch();
|
return $this->fetch();
|
||||||
}
|
}
|
||||||
@@ -120,13 +108,15 @@ class Attribute extends Admin {
|
|||||||
* @var delattr 是否删除字段表里的字段
|
* @var delattr 是否删除字段表里的字段
|
||||||
* @author colin <colin@tensent.cn>
|
* @author colin <colin@tensent.cn>
|
||||||
*/
|
*/
|
||||||
public function del() {
|
public function del(\think\Request $request) {
|
||||||
$id = input('id', '', 'trim,intval');
|
$id = $request->param('id');
|
||||||
|
$model_id = $request->param('model_id');
|
||||||
|
|
||||||
if (!$id) {
|
if (!$id) {
|
||||||
return $this->error("非法操作!");
|
return $this->error("非法操作!");
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = $this->model->del($id);
|
$result = $this->model->del($id, $model_id);
|
||||||
if ($result) {
|
if ($result) {
|
||||||
return $this->success("删除成功!");
|
return $this->success("删除成功!");
|
||||||
} else {
|
} else {
|
||||||
@@ -134,6 +124,47 @@ class Attribute extends Admin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function generate($id = '') {
|
||||||
|
if ($id) {
|
||||||
|
$model = model('Model')->where('id', $id)->find();
|
||||||
|
$result = $this->model->generate($model);
|
||||||
|
if (false !== $result) {
|
||||||
|
return $this->success('生成成功!', url('admin/model/index'));
|
||||||
|
} else {
|
||||||
|
return $this->error($this->model->getError());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return $this->error('非法操作!');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function insert(\think\Request $request) {
|
||||||
|
if (IS_POST) {
|
||||||
|
$model_id = $request->param('id');
|
||||||
|
$attr = db('Model')->where('id', $model_id)->value('attribute_list');
|
||||||
|
$attr = explode(',', $attr);
|
||||||
|
$post = $request->post();
|
||||||
|
$attribute = array_merge($attr, $post['id']);
|
||||||
|
|
||||||
|
$data = array(
|
||||||
|
'attribute_list' => implode(',', $attribute),
|
||||||
|
'table_status' => 2,
|
||||||
|
'status' => 0,
|
||||||
|
);
|
||||||
|
$result = db('Model')->where('id', $model_id)->update($data);
|
||||||
|
if (false !== $result) {
|
||||||
|
return $this->success('成功导入!');
|
||||||
|
}else{
|
||||||
|
return $this->error('导入失败!');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$this->getAttributeList();
|
||||||
|
$this->assign('id', $request->param('id'));
|
||||||
|
$this->setMeta('导入字段');
|
||||||
|
return $this->fetch();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//字段编辑所需字段
|
//字段编辑所需字段
|
||||||
protected function getField() {
|
protected function getField() {
|
||||||
return array(
|
return array(
|
||||||
@@ -161,4 +192,21 @@ class Attribute extends Admin {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getAttributeList($model_id = '') {
|
||||||
|
$map = array();
|
||||||
|
if ($model_id) {
|
||||||
|
$attribute = db('Model')->where('id', $model_id)->value('attribute_list');
|
||||||
|
$map['id'] = array('IN', $attribute);
|
||||||
|
}
|
||||||
|
|
||||||
|
$list = model('Attribute')->where($map)->order('id desc')->paginate(25);
|
||||||
|
|
||||||
|
$data = array(
|
||||||
|
'list' => $list,
|
||||||
|
'model_id' => $model_id,
|
||||||
|
'page' => $list->render(),
|
||||||
|
);
|
||||||
|
$this->assign($data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -16,20 +16,13 @@ class Content extends Admin {
|
|||||||
parent::_initialize();
|
parent::_initialize();
|
||||||
$this->getContentMenu();
|
$this->getContentMenu();
|
||||||
$this->model_id = $model_id = $this->request->param('model_id');
|
$this->model_id = $model_id = $this->request->param('model_id');
|
||||||
$row = db('Model')->select();
|
$list = db('Model')->column('*', 'id');
|
||||||
foreach ($row as $key => $value) {
|
|
||||||
$list[$value['id']] = $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (empty($list[$model_id])) {
|
if (empty($list[$model_id])) {
|
||||||
return $this->error("无此模型!");
|
return $this->error("无此模型!");
|
||||||
} else {
|
} else {
|
||||||
$this->modelInfo = $list[$model_id];
|
$this->modelInfo = $list[$model_id];
|
||||||
if ($this->modelInfo['extend'] > 1) {
|
$this->model = model('Content')->extend($this->modelInfo['name']);
|
||||||
$this->model = model('Content')->extend($this->modelInfo['name']);
|
|
||||||
} else {
|
|
||||||
$this->model = model('Document')->extend($this->modelInfo['name']);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->assign('model_id', $model_id);
|
$this->assign('model_id', $model_id);
|
||||||
@@ -49,11 +42,7 @@ class Content extends Admin {
|
|||||||
$order = "id desc";
|
$order = "id desc";
|
||||||
$map = $this->buildMap();
|
$map = $this->buildMap();
|
||||||
$field = array_filter($grid_list['fields']);
|
$field = array_filter($grid_list['fields']);
|
||||||
if ($this->modelInfo['extend'] == 1) {
|
|
||||||
array_push($field, 'is_top');
|
|
||||||
} else {
|
|
||||||
unset($map['model_id']);
|
|
||||||
}
|
|
||||||
|
|
||||||
$list = $this->model->lists($map, $order);
|
$list = $this->model->lists($map, $order);
|
||||||
|
|
||||||
@@ -247,7 +236,7 @@ class Content extends Admin {
|
|||||||
*/
|
*/
|
||||||
protected function buildMap() {
|
protected function buildMap() {
|
||||||
$map = array();
|
$map = array();
|
||||||
$data = $this->request->get();
|
$data = $this->request->param();
|
||||||
foreach ($data as $key => $value) {
|
foreach ($data as $key => $value) {
|
||||||
if ($value) {
|
if ($value) {
|
||||||
if ($key == 'keyword') {
|
if ($key == 'keyword') {
|
||||||
@@ -264,12 +253,6 @@ class Content extends Admin {
|
|||||||
if (isset($map['page'])) {
|
if (isset($map['page'])) {
|
||||||
unset($map['page']);
|
unset($map['page']);
|
||||||
}
|
}
|
||||||
if ($this->modelInfo['extend'] == 1) {
|
|
||||||
$category = isset($data['category']) ? $data['category'] : '';
|
|
||||||
$cate_list = parse_field_bind('category', $category, 0);
|
|
||||||
$map['model_id'] = $this->model_id;
|
|
||||||
$this->assign('cate_list', $cate_list);
|
|
||||||
}
|
|
||||||
$this->assign($data);
|
$this->assign($data);
|
||||||
return $map;
|
return $map;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ class Model extends Admin {
|
|||||||
public function _initialize() {
|
public function _initialize() {
|
||||||
parent::_initialize();
|
parent::_initialize();
|
||||||
$this->getContentMenu();
|
$this->getContentMenu();
|
||||||
|
$this->model = model('Model');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -25,7 +26,7 @@ class Model extends Admin {
|
|||||||
$map = array('status' => array('gt', -1));
|
$map = array('status' => array('gt', -1));
|
||||||
|
|
||||||
$order = "id desc";
|
$order = "id desc";
|
||||||
$list = model('Model')->where($map)->order($order)->paginate(10);
|
$list = $this->model->where($map)->order($order)->paginate(10);
|
||||||
|
|
||||||
$data = array(
|
$data = array(
|
||||||
'list' => $list,
|
'list' => $list,
|
||||||
@@ -44,75 +45,73 @@ class Model extends Admin {
|
|||||||
* 新增页面初始化
|
* 新增页面初始化
|
||||||
* @author huajie <banhuajie@163.com>
|
* @author huajie <banhuajie@163.com>
|
||||||
*/
|
*/
|
||||||
public function add() {
|
public function add(\think\Request $request) {
|
||||||
|
if (IS_POST) {
|
||||||
//获取所有的模型
|
$result = $this->model->validate('Model.add')->save($request->post());
|
||||||
$models = db('Model')->where(array('extend' => 0))->field('id,title')->select();
|
if (false !== $result) {
|
||||||
|
$this->success('创建成功!', url('admin/model/index'));
|
||||||
$this->assign('models', $models);
|
}else{
|
||||||
$this->setMeta('新增模型');
|
return $this->error($this->model->getError());
|
||||||
return $this->fetch();
|
}
|
||||||
|
}else{
|
||||||
|
$this->setMeta('新增模型');
|
||||||
|
return $this->fetch();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 编辑页面初始化
|
* 编辑页面初始化
|
||||||
* @author huajie <banhuajie@163.com>
|
* @author molong <molong@tensent.cn>
|
||||||
*/
|
*/
|
||||||
public function edit() {
|
public function edit(\think\Request $request) {
|
||||||
$id = input('id', '', 'trim,intval');
|
if (IS_POST) {
|
||||||
if (empty($id)) {
|
$result = $this->model->validate('Model.edit')->save($request->post(), array('id'=>$request->post('id')));
|
||||||
return $this->error('参数不能为空!');
|
if (false !== $result) {
|
||||||
}
|
$this->success('更新成功!', url('admin/model/index'));
|
||||||
|
}else{
|
||||||
/*获取一条记录的详细数据*/
|
return $this->error($this->model->getError());
|
||||||
$model = model('Model');
|
|
||||||
$data = $model::find($id);
|
|
||||||
if (!$data) {
|
|
||||||
return $this->error($Model->getError());
|
|
||||||
}
|
|
||||||
$data['attribute_list'] = empty($data['attribute_list']) ? '' : explode(",", $data['attribute_list']);
|
|
||||||
|
|
||||||
// 是否继承了其他模型
|
|
||||||
if ($data['extend'] == 1) {
|
|
||||||
$map['model_id'] = array('IN', array($data['id'], $data['extend']));
|
|
||||||
} else {
|
|
||||||
$map['model_id'] = $data['id'];
|
|
||||||
}
|
|
||||||
$map['is_show'] = 1;
|
|
||||||
$fields = db('Attribute')->where($map)->select();
|
|
||||||
|
|
||||||
// 梳理属性的可见性
|
|
||||||
foreach ($fields as $key => $field) {
|
|
||||||
if (!empty($data['attribute_list']) && !in_array($field['id'], $data['attribute_list'])) {
|
|
||||||
$field['is_show'] = 0;
|
|
||||||
}
|
}
|
||||||
$field['group'] = -1;
|
}else{
|
||||||
$field['sort'] = 0;
|
$info = $this->model->where('id', $request->param('id'))->find();
|
||||||
$fields_tem[$field['id']] = $field;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取模型排序字段
|
//获取字段列表
|
||||||
$field_sort = json_decode($data['field_sort'], true);
|
if ($info['attribute_list']) {
|
||||||
if (!empty($field_sort)) {
|
$fields = model('Attribute')->where('id', 'IN', $info['attribute_list'])->where('is_show', 1)->select();
|
||||||
foreach ($field_sort as $group => $ids) {
|
// 梳理属性的可见性
|
||||||
foreach ($ids as $key => $value) {
|
foreach ($fields as $key => $field) {
|
||||||
if (!empty($fields_tem[$value])) {
|
$field['group'] = -1;
|
||||||
$fields_tem[$value]['group'] = $group;
|
$field['sort'] = 0;
|
||||||
$fields_tem[$value]['sort'] = $key;
|
$fields_tem[$field['id']] = $field->toArray(); //数据对象转换为数组
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取模型排序字段
|
||||||
|
$field_sort = json_decode($info['attribute_sort'], true);//dump($field_sort);exit();
|
||||||
|
if (!empty($field_sort)) {
|
||||||
|
foreach ($field_sort as $group => $ids) {
|
||||||
|
foreach ($ids as $key => $value) {
|
||||||
|
if (!empty($fields_tem[$value])) {
|
||||||
|
$fields_tem[$value]['group'] = $group;
|
||||||
|
$fields_tem[$value]['sort'] = $key;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isset($fields_tem) && $fields_tem) {
|
||||||
|
// 模型字段列表排序
|
||||||
|
$fields = list_sort_by($fields_tem, "sort");
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
$fields = array();
|
||||||
}
|
}
|
||||||
|
$data = array(
|
||||||
|
'info' => $info,
|
||||||
|
'fields' => $fields
|
||||||
|
);
|
||||||
|
$this->assign($data);
|
||||||
|
$this->setMeta('编辑模型');
|
||||||
|
return $this->fetch();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($fields_tem) && $fields_tem) {
|
|
||||||
// 模型字段列表排序
|
|
||||||
$fields = list_sort_by($fields_tem, "sort");
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->assign('fields', $fields);
|
|
||||||
$this->assign('info', $data);
|
|
||||||
$this->setMeta('编辑模型');
|
|
||||||
return $this->fetch();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -120,12 +119,11 @@ class Model extends Admin {
|
|||||||
* @author huajie <banhuajie@163.com>
|
* @author huajie <banhuajie@163.com>
|
||||||
*/
|
*/
|
||||||
public function del() {
|
public function del() {
|
||||||
$mdoel = model('Model');
|
$result = $this->model->del();
|
||||||
$result = $mdoel->del();
|
|
||||||
if ($result) {
|
if ($result) {
|
||||||
return $this->success('删除模型成功!');
|
return $this->success('删除模型成功!');
|
||||||
} else {
|
} else {
|
||||||
return $this->error($mdoel->getError());
|
return $this->error($this->mdoel->getError());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,24 +144,27 @@ class Model extends Admin {
|
|||||||
* 更新数据
|
* 更新数据
|
||||||
* @author colin <colin@tensent.cn>
|
* @author colin <colin@tensent.cn>
|
||||||
*/
|
*/
|
||||||
public function status() {
|
public function status(\think\Request $request) {
|
||||||
$map['id'] = $this->request->param('ids');
|
$map['id'] = $request->param('id');
|
||||||
if (null == $map['id']) {
|
|
||||||
|
$data['status'] = $request->param('status');
|
||||||
|
|
||||||
|
if (null == $map['id'] || null == $data['status']) {
|
||||||
return $this->error('参数不正确!');
|
return $this->error('参数不正确!');
|
||||||
}
|
}
|
||||||
|
|
||||||
$data['status'] = input('get.status');
|
$model = $this->model->where($map)->find();
|
||||||
|
if ($model['table_status'] != 1 && $data['status'] == 1) {
|
||||||
if (null == $data['status']) {
|
return $this->error('数据表未创建或更新');
|
||||||
//实现单条数据数据修改
|
}
|
||||||
$status = db('Model')->where($map)->field('status')->find();
|
if ($model['list_grid'] == '' && $data['status'] == 1) {
|
||||||
$data['status'] = $status['status'] ? 0 : 1;
|
return $this->error('模型列表未定义');
|
||||||
db('Model')->where($map)->update($data);
|
}
|
||||||
} else {
|
$result = $this->model->where($map)->update($data);
|
||||||
//实现多条数据同时修改
|
if (false !== $result) {
|
||||||
$map['id'] = array('IN', $map['id']);
|
return $this->success('状态设置成功!');
|
||||||
db('Model')->where($map)->update($data);
|
}else{
|
||||||
|
return $this->error($this->model->getError());
|
||||||
}
|
}
|
||||||
return $this->success('状态设置成功!');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7271,3 +7271,5 @@ to {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
span.reloadverify{padding: 0; overflow: hidden; cursor: pointer;}
|
span.reloadverify{padding: 0; overflow: hidden; cursor: pointer;}
|
||||||
|
.footer-bar{position: fixed; bottom: 0; left: 0; right: 0; background: #fff; overflow: hidden; padding: 10px; text-align: right; z-index: 10000;}
|
||||||
|
.dialog-body{padding: 10px; padding-bottom: 60px;}
|
||||||
@@ -6,9 +6,13 @@
|
|||||||
<h2>{$meta_title}</h2>
|
<h2>{$meta_title}</h2>
|
||||||
</div>
|
</div>
|
||||||
<div class="pull-right">
|
<div class="pull-right">
|
||||||
<a class="btn btn-info" href="{:url('Model/index')}">返回</a>
|
<a class="btn btn-danger" href="{:url('add',array('model_id'=>$model_id))}"><i class="fa fa-plus"></i> 新 增</a>
|
||||||
<a class="btn btn-primary" href="{:url('add',array('model_id'=>$model_id))}">新 增</a>
|
{if $model_id}
|
||||||
<button class="btn btn-danger ajax-post confirm" url="{:url('del')}" target-form="ids">删 除</button>
|
<button class="btn btn-primary openDilog" url="{:url('insert?id='.$model_id)}">导入字段</button>
|
||||||
|
<button class="btn btn-primary ajax-get" url="{:url('generate?id='.$model_id)}">生成数据库</button>
|
||||||
|
{/if}
|
||||||
|
<!-- <button class="btn btn-danger ajax-post confirm" url="{:url('del')}" target-form="ids"><i class="fa fa-remove"></i> 删 除</button> -->
|
||||||
|
<a class="btn btn-warning" href="{:url('Model/index')}"><i class="fa fa-reply"></i> 返回</a>
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
<div class="main-box-body clearfix">
|
<div class="main-box-body clearfix">
|
||||||
@@ -36,7 +40,7 @@
|
|||||||
<td>{$item['value']}</td>
|
<td>{$item['value']}</td>
|
||||||
<td>
|
<td>
|
||||||
<a href="{:url('edit',array('id'=>$item['id']))}">编辑</a>
|
<a href="{:url('edit',array('id'=>$item['id']))}">编辑</a>
|
||||||
<a href="{:url('del',array('id'=>$item['id']))}" class="confirm ajax-get">删除</a>
|
<a href="{:url('del',array('id'=>$item['id'], 'model_id'=>$model_id))}" class="confirm ajax-get">删除</a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{/volist}
|
{/volist}
|
||||||
@@ -47,3 +51,18 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{/block}
|
{/block}
|
||||||
|
{block name="script"}
|
||||||
|
<script type="text/javascript" src="__PUBLIC__/plugs/layer/layer.js"></script>
|
||||||
|
<script type="text/javascript">
|
||||||
|
$(function(){
|
||||||
|
$('.openDilog').click(function(){
|
||||||
|
layer.open({
|
||||||
|
type: 2,
|
||||||
|
title: false,
|
||||||
|
area: ['900px', '560px'],
|
||||||
|
content: $('.openDilog').attr('url')
|
||||||
|
});
|
||||||
|
});
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
{/block}
|
||||||
60
application/admin/view/attribute/insert.html
Normal file
60
application/admin/view/attribute/insert.html
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
{include file="admin@public/header" /}
|
||||||
|
<div class="dialog-body">
|
||||||
|
<div class="main-box clearfix">
|
||||||
|
<header class="main-box-header clearfix">
|
||||||
|
<div class="pull-left">
|
||||||
|
<h2>{$meta_title}</h2>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
<div class="main-box-body clearfix">
|
||||||
|
<div class="table-responsive clearfix">
|
||||||
|
<table class="table table-hover">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th><input class="checkbox check-all" type="checkbox"></th>
|
||||||
|
<th>表单标题</th>
|
||||||
|
<th>字段名</th>
|
||||||
|
<th>字段类型</th>
|
||||||
|
<th>字段长度</th>
|
||||||
|
<th>默认值</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{volist name="list" id="item"}
|
||||||
|
<tr>
|
||||||
|
<td><input class="ids row-selected" type="checkbox" name="id[]" value="{$item['id']}"></td>
|
||||||
|
<td>{$item['title']}</td>
|
||||||
|
<td>{$item['name']}</td>
|
||||||
|
<td>{$item['type_text']}</td>
|
||||||
|
<td>{$item['length']}</td>
|
||||||
|
<td>{$item['value']}</td>
|
||||||
|
</tr>
|
||||||
|
{/volist}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
{$page}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="footer-bar">
|
||||||
|
<button class="btn btn-primary insert-btn">确认导入</button>
|
||||||
|
</div>
|
||||||
|
<script type="text/javascript">
|
||||||
|
var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
|
||||||
|
//关闭iframe
|
||||||
|
$('button.insert-btn').click(function(){
|
||||||
|
$.ajax({
|
||||||
|
url : "{:url('admin/attribute/insert?id='.$id)}",
|
||||||
|
data : $('input.ids:checked').serialize(),
|
||||||
|
type : "POST",
|
||||||
|
success : function(res){
|
||||||
|
if (res.code == 1) {
|
||||||
|
parent.layer.close(index);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
dataType : 'json'
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
{include file="admin@public/footer" /}
|
||||||
@@ -12,7 +12,7 @@
|
|||||||
<div class="main-box-body clearfix">
|
<div class="main-box-body clearfix">
|
||||||
|
|
||||||
<!-- 表单 -->
|
<!-- 表单 -->
|
||||||
<form id="form" action="{:url('update')}" method="post" class="form-horizontal form">
|
<form id="form" method="post" class="form-horizontal form">
|
||||||
<!-- 基础 -->
|
<!-- 基础 -->
|
||||||
<div id="tab1" class="tab-pane in tab1">
|
<div id="tab1" class="tab-pane in tab1">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
@@ -29,50 +29,6 @@
|
|||||||
<span class="help-block">(请输入模型的名称)</span>
|
<span class="help-block">(请输入模型的名称)</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
|
||||||
<label class="col-lg-2 control-label">模型类型</label>
|
|
||||||
<div class="col-lg-3 col-sm-10">
|
|
||||||
<select name="extend" class="form-control" style="width:auto">
|
|
||||||
<option value="2">独立模型</option>
|
|
||||||
<option value="1" selected="selected">文档模型</option>
|
|
||||||
</select>
|
|
||||||
<span class="help-block">(目前只支持独立模型和文档模型)</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label class="col-lg-2 control-label">引擎类型</label>
|
|
||||||
<div class="col-lg-3 col-sm-10">
|
|
||||||
<select name="engine_type" class="form-control" style="width:auto">
|
|
||||||
<option value="MyISAM">MyISAM</option>
|
|
||||||
<option value="InnoDB">InnoDB</option>
|
|
||||||
<option value="MEMORY">MEMORY</option>
|
|
||||||
<option value="BLACKHOLE">BLACKHOLE</option>
|
|
||||||
<option value="MRG_MYISAM">MRG_MYISAM</option>
|
|
||||||
<option value="ARCHIVE">ARCHIVE</option>
|
|
||||||
</select>
|
|
||||||
<span class="help-block"></span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label class="col-lg-2 control-label">是否需要主键</label>
|
|
||||||
<div class="col-lg-10">
|
|
||||||
<select name="need_pk" class="form-control" style="width:auto">
|
|
||||||
<option value="1" selected="selected">是</option>
|
|
||||||
<option value="0">否</option>
|
|
||||||
</select>
|
|
||||||
<span class="help-block">(选“是”则会新建默认的id字段作为主键)</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label class="col-lg-2 control-label">是否会员显示</label>
|
|
||||||
<div class="col-lg-10">
|
|
||||||
<select name="is_user_show" class="form-control" style="width:auto">
|
|
||||||
<option value="1" selected="selected">是</option>
|
|
||||||
<option value="0">否</option>
|
|
||||||
</select>
|
|
||||||
<span class="help-block">(选“是”则会新建默认的id字段作为主键)</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="col-lg-2 control-label">模型图标</label>
|
<label class="col-lg-2 control-label">模型图标</label>
|
||||||
<div class="col-lg-6 col-sm-10">
|
<div class="col-lg-6 col-sm-10">
|
||||||
@@ -85,7 +41,6 @@
|
|||||||
<!-- 按钮 -->
|
<!-- 按钮 -->
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<div class="col-lg-offset-2 col-lg-10">
|
<div class="col-lg-offset-2 col-lg-10">
|
||||||
<input type="hidden" name="id" value="{$info.id|default=''}">
|
|
||||||
<button class="btn btn-success submit-btn ajax-post" type="submit" target-form="form-horizontal">确 定</button>
|
<button class="btn btn-success submit-btn ajax-post" type="submit" target-form="form-horizontal">确 定</button>
|
||||||
<button class="btn btn-danger btn-return" onclick="javascript:history.back(-1);return false;">返 回</button>
|
<button class="btn btn-danger btn-return" onclick="javascript:history.back(-1);return false;">返 回</button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -6,13 +6,13 @@
|
|||||||
<div class="main-box clearfix">
|
<div class="main-box clearfix">
|
||||||
<header class="main-box-header clearfix">
|
<header class="main-box-header clearfix">
|
||||||
<div class="pull-left">
|
<div class="pull-left">
|
||||||
<h2>{if condition="ACTION_NAME eq 'add'"}新增{else/}编辑{/if}模型</h2>
|
<h2>编辑模型</h2>
|
||||||
</div>
|
</div>
|
||||||
<div class="pull-right">
|
<div class="pull-right">
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
<div class="main-box-body clearfix">
|
<div class="main-box-body clearfix">
|
||||||
<form id="form" action="{:url('update')}" method="post" class="form form-horizontal">
|
<form id="form" method="post" class="form form-horizontal">
|
||||||
<div class="tabs-wrapper">
|
<div class="tabs-wrapper">
|
||||||
<ul class="nav nav-tabs">
|
<ul class="nav nav-tabs">
|
||||||
<li class="active"><a href="#tab1" data-toggle="tab">基 础</a></li>
|
<li class="active"><a href="#tab1" data-toggle="tab">基 础</a></li>
|
||||||
@@ -25,7 +25,7 @@
|
|||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="col-lg-2 control-label">模型标识</label>
|
<label class="col-lg-2 control-label">模型标识</label>
|
||||||
<div class="col-lg-6 col-sm-10">
|
<div class="col-lg-6 col-sm-10">
|
||||||
<input type="text" class="form-control disabled" name="name" value="{$info.name}" disabled>
|
<input type="text" class="form-control disabled" name="name" value="{$info['name']}" disabled>
|
||||||
<span class="help-block">(请输入文档模型标识)</span>
|
<span class="help-block">(请输入文档模型标识)</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -36,27 +36,6 @@
|
|||||||
<span class="help-block">(请输入模型的名称)</span>
|
<span class="help-block">(请输入模型的名称)</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
|
||||||
<label class="col-lg-2 control-label">模型类型</label>
|
|
||||||
<div class="col-lg-3 col-sm-10">
|
|
||||||
<select name="extend" class="form-control disabled" readonly disabled>
|
|
||||||
<option value="0" {if condition="$info['extend'] eq '0'"}selected{/if}>--请选择--</option>
|
|
||||||
<option value="1" {if condition="$info['extend'] eq '1'"}selected{/if}>文档模型</option>
|
|
||||||
<option value="2" {if condition="$info['extend'] eq '2'"}selected{/if}>独立模型</option>
|
|
||||||
</select>
|
|
||||||
<span class="help-block">(目前只支持独立模型和文档模型)</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label class="col-lg-2 control-label">是否会员显示</label>
|
|
||||||
<div class="col-lg-10">
|
|
||||||
<select name="is_user_show" class="form-control" style="width:auto">
|
|
||||||
<option value="1" {if $info['is_user_show'] ==1}selected="selected"{/if}>是</option>
|
|
||||||
<option value="0" {if $info['is_user_show'] ==0}selected="selected"{/if}>否</option>
|
|
||||||
</select>
|
|
||||||
<span class="help-block">(选“是”则会新建默认的id字段作为主键)</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="col-lg-2 control-label">模型图标</label>
|
<label class="col-lg-2 control-label">模型图标</label>
|
||||||
<div class="col-lg-6 col-sm-10">
|
<div class="col-lg-6 col-sm-10">
|
||||||
@@ -70,21 +49,21 @@
|
|||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="col-lg-2 control-label">字段别名定义</label>
|
<label class="col-lg-2 control-label">字段别名定义</label>
|
||||||
<div class="col-lg-6 col-sm-10">
|
<div class="col-lg-6 col-sm-10">
|
||||||
<textarea name="attribute_alias" class="form-control">{$info.attribute_alias}</textarea>
|
<textarea name="attribute_alias" class="form-control">{$info['attribute_alias']}</textarea>
|
||||||
<span class="help-block">(用于表单显示的名称)</span>
|
<span class="help-block">(用于表单显示的名称)</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="col-lg-2 control-label">表单显示分组</label>
|
<label class="col-lg-2 control-label">表单显示分组</label>
|
||||||
<div class="col-lg-6 col-sm-10">
|
<div class="col-lg-6 col-sm-10">
|
||||||
<input type="text" class="form-control" name="field_group" value="{$info.field_group}">
|
<input type="text" class="form-control" name="attribute_group" value="{$info['attribute_group']}">
|
||||||
<span class="help-block">(用于表单显示的分组,以及设置该模型表单排序的显示)</span>
|
<span class="help-block">(用于表单显示的分组,以及设置该模型表单排序的显示)</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="col-lg-2 control-label">表单显示排序</label>
|
<label class="col-lg-2 control-label">表单显示排序</label>
|
||||||
<div class="col-lg-10 boards" id="field_group_sort">
|
<div class="col-lg-10 boards" id="attribute_group_sort">
|
||||||
{volist name=":parse_field_attr($info['field_group'])" id="vo"}
|
{volist name=":parse_field_attr($info['attribute_group'])" id="vo"}
|
||||||
<div class="board panel panel-info">
|
<div class="board panel panel-info">
|
||||||
<div class="panel-heading">{$vo}</div>
|
<div class="panel-heading">{$vo}</div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
@@ -93,7 +72,7 @@
|
|||||||
{if (($field['group'] == -1) or ($field['group'] eq $key))}
|
{if (($field['group'] == -1) or ($field['group'] eq $key))}
|
||||||
<div class="board-item">
|
<div class="board-item">
|
||||||
<span data="{$field['id']}">{$field['title']} [{$field['name']}]</span>
|
<span data="{$field['id']}">{$field['title']} [{$field['name']}]</span>
|
||||||
<input type="hidden" name="field_sort[{$key}][]" value="{$field['id']}"/>
|
<input type="hidden" name="attribute_sort[{$key}][]" value="{$field['id']}"/>
|
||||||
</div>
|
</div>
|
||||||
{php}
|
{php}
|
||||||
unset($fields[$k]);
|
unset($fields[$k]);
|
||||||
@@ -112,7 +91,7 @@
|
|||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="col-lg-2 control-label">列表定义</label>
|
<label class="col-lg-2 control-label">列表定义</label>
|
||||||
<div class="col-lg-6 col-sm-10">
|
<div class="col-lg-6 col-sm-10">
|
||||||
<textarea name="list_grid" class="form-control">{$info.list_grid}</textarea>
|
<textarea name="list_grid" class="form-control">{$info['list_grid']}</textarea>
|
||||||
<span class="help-block">(默认列表模板的展示规则)</span>
|
<span class="help-block">(默认列表模板的展示规则)</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -120,14 +99,14 @@
|
|||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="col-lg-2 control-label">默认搜索字段</label>
|
<label class="col-lg-2 control-label">默认搜索字段</label>
|
||||||
<div class="col-lg-6 col-sm-10">
|
<div class="col-lg-6 col-sm-10">
|
||||||
<input type="text" class="form-control" name="search_key" value="{$info.search_key}">
|
<input type="text" class="form-control" name="search_key" value="{$info['search_key']}">
|
||||||
<span class="help-block">(默认列表模板的默认搜索项)</span>
|
<span class="help-block">(默认列表模板的默认搜索项)</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="col-lg-2 control-label">高级搜索字段</label>
|
<label class="col-lg-2 control-label">高级搜索字段</label>
|
||||||
<div class="col-lg-6 col-sm-10">
|
<div class="col-lg-6 col-sm-10">
|
||||||
<input type="text" class="form-control" name="search_list" value="{$info.search_list}">
|
<input type="text" class="form-control" name="search_list" value="{$info['search_list']}">
|
||||||
<span class="help-block">(默认列表模板的高级搜索项)</span>
|
<span class="help-block">(默认列表模板的高级搜索项)</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -180,11 +159,11 @@
|
|||||||
<script type="text/javascript" src="__PUBLIC__/plugs/board/board.min.js"></script>
|
<script type="text/javascript" src="__PUBLIC__/plugs/board/board.min.js"></script>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
$(function(){
|
$(function(){
|
||||||
$('.form-group #field_sort').boards();
|
$('.form-group #attribute_sort').boards();
|
||||||
$('.form-group #field_group_sort').boards({
|
$('.form-group #attribute_group_sort').boards({
|
||||||
drop: function(e){
|
drop: function(e){
|
||||||
var group = e.target.closest('.board').find('.board-list').attr('data-group');
|
var group = e.target.closest('.board').find('.board-list').attr('data-group');
|
||||||
e.element.find('input').attr('name','field_sort[' + group + '][]')
|
e.element.find('input').attr('name','attribute_sort[' + group + '][]')
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -8,7 +8,6 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="pull-right">
|
<div class="pull-right">
|
||||||
<a class="btn btn-success" href="{:url('Model/add')}">新 增</a>
|
<a class="btn btn-success" href="{:url('Model/add')}">新 增</a>
|
||||||
<button class="btn btn-info ajax-post" target-form="ids" url="{:url('Model/status',array('status'=>1))}">启 用</button>
|
|
||||||
<button class="btn ajax-post" target-form="ids" url="{:url('Model/status',array('status'=>0))}">禁 用</button>
|
<button class="btn ajax-post" target-form="ids" url="{:url('Model/status',array('status'=>0))}">禁 用</button>
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
@@ -36,7 +35,7 @@
|
|||||||
<input class="ids" type="checkbox" name="ids[]" value="{$item['id']}" />
|
<input class="ids" type="checkbox" name="ids[]" value="{$item['id']}" />
|
||||||
</td>
|
</td>
|
||||||
<td>{$item['id']}</td>
|
<td>{$item['id']}</td>
|
||||||
<td>{$item['name']}</td>
|
<td><i class="fa fa-{$item['icon']}"></i> {$item['name']}</td>
|
||||||
<td>
|
<td>
|
||||||
<a data-id="{$item.id}" href="{:url('model/edit?id='.$item['id'])}">{$item.title}</a>
|
<a data-id="{$item.id}" href="{:url('model/edit?id='.$item['id'])}">{$item.title}</a>
|
||||||
</td>
|
</td>
|
||||||
@@ -52,17 +51,15 @@
|
|||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<a href="{:url('admin/attribute/index?model_id='.$item['id'])}">字段</a>
|
<a href="{:url('admin/attribute/index?model_id='.$item['id'])}">字段</a>
|
||||||
<a href="{:url('model/status?ids='.$item['id'].'&status='.abs(1-$item['status']))}" class="ajax-get">{$item['status']|show_status_op}</a>
|
<a href="{:url('model/status?id='.$item['id'].'&status='.abs(1-$item['status']))}" class="ajax-get">{$item['status']|show_status_op}</a>
|
||||||
<a href="{:url('model/edit?id='.$item['id'])}">编辑</a>
|
<a href="{:url('model/edit?id='.$item['id'])}">编辑</a>
|
||||||
<a href="{:url('model/del?id='.$item['id'])}" class="confirm ajax-get">删除</a>
|
<a href="{:url('model/del?id='.$item['id'])}" class="confirm ajax-get">删除</a>
|
||||||
{if $item['extend']}
|
|
||||||
<a href="{:url('admin/content/index?model_id='.$item['id'])}">数据</a>
|
<a href="{:url('admin/content/index?model_id='.$item['id'])}">数据</a>
|
||||||
{/if}
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{/volist}
|
{/volist}
|
||||||
{else/}
|
{else/}
|
||||||
<td colspan="7" class="text-center">aOh! 暂时还没有内容!</td>
|
<td colspan="7" class="text-center">aOh! 暂时还没有创建模型!</td>
|
||||||
{/notempty}
|
{/notempty}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|||||||
@@ -1,28 +1,5 @@
|
|||||||
<!DOCTYPE html>
|
{include file="admin@public/header" /}
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8"/>
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
|
|
||||||
<title>SentCMS网站管理系统后台</title>
|
|
||||||
<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/bootstrap/bootstrap.min.css"/>
|
|
||||||
<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/libs/font-awesome.css"/>
|
|
||||||
<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/libs/nanoscroller.css"/>
|
|
||||||
<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/common.css"/>
|
|
||||||
<!-- <link href='//fonts.googleapis.com/css?family=Open+Sans:400,600,700,300|Titillium+Web:200,300,400' rel='stylesheet' type='text/css'> -->
|
|
||||||
<link rel="stylesheet" type="text/css" href="__CSS__/style.css"/>
|
|
||||||
<script src="__PUBLIC__/js/jquery.js"></script>
|
|
||||||
<script type="text/javascript">
|
|
||||||
var BASE_URL = "{:config('base_url')}"; //根目录地址
|
|
||||||
</script>
|
|
||||||
<!--[if lt IE 9]>
|
|
||||||
<script src="__PUBLIC__/js/html5shiv.js"></script>
|
|
||||||
<script src="__PUBLIC__/js/respond.min.js"></script>
|
|
||||||
<![endif]-->
|
|
||||||
{block name="style"}{/block}
|
{block name="style"}{/block}
|
||||||
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div id="theme-wrapper">
|
<div id="theme-wrapper">
|
||||||
<header class="navbar" id="header-navbar">
|
<header class="navbar" id="header-navbar">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
@@ -232,28 +209,5 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{include file="admin@public/tool" /}
|
{include file="admin@public/tool" /}
|
||||||
<script src="__PUBLIC__/js/bootstrap.js"></script>
|
{include file="admin@public/footer" /}
|
||||||
<script src="__PUBLIC__/js/jquery.nanoscroller.min.js"></script>
|
|
||||||
<script src="__PUBLIC__/js/pace.min.js"></script>
|
|
||||||
|
|
||||||
<script src="__PUBLIC__/js/hopscotch.js"></script>
|
|
||||||
<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/libs/hopscotch.css">
|
|
||||||
|
|
||||||
<script src="__PUBLIC__/js/messager.js"></script>
|
|
||||||
<script src="__JS__/app.js"></script>
|
|
||||||
<script type="text/javascript">
|
|
||||||
(function(){
|
|
||||||
var SentCMS = window.Sent = {
|
|
||||||
"ROOT" : "__ROOT__", //当前网站地址
|
|
||||||
"APP" : "__APP__", //当前项目地址
|
|
||||||
"PUBLIC" : "__PUBLIC__", //项目公共目录地址
|
|
||||||
"DEEP" : "{:config('URL_PATHINFO_DEPR')}", //PATHINFO分割符
|
|
||||||
"MODEL" : ["{:config('URL_MODEL')}", "{:config('URL_CASE_INSENSITIVE')}", "{:config('URL_HTML_SUFFIX')}"],
|
|
||||||
"VAR" : ["{:config('VAR_MODULE')}", "{:config('VAR_CONTROLLER')}", "{:config('VAR_ACTION')}"]
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
</script>
|
|
||||||
<script src="__PUBLIC__/js/core.js"></script>
|
|
||||||
{block name="script"}{/block}
|
{block name="script"}{/block}
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
24
application/admin/view/public/footer.html
Normal file
24
application/admin/view/public/footer.html
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<script src="__PUBLIC__/js/bootstrap.js"></script>
|
||||||
|
<script src="__PUBLIC__/js/jquery.nanoscroller.min.js"></script>
|
||||||
|
<script src="__PUBLIC__/js/pace.min.js"></script>
|
||||||
|
|
||||||
|
<script src="__PUBLIC__/js/hopscotch.js"></script>
|
||||||
|
<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/libs/hopscotch.css">
|
||||||
|
|
||||||
|
<script src="__PUBLIC__/js/messager.js"></script>
|
||||||
|
<script src="__JS__/app.js"></script>
|
||||||
|
<script type="text/javascript">
|
||||||
|
(function(){
|
||||||
|
var SentCMS = window.Sent = {
|
||||||
|
"ROOT" : "__ROOT__", //当前网站地址
|
||||||
|
"APP" : "__APP__", //当前项目地址
|
||||||
|
"PUBLIC" : "__PUBLIC__", //项目公共目录地址
|
||||||
|
"DEEP" : "{:config('URL_PATHINFO_DEPR')}", //PATHINFO分割符
|
||||||
|
"MODEL" : ["{:config('URL_MODEL')}", "{:config('URL_CASE_INSENSITIVE')}", "{:config('URL_HTML_SUFFIX')}"],
|
||||||
|
"VAR" : ["{:config('VAR_MODULE')}", "{:config('VAR_CONTROLLER')}", "{:config('VAR_ACTION')}"]
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
</script>
|
||||||
|
<script src="__PUBLIC__/js/core.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
23
application/admin/view/public/header.html
Normal file
23
application/admin/view/public/header.html
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8"/>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
|
||||||
|
<title>SentCMS网站管理系统后台</title>
|
||||||
|
<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/bootstrap/bootstrap.min.css"/>
|
||||||
|
<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/libs/font-awesome.css"/>
|
||||||
|
<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/libs/nanoscroller.css"/>
|
||||||
|
<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/common.css"/>
|
||||||
|
<!-- <link href='//fonts.googleapis.com/css?family=Open+Sans:400,600,700,300|Titillium+Web:200,300,400' rel='stylesheet' type='text/css'> -->
|
||||||
|
<link rel="stylesheet" type="text/css" href="__CSS__/style.css"/>
|
||||||
|
<script src="__PUBLIC__/js/jquery.js"></script>
|
||||||
|
<script type="text/javascript">
|
||||||
|
var BASE_URL = "{:config('base_url')}"; //根目录地址
|
||||||
|
</script>
|
||||||
|
<!--[if lt IE 9]>
|
||||||
|
<script src="__PUBLIC__/js/html5shiv.js"></script>
|
||||||
|
<script src="__PUBLIC__/js/respond.min.js"></script>
|
||||||
|
<![endif]-->
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
// SentCMS常量定义
|
// SentCMS常量定义
|
||||||
define('SENTCMS_VERSION', '3.0.20161201');
|
define('SENTCMS_VERSION', '3.1.201706');
|
||||||
define('SENT_ADDON_PATH', ROOT_PATH . DS . 'addons' . DS);
|
define('SENT_ADDON_PATH', ROOT_PATH . DS . 'addons' . DS);
|
||||||
|
|
||||||
//字符串解密加密
|
//字符串解密加密
|
||||||
|
|||||||
@@ -51,12 +51,7 @@ class InitHook {
|
|||||||
foreach ($list as $key => $value) {
|
foreach ($list as $key => $value) {
|
||||||
$route[$value['rule']] = $value['url'];
|
$route[$value['rule']] = $value['url'];
|
||||||
}
|
}
|
||||||
$model = db('Model');
|
$list = db('Model')->field("name,id")->select();
|
||||||
$map = array(
|
|
||||||
'status' => array('gt', 0),
|
|
||||||
'extend' => array('gt', 0),
|
|
||||||
);
|
|
||||||
$list = $model->where($map)->field("name,id,title,'' as 'style'")->select();
|
|
||||||
foreach ($list as $key => $value) {
|
foreach ($list as $key => $value) {
|
||||||
$route["admin/" . $value['name'] . "/index"] = "admin/content/index?model_id=" . $value['id'];
|
$route["admin/" . $value['name'] . "/index"] = "admin/content/index?model_id=" . $value['id'];
|
||||||
$route["admin/" . $value['name'] . "/add"] = "admin/content/add?model_id=" . $value['id'];
|
$route["admin/" . $value['name'] . "/add"] = "admin/content/add?model_id=" . $value['id'];
|
||||||
|
|||||||
@@ -174,8 +174,7 @@ class Admin extends Base {
|
|||||||
$model = \think\Loader::model('Model');
|
$model = \think\Loader::model('Model');
|
||||||
$list = array();
|
$list = array();
|
||||||
$map = array(
|
$map = array(
|
||||||
'status' => array('gt', 0),
|
'status' => array('gt', 0)
|
||||||
'extend' => array('gt', 0),
|
|
||||||
);
|
);
|
||||||
$list = $model::where($map)->field("name,id,title,icon,'' as 'style'")->select();
|
$list = $model::where($map)->field("name,id,title,icon,'' as 'style'")->select();
|
||||||
|
|
||||||
|
|||||||
@@ -65,23 +65,21 @@ class Attribute extends Base{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function del($id){
|
public function del($id, $model_id){
|
||||||
$map['id'] = $id;
|
$map['id'] = $id;
|
||||||
$info = $this->find($id);
|
$info = $this->find($id);
|
||||||
$model = db('Model')->where(array('id'=>$info['model_id']))->find();
|
$tablename = db('Model')->where(array('id'=>$model_id))->value('name');
|
||||||
|
|
||||||
//先删除字段表内的数据
|
//先删除字段表内的数据
|
||||||
$result = $this->where($map)->delete();
|
$result = $this->where($map)->delete();
|
||||||
if ($result) {
|
if ($result) {
|
||||||
if ($model['extend'] == 1) {
|
$tablename = strtolower($tablename);
|
||||||
$tablename = 'document_'.$model['name'];
|
|
||||||
}else{
|
|
||||||
$tablename = $model['name'];
|
|
||||||
}
|
|
||||||
|
|
||||||
//删除模型表中字段
|
//删除模型表中字段
|
||||||
$db = new \com\Datatable();
|
$db = new \com\Datatable();
|
||||||
$result = $db->del_field($tablename,$info['name'])->query();
|
if (!$db->CheckField($tablename,$info['name'])) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
$result = $db->delField($tablename,$info['name'])->query();
|
||||||
if ($result) {
|
if ($result) {
|
||||||
return true;
|
return true;
|
||||||
}else{
|
}else{
|
||||||
@@ -134,4 +132,15 @@ class Attribute extends Base{
|
|||||||
$result = $db->create();
|
$result = $db->create();
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function generate($model){
|
||||||
|
$tablename = strtolower($model['name']);
|
||||||
|
//实例化一个数据库操作类
|
||||||
|
$db = new \com\Datatable();
|
||||||
|
//检查表是否存在并创建
|
||||||
|
if (!$db->CheckTable($tablename)) {
|
||||||
|
//创建新表
|
||||||
|
$db->initTable($tablename, $model['title'], 'id')->query();
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -10,34 +10,30 @@
|
|||||||
namespace app\common\model;
|
namespace app\common\model;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置模型
|
* 设置模型
|
||||||
*/
|
*/
|
||||||
class Model extends Base{
|
class Model extends Base {
|
||||||
|
|
||||||
protected $auto = [ 'update_time'];
|
protected $auto = ['update_time'];
|
||||||
protected $insert = ['name', 'create_time', 'status'=>1];
|
protected $insert = ['name', 'create_time', 'status' => 0];
|
||||||
protected $type = array(
|
protected $type = array(
|
||||||
'id' => 'integer',
|
'id' => 'integer',
|
||||||
'create_time' => 'integer',
|
'create_time' => 'integer',
|
||||||
'update_time' => 'integer'
|
'update_time' => 'integer',
|
||||||
);
|
);
|
||||||
|
|
||||||
public function setFieldSortAttr($value){
|
protected function setAttributeSortAttr($value){
|
||||||
return empty($value) ? '' : json_encode($value);
|
return $value ? json_encode($value) : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setNameAttr($value){
|
public function setNameAttr($value) {
|
||||||
return strtolower($value);
|
return strtolower($value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setAttributeListAttr($value){
|
public function getStatusTextAttr($value, $data) {
|
||||||
return empty($value) ? '' : json_encode($value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getStatusTextAttr($value, $data){
|
|
||||||
$status = array(
|
$status = array(
|
||||||
0 => '禁用',
|
0 => '禁用',
|
||||||
1 => '启用',
|
1 => '启用',
|
||||||
);
|
);
|
||||||
return $status[$data['status']];
|
return $status[$data['status']];
|
||||||
}
|
}
|
||||||
@@ -47,67 +43,59 @@ class Model extends Base{
|
|||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function change() {
|
public function change() {
|
||||||
if(IS_POST){
|
if (IS_POST) {
|
||||||
$data = \think\Request::instance()->post();
|
$data = \think\Request::instance()->post();
|
||||||
if($data){
|
if ($data) {
|
||||||
if (empty($data['id'])) {
|
if (empty($data['id'])) {
|
||||||
/*创建表*/
|
/*创建表*/
|
||||||
$db = new \com\Datatable();
|
$db = new \com\Datatable();
|
||||||
|
|
||||||
if ($data['extend'] == 1) {
|
if ($data['extend'] == 1) {
|
||||||
//文档模型
|
//文档模型
|
||||||
$sql = $db->start_table('document_'.$data['name'])->create_id('doc_id', 11 , '主键' , false)->create_key('doc_id');
|
$sql = $db->start_table('document_' . $data['name'])->create_id('doc_id', 11, '主键', false)->create_key('doc_id');
|
||||||
}else{
|
} else {
|
||||||
$sql = $db->start_table($data['name'])->create_id('id', 11 , '主键' , true)->create_uid()->create_key('id');
|
$sql = $db->start_table($data['name'])->create_id('id', 11, '主键', true)->create_uid()->create_key('id');
|
||||||
}
|
}
|
||||||
//执行操作数据库,建立数据表
|
//执行操作数据库,建立数据表
|
||||||
$result = $sql->end_table($data['title'], $data['engine_type'])->create();
|
$result = $sql->end_table($data['title'], $data['engine_type'])->create();
|
||||||
if ($result) {
|
if ($result) {
|
||||||
$id = $this->validate('model.add')->save($data);
|
$id = $this->validate('model.add')->save($data);
|
||||||
if (false === $id) {
|
if (false === $id) {
|
||||||
return array('info'=>$this->getError(), 'status'=>0);
|
return array('info' => $this->getError(), 'status' => 0);
|
||||||
}else{
|
} else {
|
||||||
// 清除模型缓存数据
|
// 清除模型缓存数据
|
||||||
cache('document_model_list', null);
|
cache('document_model_list', null);
|
||||||
|
|
||||||
//记录行为
|
//记录行为
|
||||||
action_log('update_model', 'model', $id, session('auth_user.uid'));
|
action_log('update_model', 'model', $id, session('auth_user.uid'));
|
||||||
return $id ? array('info'=>'创建模型成功!','status'=>1) : array('info'=>'创建模型失败!','status'=>1);
|
return $id ? array('info' => '创建模型成功!', 'status' => 1) : array('info' => '创建模型失败!', 'status' => 1);
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//修改
|
//修改
|
||||||
$status = $this->validate('model.edit')->save($data,array('id'=>$data['id']));
|
$status = $this->validate('model.edit')->save($data, array('id' => $data['id']));
|
||||||
if (false === $status) {
|
if (false === $status) {
|
||||||
return array('info'=>$this->getError(), 'status'=>0);
|
return array('info' => $this->getError(), 'status' => 0);
|
||||||
}else{
|
} else {
|
||||||
// 清除模型缓存数据
|
// 清除模型缓存数据
|
||||||
cache('document_model_list', null);
|
cache('document_model_list', null);
|
||||||
//记录行为
|
//记录行为
|
||||||
action_log('update_model','model',$data['id'],session('auth_user.uid'));
|
action_log('update_model', 'model', $data['id'], session('auth_user.uid'));
|
||||||
return array('info'=>'保存模型成功!','status'=>1);
|
return array('info' => '保存模型成功!', 'status' => 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
return array('info'=>$this->getError(),'status'=>0);
|
return array('info' => $this->getError(), 'status' => 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function del(){
|
public function del() {
|
||||||
$id = input('id','','trim,intval');
|
$id = input('id', '', 'trim,intval');
|
||||||
$model = $this->db()->where(array('id'=>$id))->find();
|
$tablename = $this->where('id', $id)->value('name');
|
||||||
|
|
||||||
if ($model['extend'] == 0) {
|
|
||||||
$this->error = "基础模型不允许删除!";
|
|
||||||
return false;
|
|
||||||
}elseif ($model['extend'] == 1){
|
|
||||||
$tablename = 'document_'.$model['name'];
|
|
||||||
}elseif ($model['extend'] == 2){
|
|
||||||
$tablename = $model['name'];
|
|
||||||
}
|
|
||||||
//删除数据表
|
//删除数据表
|
||||||
$db = new \com\Datatable();
|
$db = new \com\Datatable();
|
||||||
if ($db->CheckTable($tablename)) {
|
if ($db->CheckTable($tablename)) {
|
||||||
@@ -118,16 +106,16 @@ class Model extends Base{
|
|||||||
$this->error = "数据表删除失败!";
|
$this->error = "数据表删除失败!";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$result = $this->db()->where(array('id'=>$id))->delete();
|
$result = $this->where('id', $id)->delete();
|
||||||
if ($result) {
|
if ($result) {
|
||||||
return true;
|
return true;
|
||||||
}else{
|
} else {
|
||||||
$this->error = "模型删除失败!";
|
$this->error = "模型删除失败!";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function attribute(){
|
public function attribute() {
|
||||||
return $this->hasMany('Attribute');
|
return $this->hasMany('Attribute');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,10 +124,10 @@ class Model extends Base{
|
|||||||
* @param [array] $model [字段]
|
* @param [array] $model [字段]
|
||||||
* @return [array] [解析后的字段]
|
* @return [array] [解析后的字段]
|
||||||
*/
|
*/
|
||||||
public function preFields($model){
|
public function preFields($model) {
|
||||||
$fields = $model->attribute;
|
$fields = $model->attribute;
|
||||||
$groups = parse_config_attr($model['field_group']);
|
$groups = parse_config_attr($model['field_group']);
|
||||||
$field_sort = json_decode($model['field_sort'],true);;
|
$field_sort = json_decode($model['field_sort'], true);
|
||||||
|
|
||||||
//获得数组的第一条数组
|
//获得数组的第一条数组
|
||||||
$first_key = array_keys($groups);
|
$first_key = array_keys($groups);
|
||||||
@@ -154,8 +142,8 @@ class Model extends Base{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
//未进行排序的放入第一组中
|
//未进行排序的放入第一组中
|
||||||
$fields[] = array('name'=>'model_id','type'=>'hidden'); //加入模型ID值
|
$fields[] = array('name' => 'model_id', 'type' => 'hidden'); //加入模型ID值
|
||||||
$fields[] = array('name'=>'id','type'=>'hidden'); //加入模型ID值
|
$fields[] = array('name' => 'id', 'type' => 'hidden'); //加入模型ID值
|
||||||
foreach ($fields as $key => $value) {
|
foreach ($fields as $key => $value) {
|
||||||
$groupfield[$first_key[0]][] = $value;
|
$groupfield[$first_key[0]][] = $value;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,5 +29,4 @@ class Model extends Base{
|
|||||||
'add' => 'name,title',
|
'add' => 'name,title',
|
||||||
'edit' => 'title',
|
'edit' => 'title',
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -13,45 +13,59 @@ use think\Db;
|
|||||||
* 数据库管理类
|
* 数据库管理类
|
||||||
* @author colin <colin@tensent.cn>
|
* @author colin <colin@tensent.cn>
|
||||||
*/
|
*/
|
||||||
class Datatable{
|
class Datatable {
|
||||||
|
|
||||||
protected $table; /*数据库操作的表*/
|
protected $table; /*数据库操作的表*/
|
||||||
protected $fields = array(); /*数据库操作字段*/
|
protected $fields = array(); /*数据库操作字段*/
|
||||||
protected $charset = 'utf8'; /*数据库操作字符集*/
|
protected $charset = 'utf8'; /*数据库操作字符集*/
|
||||||
public $prefix = ''; /*数据库操作表前缀*/
|
public $prefix = ''; /*数据库操作表前缀*/
|
||||||
protected $model_table_prefix = ''; /*模型默认创建的表前缀*/
|
protected $model_table_prefix = ''; /*模型默认创建的表前缀*/
|
||||||
protected $engine_type = 'MyISAM'; /*数据库引擎*/
|
protected $engine_type = 'MyISAM'; /*数据库引擎*/
|
||||||
protected $key = 'id'; /*数据库主键*/
|
protected $key = 'id'; /*数据库主键*/
|
||||||
public $sql = ''; /*最后生成的sql语句*/
|
public $sql = ''; /*最后生成的sql语句*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 初始化数据库信息
|
* 初始化数据库信息
|
||||||
* @author colin <colin@tensent.cn>
|
* @author colin <colin@tensent.cn>
|
||||||
*/
|
*/
|
||||||
public function __construct(){
|
public function __construct() {
|
||||||
//创建DB对象
|
//创建DB对象
|
||||||
$this->prefix = config('database.prefix');
|
$this->prefix = config('database.prefix');
|
||||||
$this->model_table_prefix = config('model_table_prefix');
|
$this->model_table_prefix = config('model_table_prefix');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 开始创建表
|
* @title 初始化表
|
||||||
* @var $table 表名
|
* @description 初始化创建表
|
||||||
* @author colin <colin@tensent.cn>
|
* @Author molong
|
||||||
|
* @DateTime 2017-06-11
|
||||||
|
* @param string $table 表名
|
||||||
|
* @return void 空
|
||||||
*/
|
*/
|
||||||
public function start_table($table){
|
public function initTable($table = '', $comment = '', $pk = '', $time = true){
|
||||||
$this->table = $this->getTablename($table,true);
|
$this->table = $this->getTablename($table, true);
|
||||||
$this->sql .= "CREATE TABLE IF NOT EXISTS `".$this->table."`(";
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
if ($pk) {
|
||||||
* 创建字段
|
$sql[] = $this->generateField('id', 'int', 11, '', '主键', true);
|
||||||
* @var $sql 要执行的字段sql语句可以为array()或者strubf
|
}
|
||||||
* @author colin <colin@tensent.cn>
|
if ($time) {
|
||||||
*/
|
//初始化表内含创建时间和更新时间两个字段
|
||||||
public function create_field($sql){
|
$sql[] = $this->generateField('create_time', 'int', 11, 0, '创建时间', false);
|
||||||
$this->sql .= $sql.',';
|
$sql[] = $this->generateField('update_time', 'int', 11, 0, '创建时间', false);
|
||||||
|
}
|
||||||
|
|
||||||
|
$primary = $pk ? "PRIMARY KEY (`".$pk."`)" : '';
|
||||||
|
if ($primary) {
|
||||||
|
$generatesql = implode(',', $sql) . ',';
|
||||||
|
}else{
|
||||||
|
$generatesql = implode(',', $sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
$create = "CREATE TABLE IF NOT EXISTS `" . $this->table . "`("
|
||||||
|
. $generatesql
|
||||||
|
. $primary
|
||||||
|
. ") ENGINE=" . $this->engine_type . " AUTO_INCREMENT=1 DEFAULT CHARSET=" . $this->charset . " ROW_FORMAT=DYNAMIC COMMENT='" . $comment . "';";
|
||||||
|
$this->sql = $create;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,20 +75,16 @@ class Datatable{
|
|||||||
* @var comment 字段的描述
|
* @var comment 字段的描述
|
||||||
* @author colin <colin@tensent.cn>
|
* @author colin <colin@tensent.cn>
|
||||||
*/
|
*/
|
||||||
public function create_id($key = 'id', $length = 11 , $comment = '主键' , $is_auto_increment = true){
|
public function generateField($key = '', $type = '', $length = 11, $default = '', $comment = '主键', $is_auto_increment = false){
|
||||||
$auto_increment = $is_auto_increment ? 'AUTO_INCREMENT' : '';
|
if ($key && $type) {
|
||||||
$this->sql .= "`{$key}` int({$length}) unsigned NOT NULL $auto_increment COMMENT '{$comment}',";
|
$auto_increment = $is_auto_increment ? 'AUTO_INCREMENT' : '';
|
||||||
return $this;
|
$field_type = $length ? $type.'('.$length.')' : $type;
|
||||||
}
|
$signed = in_array($type, array('int', 'float', 'double')) ? 'signed' : '';
|
||||||
/**
|
$comment = $comment ? "COMMENT '" . $comment . "'" : "";
|
||||||
* 快速创建ID字段
|
$default = $default ? "DEFAULT '" . $default . "'" : "";
|
||||||
* @var length 字段的长度
|
$sql = "`{$key}` {$field_type} {$signed} NOT NULL {$default} $auto_increment {$comment}";
|
||||||
* @var comment 字段的描述
|
}
|
||||||
* @author colin <colin@tensent.cn>
|
return $sql;
|
||||||
*/
|
|
||||||
public function create_uid(){
|
|
||||||
$this->sql .= "`uid` int(11) NOT NULL DEFAULT '0' COMMENT '用户uid',";
|
|
||||||
return $this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -84,32 +94,32 @@ class Datatable{
|
|||||||
* @var $is_more 是否为多条同时插入
|
* @var $is_more 是否为多条同时插入
|
||||||
* @author colin <colin@tensent.cn>
|
* @author colin <colin@tensent.cn>
|
||||||
*/
|
*/
|
||||||
public function colum_field($table,$attr = array()){
|
public function columField($table, $attr = array()) {
|
||||||
$field_attr['table'] = $table ? $this->getTablename($table,true) : $this->table;
|
$field_attr['table'] = $table ? $this->getTablename($table, true) : $this->table;
|
||||||
$field_attr['field'] = $attr['field'];
|
$field_attr['field'] = $attr['field'];
|
||||||
$field_attr['type'] = $attr['type'] ? $attr['type'] : 'varchar';
|
$field_attr['type'] = $attr['type'] ? $attr['type'] : 'varchar';
|
||||||
if (intval($attr['length']) && $attr['length']) {
|
if (intval($attr['length']) && $attr['length']) {
|
||||||
$field_attr['length'] = "(".$attr['length'].")";
|
$field_attr['length'] = "(" . $attr['length'] . ")";
|
||||||
}else{
|
} else {
|
||||||
$field_attr['length'] = "";
|
$field_attr['length'] = "";
|
||||||
}
|
}
|
||||||
$field_attr['is_null'] = $attr['is_null'] ? 'NOT NULL' : 'null';
|
$field_attr['is_null'] = $attr['is_null'] ? 'NOT NULL' : 'null';
|
||||||
$field_attr['default'] = $attr['default'] != '' ? 'default "'.$attr['default'].'"' : 'default null';
|
$field_attr['default'] = $attr['default'] != '' ? 'default "' . $attr['default'] . '"' : 'default null';
|
||||||
if($field_attr['is_null'] == 'null'){
|
if ($field_attr['is_null'] == 'null') {
|
||||||
$field_attr['default'] = $field_attr['default'];
|
$field_attr['default'] = $field_attr['default'];
|
||||||
}else{
|
} else {
|
||||||
$field_attr['default'] = '';
|
$field_attr['default'] = '';
|
||||||
}
|
}
|
||||||
$field_attr['comment'] = (isset($attr['comment']) && $attr['comment']) ? $attr['comment'] : '';
|
$field_attr['comment'] = (isset($attr['comment']) && $attr['comment']) ? $attr['comment'] : '';
|
||||||
$field_attr['oldname'] = (isset($attr['oldname']) && $attr['oldname']) ? $attr['oldname'] : '';
|
$field_attr['oldname'] = (isset($attr['oldname']) && $attr['oldname']) ? $attr['oldname'] : '';
|
||||||
$field_attr['newname'] = (isset($attr['newname']) && $attr['newname']) ? $attr['newname'] : $field_attr['field'];
|
$field_attr['newname'] = (isset($attr['newname']) && $attr['newname']) ? $attr['newname'] : $field_attr['field'];
|
||||||
$field_attr['after'] = (isset($attr['after']) && $attr['after']) ? ' AFTER `'.$attr['after'].'`' : '';
|
$field_attr['after'] = (isset($attr['after']) && $attr['after']) ? ' AFTER `' . $attr['after'] . '`' : '';
|
||||||
$field_attr['action'] = (isset($attr['action']) && $attr['action']) ? $attr['action'] : 'ADD';
|
$field_attr['action'] = (isset($attr['action']) && $attr['action']) ? $attr['action'] : 'ADD';
|
||||||
//确认表是否存在
|
//确认表是否存在
|
||||||
|
|
||||||
if($field_attr['action'] == 'ADD'){
|
if ($field_attr['action'] == 'ADD') {
|
||||||
$this->sql = "ALTER TABLE `{$field_attr['table']}` ADD `{$field_attr['field']}` {$field_attr['type']}{$field_attr['length']} {$field_attr['is_null']} {$field_attr['default']} COMMENT '{$field_attr['comment']}'";
|
$this->sql = "ALTER TABLE `{$field_attr['table']}` ADD `{$field_attr['field']}` {$field_attr['type']}{$field_attr['length']} {$field_attr['is_null']} {$field_attr['default']} COMMENT '{$field_attr['comment']}'";
|
||||||
}elseif($field_attr['action'] == 'CHANGE'){
|
} elseif ($field_attr['action'] == 'CHANGE') {
|
||||||
$this->sql = "ALTER TABLE `{$field_attr['table']}` CHANGE `{$field_attr['oldname']}` `{$field_attr['newname']}` {$field_attr['type']}{$field_attr['length']} {$field_attr['is_null']} {$field_attr['default']} COMMENT '{$field_attr['comment']}'";
|
$this->sql = "ALTER TABLE `{$field_attr['table']}` CHANGE `{$field_attr['oldname']}` `{$field_attr['newname']}` {$field_attr['type']}{$field_attr['length']} {$field_attr['is_null']} {$field_attr['default']} COMMENT '{$field_attr['comment']}'";
|
||||||
}
|
}
|
||||||
return $this;
|
return $this;
|
||||||
@@ -121,8 +131,8 @@ class Datatable{
|
|||||||
* @var $field 字段名
|
* @var $field 字段名
|
||||||
* @author colin <colin@tensent.cn>
|
* @author colin <colin@tensent.cn>
|
||||||
*/
|
*/
|
||||||
public function del_field($table,$field){
|
public function delField($table, $field) {
|
||||||
$table = $table ? $this->getTablename($table,true) : $this->table;
|
$table = $table ? $this->getTablename($table, true) : $this->table;
|
||||||
$this->sql = "ALTER TABLE `$table` DROP `$field`";
|
$this->sql = "ALTER TABLE `$table` DROP `$field`";
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@@ -132,26 +142,12 @@ class Datatable{
|
|||||||
* @var $table 追加字段的表名
|
* @var $table 追加字段的表名
|
||||||
* @author colin <colin@tensent.cn>
|
* @author colin <colin@tensent.cn>
|
||||||
*/
|
*/
|
||||||
public function del_table($table){
|
public function delTable($table) {
|
||||||
$table = $table ? $this->getTablename($table,true) : $this->table;
|
$table = $table ? $this->getTablename($table, true) : $this->table;
|
||||||
$this->sql = "DROP TABLE `$table`";
|
$this->sql = "DROP TABLE `$table`";
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 主键设置
|
|
||||||
* @var $key 要被设置主键的字段
|
|
||||||
* @author colin <colin@tensent.cn>
|
|
||||||
*/
|
|
||||||
public function create_key($key = null){
|
|
||||||
if(null != $key){
|
|
||||||
$this->key = $key;
|
|
||||||
}
|
|
||||||
$this->sql .= "PRIMARY KEY (`".$this->key."`)";
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 结束表
|
* 结束表
|
||||||
* @var $engine_type 数据库引擎
|
* @var $engine_type 数据库引擎
|
||||||
@@ -159,15 +155,15 @@ class Datatable{
|
|||||||
* @var $charset 数据库编码
|
* @var $charset 数据库编码
|
||||||
* @author colin <colin@tensent.cn>
|
* @author colin <colin@tensent.cn>
|
||||||
*/
|
*/
|
||||||
public function end_table($comment,$engine_type = null,$charset = null){
|
public function endTable($comment, $engine_type = null, $charset = null) {
|
||||||
if(null != $charset){
|
if (null != $charset) {
|
||||||
$this->charset = $charset;
|
$this->charset = $charset;
|
||||||
}
|
}
|
||||||
if(null != $engine_type){
|
if (null != $engine_type) {
|
||||||
$this->engine_type = $engine_type;
|
$this->engine_type = $engine_type;
|
||||||
}
|
}
|
||||||
$end = "ENGINE=".$this->engine_type." AUTO_INCREMENT=1 DEFAULT CHARSET=".$this->charset." ROW_FORMAT=DYNAMIC COMMENT='".$comment."';";
|
$end = "ENGINE=" . $this->engine_type . " AUTO_INCREMENT=1 DEFAULT CHARSET=" . $this->charset . " ROW_FORMAT=DYNAMIC COMMENT='" . $comment . "';";
|
||||||
$this->sql .= ")".$end;
|
$this->sql .= ")" . $end;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -176,7 +172,7 @@ class Datatable{
|
|||||||
* @return int 0
|
* @return int 0
|
||||||
* @author colin <colin@tensent.cn>
|
* @author colin <colin@tensent.cn>
|
||||||
*/
|
*/
|
||||||
public function create(){
|
public function create() {
|
||||||
$res = Db::execute($this->sql);
|
$res = Db::execute($this->sql);
|
||||||
return $res !== false;
|
return $res !== false;
|
||||||
}
|
}
|
||||||
@@ -186,7 +182,7 @@ class Datatable{
|
|||||||
* @return int 0
|
* @return int 0
|
||||||
* @author colin <colin@tensent.cn>
|
* @author colin <colin@tensent.cn>
|
||||||
*/
|
*/
|
||||||
public function query(){
|
public function query() {
|
||||||
return $this->create();
|
return $this->create();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,7 +190,7 @@ class Datatable{
|
|||||||
* 获取最后生成的sql语句
|
* 获取最后生成的sql语句
|
||||||
* @author colin <colin@tensent.cn>
|
* @author colin <colin@tensent.cn>
|
||||||
*/
|
*/
|
||||||
public function getLastSql(){
|
public function getLastSql() {
|
||||||
return $this->sql;
|
return $this->sql;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -204,11 +200,11 @@ class Datatable{
|
|||||||
* @var $prefix 获取表前缀? 默认为不获取 false
|
* @var $prefix 获取表前缀? 默认为不获取 false
|
||||||
* @author colin <colin@tensent.cn>
|
* @author colin <colin@tensent.cn>
|
||||||
*/
|
*/
|
||||||
public function getTablename($table , $prefix = false){
|
public function getTablename($table, $prefix = false) {
|
||||||
if(false == $prefix){
|
if (false == $prefix) {
|
||||||
$this->table = $this->model_table_prefix.$table;
|
$this->table = $this->model_table_prefix . $table;
|
||||||
}else{
|
} else {
|
||||||
$this->table = $this->prefix.$this->model_table_prefix.$table;
|
$this->table = $this->prefix . $this->model_table_prefix . $table;
|
||||||
}
|
}
|
||||||
return $this->table;
|
return $this->table;
|
||||||
}
|
}
|
||||||
@@ -218,23 +214,23 @@ class Datatable{
|
|||||||
* @var $table 要获取名字的表名 可以为sent_tengsu_photo、tengsu_photo、photo
|
* @var $table 要获取名字的表名 可以为sent_tengsu_photo、tengsu_photo、photo
|
||||||
* @author colin <colin@tensent.cn>
|
* @author colin <colin@tensent.cn>
|
||||||
*/
|
*/
|
||||||
public function getFields($table){
|
public function getFields($table) {
|
||||||
if(false == $table){
|
if (false == $table) {
|
||||||
$table = $this->table;//为空调用当前table
|
$table = $this->table; //为空调用当前table
|
||||||
}else{
|
} else {
|
||||||
$table = $table;
|
$table = $table;
|
||||||
}
|
}
|
||||||
$patten = "/\./";
|
$patten = "/\./";
|
||||||
if(!preg_match_all($patten,$table)){
|
if (!preg_match_all($patten, $table)) {
|
||||||
//匹配_
|
//匹配_
|
||||||
$patten = "/_+/";
|
$patten = "/_+/";
|
||||||
if(!preg_match_all($patten, $table)){
|
if (!preg_match_all($patten, $table)) {
|
||||||
$table = $this->prefix.$this->model_table_prefix.$table;
|
$table = $this->prefix . $this->model_table_prefix . $table;
|
||||||
}else{
|
} else {
|
||||||
//匹配是否包含表前缀,如果是 那么就是手动输入
|
//匹配是否包含表前缀,如果是 那么就是手动输入
|
||||||
$patten = "/$this->prefix/";
|
$patten = "/$this->prefix/";
|
||||||
if(!preg_match_all($patten,$table)){
|
if (!preg_match_all($patten, $table)) {
|
||||||
$table = $this->prefix.$table;
|
$table = $this->prefix . $table;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -248,10 +244,10 @@ class Datatable{
|
|||||||
* @author colin <colin@tensent.cn>
|
* @author colin <colin@tensent.cn>
|
||||||
* @return boolen
|
* @return boolen
|
||||||
*/
|
*/
|
||||||
public function CheckTable($table){
|
public function CheckTable($table) {
|
||||||
//获取表名
|
//获取表名
|
||||||
$this->table = $this->getTablename($table,true);
|
$this->table = $this->getTablename($table, true);
|
||||||
$result = Db::execute("SHOW TABLES LIKE '%$this->table%'");
|
$result = Db::execute("SHOW TABLES LIKE '%$this->table%'");
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -262,12 +258,12 @@ class Datatable{
|
|||||||
* @author colin <colin@tensent.cn>
|
* @author colin <colin@tensent.cn>
|
||||||
* @return boolen
|
* @return boolen
|
||||||
*/
|
*/
|
||||||
public function CheckField($table,$field){
|
public function CheckField($table, $field) {
|
||||||
//检查字段是否存在
|
//检查字段是否存在
|
||||||
$table = $this->getTablename($table,true);
|
$table = $this->getTablename($table, true);
|
||||||
if(!Db::query("Describe $table $field")){
|
if (!Db::query("Describe $table $field")) {
|
||||||
return false;
|
return false;
|
||||||
}else{
|
} else {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user