合并相同卡

This commit is contained in:
邓皓元 2019-04-25 23:58:40 +08:00
parent 65e06acb1c
commit f04e013498

View File

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