mirror of
				https://github.com/v2board/v2board.git
				synced 2025-10-31 17:31:49 +08:00 
			
		
		
		
	add onetime plan
This commit is contained in:
		| @@ -60,15 +60,21 @@ class CheckOrder extends Command | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private function orderHandle($order) |     private function orderHandle(Order $order) | ||||||
|     { |     { | ||||||
|         $user = User::find($order->user_id); |         $user = User::find($order->user_id); | ||||||
|         return $this->buy($order, $user); |         $plan = Plan::find($order->plan_id); | ||||||
|  |         switch ($plan->type) { | ||||||
|  |             // cycle | ||||||
|  |             case 0: return $this->buyByCycle($order, $user, $plan); | ||||||
|  |             // onetime | ||||||
|  |             case 1: return $this->buyByOneTime($order, $user, $plan); | ||||||
|  |         } | ||||||
|  |         return $this->buy($order, $user, $plan); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private function buy($order, $user) |     private function buyByCycle(Order $order, User $user, Plan $plan) | ||||||
|     { |     { | ||||||
|         $plan = Plan::find($order->plan_id); |  | ||||||
|         // change plan process |         // change plan process | ||||||
|         if ($order->type == 3) { |         if ($order->type == 3) { | ||||||
|             $user->expired_at = time(); |             $user->expired_at = time(); | ||||||
| @@ -83,7 +89,24 @@ class CheckOrder extends Command | |||||||
|         $user->plan_id = $plan->id; |         $user->plan_id = $plan->id; | ||||||
|         $user->group_id = $plan->group_id; |         $user->group_id = $plan->group_id; | ||||||
|         $user->expired_at = $this->getTime($order->cycle, $user->expired_at); |         $user->expired_at = $this->getTime($order->cycle, $user->expired_at); | ||||||
|  |         if ($user->save()) { | ||||||
|  |             $order->status = 3; | ||||||
|  |             $order->save(); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     private function buyByOneTime(Order $order, User $user, Plan $plan) | ||||||
|  |     { | ||||||
|  |         if ($order->refund_amount) { | ||||||
|  |             $user->balance = $user->balance + $order->refund_amount; | ||||||
|  |         } | ||||||
|  |         $user->transfer_enable = $plan->transfer_enable * 1073741824; | ||||||
|  |         $user->enable = 1; | ||||||
|  |         $user->u = 0; | ||||||
|  |         $user->d = 0; | ||||||
|  |         $user->plan_id = $plan->id; | ||||||
|  |         $user->group_id = $plan->group_id; | ||||||
|  |         $user->expired_at = 0; | ||||||
|         if ($user->save()) { |         if ($user->save()) { | ||||||
|             $order->status = 3; |             $order->status = 3; | ||||||
|             $order->save(); |             $order->save(); | ||||||
|   | |||||||
| @@ -38,7 +38,10 @@ class ResetTraffic extends Command | |||||||
|      */ |      */ | ||||||
|     public function handle() |     public function handle() | ||||||
|     { |     { | ||||||
|         DB::table('v2_user')->update([ |         //  get plans of cycle type | ||||||
|  |         $plans = Plan::where('type', 0)->get(); | ||||||
|  |         $users = User::whereIn('plan_id', $plans)->get(); | ||||||
|  |         $users->update([ | ||||||
|             'u' => 0, |             'u' => 0, | ||||||
|             'd' => 0 |             'd' => 0 | ||||||
|         ]); |         ]); | ||||||
|   | |||||||
							
								
								
									
										31
									
								
								app/Services/ServerService.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								app/Services/ServerService.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,31 @@ | |||||||
|  | <?php | ||||||
|  |  | ||||||
|  | namespace App\Services; | ||||||
|  |  | ||||||
|  | use App\Models\User; | ||||||
|  |  | ||||||
|  | class ServerService | ||||||
|  | { | ||||||
|  |     public function getAvailableUsers($groupId) | ||||||
|  |     { | ||||||
|  |         return User::whereIn('group_id', $groupId) | ||||||
|  |             ->whereRaw('u + d < transfer_enable') | ||||||
|  |             ->where(function ($query) { | ||||||
|  |                 $query->where('expired_at', '>=', time()) | ||||||
|  |                     ->orWhere('expired_at', 0); | ||||||
|  |             }) | ||||||
|  |             ->select([ | ||||||
|  |                 'id', | ||||||
|  |                 'email', | ||||||
|  |                 't', | ||||||
|  |                 'u', | ||||||
|  |                 'd', | ||||||
|  |                 'transfer_enable', | ||||||
|  |                 'enable', | ||||||
|  |                 'v2ray_uuid', | ||||||
|  |                 'v2ray_alter_id', | ||||||
|  |                 'v2ray_level' | ||||||
|  |             ]) | ||||||
|  |             ->get(); | ||||||
|  |     } | ||||||
|  | } | ||||||
		Reference in New Issue
	
	Block a user