导出
This commit is contained in:
parent
b2386bf963
commit
4ce6b81341
10
tests/ExportTest.php
Normal file
10
tests/ExportTest.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
require_once realpath(dirname(__FILE__) . '/TestCase.php');
|
||||
|
||||
require __DIR__ . '/Exports/CustomExport.php';
|
||||
|
||||
use Test\Exports\CustomExport;
|
||||
use Dipper\Excel\Facades\Excel;
|
||||
|
||||
Excel::queue(new CustomExport(), '客户导出.xlsx', 'public');
|
86
tests/Exports/CustomExport.php
Normal file
86
tests/Exports/CustomExport.php
Normal file
@ -0,0 +1,86 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* @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