修改旧平台

This commit is contained in:
邓皓元 2019-04-25 15:22:25 +08:00
parent 05d83ba676
commit f53386f10c
4 changed files with 120 additions and 0 deletions

50
tests/OldActivityTest.php Normal file
View File

@ -0,0 +1,50 @@
<?php
require_once realpath(dirname(__FILE__) . '/TestCase.php');
use Illuminate\Http\UploadedFile;
use App\Domains\Export\Services\ImportService;
echo 'started.' . PHP_EOL;
$file = new UploadedFile(__DIR__ . '/漏激活的卡.xls', '漏激活的卡.xls');
$data = ImportService::load($file);
echo 'loaded.' . PHP_EOL;
foreach ($data as $item) {
$item = array_values($item);
$rows = DB::connection('vd_old')->table('ckb_custom_handle_log')->where('custom_no', $item[0])->get()->collect()->toArray();
echo $item[0] . PHP_EOL;
if (count($rows) == 1 && $rows[0]['type'] == 13) {
echo '.' . PHP_EOL;
$attributes = $rows[0];
if (preg_match('/_(\d+)MONTH/', $attributes['content'], $content)) {
$month = $content['1'];
$attributes['type'] = 10;
$attributes['valid_start_time'] = strtotime($item[2]);
$attributes['valid_end_time'] = strtotime("+{$month} month", $attributes['valid_start_time']);
$attributes['valid_end_time'] = strtotime('-1 second', $attributes['valid_end_time']);
$attributes['create_time'] = strtotime($item[2]);
$attributes['task_number'] = 'jh20190425';
DB::transaction(function () use ($attributes) {
DB::connection('vd_old')->table('ckb_custom_handle_log')->insert($attributes);
DB::connection('vd_old')->table('ckb_custom')->where('custom_no', $attributes['custom_no'])->update([
'card_cycle_start' => $attributes['valid_start_time'],
'card_cycle_end' => $attributes['valid_end_time'],
]);
DB::connection('vd_old')->table('ckb_user_package')->where('custom_no', $attributes['custom_no'])->update([
'service_start_time' => $attributes['valid_start_time'],
'service_end_time' => $attributes['valid_end_time'],
]);
});
}
}
}

70
tests/OldTimeTest.php Normal file
View File

@ -0,0 +1,70 @@
<?php
require_once realpath(dirname(__FILE__) . '/TestCase.php');
use Illuminate\Http\UploadedFile;
use App\Domains\Export\Services\ImportService;
use Illuminate\Support\Facades\DB;
echo 'started.' . PHP_EOL;
$file = new UploadedFile(__DIR__ . '/服务时间有重叠的卡.xls', '服务时间有重叠的卡.xls');
$data = ImportService::load($file);
echo 'loaded.' . PHP_EOL;
$packages = DB::table('virtual_packages')->get()->collect()->keyBy('sn')->toArray();
foreach ($data as $values) {
$values = array_values($values);
continue;
$rows = DB::connection('vd_old')->table('ckb_custom_handle_log')->whereNotIn('type', [10, 15])
->where('valid_start_time', '>=', 1546272000)
->where('custom_no', $values[0])->orderBy('create_time')->get()->collect()->toArray();
foreach ($rows as $key => $item) {
if ($key === 0) {
$endTime = $item['valid_end_time'];
} else {
$startTime = strtotime("+{$package['effect_months']} month", $endTime + 1);
$startTime = $item['create_time'] > $startTime ? strtotime(date('Y-m-01 00:00:00', $item['create_time'])) : $startTime;
$package = $packages[$item['content']];
$month = $package['service_months'] + $package['delay_months'];
$endTime = strtotime("+{$month} month", $startTime);
$item['valid_start_time'] = $startTime;
$item['valid_end_time'] = $endTime;
DB::connection('vd_old')->table('ckb_custom_handle_log')->where('id', $item['id'])->update([
'valid_start_time' => $item['valid_start_time'],
'valid_end_time' => $item['valid_end_time'],
]);
}
}
}
$subQuery = DB::raw('(
SELECT
custom_no AS cno,
MIN(valid_start_time) AS valid_start_time,
MAX(valid_end_time) AS valid_end_time
FROM ckb_custom_handle_log
GROUP BY custom_no
) t');
$res = DB::connection('vd_old')->table('ckb_custom')->join($subQuery, function($join) {
$join->on('t.cno', '=', 'ckb_custom.custom_no');
})->whereIn('custom_no', $custom_nos)->update([
'card_cycle_start' => DB::raw('t.valid_start_time'),
'valid_end_time' => DB::raw('t.valid_end_time'),
]);
$res = DB::connection('vd_old')->table('ckb_user_package')->join($subQuery, function($join) {
$join->on('t.cno', '=', 'ckb_user_package.custom_no');
})->whereIn('custom_no', $custom_nos)->update([
'service_start_time' => DB::raw('t.valid_start_time'),
'service_end_time' => DB::raw('t.valid_end_time'),
]);

Binary file not shown.

BIN
tests/漏激活的卡.xls Normal file

Binary file not shown.