mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-06 23:02:48 +08:00
Model类抛出异常 create方法默认传入 \think\Input::post();
This commit is contained in:
@@ -265,8 +265,7 @@ class Model
|
|||||||
// 重置数据
|
// 重置数据
|
||||||
$this->data = [];
|
$this->data = [];
|
||||||
} else {
|
} else {
|
||||||
$this->error = Lang::get('_DATA_TYPE_INVALID_');
|
throw new Exception('invalid data');
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 数据处理
|
// 数据处理
|
||||||
@@ -309,8 +308,7 @@ class Model
|
|||||||
public function addAll($dataList, $options = [], $replace = false)
|
public function addAll($dataList, $options = [], $replace = false)
|
||||||
{
|
{
|
||||||
if (empty($dataList)) {
|
if (empty($dataList)) {
|
||||||
$this->error = Lang::get('_DATA_TYPE_INVALID_');
|
throw new Exception('no data to write')
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
// 数据处理
|
// 数据处理
|
||||||
foreach ($dataList as $key => $data) {
|
foreach ($dataList as $key => $data) {
|
||||||
@@ -344,16 +342,14 @@ class Model
|
|||||||
// 重置数据
|
// 重置数据
|
||||||
$this->data = [];
|
$this->data = [];
|
||||||
} else {
|
} else {
|
||||||
$this->error = Lang::get('_DATA_TYPE_INVALID_');
|
throw new Exception('no data require update');
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 数据处理
|
// 数据处理
|
||||||
$data = $this->_write_data($data, 'update');
|
$data = $this->_write_data($data, 'update');
|
||||||
if (empty($data)) {
|
if (empty($data)) {
|
||||||
// 没有数据则不执行
|
// 没有数据则不执行
|
||||||
$this->error = Lang::get('_DATA_TYPE_INVALID_');
|
throw new Exception('no data require update');
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
// 分析表达式
|
// 分析表达式
|
||||||
$options = $this->_parseOptions();
|
$options = $this->_parseOptions();
|
||||||
@@ -370,16 +366,14 @@ class Model
|
|||||||
$where[$field] = $data[$field];
|
$where[$field] = $data[$field];
|
||||||
} else {
|
} else {
|
||||||
// 如果缺少复合主键数据则不执行
|
// 如果缺少复合主键数据则不执行
|
||||||
$this->error = Lang::get('_OPERATION_WRONG_');
|
throw new Exception('miss complex primary data');
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
unset($data[$field]);
|
unset($data[$field]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!isset($where)) {
|
if (!isset($where)) {
|
||||||
// 如果没有任何更新条件则不执行
|
// 如果没有任何更新条件则不执行
|
||||||
$this->error = Lang::get('_OPERATION_WRONG_');
|
throw new Exception('no data to update without where');
|
||||||
return false;
|
|
||||||
} else {
|
} else {
|
||||||
$options['where'] = $where;
|
$options['where'] = $where;
|
||||||
}
|
}
|
||||||
@@ -421,7 +415,7 @@ class Model
|
|||||||
if (!empty($this->data) && isset($this->data[$pk])) {
|
if (!empty($this->data) && isset($this->data[$pk])) {
|
||||||
return $this->delete($this->data[$pk]);
|
return $this->delete($this->data[$pk]);
|
||||||
} else {
|
} else {
|
||||||
return false;
|
throw new Exception('no data to delete without where');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (is_numeric($options) || is_string($options)) {
|
if (is_numeric($options) || is_string($options)) {
|
||||||
@@ -450,14 +444,14 @@ class Model
|
|||||||
}
|
}
|
||||||
$options['where'] = $where;
|
$options['where'] = $where;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
throw new Exception('miss complex primary data');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 分析表达式
|
// 分析表达式
|
||||||
$options = $this->_parseOptions($options);
|
$options = $this->_parseOptions($options);
|
||||||
if (empty($options['where'])) {
|
if (empty($options['where'])) {
|
||||||
// 如果条件为空 不进行删除操作 除非设置 1=1
|
// 如果条件为空 不进行删除操作 除非设置 1=1
|
||||||
return false;
|
throw new Exception('no data to delete without where');
|
||||||
}
|
}
|
||||||
if (isset($options['where'][$pk])) {
|
if (isset($options['where'][$pk])) {
|
||||||
$pkValue = $options['where'][$pk];
|
$pkValue = $options['where'][$pk];
|
||||||
@@ -511,7 +505,7 @@ class Model
|
|||||||
}
|
}
|
||||||
$options['where'] = $where;
|
$options['where'] = $where;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
throw new Exception('miss complex primary data');
|
||||||
}
|
}
|
||||||
} elseif (false === $options) {
|
} elseif (false === $options) {
|
||||||
// 用于子查询 不查询只返回SQL
|
// 用于子查询 不查询只返回SQL
|
||||||
@@ -689,7 +683,7 @@ class Model
|
|||||||
$condition = $this->options['where'];
|
$condition = $this->options['where'];
|
||||||
if (empty($condition)) {
|
if (empty($condition)) {
|
||||||
// 没有条件不做任何更新
|
// 没有条件不做任何更新
|
||||||
return false;
|
throw new Exception('no data to update');
|
||||||
}
|
}
|
||||||
if ($lazyTime > 0) {
|
if ($lazyTime > 0) {
|
||||||
// 延迟写入
|
// 延迟写入
|
||||||
@@ -717,7 +711,7 @@ class Model
|
|||||||
$condition = $this->options['where'];
|
$condition = $this->options['where'];
|
||||||
if (empty($condition)) {
|
if (empty($condition)) {
|
||||||
// 没有条件不做任何更新
|
// 没有条件不做任何更新
|
||||||
return false;
|
throw new Exception('no data to update');
|
||||||
}
|
}
|
||||||
if ($lazyTime > 0) {
|
if ($lazyTime > 0) {
|
||||||
// 延迟写入
|
// 延迟写入
|
||||||
@@ -867,7 +861,7 @@ class Model
|
|||||||
}
|
}
|
||||||
$options['where'] = $where;
|
$options['where'] = $where;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
throw new Exception('miss complex primary data');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 总是查找一条记录
|
// 总是查找一条记录
|
||||||
@@ -941,14 +935,13 @@ class Model
|
|||||||
{
|
{
|
||||||
// 如果没有传值默认取POST数据
|
// 如果没有传值默认取POST数据
|
||||||
if (empty($data)) {
|
if (empty($data)) {
|
||||||
$data = $_POST;
|
$data = \think\Input::post();
|
||||||
} elseif (is_object($data)) {
|
} elseif (is_object($data)) {
|
||||||
$data = get_object_vars($data);
|
$data = get_object_vars($data);
|
||||||
}
|
}
|
||||||
// 验证数据
|
// 验证数据
|
||||||
if (empty($data) || !is_array($data)) {
|
if (empty($data) || !is_array($data)) {
|
||||||
$this->error = Lang::get('_DATA_TYPE_INVALID_');
|
throw new Exception('invalid data type');
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 状态
|
// 状态
|
||||||
|
|||||||
Reference in New Issue
Block a user