From 250f6ea95d29c6e972170e594b8fedbc3aa87915 Mon Sep 17 00:00:00 2001 From: molong Date: Mon, 19 Jun 2017 11:11:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/controller/Attribute.php | 15 ----- application/common/model/Attribute.php | 65 +--------------------- application/common/validate/Attribute.php | 3 +- 3 files changed, 2 insertions(+), 81 deletions(-) diff --git a/application/admin/controller/Attribute.php b/application/admin/controller/Attribute.php index ffa0a04f..0361e836 100644 --- a/application/admin/controller/Attribute.php +++ b/application/admin/controller/Attribute.php @@ -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() { diff --git a/application/common/model/Attribute.php b/application/common/model/Attribute.php index 8a4dda21..415c9eee 100644 --- a/application/common/model/Attribute.php +++ b/application/common/model/Attribute.php @@ -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; - } } \ No newline at end of file diff --git a/application/common/validate/Attribute.php b/application/common/validate/Attribute.php index 3bee6c42..aeaf1f99 100644 --- a/application/common/validate/Attribute.php +++ b/application/common/validate/Attribute.php @@ -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' => '描述不能为空!',