模型bug修复
This commit is contained in:
@@ -10,6 +10,7 @@
|
|||||||
namespace app\common\model;
|
namespace app\common\model;
|
||||||
|
|
||||||
use \think\Validate;
|
use \think\Validate;
|
||||||
|
use \think\Loader;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @title 基础模型
|
* @title 基础模型
|
||||||
@@ -38,25 +39,39 @@ class BaseModel {
|
|||||||
public function save($data, $where = array()) {
|
public function save($data, $where = array()) {
|
||||||
$this->data = $data;
|
$this->data = $data;
|
||||||
$rule = $msg = array();
|
$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) {
|
foreach ($attr as $key => $value) {
|
||||||
if ($value['is_must'] == 1) {
|
if ($value['is_must'] == 1) {
|
||||||
$rule[$value['name']] = "require";
|
$rule[$value['name']] = "require";
|
||||||
$msg[$value['name'] . '.require'] = $value['title'] . "不能为空!";
|
$msg[$value['name'] . '.require'] = $value['title'] . "不能为空!";
|
||||||
}
|
}
|
||||||
}
|
if ($value['name'] == 'uid') {
|
||||||
$validate = new Validate($rule, $msg);
|
$this->data['uid'] = session('user_auth.uid');
|
||||||
$result = $validate->check($data);
|
}
|
||||||
if (!$result) {
|
if ($value['is_must'] == 1 && $value['is_show'] == 0) {
|
||||||
$this->error = $validate->getError();
|
$this->data[$value['name']] = $value['value'];
|
||||||
return false;
|
}
|
||||||
}
|
}
|
||||||
$this->autoCompleteData($this->auto);
|
$this->autoCompleteData($this->auto);
|
||||||
if (!empty($where)) {
|
if (!empty($where)) {
|
||||||
$this->autoCompleteData($this->update);
|
$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);
|
return $this->where($where)->update($this->data);
|
||||||
} else {
|
} else {
|
||||||
$this->autoCompleteData($this->insert);
|
$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);
|
return $this->insert($this->data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user