From 87d07a2f0230ff37f627d1093b5ce25d58b9d1a5 Mon Sep 17 00:00:00 2001 From: denghy Date: Tue, 15 Jan 2019 09:15:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B2=A1=E6=9C=89=E9=94=80=E5=94=AE=E8=AE=B0?= =?UTF-8?q?=E5=BD=95=E7=9A=84=E5=8D=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/ExportTest.php | 83 ++++++++++++++++++++++++++++-- tests/Exports/CustomExport.php | 92 ---------------------------------- 2 files changed, 79 insertions(+), 96 deletions(-) delete mode 100644 tests/Exports/CustomExport.php diff --git a/tests/ExportTest.php b/tests/ExportTest.php index 723ac368..c7343994 100644 --- a/tests/ExportTest.php +++ b/tests/ExportTest.php @@ -1,10 +1,85 @@ table('ckb_custom') + ->select('custom_no') + ->whereRaw('custom_no NOT IN (SELECT custom_no FROM ckb_custom_handle_log WHERE type = 13)') + ->get()->pluck('custom_no')->toArray(); + +$companies = DB::connection('vd_old')->table('ckb_company')->get()->pluck('unicom_name', 'id')->toArray(); +$packages = DB::connection('vd_old')->table('ckb_package')->get()->pluck('name', 'package_sn')->toArray(); + +$spreadsheet = new Spreadsheet(); + +$sheet = $spreadsheet->getActiveSheet(); + +$startCell = 'A1'; + +$sheet->fromArray([ + 'SIM', + 'IMSI', + 'ICCID', + '客户编号', + '企业ID', + '企业名称', + '套餐编号', + '套餐名称', + '服务开始时间', + '服务结束时间', + '任务编号', + '创建时间', +]); + +foreach ($group as $nos) { + echo '.'; + $customs = DB::connection('vd_old')->table('ckb_custom')->select(['card_number', 'imsi', 'iccid', 'custom_no', 'company', 'create_time', 'task_number']) + ->whereIn('custom_no', $nos)->get()->keyBy('custom_no'); + + $userPackages = DB::connection('vd_old')->table('ckb_user_package')->select(['custom_no','package_sn','service_start_time','service_end_time']) + ->whereIn('custom_no', $nos)->get()->keyBy('custom_no'); + + $array = []; + + $startCell = 'A' . ($sheet->getHighestRow() + 1); + + foreach ($nos as $no) { + $custom = (array)$customs[$no]; + $userPackage = (array) $userPackages[$no]; + $item = array_merge($custom, $userPackage); + + $item = [ + 'sim' => ' ' . $item['card_number'], + 'imsi' => ' ' . $item['imsi'], + 'iccid' => ' ' . $item['iccid'], + 'custom_no' => $item['custom_no'], + 'company' => $item['company'], + 'company_name' => $companies[$item['company']], + 'package' => $userPackage['package_sn'], + 'package_name' => $packages[$userPackage['package_sn']], + 'service_start_time' => date('Y-m-d H:i:s', $userPackage['service_start_time']), + 'service_end_time' => date('Y-m-d H:i:s', $userPackage['service_end_time']), + 'task_number' => $item['task_number'], + 'create_time' => date('Y-m-d H:i:s', $item['create_time']), + ]; + + $array[] = $item; + } + + $sheet->fromArray($array, null, $startCell); +} + +$writer = IOFactory::createWriter($spreadsheet, 'Xlsx'); + +$writer->save(__DIR__ . '/没有销售记录的卡.xlsx'); diff --git a/tests/Exports/CustomExport.php b/tests/Exports/CustomExport.php deleted file mode 100644 index 4102f76c..00000000 --- a/tests/Exports/CustomExport.php +++ /dev/null @@ -1,92 +0,0 @@ -table('ckb_custom') - ->select(['id', 'custom_no', 'imsi', 'carrieroperator', 'iccid', 'card_number', 'card_from', 'iccid', 'company', 'custom_state', 'create_time' ,'update_time', 'card_cycle_start']) - ->orderBy('id'); - - return $query; - } - - /** - * @param mixed $rows - * - * @return mixed - */ - public function rows($rows) - { - echo '.'; - $userPackages = DB::connection('vd_old')->table('ckb_user_package')->whereIn('custom_no', array_pluck($rows, 'custom_no'))->get()->keyBy('custom_no'); - $companies = DB::connection('vd_old')->table('ckb_company')->get()->pluck('unicom_name', 'id')->toArray(); - $packages = DB::connection('vd_old')->table('ckb_package')->get()->pluck('name', 'package_sn')->toArray(); - - $logs = DB::connection('vd_old')->table('ckb_custom_handle_log')->select('custom_no')->where('type', 13)->get()->pluck('custom_no')->toArray(); - - $array = []; - - foreach ($rows as $key => $item) { - if ($logs[$item['custom_no']]) { - continue; - } - - $userPackage = $userPackages[$item['custom_no']]; - - $array[] = [ - 'sim' => $item['card_number'], - 'imsi' => $item['imsi'], - 'iccid' => $item['iccid'], - 'custom_no' => $item['custom_no'], - 'company' => $item['company'], - 'company_name' => $companies[$item['company']], - 'package' => $userPackage->package_sn, - 'package_name' => $packages[$userPackage->package_sn], - 'create_time' => $item['create_time'], - 'service_start_time' => date('Y-m-d H:i:s', $userPackage->service_start_time), - 'service_end_time' => date('Y-m-d H:i:s', $userPackage->service_end_time), - 'task_number' -> $item['task_number'], - ]; - } - - return $array; - } - - public function headings(): array - { - return [ - 'SIM', - 'IMSI', - 'ICCID', - '客户编号', - '企业ID', - '企业名称', - '套餐编号', - '套餐名称', - '创建时间', - '服务开始时间', - '服务结束时间', - '任务编号', - ]; - } -}