93 lines
2.8 KiB
PHP
93 lines
2.8 KiB
PHP
<?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',
|
|
'企业名称',
|
|
'套餐编号',
|
|
'套餐名称',
|
|
'创建时间',
|
|
'服务开始时间',
|
|
'服务结束时间',
|
|
'任务编号',
|
|
];
|
|
}
|
|
}
|