mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-08 07:32:48 +08:00
改进数据副本的处理
This commit is contained in:
@@ -179,9 +179,10 @@ class Model
|
|||||||
* 对写入到数据库的数据进行处理
|
* 对写入到数据库的数据进行处理
|
||||||
* @access protected
|
* @access protected
|
||||||
* @param mixed $data 要操作的数据
|
* @param mixed $data 要操作的数据
|
||||||
|
* @param string $type insert 或者 update
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function _write_data($data)
|
protected function _write_data($data, $type)
|
||||||
{
|
{
|
||||||
if (!empty($this->duplicate)) {
|
if (!empty($this->duplicate)) {
|
||||||
// 存在数据副本
|
// 存在数据副本
|
||||||
@@ -190,16 +191,17 @@ class Model
|
|||||||
// 没有数据变化
|
// 没有数据变化
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
// 保留主键信息
|
|
||||||
$pk = $this->getPk();
|
if ('update' == $type) {
|
||||||
if (is_array($pk)) {
|
// 保留主键信息
|
||||||
foreach ($pk as $key) {
|
$pk = $this->getPk();
|
||||||
if (isset($this->duplicate[$key])) {
|
if (is_array($pk)) {
|
||||||
$data[$key] = $this->duplicate[$key];
|
foreach ($pk as $key) {
|
||||||
|
if (isset($this->duplicate[$key])) {
|
||||||
|
$data[$key] = $this->duplicate[$key];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
} elseif (isset($this->duplicate[$pk])) {
|
||||||
} else {
|
|
||||||
if (isset($this->duplicate[$pk])) {
|
|
||||||
$data[$pk] = $this->duplicate[$pk];
|
$data[$pk] = $this->duplicate[$pk];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -264,7 +266,7 @@ class Model
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 数据处理
|
// 数据处理
|
||||||
$data = $this->_write_data($data);
|
$data = $this->_write_data($data, 'insert');
|
||||||
// 分析表达式
|
// 分析表达式
|
||||||
$options = $this->_parseOptions();
|
$options = $this->_parseOptions();
|
||||||
if (false === $this->_before_insert($data, $options)) {
|
if (false === $this->_before_insert($data, $options)) {
|
||||||
@@ -308,7 +310,7 @@ class Model
|
|||||||
}
|
}
|
||||||
// 数据处理
|
// 数据处理
|
||||||
foreach ($dataList as $key => $data) {
|
foreach ($dataList as $key => $data) {
|
||||||
$dataList[$key] = $this->_write_data($data);
|
$dataList[$key] = $this->_write_data($data, 'insert');
|
||||||
}
|
}
|
||||||
// 分析表达式
|
// 分析表达式
|
||||||
$options = $this->_parseOptions($options);
|
$options = $this->_parseOptions($options);
|
||||||
@@ -343,7 +345,7 @@ class Model
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 数据处理
|
// 数据处理
|
||||||
$data = $this->_write_data($data);
|
$data = $this->_write_data($data, 'update');
|
||||||
if (empty($data)) {
|
if (empty($data)) {
|
||||||
// 没有数据则不执行
|
// 没有数据则不执行
|
||||||
$this->error = Lang::get('_DATA_TYPE_INVALID_');
|
$this->error = Lang::get('_DATA_TYPE_INVALID_');
|
||||||
|
|||||||
Reference in New Issue
Block a user