Browse Source

修正每月流量重置BUG

admin 7 years ago
parent
commit
d83b01be76
2 changed files with 15 additions and 12 deletions
  1. 14 11
      app/Console/Commands/AutoResetUserTraffic.php
  2. 1 1
      app/Console/Kernel.php

+ 14 - 11
app/Console/Commands/AutoResetUserTraffic.php

@@ -32,25 +32,28 @@ class AutoResetUserTraffic extends Command
                         continue;
                     }
 
-                    // 取出用户最后购买的有效套餐 TODO:需要改掉,不应该是最后购买的套餐
-                    $order = Order::query()->with(['user', 'goods'])->whereHas('goods', function ($q) {
-                        $q->where('type', 2);
-                    })->where('user_id', $user->id)->where('is_expire', 0)->orderBy('oid', 'desc')->first();
+                    // 取出用户最后购买的有效套餐
+                    $order = Order::query()
+                        ->with(['user', 'goods'])
+                        ->whereHas('goods', function ($q) {
+                            $q->where('type', 2);
+                        })
+                        ->where('user_id', $user->id)
+                        ->where('is_expire', 0)
+                        ->orderBy('oid', 'desc')
+                        ->first();
 
                     if (!$order) {
                         continue;
                     }
 
-                    // TODO:需要改掉,改成下一次重置日,每月不定时,类似搬瓦工
+                    $month = abs(date('m'));
                     $today = abs(date('d'));
-                    $reset_days = [$today, 29, 30, 31];
-                    if (in_array($order->user->traffic_reset_day, $reset_days)) {
+                    if ($order->user->traffic_reset_day == $today) {
                         // 跳过本月,防止异常重置
-                        if (date('m') == date('m', strtotime($order->expire_at))) {
+                        if ($month == date('m', strtotime($order->expire_at))) {
                             continue;
-                        }
-
-                        if (date('m') == date('m', strtotime($order->created_at))) {
+                        } elseif ($month == date('m', strtotime($order->created_at))) {
                             continue;
                         }
 

+ 1 - 1
app/Console/Kernel.php

@@ -39,7 +39,7 @@ class Kernel extends ConsoleKernel
         $schedule->command('autoJob')->everyMinute();
         $schedule->command('autoClearLog')->everyThirtyMinutes();
         $schedule->command('autoDecGoodsTraffic')->everyTenMinutes();
-        $schedule->command('autoResetUserTraffic')->everyFiveMinutes();
+        $schedule->command('autoResetUserTraffic')->monthlyOn(1);
         $schedule->command('autoCheckNodeStatus')->hourly();
         $schedule->command('autoStatisticsNodeDailyTraffic')->dailyAt('23:55');
         $schedule->command('autoStatisticsNodeHourlyTraffic')->hourly();