vd/tests/ExampleTest.php
2019-03-25 17:01:17 +08:00

43 lines
1.4 KiB
PHP

<?php
use Carbon\Carbon;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
require_once realpath(dirname(__FILE__) . '/TestCase.php');
Schema::table('virtual_order_cards_partition', function ($table) {
$table->timestamp('refunded_at')->nullable()->comment('退货时间');
});
Schema::table('real_order_cards_partition', function ($table) {
$table->timestamp('refunded_at')->nullable()->comment('退货时间');
});
dd();
$handle = fopen(__DIR__ . '/interval.csv', 'w');
$custom_no = DB::connection('vd_old')->table('ckb_custom_handle_log')->select('custom_no')->distinct()->where('type', 11)->get()->pluck('custom_no')->toArray();
fputcsv($handle, ['客户编号', '间隔时间']);
foreach (array_chunk($custom_no, 1000) as $values) {
$res = DB::connection('vd_old')->table('ckb_custom_handle_log')->whereIn('custom_no', $values)->whereIn('type', [10, 11])->orderBy('valid_start_time')->get()->groupBy('custom_no');
foreach ($res as $no => $group) {
echo $no . PHP_EOL;
for ($i=1; $i < count($group); $i++) {
$item1 = $group[$i - 1];
$item2 = $group[$i];
$interval = Carbon::createFromTimestamp(intval($item2->valid_start_time))->diffInMonths(Carbon::createFromTimestamp(intval($item1->valid_end_time)));
fputcsv($handle, [$no, $interval]);
}
}
}
fclose($handle);
dd(1);