mirror of
				https://github.com/v2board/v2board.git
				synced 2025-10-31 09:21:46 +08:00 
			
		
		
		
	update: new auth
This commit is contained in:
		| @@ -19,7 +19,7 @@ class PlanService | ||||
|     { | ||||
|         if ($this->plan->capacity_limit === NULL) return true; | ||||
|         $count = User::where('plan_id', $this->plan->plan_id)->count(); | ||||
|         return $this->plan->capacity_limit - $count; | ||||
|         return ($this->plan->capacity_limit - $count) > 0; | ||||
|     } | ||||
|  | ||||
|     public static function countActiveUsers() | ||||
|   | ||||
| @@ -15,48 +15,85 @@ use Illuminate\Support\Facades\DB; | ||||
|  | ||||
| class UserService | ||||
| { | ||||
|     private function calcResetDayByMonthFirstDay() | ||||
|     { | ||||
|         $today = date('d'); | ||||
|         $lastDay = date('d', strtotime('last day of +0 months')); | ||||
|         return $lastDay - $today; | ||||
|     } | ||||
|  | ||||
|     private function calcResetDayByExpireDay(int $expiredAt) | ||||
|     { | ||||
|         $day = date('d', $expiredAt); | ||||
|         $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; | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private function calcResetDayByYearFirstDay() | ||||
|     { | ||||
|         $nextYear = strtotime(date("Y-01-01", strtotime('+1 year'))); | ||||
|         return (int)(($nextYear - time()) / 86400); | ||||
|     } | ||||
|  | ||||
|     private function calcResetDayByYearExpiredAt(int $expiredAt) | ||||
|     { | ||||
|         $md = date('m-d', $expiredAt); | ||||
|         $nowYear = strtotime(date("Y-{$md}")); | ||||
|         $nextYear = strtotime('+1 year', $nowYear); | ||||
|         return (int)(($nextYear - time()) / 86400); | ||||
|     } | ||||
|  | ||||
|     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 (!isset($user->plan->reset_traffic_method)) return null; | ||||
|         if ($user->plan->reset_traffic_method === 2) return null; | ||||
|         switch (true) { | ||||
|             case ($user->plan->reset_traffic_method === NULL): { | ||||
|                 $resetTrafficMethod = config('v2board.reset_traffic_method', 0); | ||||
|                 switch ((int)$resetTrafficMethod) { | ||||
|                     // month first day | ||||
|                     case 0: | ||||
|                         return $this->calcResetDayByMonthFirstDay(); | ||||
|                     // expire day | ||||
|                     case 1: | ||||
|                         return $this->calcResetDayByExpireDay($user->expired_at); | ||||
|                     // no action | ||||
|                     case 2: | ||||
|                         return null; | ||||
|                     // year first day | ||||
|                     case 3: | ||||
|                         return $this->calcResetDayByYearFirstDay(); | ||||
|                     // year expire day | ||||
|                     case 4: | ||||
|                         return $this->calcResetDayByYearExpiredAt($user->expired_at); | ||||
|                 } | ||||
|                 break; | ||||
|             } | ||||
|             if ((int)$day >= (int)$today) { | ||||
|                 return $day - $today; | ||||
|             } else { | ||||
|                 return $lastDay - $today + $day; | ||||
|             case ($user->plan->reset_traffic_method === 0): { | ||||
|                 return $this->calcResetDayByMonthFirstDay(); | ||||
|             } | ||||
|             case ($user->plan->reset_traffic_method === 1): { | ||||
|                 return $this->calcResetDayByExpireDay($user->expired_at); | ||||
|             } | ||||
|             case ($user->plan->reset_traffic_method === 2): { | ||||
|                 return null; | ||||
|             } | ||||
|             case ($user->plan->reset_traffic_method === 3): { | ||||
|                 return $this->calcResetDayByYearFirstDay(); | ||||
|             } | ||||
|             case ($user->plan->reset_traffic_method === 4): { | ||||
|                 return $this->calcResetDayByYearExpiredAt($user->expired_at); | ||||
|             } | ||||
|         } | ||||
|         if ((int)config('v2board.reset_traffic_method') === 3 || | ||||
|             (isset($user->plan->reset_traffic_method) && $user->plan->reset_traffic_method === 3)) | ||||
|         { | ||||
|             $nextYear = strtotime(date("Y-01-01", strtotime('+1 year'))); | ||||
|             return (int)(($nextYear - time()) / 86400); | ||||
|         } | ||||
|         if ((int)config('v2board.reset_traffic_method') === 4 || | ||||
|             (isset($user->plan->reset_traffic_method) && $user->plan->reset_traffic_method === 4)) | ||||
|         { | ||||
|             $md = date('m-d', $user->expired_at); | ||||
|             $nowYear = strtotime(date("Y-{$md}")); | ||||
|             $nextYear = strtotime('+1 year', $nowYear); | ||||
|             return (int)(($nextYear - time()) / 86400); | ||||
|         } | ||||
|         return null; | ||||
|     } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user