修复bug
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user