修复bug

This commit is contained in:
2017-06-19 11:11:28 +08:00
parent d8feb066ea
commit 250f6ea95d
3 changed files with 2 additions and 81 deletions

View File

@@ -128,21 +128,6 @@ class Attribute extends Admin {
return $this->error($this->model->getError());
}
}
public function generate($id = '') {
if ($id) {
$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());
}
} else {
return $this->error('非法操作!');
}
}
//字段编辑所需字段
protected function getField() {

View File

@@ -33,7 +33,7 @@ class Attribute extends Base{
'is_must' => $data['is_must'],
'sort' => 0,
);
$attr['after'] = db('Attribute')->where('model_id', $data['model_id'])->order('id desc')->value('name');
$attr['after'] = db('Attribute')->where('name', '<>', $data['name'])->where('model_id', $data['model_id'])->order('id desc')->value('name');
return $db->columField(strtolower($name), $attr)->query();
}
});
@@ -76,28 +76,6 @@ class Attribute extends Base{
return $list;
}
public function change(){
$data = \think\Request::instance()->post();
if ($data['id']) {
$status = $this->validate('attribute.edit')->save($data, array('id'=>$data['id']));
}else{
$status = $this->validate('attribute.add')->save($data);
}
if (false !== $status) {
//在数据库内添加字段
$result = $this->checkTableField($data);
if (!$result) {
$this->error = "字段创建失败!";
return false;
}
return $status;
}else{
return false;
}
}
public function del($id, $model_id){
$map['id'] = $id;
$info = $this->find($id);
@@ -124,45 +102,4 @@ class Attribute extends Base{
return false;
}
}
protected function checkTableField($field){
$model = db('Model')->find($field['model_id']);
if ($model['extend'] == 1) {
$tablename = 'document_'.$model['name'];
$key = "doc_id";
}else{
$tablename = $model['name'];
$key = "id";
}
//实例化一个数据库操作类
$db = new \com\Datatable();
//检查表是否存在并创建
if (!$db->CheckTable($tablename)) {
//创建新表
$db->start_table($tablename)->create_id($key)->create_key($key)->end_table()->query();
};
$oldname = "";
if ($field['id']) {
$oldname = $this->db()->where(array('id'=>$field['id']))->value('name');
}
$attribute_type = get_attribute_type();
$field['field'] = $field['name'];
$field['type'] = $attribute_type[$field['type']][1];
$field['is_null'] = $field['is_must']; //是否为null
$field['default'] = $field['value']; //字段默认值
$field['comment'] = $field['remark']; //字段注释
if($db->CheckField($tablename,$oldname) && $oldname){
$field['action'] = 'CHANGE';
$field['oldname'] = $oldname;
$field['newname'] = $field['name'];
$db->colum_field($tablename,$field);
}else{
$field['action'] = 'ADD';
$db->colum_field($tablename,$field);
}
$result = $db->create();
return $result;
}
}

View File

@@ -15,7 +15,7 @@ namespace app\common\validate;
class Attribute extends Base {
protected $rule = array(
'name' => 'require|unique:attribute|/^[a-zA-Z]\w{0,39}$/',
'name' => 'require|/^[a-zA-Z]\w{0,39}$/',
'title' => 'require',
'type' => 'require',
'length' => 'requireIn:type,textarea,editor|integer',
@@ -27,7 +27,6 @@ class Attribute extends Base {
'length.requireIn' => '字段长度必须!',
'length.integer' => '字段必须为整形',
'name.require' => '字段名不能为空!',
'name.unique' => '字段名已存在!',
'title.require' => '字段标题不能为空!',
'type.require' => '类型不能为空!',
'remark.require' => '描述不能为空!',