diff --git a/tests/OldActivityTest.php b/tests/OldActivityTest.php new file mode 100644 index 00000000..c864f330 --- /dev/null +++ b/tests/OldActivityTest.php @@ -0,0 +1,50 @@ +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'], + ]); + }); + } + } +} diff --git a/tests/OldTimeTest.php b/tests/OldTimeTest.php new file mode 100644 index 00000000..1abb96dd --- /dev/null +++ b/tests/OldTimeTest.php @@ -0,0 +1,70 @@ +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'), +]); diff --git a/tests/服务时间有重叠的卡.xls b/tests/服务时间有重叠的卡.xls new file mode 100644 index 00000000..57e13353 Binary files /dev/null and b/tests/服务时间有重叠的卡.xls differ diff --git a/tests/漏激活的卡.xls b/tests/漏激活的卡.xls new file mode 100644 index 00000000..7f203d78 Binary files /dev/null and b/tests/漏激活的卡.xls differ