去掉事务

This commit is contained in:
邓皓元 2019-04-26 00:52:19 +08:00
parent f04e013498
commit a6cc1c50dc

View File

@ -71,32 +71,30 @@ class FlowPoolMonthSync extends Command
$array = array_merge($array, $items);
}
DB::transaction(function () use ($array) {
$this->line('插入数据,条数 #:' . count($array));
$this->line('插入数据,条数 #:' . count($array));
foreach (array_groupBy($array, 'month') as $month => $group) {
$news = [];
foreach (array_groupBy($array, 'month') as $month => $group) {
$news = [];
$group = array_groupBy($group, 'sim');
$group = array_groupBy($group, 'sim');
foreach ($group as $sim => $item) {
if (count($item) > 1) {
$temp = $item[0];
$temp['mebibyte'] = array_sum(array_pluck($item, 'mebibyte'));
$group[$sim] = [$temp];
}
}
$news = array_merge($news, array_collapse($group));
$table = FlowPoolService::checkTable($month);
foreach (array_chunk($news, 1000) as $values) {
echo '.';
app(FlowPoolMonth::class)->setTable($table)->upsert($values, ['sim', 'month']);
foreach ($group as $sim => $item) {
if (count($item) > 1) {
$temp = $item[0];
$temp['mebibyte'] = array_sum(array_pluck($item, 'mebibyte'));
$group[$sim] = [$temp];
}
}
});
$news = array_merge($news, array_collapse($group));
$table = FlowPoolService::checkTable($month);
foreach (array_chunk($news, 1000) as $values) {
echo '.';
app(FlowPoolMonth::class)->setTable($table)->upsert($values, ['sim', 'month']);
}
}
$this->line($this->description . ' End');
}