mirror of
https://github.com/v2board/v2board.git
synced 2025-01-25 15:39:10 +08:00
update
This commit is contained in:
parent
c17b614e13
commit
867f1760d3
@ -81,10 +81,15 @@ class CheckOrder extends Command
|
||||
abort(500, '开通失败');
|
||||
}
|
||||
}
|
||||
if ((string)$order->cycle === 'onetime_price') {
|
||||
$this->buyByOneTime($order, $user, $plan);
|
||||
} else {
|
||||
$this->buyByCycle($order, $user, $plan);
|
||||
switch ((string)$order->cycle) {
|
||||
case 'onetime_price':
|
||||
$this->buyByOneTime($order, $user, $plan);
|
||||
break;
|
||||
case 'reset_price':
|
||||
$this->buyReset($user);
|
||||
break;
|
||||
default:
|
||||
$this->buyByCycle($order, $user, $plan);
|
||||
}
|
||||
if (!$user->save()) {
|
||||
DB::rollBack();
|
||||
@ -99,6 +104,12 @@ class CheckOrder extends Command
|
||||
DB::commit();
|
||||
}
|
||||
|
||||
private function buyReset(User $user)
|
||||
{
|
||||
$user->u = 0;
|
||||
$user->d = 0;
|
||||
}
|
||||
|
||||
private function buyByCycle(Order $order, User $user, Plan $plan)
|
||||
{
|
||||
// change plan process
|
||||
|
@ -150,7 +150,6 @@ class ClientController extends Controller
|
||||
private function clash($user, $server)
|
||||
{
|
||||
$proxy = [];
|
||||
$proxyGroup = [];
|
||||
$proxies = [];
|
||||
$rules = [];
|
||||
foreach ($server as $item) {
|
||||
@ -180,28 +179,80 @@ class ClientController extends Controller
|
||||
array_push($proxies, $item->name);
|
||||
}
|
||||
|
||||
array_push($proxyGroup, [
|
||||
'name' => 'auto',
|
||||
'type' => 'url-test',
|
||||
'proxies' => $proxies,
|
||||
'url' => 'https://www.bing.com',
|
||||
'interval' => 300
|
||||
]);
|
||||
array_push($proxyGroup, [
|
||||
'name' => 'fallback-auto',
|
||||
'type' => 'fallback',
|
||||
'proxies' => $proxies,
|
||||
'url' => 'https://www.bing.com',
|
||||
'interval' => 300
|
||||
]);
|
||||
array_push($proxyGroup, [
|
||||
'name' => 'select',
|
||||
'type' => 'select',
|
||||
'proxies' => array_merge($proxies, [
|
||||
'auto',
|
||||
'fallback-auto'
|
||||
])
|
||||
]);
|
||||
$proxyGroup = [
|
||||
[
|
||||
'name' => '🔰 节点选择',
|
||||
'type' => 'select',
|
||||
'proxies' => array_merge([
|
||||
'♻️ 自动选择',
|
||||
'🎯 全球直连'
|
||||
], $proxies)
|
||||
], [
|
||||
'name' => '♻️ 自动选择',
|
||||
'type' => 'url-test',
|
||||
'url' => 'http://www.gstatic.com/generate_204',
|
||||
'interval' => 300,
|
||||
'proxies' => $proxies
|
||||
], [
|
||||
'name' => '🌍 国外媒体',
|
||||
'type' => 'select',
|
||||
'proxies' => array_merge([
|
||||
'🔰 节点选择',
|
||||
'♻️ 自动选择',
|
||||
'🎯 全球直连'
|
||||
], $proxies)
|
||||
], [
|
||||
'name' => '🌏 国内媒体',
|
||||
'type' => 'select',
|
||||
'proxies' => array_merge([
|
||||
'🎯 全球直连',
|
||||
'🔰 节点选择'
|
||||
], $proxies)
|
||||
], [
|
||||
'name' => 'Ⓜ️ 微软服务',
|
||||
'type' => 'select',
|
||||
'proxies' => array_merge([
|
||||
'🎯 全球直连',
|
||||
'🔰 节点选择'
|
||||
], $proxies)
|
||||
], [
|
||||
'name' => '📲 电报信息',
|
||||
'type' => 'select',
|
||||
'proxies' => array_merge([
|
||||
'🎯 全球直连',
|
||||
'🔰 节点选择'
|
||||
], $proxies)
|
||||
], [
|
||||
'name' => '🍎 苹果服务',
|
||||
'type' => 'select',
|
||||
'proxies' => array_merge([
|
||||
'🔰 节点选择',
|
||||
'♻️ 自动选择',
|
||||
'🎯 全球直连'
|
||||
], $proxies)
|
||||
], [
|
||||
'name' => '🎯 全球直连',
|
||||
'type' => 'select',
|
||||
'proxies' => [
|
||||
'DIRECT'
|
||||
]
|
||||
], [
|
||||
'name' => '🛑 全球拦截',
|
||||
'type' => 'select',
|
||||
'proxies' => [
|
||||
'REJECT',
|
||||
'DIRECT'
|
||||
]
|
||||
], [
|
||||
'name' => '🐟 漏网之鱼',
|
||||
'type' => 'select',
|
||||
'proxies' => array_merge([
|
||||
'🔰 节点选择',
|
||||
'♻️ 自动选择',
|
||||
'🎯 全球直连'
|
||||
], $proxies)
|
||||
]
|
||||
];
|
||||
|
||||
try {
|
||||
$rules = [];
|
||||
|
@ -3,11 +3,13 @@
|
||||
namespace App\Http\Controllers\Server;
|
||||
|
||||
use App\Services\ServerService;
|
||||
use App\Services\UserService;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
use App\Models\Server;
|
||||
use App\Models\ServerLog;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
@ -63,28 +65,31 @@ class DeepbworkController extends Controller
|
||||
$server = Server::find($request->input('node_id'));
|
||||
if (!$server) {
|
||||
return response([
|
||||
'ret' => 1,
|
||||
'msg' => 'ok'
|
||||
'ret' => 0,
|
||||
'msg' => 'server is not found'
|
||||
]);
|
||||
}
|
||||
$data = file_get_contents('php://input');
|
||||
$data = json_decode($data, true);
|
||||
$serverService = new ServerService();
|
||||
$userService = new UserService();
|
||||
foreach ($data as $item) {
|
||||
$u = $item['u'] * $server->rate;
|
||||
$d = $item['d'] * $server->rate;
|
||||
$user = User::find($item['user_id']);
|
||||
$user->t = time();
|
||||
$user->u = $user->u + $u;
|
||||
$user->d = $user->d + $d;
|
||||
$user->save();
|
||||
if (!$userService->trafficFetch($u, $d, $item['user_id'])) {
|
||||
return response([
|
||||
'ret' => 0,
|
||||
'msg' => 'user fetch fail'
|
||||
]);
|
||||
}
|
||||
|
||||
$serverLog = new ServerLog();
|
||||
$serverLog->user_id = $item['user_id'];
|
||||
$serverLog->server_id = $request->input('node_id');
|
||||
$serverLog->u = $item['u'];
|
||||
$serverLog->d = $item['d'];
|
||||
$serverLog->rate = $server->rate;
|
||||
$serverLog->save();
|
||||
$serverService->log(
|
||||
$item['user_id'],
|
||||
$request->input('node_id'),
|
||||
$u,
|
||||
$d,
|
||||
$server->rate
|
||||
);
|
||||
}
|
||||
|
||||
return response([
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace App\Http\Controllers\Server;
|
||||
|
||||
use App\Services\ServerService;
|
||||
use App\Services\UserService;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
@ -58,22 +59,25 @@ class PoseidonController extends Controller
|
||||
}
|
||||
$data = file_get_contents('php://input');
|
||||
$data = json_decode($data, true);
|
||||
$serverService = new ServerService();
|
||||
$userService = new UserService();
|
||||
foreach ($data as $item) {
|
||||
$u = $item['u'] * $server->rate;
|
||||
$d = $item['d'] * $server->rate;
|
||||
$user = User::find($item['user_id']);
|
||||
$user->t = time();
|
||||
$user->u = $user->u + $u;
|
||||
$user->d = $user->d + $d;
|
||||
$user->save();
|
||||
if (!$userService->trafficFetch($u, $d, $item['user_id'])) {
|
||||
return response([
|
||||
'ret' => 0,
|
||||
'msg' => 'user fetch fail'
|
||||
]);
|
||||
}
|
||||
|
||||
$serverLog = new ServerLog();
|
||||
$serverLog->user_id = $item['user_id'];
|
||||
$serverLog->server_id = $request->input('node_id');
|
||||
$serverLog->u = $item['u'];
|
||||
$serverLog->d = $item['d'];
|
||||
$serverLog->rate = $server->rate;
|
||||
$serverLog->save();
|
||||
$serverService->log(
|
||||
$item['user_id'],
|
||||
$request->input('node_id'),
|
||||
$u,
|
||||
$d,
|
||||
$server->rate
|
||||
);
|
||||
}
|
||||
|
||||
return $this->success('');
|
||||
|
@ -89,6 +89,10 @@ class OrderController extends Controller
|
||||
abort(500, '该订阅周期无法进行购买,请选择其他周期');
|
||||
}
|
||||
|
||||
if ($request->input('cycle') === 'reset_price' && !$user->plan_id) {
|
||||
abort(500, '必须存在订阅才可以购买流量重置包');
|
||||
}
|
||||
|
||||
DB::beginTransaction();
|
||||
$order = new Order();
|
||||
$orderService = new OrderService($order);
|
||||
|
@ -15,7 +15,8 @@ class PlanSave extends FormRequest
|
||||
'quarter_price' => 'nullable|integer',
|
||||
'half_year_price' => 'nullable|integer',
|
||||
'year_price' => 'nullable|integer',
|
||||
'onetime_price' => 'nullable|integer'
|
||||
'onetime_price' => 'nullable|integer',
|
||||
'reset_price' => 'nullable|reset_price'
|
||||
];
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
@ -39,7 +40,8 @@ class PlanSave extends FormRequest
|
||||
'quarter_price.integer' => '季付金额格式有误',
|
||||
'half_year_price.integer' => '半年付金额格式有误',
|
||||
'year_price.integer' => '年付金额格式有误',
|
||||
'onetime_price.integer' => '一次性金额有误'
|
||||
'onetime_price.integer' => '一次性金额有误',
|
||||
'reset_price.integer' => '流量重置包金额有误'
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ class OrderSave extends FormRequest
|
||||
{
|
||||
return [
|
||||
'plan_id' => 'required',
|
||||
'cycle' => 'required|in:month_price,quarter_price,half_year_price,year_price,onetime_price'
|
||||
'cycle' => 'required|in:month_price,quarter_price,half_year_price,year_price,onetime_price,reset_price'
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -44,8 +44,11 @@ class OrderService
|
||||
public function setOrderType(User $user)
|
||||
{
|
||||
$order = $this->order;
|
||||
if ($order->cycle === 'reset_price') {
|
||||
$order->type = 4;
|
||||
}
|
||||
if ($user->plan_id !== NULL && $order->plan_id !== $user->plan_id) {
|
||||
if (!(int)config('v2board.plan_change_enable', 1)) abort(500, '目前不允许更改订阅,请联系客服或提交工单');
|
||||
if (!(int)config('v2board.plan_change_enable', 1)) abort(500, '目前不允许更改订阅,请联系客服或提交工单操作');
|
||||
$order->type = 3;
|
||||
$this->getSurplusValue($user, $order);
|
||||
if ($order->surplus_amount >= $order->total_amount) {
|
||||
@ -106,7 +109,7 @@ class OrderService
|
||||
}
|
||||
$notUsedTrafficPrice = $plan->transfer_enable - (($user->u + $user->d) / 1073741824);
|
||||
$result = $trafficUnitPrice * $notUsedTrafficPrice;
|
||||
$orderModel = Order::where('user_id', $user->id)->where('status', 3);
|
||||
$orderModel = Order::where('user_id', $user->id)->where('cycle', '!=', 'reset_price')->where('status', 3);
|
||||
$order->surplus_amount = $result > 0 ? $result : 0;
|
||||
$order->surplus_order_ids = json_encode(array_map(function ($v) { return $v['id'];}, $orderModel->get()->toArray()));
|
||||
}
|
||||
@ -119,7 +122,7 @@ class OrderService
|
||||
'half_year_price' => 6,
|
||||
'year_price' => 12
|
||||
];
|
||||
$orderModel = Order::where('user_id', $user->id)->where('status', 3);
|
||||
$orderModel = Order::where('user_id', $user->id)->where('cycle', '!=', 'reset_price')->where('status', 3);
|
||||
|
||||
$totalValue = $orderModel->sum('total_amount') + $orderModel->sum('balance_amount');
|
||||
if ($totalValue <= 0) {
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\ServerLog;
|
||||
use App\Models\User;
|
||||
use App\Models\Server;
|
||||
|
||||
@ -134,4 +135,26 @@ class ServerService
|
||||
$json->inbound->streamSettings->tlsSettings->certificates[0] = $tls;
|
||||
}
|
||||
}
|
||||
|
||||
public function log(int $userId, int $serverId, int $u, int $d, float $rate)
|
||||
{
|
||||
$serverLog = ServerLog::where('user_id', $userId)
|
||||
->where('server_id', $serverId)
|
||||
->where('created_at', '>=', strtotime(date('Y-m-d h:00:00')))
|
||||
->orderBy('DESC', 'created_at')
|
||||
->first();
|
||||
if ($serverLog) {
|
||||
$serverLog->u = $serverLog->u + $u;
|
||||
$serverLog->d = $serverLog->d + $d;
|
||||
$serverLog->save();
|
||||
} else {
|
||||
$serverLog = new ServerLog();
|
||||
$serverLog->user_id = $userId;
|
||||
$serverLog->server_id = $serverId;
|
||||
$serverLog->u = $u;
|
||||
$serverLog->d = $d;
|
||||
$serverLog->rate = $rate;
|
||||
$serverLog->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -75,4 +75,19 @@ class UserService
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function trafficFetch(int $u, int $d, int $userId)
|
||||
{
|
||||
$user = User::find($userId);
|
||||
if (!$user) {
|
||||
return false;
|
||||
}
|
||||
$user->t = time();
|
||||
$user->u = $user->u + $u;
|
||||
$user->d = $user->d + $d;
|
||||
if (!$user->save()) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -228,3 +228,10 @@ ADD `sort` int(11) NULL AFTER `show`;
|
||||
|
||||
ALTER TABLE `v2_plan`
|
||||
ADD `sort` int(11) NULL AFTER `show`;
|
||||
|
||||
ALTER TABLE `v2_plan`
|
||||
CHANGE `month_price` `month_price` int(11) NULL AFTER `content`,
|
||||
CHANGE `quarter_price` `quarter_price` int(11) NULL AFTER `month_price`,
|
||||
CHANGE `half_year_price` `half_year_price` int(11) NULL AFTER `quarter_price`,
|
||||
CHANGE `year_price` `year_price` int(11) NULL AFTER `half_year_price`,
|
||||
ADD `reset_price` int(11) NULL AFTER `onetime_price`;
|
||||
|
1
init.sh
1
init.sh
@ -1,3 +1,4 @@
|
||||
wget https://getcomposer.org/download/1.9.0/composer.phar
|
||||
php composer.phar install -vvv
|
||||
php artisan v2board:install
|
||||
chown -R www ./
|
||||
|
2
public/assets/admin/umi.js
vendored
2
public/assets/admin/umi.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user