mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-08 07:32:48 +08:00
修正Query类的chunk方法
This commit is contained in:
@@ -1254,21 +1254,27 @@ class Query
|
|||||||
*/
|
*/
|
||||||
public function chunk($count, $callback, $column = null)
|
public function chunk($count, $callback, $column = null)
|
||||||
{
|
{
|
||||||
$column = $column ?: $this->connection->getTableInfo('', 'pk');
|
$column = $column ?: $this->connection->getTableInfo('', 'pk');
|
||||||
$options = $this->getOptions();
|
$options = $this->getOptions();
|
||||||
|
if (empty($options['table'])) {
|
||||||
|
$table = $this->connection->getTable();
|
||||||
|
}
|
||||||
$resultSet = $this->limit($count)->order($column, 'asc')->select();
|
$resultSet = $this->limit($count)->order($column, 'asc')->select();
|
||||||
|
|
||||||
while (!empty($resultSet)) {
|
while (!empty($resultSet)) {
|
||||||
if (false === call_user_func($callback, $resultSet)) {
|
if (false === call_user_func($callback, $resultSet)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$end = end($resultSet);
|
$end = end($resultSet);
|
||||||
$lastId = is_array($end) ? $end[$column] : $end->$column;
|
$lastId = is_array($end) ? $end[$column] : $end->$column;
|
||||||
$resultSet = $this->options($options)
|
$this->options($options)
|
||||||
->limit($count)
|
->limit($count)
|
||||||
->where($column, '>', $lastId)
|
->where($column, '>', $lastId)
|
||||||
->order($column, 'asc')
|
->order($column, 'asc');
|
||||||
->select();
|
if (isset($table)) {
|
||||||
|
$this->table($table);
|
||||||
|
}
|
||||||
|
$resultSet = $this->select();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user