add onetime plan

This commit is contained in:
Tokumeikoi 2020-02-28 01:12:55 +08:00
parent 0f9cb9696d
commit e7fd81bf4c
6 changed files with 31 additions and 56 deletions

View File

@ -1,53 +0,0 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Models\Order;
use App\Models\User;
class CheckExpire extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'check:expire';
/**
* The console command description.
*
* @var string
*/
protected $description = '过期检查';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$users = User::all();
foreach ($users as $user) {
if ($user->expired_at < time() || $user->u + $user->d >= $user->transfer_enable) {
$user->enable = 0;
} else {
$user->enable = 1;
}
$user->save();
}
}
}

View File

@ -28,7 +28,6 @@ class Kernel extends ConsoleKernel
$schedule->command('v2board:cache')->hourly(); $schedule->command('v2board:cache')->hourly();
// check // check
$schedule->command('check:order')->everyMinute(); $schedule->command('check:order')->everyMinute();
$schedule->command('check:expire')->everyMinute();
$schedule->command('check:commission')->everyMinute(); $schedule->command('check:commission')->everyMinute();
// reset // reset
$schedule->command('reset:traffic')->monthly(); $schedule->command('reset:traffic')->monthly();

View File

@ -3,10 +3,12 @@
namespace App\Http\Controllers\Client; namespace App\Http\Controllers\Client;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Http\Middleware\User;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Models\Server; use App\Models\Server;
use App\Utils\Helper; use App\Utils\Helper;
use Symfony\Component\Yaml\Yaml; use Symfony\Component\Yaml\Yaml;
use App\Services\UserService;
class ClientController extends Controller class ClientController extends Controller
{ {
@ -15,7 +17,8 @@ class ClientController extends Controller
$user = $request->user; $user = $request->user;
$server = []; $server = [];
// account not expired and is not banned. // account not expired and is not banned.
if ($user->expired_at > time() && !$user->banned) { $userService = new UserService($user);
if ($userService->isAvailable()) {
$servers = Server::where('show', 1) $servers = Server::where('show', 1)
->orderBy('name') ->orderBy('name')
->get(); ->get();

View File

@ -3,6 +3,7 @@
namespace App\Http\Controllers\User; namespace App\Http\Controllers\User;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Services\UserService;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Cache;
use App\Models\Server; use App\Models\Server;
@ -17,7 +18,8 @@ class ServerController extends Controller
{ {
$user = User::find($request->session()->get('id')); $user = User::find($request->session()->get('id'));
$server = []; $server = [];
if ($user->expired_at > time()) { $userService = new UserService($user);
if ($userService->isAvailable()) {
$servers = Server::where('show', 1) $servers = Server::where('show', 1)
->orderBy('name') ->orderBy('name')
->get(); ->get();

View File

@ -14,6 +14,7 @@ class ServerService
$query->where('expired_at', '>=', time()) $query->where('expired_at', '>=', time())
->orWhere('expired_at', 0); ->orWhere('expired_at', 0);
}) })
->where('enable', 1)
->select([ ->select([
'id', 'id',
'email', 'email',

View File

@ -0,0 +1,23 @@
<?php
namespace App\Services;
use App\Models\User;
class UserService
{
public $user;
public function __construct(User $user)
{
$this->user = $user;
}
public function isAvailable()
{
if ($this->user->transfer_enable && ($this->user->expired_at > time() || $this->user->expired_at == 0)) {
return true;
}
return false;
}
}