模型基本雏形
This commit is contained in:
@@ -46,7 +46,17 @@ class Attribute extends Admin {
|
||||
* @author colin <colin@tensent.cn>
|
||||
*/
|
||||
public function index($model_id = null) {
|
||||
$this->getAttributeList($model_id);
|
||||
if (!$model_id) {
|
||||
return $this->error('非法操作!');
|
||||
}
|
||||
$list = model('Attribute')->where('model_id', $model_id)->order('id desc')->paginate(25);
|
||||
|
||||
$data = array(
|
||||
'list' => $list,
|
||||
'model_id' => $model_id,
|
||||
'page' => $list->render(),
|
||||
);
|
||||
$this->assign($data);
|
||||
$this->setMeta('字段管理');
|
||||
return $this->fetch();
|
||||
}
|
||||
@@ -55,19 +65,15 @@ class Attribute extends Admin {
|
||||
* 创建字段
|
||||
* @author colin <colin@tensent.cn>
|
||||
*/
|
||||
public function add() {
|
||||
$model_id = input('model_id', '', 'trim,intval');
|
||||
public function add($model_id = '') {
|
||||
if (IS_POST) {
|
||||
$result = $this->model->change();
|
||||
if ($result) {
|
||||
$result = $this->model->validate('attribute.add')->save($this->param);
|
||||
if (false !== $result) {
|
||||
return $this->success("创建成功!", url('Attribute/index', array('model_id' => $model_id)));
|
||||
} else {
|
||||
return $this->error($this->model->getError());
|
||||
}
|
||||
} else {
|
||||
if (!$model_id) {
|
||||
return $this->error('非法操作!');
|
||||
}
|
||||
$data = array(
|
||||
'info' => array('model_id' => $model_id),
|
||||
'fieldGroup' => $this->field,
|
||||
@@ -82,16 +88,15 @@ class Attribute extends Admin {
|
||||
* 编辑字段方法
|
||||
* @author colin <colin@tensent.cn>
|
||||
*/
|
||||
public function edit() {
|
||||
public function edit($id = '', $model_id = '') {
|
||||
if (IS_POST) {
|
||||
$result = $this->model->change();
|
||||
$result = $this->model->validate('attribute.edit')->save($this->param, array('id'=>$id));
|
||||
if ($result) {
|
||||
return $this->success("修改成功!", url('Attribute/index', array('model_id' => $_POST['model_id'])));
|
||||
return $this->success("修改成功!", url('Attribute/index', array('model_id' => $model_id)));
|
||||
} else {
|
||||
return $this->error($this->model->getError());
|
||||
}
|
||||
} else {
|
||||
$id = input('id', '', 'trim,intval');
|
||||
$info = db('Attribute')->find($id);
|
||||
$data = array(
|
||||
'info' => $info,
|
||||
@@ -129,6 +134,7 @@ class Attribute extends Admin {
|
||||
$model = model('Model')->where('id', $id)->find();
|
||||
$result = $this->model->generate($model);
|
||||
if (false !== $result) {
|
||||
db('Model')->where('id', $id)->setField('table_status', 1);
|
||||
return $this->success('生成成功!', url('admin/model/index'));
|
||||
} else {
|
||||
return $this->error($this->model->getError());
|
||||
@@ -137,34 +143,7 @@ class Attribute extends Admin {
|
||||
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() {
|
||||
return array(
|
||||
@@ -192,21 +171,4 @@ 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);
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,7 @@ class Content extends Admin {
|
||||
return $this->error("无此模型!");
|
||||
} else {
|
||||
$this->modelInfo = $list[$model_id];
|
||||
$this->model = model('Content')->extend($this->modelInfo['name']);
|
||||
$this->model = new \app\common\model\Content($this->modelInfo['name']);
|
||||
}
|
||||
|
||||
$this->assign('model_id', $model_id);
|
||||
@@ -44,7 +44,7 @@ class Content extends Admin {
|
||||
$field = array_filter($grid_list['fields']);
|
||||
|
||||
|
||||
$list = $this->model->lists($map, $order);
|
||||
$list = $this->model->where($map)->order($order)->paginate($this->modelInfo['list_row']);
|
||||
|
||||
$data = array(
|
||||
'grid' => $grid_list,
|
||||
@@ -67,7 +67,7 @@ class Content extends Admin {
|
||||
*/
|
||||
public function add() {
|
||||
if (IS_POST) {
|
||||
$result = $this->model->change();
|
||||
$result = $this->model->save($this->param);
|
||||
if ($result) {
|
||||
return $this->success("添加成功!", url('admin/content/index', array('model_id' => $this->modelInfo['id'])));
|
||||
} else {
|
||||
@@ -98,7 +98,7 @@ class Content extends Admin {
|
||||
*/
|
||||
public function edit($id) {
|
||||
if (IS_POST) {
|
||||
$result = $this->model->change();
|
||||
$result = $this->model->save($this->param, array('id'=> $id));
|
||||
if ($result !== false) {
|
||||
return $this->success("更新成功!", url('admin/content/index', array('model_id' => $this->modelInfo['id'])));
|
||||
} else {
|
||||
@@ -108,7 +108,7 @@ class Content extends Admin {
|
||||
if (!$id) {
|
||||
return $this->error("非法操作!");
|
||||
}
|
||||
$info = $this->model->detail($id);
|
||||
$info = $this->model->find($id);
|
||||
if (!$info) {
|
||||
return $this->error($this->model->getError());
|
||||
}
|
||||
@@ -186,16 +186,9 @@ class Content extends Admin {
|
||||
* @author molong <ycgpp@126.com>
|
||||
*/
|
||||
protected function getField() {
|
||||
$field_group = parse_config_attr($this->modelInfo['field_group']);
|
||||
$field_sort = json_decode($this->modelInfo['field_sort'], true);
|
||||
$field_group = parse_config_attr($this->modelInfo['attribute_group']);
|
||||
|
||||
if ($this->modelInfo['extend'] > 1) {
|
||||
$map['model_id'] = $this->modelInfo['id'];
|
||||
} else {
|
||||
$model_id[] = $this->modelInfo['id'];
|
||||
$model_id[] = 1;
|
||||
$map['model_id'] = array('IN', $model_id);
|
||||
}
|
||||
$map['model_id'] = $this->modelInfo['id'];
|
||||
if ($this->request->action() == 'add') {
|
||||
$map['is_show'] = array('in', array('1', '2'));
|
||||
} elseif ($this->request->action() == 'edit') {
|
||||
@@ -204,30 +197,13 @@ class Content extends Admin {
|
||||
|
||||
//获得数组的第一条数组
|
||||
$first_key = array_keys($field_group);
|
||||
$fields = model('Attribute')->getFieldlist($map);
|
||||
if (!empty($field_sort)) {
|
||||
foreach ($field_sort as $key => $value) {
|
||||
foreach ($value as $index) {
|
||||
if (isset($fields[$index])) {
|
||||
$groupfield[$key][] = $fields[$index];
|
||||
unset($fields[$index]);
|
||||
}
|
||||
}
|
||||
$rows = model('Attribute')->where($map)->order('group_id asc, sort asc')->select();
|
||||
if (!empty($rows)) {
|
||||
foreach ($rows as $key => $value) {
|
||||
$fields[$field_group[$value['group_id']]][] = $value;
|
||||
}
|
||||
}
|
||||
//未进行排序的放入第一组中
|
||||
$fields[] = array('name' => 'model_id', 'type' => 'hidden'); //加入模型ID值
|
||||
$fields[] = array('name' => 'id', 'type' => 'hidden'); //加入模型ID值
|
||||
foreach ($fields as $key => $value) {
|
||||
$groupfield[$first_key[0]][] = $value;
|
||||
}
|
||||
|
||||
foreach ($field_group as $key => $value) {
|
||||
if ($groupfield[$key]) {
|
||||
$data[$value] = $groupfield[$key];
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -253,6 +229,9 @@ class Content extends Admin {
|
||||
if (isset($map['page'])) {
|
||||
unset($map['page']);
|
||||
}
|
||||
if (isset($map['model_id'])) {
|
||||
unset($map['model_id']);
|
||||
}
|
||||
$this->assign($data);
|
||||
return $map;
|
||||
}
|
||||
|
||||
@@ -49,6 +49,8 @@ class Model extends Admin {
|
||||
if (IS_POST) {
|
||||
$result = $this->model->validate('Model.add')->save($request->post());
|
||||
if (false !== $result) {
|
||||
//记录行为
|
||||
action_log('add_model', 'model', $result, session('auth_user.uid'));
|
||||
$this->success('创建成功!', url('admin/model/index'));
|
||||
}else{
|
||||
return $this->error($this->model->getError());
|
||||
@@ -67,6 +69,8 @@ class Model extends Admin {
|
||||
if (IS_POST) {
|
||||
$result = $this->model->validate('Model.edit')->save($request->post(), array('id'=>$request->post('id')));
|
||||
if (false !== $result) {
|
||||
//记录行为
|
||||
action_log('update_model', 'model', $request->post('id'), session('auth_user.uid'));
|
||||
$this->success('更新成功!', url('admin/model/index'));
|
||||
}else{
|
||||
return $this->error($this->model->getError());
|
||||
@@ -75,31 +79,11 @@ class Model extends Admin {
|
||||
$info = $this->model->where('id', $request->param('id'))->find();
|
||||
|
||||
//获取字段列表
|
||||
if ($info['attribute_list']) {
|
||||
$fields = model('Attribute')->where('id', 'IN', $info['attribute_list'])->where('is_show', 1)->select();
|
||||
$rows = db('Attribute')->where('model_id', $request->param('id'))->where('is_show', 1)->order('group_id asc, sort asc')->select();
|
||||
if ($rows) {
|
||||
// 梳理属性的可见性
|
||||
foreach ($fields as $key => $field) {
|
||||
$field['group'] = -1;
|
||||
$field['sort'] = 0;
|
||||
$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");
|
||||
foreach ($rows as $key => $field) {
|
||||
$fields[$field['group_id']][] = $field;
|
||||
}
|
||||
}else{
|
||||
$fields = array();
|
||||
|
||||
@@ -7,10 +7,6 @@
|
||||
</div>
|
||||
<div class="pull-right">
|
||||
<a class="btn btn-danger" href="{:url('add',array('model_id'=>$model_id))}"><i class="fa fa-plus"></i> 新 增</a>
|
||||
{if $model_id}
|
||||
<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>
|
||||
@@ -39,7 +35,7 @@
|
||||
<td>{$item['length']}</td>
|
||||
<td>{$item['value']}</td>
|
||||
<td>
|
||||
<a href="{:url('edit',array('id'=>$item['id']))}">编辑</a>
|
||||
<a href="{:url('edit',array('id'=>$item['id'], 'model_id'=>$model_id))}">编辑</a>
|
||||
<a href="{:url('del',array('id'=>$item['id'], 'model_id'=>$model_id))}" class="confirm ajax-get">删除</a>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
{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" /}
|
||||
@@ -63,21 +63,16 @@
|
||||
<div class="form-group">
|
||||
<label class="col-lg-2 control-label">表单显示排序</label>
|
||||
<div class="col-lg-10 boards" id="attribute_group_sort">
|
||||
{volist name=":parse_field_attr($info['attribute_group'])" id="vo"}
|
||||
{volist name="fields" id="field"}
|
||||
<div class="board panel panel-info">
|
||||
<div class="panel-heading">{$vo}</div>
|
||||
<div class="panel-heading">{:parse_field_attr($info['attribute_group'])[$key]}</div>
|
||||
<div class="panel-body">
|
||||
<div class="board-list" data-group="{$key}">
|
||||
{foreach name="fields" item="field" key="k"}
|
||||
{if (($field['group'] == -1) or ($field['group'] eq $key))}
|
||||
<div class="board-item">
|
||||
<span data="{$field['id']}">{$field['title']} [{$field['name']}]</span>
|
||||
<input type="hidden" name="attribute_sort[{$key}][]" value="{$field['id']}"/>
|
||||
</div>
|
||||
{php}
|
||||
unset($fields[$k]);
|
||||
{/php}
|
||||
{/if}
|
||||
{foreach name="field" item="item" key="k"}
|
||||
<div class="board-item">
|
||||
<span data="{$item['id']}">{$item['title']} [{$item['name']}]</span>
|
||||
<input type="hidden" name="attribute_sort[{$key}][]" value="{$item['id']}"/>
|
||||
</div>
|
||||
{/foreach}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user