完善模型管理
This commit is contained in:
@@ -196,11 +196,13 @@ class Content extends Admin {
|
||||
}
|
||||
|
||||
//获得数组的第一条数组
|
||||
$first_key = array_keys($field_group);
|
||||
$rows = model('Attribute')->where($map)->order('group_id asc, sort asc')->select();
|
||||
$rows = model('Attribute')->getFieldlist($map, 'id');
|
||||
if (!empty($rows)) {
|
||||
foreach ($rows as $key => $value) {
|
||||
$fields[$field_group[$value['group_id']]][] = $value;
|
||||
$list[$value['group_id']][] = $value;
|
||||
}
|
||||
foreach ($field_group as $key => $value) {
|
||||
$fields[$value] = isset($list[$key]) ? $list[$key] : array();
|
||||
}
|
||||
}else{
|
||||
$fields = array();
|
||||
|
||||
@@ -53,7 +53,7 @@ class Model extends Admin {
|
||||
action_log('add_model', 'model', $result, session('auth_user.uid'));
|
||||
$this->success('创建成功!', url('admin/model/index'));
|
||||
}else{
|
||||
return $this->error($this->model->getError());
|
||||
return $this->error($this->model->getError() ? $this->model->getError() : '模型标识为保留名称!');
|
||||
}
|
||||
}else{
|
||||
$this->setMeta('新增模型');
|
||||
@@ -78,12 +78,16 @@ class Model extends Admin {
|
||||
}else{
|
||||
$info = $this->model->where('id', $request->param('id'))->find();
|
||||
|
||||
$field_group = parse_config_attr($info['attribute_group']);
|
||||
//获取字段列表
|
||||
$rows = db('Attribute')->where('model_id', $request->param('id'))->where('is_show', 1)->order('group_id asc, sort asc')->select();
|
||||
if ($rows) {
|
||||
// 梳理属性的可见性
|
||||
foreach ($rows as $key => $field) {
|
||||
$fields[$field['group_id']][] = $field;
|
||||
$list[$field['group_id']][] = $field;
|
||||
}
|
||||
foreach ($field_group as $key => $value) {
|
||||
$fields[$value] = isset($list[$key]) ? $list[$key] : array();
|
||||
}
|
||||
}else{
|
||||
$fields = array();
|
||||
|
||||
13
application/admin/fields.php
Normal file
13
application/admin/fields.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
return array(
|
||||
'title'=> array('name' => 'title', 'title' => '标题', 'type' => 'text', 'length' => 200, 'extra' => '', 'remark' => '标题', 'is_show' => 1, 'is_must' => 1, 'value'=>''),
|
||||
'category_id' => array('name' => 'category_id', 'title' => '栏目', 'type' => 'bind', 'length' => 10, 'extra' => 'category', 'remark' => '栏目', 'is_show' => 1, 'is_must' => 1, 'value'=>'0'),
|
||||
'uid' => array('name' => 'uid', 'title' => '用户UID', 'type' => 'num', 'length' => 11, 'extra' => '', 'remark' => '用户UID', 'is_show' => 0, 'is_must' => 1, 'value'=>'0'),
|
||||
'cover_id' => array('name' => 'cover_id', 'title' => '内容封面', 'type' => 'image', 'length' => 10, 'extra' => '', 'remark' => '内容封面', 'is_show' => 1, 'is_must' => 0, 'value'=>''),
|
||||
'description' => array('name' => 'description', 'title' => '内容描述', 'type' => 'textarea', 'length' => '', 'extra' => '', 'remark' => '内容描述', 'is_show' => 1, 'is_must' => 0, 'value'=>''),
|
||||
'status' => array('name' => 'status', 'title' => '数据状态', 'type' => 'select', 'length' => 2, 'extra' => "-1:删除\r\n0:禁用\r\n1:正常\r\n2:待审核\r\n3:草稿", 'remark' => '数据状态', 'is_show' => 1, 'is_must' => 1, 'value'=>'1'),
|
||||
'is_top' => array('name' => 'is_top', 'title' => '是否置顶', 'type' => 'bool', 'length' => 2, 'extra' => '', 'remark' => '是否置顶', 'is_show' => 0, 'is_must' => 1, 'value'=>'0'),
|
||||
'view' => array('name' => 'view', 'title' => '浏览数量', 'type' => 'num', 'length' => 11, 'extra' => '', 'remark' => '浏览数量', 'is_show' => 0, 'is_must' => 1, 'value'=>'0'),
|
||||
'update_time' => array('name' => 'update_time', 'title' => '更新时间', 'type' => 'datetime', 'length' => 11, 'extra' => '', 'remark' => '更新时间', 'is_show' => 0, 'is_must' => 1, 'value'=>'0'),
|
||||
'create_time' => array('name' => 'create_time', 'title' => '添加时间', 'type' => 'datetime', 'length' => 11, 'extra' => '', 'remark' => '添加时间', 'is_show' => 0, 'is_must' => 1, 'value'=>'0'),
|
||||
);
|
||||
@@ -29,6 +29,16 @@
|
||||
<span class="help-block">(请输入模型的名称)</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-lg-2 control-label">文档模型</label>
|
||||
<div class="col-lg-6 col-sm-10">
|
||||
<select class="form-control" name="is_doc">
|
||||
<option value="1">是</option>
|
||||
<option value="0">否</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-6 col-sm-10">
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
<ul class="nav nav-tabs">
|
||||
<li class="active"><a href="#tab1" data-toggle="tab">基 础</a></li>
|
||||
<li><a href="#tab2" data-toggle="tab">设 计</a></li>
|
||||
<li><a href="#tab3" data-toggle="tab">高 级</a></li>
|
||||
</ul>
|
||||
<div class="tab-content">
|
||||
<div class="tab-pane fade in active" id="tab1">
|
||||
@@ -45,14 +44,6 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="tab-pane fade" id="tab2">
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-lg-2 control-label">字段别名定义</label>
|
||||
<div class="col-lg-6 col-sm-10">
|
||||
<textarea name="attribute_alias" class="form-control">{$info['attribute_alias']}</textarea>
|
||||
<span class="help-block">(用于表单显示的名称)</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-lg-2 control-label">表单显示分组</label>
|
||||
<div class="col-lg-6 col-sm-10">
|
||||
@@ -65,7 +56,7 @@
|
||||
<div class="col-lg-10 boards" id="attribute_group_sort">
|
||||
{volist name="fields" id="field"}
|
||||
<div class="board panel panel-info">
|
||||
<div class="panel-heading">{:parse_field_attr($info['attribute_group'])[$key]}</div>
|
||||
<div class="panel-heading">{$key}</div>
|
||||
<div class="panel-body">
|
||||
<div class="board-list" data-group="{$key}">
|
||||
{foreach name="field" item="item" key="k"}
|
||||
@@ -105,8 +96,6 @@
|
||||
<span class="help-block">(默认列表模板的高级搜索项)</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="tab-pane fade" id="tab3">
|
||||
<div class="form-group">
|
||||
<label class="col-lg-2 control-label">列表模板</label>
|
||||
<div class="col-lg-6 col-sm-10">
|
||||
|
||||
@@ -59,7 +59,7 @@ class Attribute extends Base{
|
||||
|
||||
public function getFieldlist($map,$index='id'){
|
||||
$list = array();
|
||||
$row = db('Attribute')->field('*,remark as help,type,extra as "option"')->where($map)->select();
|
||||
$row = db('Attribute')->field('*,remark as help,type,extra as "option"')->where($map)->order('group_id asc, sort asc')->select();
|
||||
foreach ($row as $key => $value) {
|
||||
if (in_array($value['type'],array('checkbox','radio','select','bool'))) {
|
||||
$value['option'] = parse_field_attr($value['extra']);
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace app\common\model;
|
||||
class Model extends Base {
|
||||
|
||||
protected $auto = ['update_time'];
|
||||
protected $insert = ['name', 'create_time', 'status' => 1, 'list_grid'=>'id:ID'];
|
||||
protected $insert = ['name', 'create_time', 'status' => 1, 'list_grid'=>"id:ID\r\ntitle:标题\r\ncreate_time:添加时间|time_format\r\nupdate_time:更新时间|time_format"];
|
||||
protected $type = array(
|
||||
'id' => 'integer',
|
||||
'create_time' => 'integer',
|
||||
@@ -32,7 +32,22 @@ class Model extends Base {
|
||||
if (!$db->CheckTable($tablename)) {
|
||||
//创建新表
|
||||
return $db->initTable($tablename, $data['title'], 'id')->query();
|
||||
};
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
});
|
||||
self::afterInsert(function($event){
|
||||
$data = $event->toArray();
|
||||
if ($data['is_doc']) {
|
||||
$fields = include(APP_PATH.'admin/fields.php');
|
||||
if (!empty($fields)) {
|
||||
foreach ($fields as $key => $value) {
|
||||
$fields[$key]['model_id'] = $data['id'];
|
||||
}
|
||||
model('Attribute')->saveAll($fields);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
});
|
||||
self::beforeUpdate(function($event){
|
||||
$data = $event->toArray();
|
||||
@@ -76,12 +91,13 @@ class Model extends Base {
|
||||
$db = new \com\Datatable();
|
||||
if ($db->CheckTable($tablename)) {
|
||||
//检测表是否存在
|
||||
$result = $db->del_table($tablename)->query();
|
||||
$result = $db->delTable($tablename)->query();
|
||||
if (!$result) {
|
||||
return false;
|
||||
$this->error = "数据表删除失败!";
|
||||
}
|
||||
}
|
||||
db('Attribute')->where('model_id', $id)->delete(); //删除字段信息
|
||||
$result = $this->where('id', $id)->delete();
|
||||
if ($result) {
|
||||
return true;
|
||||
|
||||
@@ -20,7 +20,6 @@ class Attribute extends Base {
|
||||
'type' => 'require',
|
||||
'length' => 'requireIn:type,textarea,editor|integer',
|
||||
'remark' => 'require',
|
||||
'value' => 'requireIf:is_must,1'
|
||||
);
|
||||
|
||||
protected $message = array(
|
||||
@@ -30,7 +29,6 @@ class Attribute extends Base {
|
||||
'title.require' => '字段标题不能为空!',
|
||||
'type.require' => '类型不能为空!',
|
||||
'remark.require' => '描述不能为空!',
|
||||
'value' => '必填字段默认值必须!'
|
||||
);
|
||||
|
||||
protected $scene = array(
|
||||
|
||||
@@ -58,20 +58,21 @@ class Content extends Fornt {
|
||||
}
|
||||
|
||||
$cate = $this->getCategory($id);
|
||||
|
||||
if ($this->modelInfo['extend'] == 1) {
|
||||
//获得当前栏目的所有子栏目
|
||||
$map = array();
|
||||
$attr = db('Attribute')->where('model_id', $this->modelInfo['id'])->column('name');
|
||||
if (in_array('category_id', $attr)) {
|
||||
$ids = get_category_child($id);
|
||||
$map['category_id'] = array('IN', $ids);
|
||||
$map['model_id'] = $this->modelInfo['id'];
|
||||
}
|
||||
if (in_array('status', $attr)) {
|
||||
$map['status'] = array('GT', 0);
|
||||
}
|
||||
|
||||
if ($this->modelInfo['extend'] > 1) {
|
||||
$order = "id desc";
|
||||
} else {
|
||||
if (in_array('is_top', $attr)) {
|
||||
$order = "is_top desc,id desc";
|
||||
}else{
|
||||
$order = "id desc";
|
||||
}
|
||||
|
||||
$list = $this->model->where($map)->order($order)->paginate(15);
|
||||
|
||||
$data = array(
|
||||
|
||||
Reference in New Issue
Block a user