Merge pull request #43 from v2board/dev

1.1.2
This commit is contained in:
tokumeikoi 2020-02-17 22:06:10 +08:00 committed by GitHub
commit c576299a60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 161 additions and 96 deletions

View File

@ -70,9 +70,11 @@ class CheckOrder extends Command
{ {
$plan = Plan::find($order->plan_id); $plan = Plan::find($order->plan_id);
// change plan process // change plan process
if ((int)$order->type === 3 && (int)config('v2board.try_out_plan_id') !== (int)$user->plan_id) { if ($order->type == 3) {
$transferEnableDifference = $plan->transfer_enable - ($user->transfer_enable / 1073741824); $user->expired_at = time();
$user->expired_at = $user->expired_at - ($transferEnableDifference * config('v2board.plan_transfer_hour', 12) * 3600); }
if ($order->refund_amount) {
$user->balance = $user->balance + $order->refund_amount;
} }
$user->transfer_enable = $plan->transfer_enable * 1073741824; $user->transfer_enable = $plan->transfer_enable * 1073741824;
$user->enable = 1; $user->enable = 1;

View File

@ -29,7 +29,6 @@ class ConfigController extends Controller
'app_url' => config('v2board.app_url'), 'app_url' => config('v2board.app_url'),
'subscribe_url' => config('v2board.subscribe_url'), 'subscribe_url' => config('v2board.subscribe_url'),
'plan_change_enable' => (int)config('v2board.plan_change_enable', 1), 'plan_change_enable' => (int)config('v2board.plan_change_enable', 1),
'plan_transfer_hour' => config('v2board.plan_transfer_hour', 12),
'try_out_plan_id' => (int)config('v2board.try_out_plan_id', 0), 'try_out_plan_id' => (int)config('v2board.try_out_plan_id', 0),
'try_out_hour' => (int)config('v2board.try_out_hour', 1), 'try_out_hour' => (int)config('v2board.try_out_hour', 1),
'email_whitelist_enable' => (int)config('v2board.email_whitelist_enable', 0), 'email_whitelist_enable' => (int)config('v2board.email_whitelist_enable', 0),
@ -56,7 +55,9 @@ class ConfigController extends Controller
'paytaro_app_secret' => config('v2board.paytaro_app_secret') 'paytaro_app_secret' => config('v2board.paytaro_app_secret')
], ],
'frontend' => [ 'frontend' => [
'frontend_theme' => config('v2board.frontend_theme', 1), 'frontend_theme_sidebar' => config('v2board.frontend_theme_sidebar', 'light'),
'frontend_theme_header' => config('v2board.frontend_theme_header', 'dark'),
'frontend_theme_color' => config('v2board.frontend_theme_color', 'default'),
'frontend_background_url' => config('v2board.frontend_background_url') 'frontend_background_url' => config('v2board.frontend_background_url')
], ],
'server' => [ 'server' => [

View File

@ -13,7 +13,7 @@ use Illuminate\Support\Facades\Cache;
class PoseidonController extends Controller class PoseidonController extends Controller
{ {
CONST SERVER_CONFIG = '{"api":{"services":["HandlerService","StatsService"],"tag":"api"},"stats":{},"inbound":{"port":443,"protocol":"vmess","settings":{"clients":[]},"streamSettings":{"network":"tcp"},"tag":"proxy"},"inboundDetour":[{"listen":"0.0.0.0","port":23333,"protocol":"dokodemo-door","settings":{"address":"0.0.0.0"},"tag":"api"}],"log":{"loglevel":"debug","access":"access.log","error":"error.log"},"outbound":{"protocol":"freedom","settings":{}},"routing":{"settings":{"rules":[{"inboundTag":["api"],"outboundTag":"api","type":"field"}]},"strategy":"rules"},"policy":{"levels":{"0":{"handshake":4,"connIdle":300,"uplinkOnly":5,"downlinkOnly":30,"statsUserUplink":true,"statsUserDownlink":true}}}}'; CONST SERVER_CONFIG = '{"api":{"services":["HandlerService","StatsService"],"tag":"api"},"stats":{},"inbound":{"port":443,"protocol":"vmess","settings":{"clients":[]},"streamSettings":{"network":"tcp"},"tag":"proxy"},"inboundDetour":[{"listen":"0.0.0.0","port":23333,"protocol":"dokodemo-door","settings":{"address":"0.0.0.0"},"tag":"api"}],"log":{"loglevel":"debug","access":"access.log","error":"error.log"},"outbound":{"protocol":"freedom","settings":{}},"outboundDetour":[{"protocol":"blackhole","settings":{},"tag":"block"}],"routing":{"settings":{"rules":[{"inboundTag":["api"],"outboundTag":"api","type":"field"}]},"strategy":"rules"},"policy":{"levels":{"0":{"handshake":4,"connIdle":300,"uplinkOnly":5,"downlinkOnly":30,"statsUserUplink":true,"statsUserDownlink":true}}}}';
// 后端获取用户 // 后端获取用户
public function user(Request $request) public function user(Request $request)
@ -40,6 +40,8 @@ class PoseidonController extends Controller
'v2ray_alter_id', 'v2ray_alter_id',
'v2ray_level' 'v2ray_level'
]) ])
->whereRaw('u + d < transfer_enable')
->where('enable', 1)
->get(); ->get();
$result = []; $result = [];
foreach ($users as $user) { foreach ($users as $user) {
@ -131,9 +133,34 @@ class PoseidonController extends Controller
break; break;
} }
} }
if ($server->rules) {
$rules = json_decode($server->rules);
// domain
if (isset($rules->domain)) {
$domainObj = new \StdClass();
$domainObj->type = 'field';
$domainObj->domain = $rules->domain;
$domainObj->outboundTag = 'block';
array_push($json->routing->settings->rules, $domainObj);
}
// protocol
if (isset($rules->protocol)) {
$protocolObj = new \StdClass();
$protocolObj->type = 'field';
$protocolObj->protocol = $rules->protocol;
$protocolObj->outboundTag = 'block';
array_push($json->routing->settings->rules, $protocolObj);
}
}
if ((int)$server->tls) { if ((int)$server->tls) {
$json->inbound->streamSettings->security = "tls"; $json->inbound->streamSettings->security = 'tls';
$tls = (object)array("certificateFile" => "/home/v2ray.crt", "keyFile" => "/home/v2ray.key"); $tls = (object)[
'certificateFile' => '/home/v2ray.crt',
'keyFile' => '/home/v2ray.key'
];
$json->inbound->streamSettings->tlsSettings = new \StdClass();
$json->inbound->streamSettings->tlsSettings->certificates[0] = $tls; $json->inbound->streamSettings->tlsSettings->certificates[0] = $tls;
} }

