From d6ea6c7e8029f5fbe649f0e5d5aced958a93ac2d Mon Sep 17 00:00:00 2001 From: molong Date: Wed, 9 Aug 2017 16:21:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A8=A1=E5=9E=8Bbug=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/common/model/BaseModel.php | 29 +++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/application/common/model/BaseModel.php b/application/common/model/BaseModel.php index a3f09339..91f01934 100644 --- a/application/common/model/BaseModel.php +++ b/application/common/model/BaseModel.php @@ -10,6 +10,7 @@ namespace app\common\model; use \think\Validate; +use \think\Loader; /** * @title 基础模型 @@ -38,25 +39,39 @@ class BaseModel { public function save($data, $where = array()) { $this->data = $data; $rule = $msg = array(); - $attr = db('Attribute')->where('id', $data['model_id'])->select(); + $attr = db('Attribute')->where('model_id', $data['model_id'])->select(); foreach ($attr as $key => $value) { if ($value['is_must'] == 1) { $rule[$value['name']] = "require"; $msg[$value['name'] . '.require'] = $value['title'] . "不能为空!"; } - } - $validate = new Validate($rule, $msg); - $result = $validate->check($data); - if (!$result) { - $this->error = $validate->getError(); - return false; + if ($value['name'] == 'uid') { + $this->data['uid'] = session('user_auth.uid'); + } + if ($value['is_must'] == 1 && $value['is_show'] == 0) { + $this->data[$value['name']] = $value['value']; + } } $this->autoCompleteData($this->auto); if (!empty($where)) { $this->autoCompleteData($this->update); + + $validate = new Validate($rule, $msg); + $result = $validate->check($this->data); + if (!$result) { + $this->error = $validate->getError(); + return false; + } return $this->where($where)->update($this->data); } else { $this->autoCompleteData($this->insert); + + $validate = new Validate($rule, $msg); + $result = $validate->check($this->data); + if (!$result) { + $this->error = $validate->getError(); + return false; + } return $this->insert($this->data); } }