diff --git a/app/Console/Commands/ResetTraffic.php b/app/Console/Commands/ResetTraffic.php index a2dd6302..4532ee65 100644 --- a/app/Console/Commands/ResetTraffic.php +++ b/app/Console/Commands/ResetTraffic.php @@ -3,8 +3,6 @@ namespace App\Console\Commands; use Illuminate\Console\Command; -use Illuminate\Support\Facades\DB; -use App\Models\Plan; use App\Models\User; class ResetTraffic extends Command @@ -40,12 +38,25 @@ class ResetTraffic extends Command */ public function handle() { - // get plans of cycle type - $plans = Plan::where('type', 0)->get(); - $users = User::whereIn('plan_id', $plans); - $users->update([ - 'u' => 0, - 'd' => 0 - ]); + $user = User::where('expired_at', '!=', NULL); + $resetTrafficMethod = config('v2board.reset_traffic_method', 0); + switch ($resetTrafficMethod) { + // 1 a month + case 0: + $user->update([ + 'u' => 0, + 'd' => 0 + ]); + break; + // expire day + case 1: + $startAt = strtotime(date('Y-m-d', time())); + $user->where('expired_at', '>=', $startAt) + ->where('expired_at', '<', $startAt + 24 * 3600) + ->update([ + 'u' => 0, + 'd' => 0 + ]); + } } } diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index e723eed0..b6afc47a 100755 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -30,7 +30,7 @@ class Kernel extends ConsoleKernel $schedule->command('check:order')->everyMinute(); $schedule->command('check:commission')->everyMinute(); // reset - $schedule->command('reset:traffic')->monthly(); + $schedule->command('reset:traffic')->daily(); $schedule->command('reset:serverLog')->monthly(); // send $schedule->command('send:remindMail')->dailyAt('11:30'); diff --git a/app/Http/Controllers/Admin/ConfigController.php b/app/Http/Controllers/Admin/ConfigController.php index eaf2c1c5..c256a11d 100755 --- a/app/Http/Controllers/Admin/ConfigController.php +++ b/app/Http/Controllers/Admin/ConfigController.php @@ -34,7 +34,8 @@ class ConfigController extends Controller 'email_whitelist_suffix' => config('v2board.email_whitelist_suffix', Dict::EMAIL_WHITELIST_SUFFIX_DEFAULT) ], 'subscribe' => [ - 'plan_change_enable' => (int)config('v2board.plan_change_enable', 1) + 'plan_change_enable' => (int)config('v2board.plan_change_enable', 1), + 'reset_traffic_method' => (int)config('v2board.reset_traffic_method', 0) ], 'pay' => [ // alipay diff --git a/app/Http/Requests/Admin/ConfigSave.php b/app/Http/Requests/Admin/ConfigSave.php index bc62ac83..720f03ec 100755 --- a/app/Http/Requests/Admin/ConfigSave.php +++ b/app/Http/Requests/Admin/ConfigSave.php @@ -25,6 +25,7 @@ class ConfigSave extends FormRequest 'email_whitelist_suffix' => '', // subscribe 'plan_change_enable' => 'in:0,1', + 'reset_traffic_method' => 'in:0,1', // server 'server_token' => 'nullable|min:16', 'server_license' => 'nullable', diff --git a/database/update.sql b/database/update.sql index 8dfb65d8..19f4f4fa 100644 --- a/database/update.sql +++ b/database/update.sql @@ -178,3 +178,6 @@ ADD `onetime_price` int(11) NULL AFTER `year_price`; ALTER TABLE `v2_user` DROP `banned`; + +ALTER TABLE `v2_user` +CHANGE `expired_at` `expired_at` bigint(20) NULL DEFAULT '0' AFTER `token`;