mirror of
https://github.com/v2board/v2board.git
synced 2024-11-10 17:49:11 +08:00
Merge pull request #12 from ColetteContreras/refactor-cache
Use Cache for varieties of cache server
This commit is contained in:
commit
5e9bc09396
@ -8,7 +8,7 @@ use App\Models\Order;
|
|||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
use App\Models\ServerLog;
|
use App\Models\ServerLog;
|
||||||
use App\Utils\Helper;
|
use App\Utils\Helper;
|
||||||
use Illuminate\Support\Facades\Redis;
|
use Cache;
|
||||||
|
|
||||||
class V2boardCache extends Command
|
class V2boardCache extends Command
|
||||||
{
|
{
|
||||||
@ -48,7 +48,7 @@ class V2boardCache extends Command
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function setMonthIncome() {
|
private function setMonthIncome() {
|
||||||
Redis::set(
|
Cache::put(
|
||||||
'month_income',
|
'month_income',
|
||||||
Order::where('created_at', '>=', strtotime(date('Y-m-1')))
|
Order::where('created_at', '>=', strtotime(date('Y-m-1')))
|
||||||
->where('created_at', '<', time())
|
->where('created_at', '<', time())
|
||||||
@ -58,7 +58,7 @@ class V2boardCache extends Command
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function setMonthRegisterTotal() {
|
private function setMonthRegisterTotal() {
|
||||||
Redis::set(
|
Cache::put(
|
||||||
'month_register_total',
|
'month_register_total',
|
||||||
User::where('created_at', '>=', strtotime(date('Y-m-1')))
|
User::where('created_at', '>=', strtotime(date('Y-m-1')))
|
||||||
->where('created_at', '<', time())
|
->where('created_at', '<', time())
|
||||||
|
@ -6,7 +6,7 @@ use App\Http\Requests\Admin\NoticeSave;
|
|||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Models\Notice;
|
use App\Models\Notice;
|
||||||
use Illuminate\Support\Facades\Redis;
|
use Cache;
|
||||||
|
|
||||||
class NoticeController extends Controller
|
class NoticeController extends Controller
|
||||||
{
|
{
|
||||||
|
@ -10,7 +10,7 @@ use App\Models\ServerGroup;
|
|||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
use App\Models\Plan;
|
use App\Models\Plan;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Support\Facades\Redis;
|
use Cache;
|
||||||
|
|
||||||
class ServerController extends Controller
|
class ServerController extends Controller
|
||||||
{
|
{
|
||||||
@ -22,9 +22,9 @@ class ServerController extends Controller
|
|||||||
}
|
}
|
||||||
$server[$i]['group_id'] = json_decode($server[$i]['group_id']);
|
$server[$i]['group_id'] = json_decode($server[$i]['group_id']);
|
||||||
if ($server[$i]['parent_id']) {
|
if ($server[$i]['parent_id']) {
|
||||||
$server[$i]['last_check_at'] = Redis::get('server_last_check_at_' . $server[$i]['parent_id']);
|
$server[$i]['last_check_at'] = Cache::get('server_last_check_at_' . $server[$i]['parent_id']);
|
||||||
} else {
|
} else {
|
||||||
$server[$i]['last_check_at'] = Redis::get('server_last_check_at_' . $server[$i]['id']);
|
$server[$i]['last_check_at'] = Cache::get('server_last_check_at_' . $server[$i]['id']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return response([
|
return response([
|
||||||
|
@ -10,15 +10,15 @@ use App\Models\Plan;
|
|||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Models\Ticket;
|
use App\Models\Ticket;
|
||||||
use App\Models\Order;
|
use App\Models\Order;
|
||||||
use Illuminate\Support\Facades\Redis;
|
use Cache;
|
||||||
|
|
||||||
class StatController extends Controller
|
class StatController extends Controller
|
||||||
{
|
{
|
||||||
public function getOverride (Request $request) {
|
public function getOverride (Request $request) {
|
||||||
return response([
|
return response([
|
||||||
'data' => [
|
'data' => [
|
||||||
'month_income' => Redis::get('month_income'),
|
'month_income' => Cache::get('month_income'),
|
||||||
'month_register_total' => Redis::get('month_register_total'),
|
'month_register_total' => Cache::get('month_register_total'),
|
||||||
'ticket_pendding_total' => Ticket::where('status', 0)
|
'ticket_pendding_total' => Ticket::where('status', 0)
|
||||||
->count(),
|
->count(),
|
||||||
'commission_pendding_total' => Order::where('commission_status', 0)
|
'commission_pendding_total' => Order::where('commission_status', 0)
|
||||||
|
@ -7,7 +7,7 @@ use App\Http\Controllers\Controller;
|
|||||||
use App\Models\Order;
|
use App\Models\Order;
|
||||||
use Omnipay\Omnipay;
|
use Omnipay\Omnipay;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
use Illuminate\Support\Facades\Redis;
|
use Cache;
|
||||||
use Library\BitpayX;
|
use Library\BitpayX;
|
||||||
|
|
||||||
class OrderController extends Controller
|
class OrderController extends Controller
|
||||||
@ -70,14 +70,14 @@ class OrderController extends Controller
|
|||||||
'source' => $source['id'],
|
'source' => $source['id'],
|
||||||
]);
|
]);
|
||||||
if ($charge['status'] == 'succeeded') {
|
if ($charge['status'] == 'succeeded') {
|
||||||
$trade_no = Redis::get($source['id']);
|
$trade_no = Cache::get($source['id']);
|
||||||
if (!$trade_no) {
|
if (!$trade_no) {
|
||||||
abort(500, 'redis is not found trade no by stripe source id');
|
abort(500, 'redis is not found trade no by stripe source id');
|
||||||
}
|
}
|
||||||
if (!$this->handle($trade_no, $source['id'])) {
|
if (!$this->handle($trade_no, $source['id'])) {
|
||||||
abort(500, 'fail');
|
abort(500, 'fail');
|
||||||
}
|
}
|
||||||
Redis::del($source['id']);
|
Cache::forget($source['id']);
|
||||||
die('success');
|
die('success');
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -5,7 +5,7 @@ namespace App\Http\Controllers;
|
|||||||
use App\Http\Requests\OrderSave;
|
use App\Http\Requests\OrderSave;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Redis;
|
use Cache;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use App\Models\Order;
|
use App\Models\Order;
|
||||||
@ -333,7 +333,7 @@ class OrderController extends Controller
|
|||||||
abort(500, '支付网关请求失败');
|
abort(500, '支付网关请求失败');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Redis::set($source['id'], $order->trade_no)) {
|
if (!Cache::put($source['id'], $order->trade_no)) {
|
||||||
abort(500, '订单创建失败');
|
abort(500, '订单创建失败');
|
||||||
}
|
}
|
||||||
Redis::expire($source['id'], 3600);
|
Redis::expire($source['id'], 3600);
|
||||||
@ -357,7 +357,7 @@ class OrderController extends Controller
|
|||||||
if (!$source['wechat']['qr_code_url']) {
|
if (!$source['wechat']['qr_code_url']) {
|
||||||
abort(500, '支付网关请求失败');
|
abort(500, '支付网关请求失败');
|
||||||
}
|
}
|
||||||
if (!Redis::set($source['id'], $order->trade_no)) {
|
if (!Cache::put($source['id'], $order->trade_no)) {
|
||||||
abort(500, '订单创建失败');
|
abort(500, '订单创建失败');
|
||||||
}
|
}
|
||||||
Redis::expire($source['id'], 3600);
|
Redis::expire($source['id'], 3600);
|
||||||
|
@ -7,7 +7,7 @@ use Illuminate\Http\Request;
|
|||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use Illuminate\Http\Exceptions\HttpResponseException;
|
use Illuminate\Http\Exceptions\HttpResponseException;
|
||||||
use Illuminate\Support\Facades\Mail;
|
use Illuminate\Support\Facades\Mail;
|
||||||
use Illuminate\Support\Facades\Redis;
|
use Cache;
|
||||||
|
|
||||||
class CommController extends Controller
|
class CommController extends Controller
|
||||||
{
|
{
|
||||||
@ -29,7 +29,7 @@ class CommController extends Controller
|
|||||||
public function sendEmailVerify (CommSendEmailVerify $request) {
|
public function sendEmailVerify (CommSendEmailVerify $request) {
|
||||||
$email = $request->input('email');
|
$email = $request->input('email');
|
||||||
$redisKey = 'sendEmailVerify:' . $email;
|
$redisKey = 'sendEmailVerify:' . $email;
|
||||||
if (Redis::get($redisKey)) {
|
if (Cache::get($redisKey)) {
|
||||||
abort(500, '验证码已发送,请过一会在请求');
|
abort(500, '验证码已发送,请过一会在请求');
|
||||||
}
|
}
|
||||||
$code = rand(100000, 999999);
|
$code = rand(100000, 999999);
|
||||||
@ -50,7 +50,7 @@ class CommController extends Controller
|
|||||||
abort(500, '发送失败');
|
abort(500, '发送失败');
|
||||||
}
|
}
|
||||||
|
|
||||||
Redis::set($redisKey, $code);
|
Cache::put($redisKey, $code);
|
||||||
Redis::expire($redisKey, 600);
|
Redis::expire($redisKey, 600);
|
||||||
return response([
|
return response([
|
||||||
'data' => true
|
'data' => true
|
||||||
|
@ -7,13 +7,13 @@ use Illuminate\Http\Request;
|
|||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Support\Facades\Mail;
|
use Illuminate\Support\Facades\Mail;
|
||||||
use Illuminate\Support\Facades\Redis;
|
use Cache;
|
||||||
|
|
||||||
class ForgetController extends Controller
|
class ForgetController extends Controller
|
||||||
{
|
{
|
||||||
public function index (ForgetIndex $request) {
|
public function index (ForgetIndex $request) {
|
||||||
$redisKey = 'sendEmailVerify:' . $request->input('email');
|
$redisKey = 'sendEmailVerify:' . $request->input('email');
|
||||||
if (Redis::get($redisKey) !== $request->input('email_code')) {
|
if (Cache::get($redisKey) !== $request->input('email_code')) {
|
||||||
abort(500, '邮箱验证码有误');
|
abort(500, '邮箱验证码有误');
|
||||||
}
|
}
|
||||||
$user = User::where('email', $request->input('email'))->first();
|
$user = User::where('email', $request->input('email'))->first();
|
||||||
@ -21,7 +21,7 @@ class ForgetController extends Controller
|
|||||||
if (!$user->save()) {
|
if (!$user->save()) {
|
||||||
abort(500, '重置失败');
|
abort(500, '重置失败');
|
||||||
}
|
}
|
||||||
Redis::del($redisKey);
|
Cache::forget($redisKey);
|
||||||
return response([
|
return response([
|
||||||
'data' => true
|
'data' => true
|
||||||
]);
|
]);
|
||||||
|
@ -6,7 +6,7 @@ use Illuminate\Http\Request;
|
|||||||
use App\Http\Requests\Passport\LoginIndex;
|
use App\Http\Requests\Passport\LoginIndex;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Support\Facades\Redis;
|
use Cache;
|
||||||
use App\Utils\Helper;
|
use App\Utils\Helper;
|
||||||
|
|
||||||
class LoginController extends Controller
|
class LoginController extends Controller
|
||||||
@ -44,7 +44,7 @@ class LoginController extends Controller
|
|||||||
}
|
}
|
||||||
$code = Helper::guid();
|
$code = Helper::guid();
|
||||||
$key = 'token2Login_' . $code;
|
$key = 'token2Login_' . $code;
|
||||||
Redis::set($key, $user->id);
|
Cache::put($key, $user->id);
|
||||||
Redis::expire($key, 600);
|
Redis::expire($key, 600);
|
||||||
$redirect = '/#/login?verify='. $code .'&redirect=' . ($request->input('redirect') ? $request->input('redirect') : 'dashboard');
|
$redirect = '/#/login?verify='. $code .'&redirect=' . ($request->input('redirect') ? $request->input('redirect') : 'dashboard');
|
||||||
if (config('v2board.app_url')) {
|
if (config('v2board.app_url')) {
|
||||||
@ -57,7 +57,7 @@ class LoginController extends Controller
|
|||||||
|
|
||||||
if ($request->input('verify')) {
|
if ($request->input('verify')) {
|
||||||
$key = 'token2Login_' . $request->input('verify');
|
$key = 'token2Login_' . $request->input('verify');
|
||||||
$userId = Redis::get($key);
|
$userId = Cache::get($key);
|
||||||
if (!$userId) {
|
if (!$userId) {
|
||||||
abort(500, '令牌有误');
|
abort(500, '令牌有误');
|
||||||
}
|
}
|
||||||
@ -70,7 +70,7 @@ class LoginController extends Controller
|
|||||||
if ($user->is_admin) {
|
if ($user->is_admin) {
|
||||||
$request->session()->put('is_admin', true);
|
$request->session()->put('is_admin', true);
|
||||||
}
|
}
|
||||||
Redis::del($key);
|
Cache::forget($key);
|
||||||
return response([
|
return response([
|
||||||
'data' => true
|
'data' => true
|
||||||
]);
|
]);
|
||||||
|
@ -9,7 +9,7 @@ use App\Http\Controllers\Controller;
|
|||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Models\Plan;
|
use App\Models\Plan;
|
||||||
use Illuminate\Http\Exceptions\HttpResponseException;
|
use Illuminate\Http\Exceptions\HttpResponseException;
|
||||||
use Illuminate\Support\Facades\Redis;
|
use Cache;
|
||||||
use App\Utils\Helper;
|
use App\Utils\Helper;
|
||||||
use App\Models\InviteCode;
|
use App\Models\InviteCode;
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ class RegisterController extends Controller
|
|||||||
if (empty($request->input('email_code'))) {
|
if (empty($request->input('email_code'))) {
|
||||||
abort(500, '邮箱验证码不能为空');
|
abort(500, '邮箱验证码不能为空');
|
||||||
}
|
}
|
||||||
if (Redis::get($redisKey) !== $request->input('email_code')) {
|
if (Cache::get($redisKey) !== $request->input('email_code')) {
|
||||||
abort(500, '邮箱验证码有误');
|
abort(500, '邮箱验证码有误');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -80,7 +80,7 @@ class RegisterController extends Controller
|
|||||||
abort(500, '注册失败');
|
abort(500, '注册失败');
|
||||||
}
|
}
|
||||||
if ((int)config('v2board.email_verify', 0)) {
|
if ((int)config('v2board.email_verify', 0)) {
|
||||||
Redis::del($redisKey);
|
Cache::forget($redisKey);
|
||||||
}
|
}
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'data' => true
|
'data' => true
|
||||||
|
@ -9,7 +9,7 @@ use App\Models\Plan;
|
|||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
use App\Models\ServerLog;
|
use App\Models\ServerLog;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
use Illuminate\Support\Facades\Redis;
|
use Cache;
|
||||||
|
|
||||||
class DeepbworkController extends Controller
|
class DeepbworkController extends Controller
|
||||||
{
|
{
|
||||||
@ -21,7 +21,7 @@ class DeepbworkController extends Controller
|
|||||||
if (!$server) {
|
if (!$server) {
|
||||||
abort(500, 'fail');
|
abort(500, 'fail');
|
||||||
}
|
}
|
||||||
Redis::set('server_last_check_at_' . $server->id, time());
|
Cache::put('server_last_check_at_' . $server->id, time());
|
||||||
$users = User::whereIn('group_id', json_decode($server->group_id))
|
$users = User::whereIn('group_id', json_decode($server->group_id))
|
||||||
->select([
|
->select([
|
||||||
'id',
|
'id',
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Redis;
|
use Cache;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
use App\Models\ServerLog;
|
use App\Models\ServerLog;
|
||||||
@ -29,9 +29,9 @@ class ServerController extends Controller {
|
|||||||
for ($i = 0; $i < count($server); $i++) {
|
for ($i = 0; $i < count($server); $i++) {
|
||||||
$server[$i]['link'] = Helper::buildVmessLink($server[$i], $user);
|
$server[$i]['link'] = Helper::buildVmessLink($server[$i], $user);
|
||||||
if ($server[$i]['parent_id']) {
|
if ($server[$i]['parent_id']) {
|
||||||
$server[$i]['last_check_at'] = Redis::get('server_last_check_at_' . $server[$i]['parent_id']);
|
$server[$i]['last_check_at'] = Cache::get('server_last_check_at_' . $server[$i]['parent_id']);
|
||||||
} else {
|
} else {
|
||||||
$server[$i]['last_check_at'] = Redis::get('server_last_check_at_' . $server[$i]['id']);
|
$server[$i]['last_check_at'] = Cache::get('server_last_check_at_' . $server[$i]['id']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return response([
|
return response([
|
||||||
|
Loading…
Reference in New Issue
Block a user