修改同步激活
This commit is contained in:
parent
f722eaee8e
commit
e4d33aa8ce
@ -24,35 +24,48 @@ class ActivateSync extends Command
|
||||
$packages = app(PackageRepository::class)->get()->pluck('service_cycle', 'id')->toArray();
|
||||
|
||||
$this->line('查询激活数据');
|
||||
|
||||
$res = DB::connection('mongo')->table('tblCard')->select(['cNo', 'saDate', 'sPCode'])
|
||||
->where('pNo', 'No00000000768')
|
||||
->where('isDel', '<>', 1)
|
||||
->whereBetween('saDate', [$starttime, $endtime])->get();
|
||||
->whereBetween('saDate', [$starttime, $endtime])->get()->toArray();
|
||||
|
||||
$list = $res->map(function ($item) use ($packages) {
|
||||
$activate_at = $item['saDate']->toDateTime()->format('Y-m-d H:i:s');
|
||||
$month = $packages[$item['sPCode']];
|
||||
$list = [];
|
||||
$total = [];
|
||||
|
||||
if (!$month) {
|
||||
throw new \Exception('未找到套餐数据:' . $item['sPCode']);
|
||||
$this->line('拼装更新数据:'.count($res));
|
||||
$chucks = array_chunk($res, 10000);
|
||||
foreach ($chucks as $chuck) {
|
||||
echo '.';
|
||||
$cards = Card::select(['sim', 'real_package_id'])->whereIn('sim', array_pluck($chuck, 'cNo'))->get()->keyBy('sim')->toArray();
|
||||
$total += count($cards);
|
||||
|
||||
foreach ($chuck as $card) {
|
||||
$value = $cards[$card['cNo']];
|
||||
|
||||
if (!$value) {
|
||||
echo '未找到卡' . $value['sim'] . PHP_EOL;
|
||||
continue;
|
||||
}
|
||||
|
||||
$activate_at = $card['saDate']->toDateTime()->format('Y-m-d H:i:s');
|
||||
|
||||
$month = $packages[$value['real_package_id']];
|
||||
|
||||
if (!$month) {
|
||||
throw new \Exception('未找到套餐数据:' . $value['real_package_id']);
|
||||
}
|
||||
|
||||
$list[] = [
|
||||
'sim' => $value['sim'],
|
||||
'activate_at' => $activate_at,
|
||||
'service_start_at' => $activate_at,
|
||||
'service_end_at' => Carbon::parse($activate_at)->addMonths($month)->format('Y-m-d H:i:s'),
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'sim' => $item['cNo'],
|
||||
'activate_at' => $activate_at,
|
||||
'service_start_at' => $activate_at,
|
||||
'service_end_at' => Carbon::parse($activate_at)->addMonths($month)->format('Y-m-d H:i:s'),
|
||||
];
|
||||
})->toArray();
|
||||
}
|
||||
|
||||
$this->line('更新卡表数据,总计更新条数:' . count($list));
|
||||
$total = 0;
|
||||
$sims = array_pluck($list, 'sim');
|
||||
|
||||
foreach (array_chunk($sims, 30000) as $data) {
|
||||
echo '.';
|
||||
$total += Card::whereIn('sim', array_pluck($data, 'sim'))->count();
|
||||
}
|
||||
|
||||
$except = count($list) - $total;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user