没有销售记录的卡
This commit is contained in:
parent
b5eed0c637
commit
87d07a2f02
@ -1,10 +1,85 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||
|
||||
require_once realpath(dirname(__FILE__) . '/TestCase.php');
|
||||
|
||||
require __DIR__ . '/Exports/CustomExport.php';
|
||||
set_time_limit(-1);
|
||||
ini_set('memory_limit', '4096m');
|
||||
|
||||
use Test\Exports\CustomExport;
|
||||
use Dipper\Excel\Facades\Excel;
|
||||
$nos = require __DIR__ . '/no.php';
|
||||
|
||||
Excel::queue(new CustomExport(), '客户导出.xlsx', 'public');
|
||||
$group = array_chunk($nos, '1000');
|
||||
|
||||
$nos = DB::connection('vd_old')->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');
|
||||
|
@ -1,92 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Test\Exports;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Dipper\Excel\Concerns\WithRows;
|
||||
use Dipper\Excel\Concerns\FromQuery;
|
||||
use Dipper\Excel\Concerns\Exportable;
|
||||
use Dipper\Excel\Concerns\WithHeadings;
|
||||
|
||||
class CustomExport implements FromQuery, WithHeadings, WithRows
|
||||
{
|
||||
use Exportable;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
set_time_limit(-1);
|
||||
ini_set('memory_limit', '4096m');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Builder
|
||||
*/
|
||||
public function query()
|
||||
{
|
||||
$query = DB::connection('vd_old')->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',
|
||||
'企业名称',
|
||||
'套餐编号',
|
||||
'套餐名称',
|
||||
'创建时间',
|
||||
'服务开始时间',
|
||||
'服务结束时间',
|
||||
'任务编号',
|
||||
];
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user