mirror of
				https://github.com/v2board/v2board.git
				synced 2025-10-31 09:21:46 +08:00 
			
		
		
		
	update: reset by next year
This commit is contained in:
		| @@ -99,7 +99,7 @@ class ResetTraffic extends Command | |||||||
|  |  | ||||||
|     private function resetByYear($builder):void |     private function resetByYear($builder):void | ||||||
|     { |     { | ||||||
|         if ((string)date('d') === '01' && (string)date('m') === '01') { |         if ((string)date('md') === '0101') { | ||||||
|             $builder->update([ |             $builder->update([ | ||||||
|                 'u' => 0, |                 'u' => 0, | ||||||
|                 'd' => 0 |                 'd' => 0 | ||||||
|   | |||||||
| @@ -6,6 +6,7 @@ use App\Http\Controllers\Controller; | |||||||
| use App\Http\Requests\User\UserTransfer; | use App\Http\Requests\User\UserTransfer; | ||||||
| use App\Http\Requests\User\UserUpdate; | use App\Http\Requests\User\UserUpdate; | ||||||
| use App\Http\Requests\User\UserChangePassword; | use App\Http\Requests\User\UserChangePassword; | ||||||
|  | use App\Services\UserService; | ||||||
| use App\Utils\CacheKey; | use App\Utils\CacheKey; | ||||||
| use Illuminate\Http\Request; | use Illuminate\Http\Request; | ||||||
| use App\Models\User; | use App\Models\User; | ||||||
| @@ -121,7 +122,8 @@ class UserController extends Controller | |||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         $user['subscribe_url'] = Helper::getSubscribeUrl("/api/v1/client/subscribe?token={$user['token']}"); |         $user['subscribe_url'] = Helper::getSubscribeUrl("/api/v1/client/subscribe?token={$user['token']}"); | ||||||
|         $user['reset_day'] = $this->getResetDay($user); |         $userService = new UserService(); | ||||||
|  |         $user['reset_day'] = $userService->getResetDay($user); | ||||||
|         return response([ |         return response([ | ||||||
|             'data' => $user |             'data' => $user | ||||||
|         ]); |         ]); | ||||||
| @@ -184,45 +186,6 @@ class UserController extends Controller | |||||||
|         ]); |         ]); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private function getResetDay(User $user) |  | ||||||
|     { |  | ||||||
|         if ($user->expired_at <= time() || $user->expired_at === NULL) return null; |  | ||||||
|         // if reset method is not reset |  | ||||||
|         if (isset($user->plan->reset_traffic_method) && $user->plan->reset_traffic_method === 2) return null; |  | ||||||
|  |  | ||||||
|         if ((int)config('v2board.reset_traffic_method') === 0 || |  | ||||||
|             (isset($user->plan->reset_traffic_method) && $user->plan->reset_traffic_method === 0)) |  | ||||||
|         { |  | ||||||
|             $day = date('d', $user->expired_at); |  | ||||||
|             $today = date('d'); |  | ||||||
|             $lastDay = date('d', strtotime('last day of +0 months')); |  | ||||||
|             return $lastDay - $today; |  | ||||||
|         } |  | ||||||
|         if ((int)config('v2board.reset_traffic_method') === 1 || |  | ||||||
|             (isset($user->plan->reset_traffic_method) && $user->plan->reset_traffic_method === 1)) |  | ||||||
|         { |  | ||||||
|             $day = date('d', $user->expired_at); |  | ||||||
|             $today = date('d'); |  | ||||||
|             $lastDay = date('d', strtotime('last day of +0 months')); |  | ||||||
|             if ((int)$day >= (int)$today && (int)$day >= (int)$lastDay) { |  | ||||||
|                 return $lastDay - $today; |  | ||||||
|             } |  | ||||||
|             if ((int)$day >= (int)$today) { |  | ||||||
|                 return $day - $today; |  | ||||||
|             } else { |  | ||||||
|                 return $lastDay - $today + $day; |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|         if ((int)config('v2board.reset_traffic_method') === 2 || |  | ||||||
|             (isset($user->plan->reset_traffic_method) && $user->plan->reset_traffic_method === 2)) |  | ||||||
|         { |  | ||||||
|             $nextYear = strtotime(date("Y-01-01", strtotime('+1 year'))); |  | ||||||
|             return (int)(($nextYear - time()) / 86400); |  | ||||||
|         } |  | ||||||
|         return null; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|  |  | ||||||
|     public function getQuickLoginUrl(Request $request) |     public function getQuickLoginUrl(Request $request) | ||||||
|     { |     { | ||||||
|         $user = User::find($request->session()->get('id')); |         $user = User::find($request->session()->get('id')); | ||||||
|   | |||||||
| @@ -15,6 +15,44 @@ use Illuminate\Support\Facades\DB; | |||||||
|  |  | ||||||
| class UserService | class UserService | ||||||
| { | { | ||||||
|  |     public function getResetDay(User $user) | ||||||
|  |     { | ||||||
|  |         if ($user->expired_at <= time() || $user->expired_at === NULL) return null; | ||||||
|  |         // if reset method is not reset | ||||||
|  |         if (isset($user->plan->reset_traffic_method) && $user->plan->reset_traffic_method === 2) return null; | ||||||
|  |  | ||||||
|  |         if ((int)config('v2board.reset_traffic_method') === 0 || | ||||||
|  |             (isset($user->plan->reset_traffic_method) && $user->plan->reset_traffic_method === 0)) | ||||||
|  |         { | ||||||
|  |             $day = date('d', $user->expired_at); | ||||||
|  |             $today = date('d'); | ||||||
|  |             $lastDay = date('d', strtotime('last day of +0 months')); | ||||||
|  |             return $lastDay - $today; | ||||||
|  |         } | ||||||
|  |         if ((int)config('v2board.reset_traffic_method') === 1 || | ||||||
|  |             (isset($user->plan->reset_traffic_method) && $user->plan->reset_traffic_method === 1)) | ||||||
|  |         { | ||||||
|  |             $day = date('d', $user->expired_at); | ||||||
|  |             $today = date('d'); | ||||||
|  |             $lastDay = date('d', strtotime('last day of +0 months')); | ||||||
|  |             if ((int)$day >= (int)$today && (int)$day >= (int)$lastDay) { | ||||||
|  |                 return $lastDay - $today; | ||||||
|  |             } | ||||||
|  |             if ((int)$day >= (int)$today) { | ||||||
|  |                 return $day - $today; | ||||||
|  |             } else { | ||||||
|  |                 return $lastDay - $today + $day; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         if ((int)config('v2board.reset_traffic_method') === 2 || | ||||||
|  |             (isset($user->plan->reset_traffic_method) && $user->plan->reset_traffic_method === 2)) | ||||||
|  |         { | ||||||
|  |             $nextYear = strtotime(date("Y-01-01", strtotime('+1 year'))); | ||||||
|  |             return (int)(($nextYear - time()) / 86400); | ||||||
|  |         } | ||||||
|  |         return null; | ||||||
|  |     } | ||||||
|  |  | ||||||
|     public function isAvailable(User $user) |     public function isAvailable(User $user) | ||||||
|     { |     { | ||||||
|         if (!$user->banned && $user->transfer_enable && ($user->expired_at > time() || $user->expired_at === NULL)) { |         if (!$user->banned && $user->transfer_enable && ($user->expired_at > time() || $user->expired_at === NULL)) { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user