$count = Route::find()->where(['ro_visible'=>1])->count();//统计数据表数量标签:rt,上百万,分页,route,查询处理,tr,limit,region,name From: https://www.cnblogs.com/cuishilei/p/17370608.html
$limit = 100;
$pagecount = ceil($count/$limit); // 计算数据表的 页数
//事务执行
$tr = Yii::$app->db->beginTransaction();
try {
for ($page = 1; $page <= $pagecount; $page++) {
$offset = ($page - 1) * $limit;
$routes = Route::find()->where(['ro_visible'=>1])->limit($limit)->offset($offset)->all();//分页查询
foreach ($routes as $route) {
$rt_name=RouteType::find()->select('rt_name')->where(['rt_id'=>$route['rt_id']])->one();
//处理分页查询出来的数据 及逻辑更新
$route->ro_name = $route['start_region_name'].$route['child_start_region_name'].'-'.$route['stop_region_name'].$route['child_stop_region_name'].'-'.$rt_name['rt_name'];
$route->save();
}
}
$tr->commit();
$this->message('执行成功');
} catch (\Exception $exception) {
$tr->rollBack();
$this->message($exception->getMessage());
}