View File

@ -51,7 +51,6 @@ class OrderController extends Controller
abort(500, '订单不存在'); abort(500, '订单不存在');
} }
$order['plan'] = Plan::find($order->plan_id); $order['plan'] = Plan::find($order->plan_id);
$order['plan_transfer_hour'] = config('v2board.plan_transfer_hour', 12);
$order['try_out_plan_id'] = (int)config('v2board.try_out_plan_id'); $order['try_out_plan_id'] = (int)config('v2board.try_out_plan_id');
if (!$order['plan']) { if (!$order['plan']) {
abort(500, '订阅不存在'); abort(500, '订阅不存在');
@ -72,6 +71,24 @@ class OrderController extends Controller
return true; return true;
} }
// surplus value
private function getSurplusValue(User $user)
{
$plan = Plan::find($user->plan_id);
$dayPrice = 0;
if ($plan->month_price) {
$dayPrice = $plan->month_price / 30;
} else if ($plan->quarter_price) {
$dayPrice = $plan->quarter_price / 91;
} else if ($plan->half_year_price) {
$dayPrice = $plan->half_year_price / 183;
} else if ($plan->year_price) {
$dayPrice = $plan->year_price / 365;
}
$remainingDay = ($user->expired_at - time()) / 86400;
return $remainingDay * $dayPrice;
}
public function save(OrderSave $request) public function save(OrderSave $request)
{ {
if ($this->isNotCompleteOrderByUserId($request->session()->get('id'))) { if ($this->isNotCompleteOrderByUserId($request->session()->get('id'))) {
@ -122,8 +139,15 @@ class OrderController extends Controller
$order->total_amount = $plan[$request->input('cycle')]; $order->total_amount = $plan[$request->input('cycle')];
// renew and change subscribe process // renew and change subscribe process
if ($user->expired_at > time() && $order->plan_id !== $user->plan_id) { if ($user->expired_at > time() && $order->plan_id !== $user->plan_id) {
$order->type = 3;
if (!(int)config('v2board.plan_change_enable', 1)) abort(500, '目前不允许更改订阅,请联系管理员'); if (!(int)config('v2board.plan_change_enable', 1)) abort(500, '目前不允许更改订阅,请联系管理员');
$order->type = 3;
$order->surplus_amount = $this->getSurplusValue($user);
if ($order->surplus_amount >= $order->total_amount) {
$order->refund_amount = $order->surplus_amount - $order->total_amount;
$order->total_amount = 0;
} else {
$order->total_amount = $order->total_amount - $order->surplus_amount;
}
} else if ($user->expired_at > time() && $order->plan_id == $user->plan_id) { } else if ($user->expired_at > time() && $order->plan_id == $user->plan_id) {
$order->type = 2; $order->type = 2;
} else { } else {
@ -155,12 +179,6 @@ class OrderController extends Controller
// discount complete // discount complete
$order->total_amount = $order->total_amount - $order->discount_amount; $order->total_amount = $order->total_amount - $order->discount_amount;
// discount end // discount end
// free process
if ($order->total_amount <= 0) {
$order->total_amount = 0;
$order->status = 1;
}
// invite process // invite process
if ($user->invite_user_id && $order->total_amount > 0) { if ($user->invite_user_id && $order->total_amount > 0) {
$order->invite_user_id = $user->invite_user_id; $order->invite_user_id = $user->invite_user_id;
@ -194,6 +212,13 @@ class OrderController extends Controller
if (!$order) { if (!$order) {
abort(500, '订单不存在或已支付'); abort(500, '订单不存在或已支付');
} }
// free process
if ($order->total_amount <= 0) {
$order->total_amount = 0;
$order->status = 1;
$order->save();
exit();
}
switch ($method) { switch ($method) {
// return type => 0: QRCode / 1: URL // return type => 0: QRCode / 1: URL
case 0: case 0:

View File

@ -18,7 +18,6 @@ class ConfigSave extends FormRequest
'app_description' => '', 'app_description' => '',
'app_url' => 'url', 'app_url' => 'url',
'subscribe_url' => 'url', 'subscribe_url' => 'url',
'plan_transfer_hour' => 'numeric',
'plan_change_enable' => 'in:0,1', 'plan_change_enable' => 'in:0,1',
'try_out_enable' => 'in:0,1', 'try_out_enable' => 'in:0,1',
'try_out_plan_id' => 'integer', 'try_out_plan_id' => 'integer',
@ -47,7 +46,9 @@ class ConfigSave extends FormRequest
'paytaro_app_id' => '', 'paytaro_app_id' => '',
'paytaro_app_secret' => '', 'paytaro_app_secret' => '',
// frontend // frontend
'frontend_theme' => 'in:1,2', 'frontend_theme_sidebar' => 'in:dark,light',
'frontend_theme_header' => 'in:dark,light',
'frontend_theme_color' => 'in:default,darkblue,black',
'frontend_background_url' => 'nullable|url', 'frontend_background_url' => 'nullable|url',
// tutorial // tutorial
'apple_id' => 'email', 'apple_id' => 'email',

View File

@ -21,6 +21,7 @@ class PassportRoute
// Comm // Comm
$router->get ('/comm/config', 'Passport\\CommController@config'); $router->get ('/comm/config', 'Passport\\CommController@config');
$router->post('/comm/sendEmailVerify', 'Passport\\CommController@sendEmailVerify'); $router->post('/comm/sendEmailVerify', 'Passport\\CommController@sendEmailVerify');
$router->post('/comm/pv', 'Passport\\CommController@pv');
}); });
} }
} }

View File

@ -234,5 +234,5 @@ return [
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
*/ */
'version' => '1.1.1' 'version' => '1.1.2'
]; ];

View File

@ -156,3 +156,9 @@ CREATE TABLE `failed_jobs` (
ALTER TABLE `v2_user` ALTER TABLE `v2_user`
ADD `discount` int(11) NULL AFTER `balance`; ADD `discount` int(11) NULL AFTER `balance`;
ALTER TABLE `v2_order`
ADD `surplus_amount` int(11) NULL COMMENT '剩余价值' AFTER `discount_amount`;
ALTER TABLE `v2_order`
ADD `refund_amount` int(11) NULL COMMENT '退款金额' AFTER `surplus_amount`;

File diff suppressed because one or more lines are too long

View File

@ -1,12 +1,14 @@
window.v2board = { window.v2board = {
// 站点标题 // 站点标题
title: 'V2Board', title: 'V2Board',
// 站点描述
description: 'V2Board is best',
// API // API
host: '', host: '',
// 主题 // 主题
theme: '1', theme: {
sidebar: 'light',
header: 'dark',
color: 'default'
},
// 背景 // 背景
background_url: '' background_url: ''
} }

4
public/assets/admin/theme/black.css vendored Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

2
public/assets/admin/theme/default.css vendored Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -6,7 +6,11 @@ window.v2board = {
// API // API
host: '', host: '',
// 主题 // 主题
theme: '1', theme: {
sidebar: 'light',
header: 'dark',
color: 'default'
},
// 背景 // 背景
background_url: '' background_url: ''
} }

4
public/assets/user/theme/black.css vendored Normal file

File diff suppressed because one or more lines are too long

4
public/assets/user/theme/darkblue.css vendored Normal file

File diff suppressed because one or more lines are too long

2
public/assets/user/theme/default.css vendored Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -13,7 +13,11 @@
<script> <script>
window.v2board = { window.v2board = {
title: '{{$title}}', title: '{{$title}}',
theme: '{{$theme}}', theme: {
sidebar: '{{$theme_sidebar}}',
header: '{{$theme_header}}',
color: '{{$theme_color}}',
},
verison: '{{$verison}}', verison: '{{$verison}}',
background_url: '{{$backgroun_url}}' background_url: '{{$backgroun_url}}'
} }

View File

@ -13,7 +13,11 @@
<script> <script>
window.v2board = { window.v2board = {
title: '{{$title}}', title: '{{$title}}',
theme: '{{$theme}}', theme: {
sidebar: '{{$theme_sidebar}}',
header: '{{$theme_header}}',
color: '{{$theme_color}}',
},
verison: '{{$verison}}', verison: '{{$verison}}',
background_url: '{{$backgroun_url}}', background_url: '{{$backgroun_url}}',
description: '{{$description}}' description: '{{$description}}'

View File

@ -21,7 +21,9 @@ Route::get('/', function (Request $request) {
} }
return view('app', [ return view('app', [
'title' => config('v2board.app_name', 'V2Board'), 'title' => config('v2board.app_name', 'V2Board'),
'theme' => config('v2board.frontend_theme', 1), 'theme_sidebar' => config('v2board.frontend_theme_sidebar', 'light'),
'theme_header' => config('v2board.frontend_theme_header', 'dark'),
'theme_color' => config('v2board.frontend_theme_color', 'default'),
'backgroun_url' => config('v2board.frontend_background_url'), 'backgroun_url' => config('v2board.frontend_background_url'),
'verison' => config('app.version'), 'verison' => config('app.version'),
'description' => config('v2board.app_description', 'V2Board is best') 'description' => config('v2board.app_description', 'V2Board is best')
@ -31,7 +33,9 @@ Route::get('/', function (Request $request) {
Route::get('/admin', function () { Route::get('/admin', function () {
return view('admin', [ return view('admin', [
'title' => config('v2board.app_name', 'V2Board'), 'title' => config('v2board.app_name', 'V2Board'),
'theme' => config('v2board.frontend_theme', 1), 'theme_sidebar' => config('v2board.frontend_theme_sidebar', 'light'),
'theme_header' => config('v2board.frontend_theme_header', 'dark'),
'theme_color' => config('v2board.frontend_theme_color', 'default'),
'backgroun_url' => config('v2board.frontend_background_url'), 'backgroun_url' => config('v2board.frontend_background_url'),
'verison' => config('app.version') 'verison' => config('app.version')
]); ]);