mirror of
https://github.com/cedar2025/Xboard.git
synced 2025-01-22 10:38:14 -05:00
fix: correct know file issues
This commit is contained in:
parent
8ec568c24d
commit
e41c47beeb
@ -121,6 +121,7 @@ class UniProxyController extends Controller
|
||||
: $protocolSettings['reality_settings']
|
||||
],
|
||||
'hysteria' => [
|
||||
'server_port' => (int) $serverPort,
|
||||
'version' => (int) $protocolSettings['version'],
|
||||
'host' => $host,
|
||||
'server_name' => $protocolSettings['tls']['server_name'],
|
||||
|
@ -95,11 +95,11 @@ class OrderController extends Controller
|
||||
}
|
||||
|
||||
[$operator, $filterValue] = explode(':', $value, 2);
|
||||
|
||||
|
||||
// Convert numeric strings to appropriate type
|
||||
if (is_numeric($filterValue)) {
|
||||
$filterValue = strpos($filterValue, '.') !== false
|
||||
? (float) $filterValue
|
||||
$filterValue = strpos($filterValue, '.') !== false
|
||||
? (float) $filterValue
|
||||
: (int) $filterValue;
|
||||
}
|
||||
|
||||
@ -215,11 +215,11 @@ class OrderController extends Controller
|
||||
$orderService = new OrderService($order);
|
||||
$order->user_id = $user->id;
|
||||
$order->plan_id = $plan->id;
|
||||
$order->period = $request->input('period');
|
||||
$order->period = PlanService::getPeriodKey($request->input('period'));
|
||||
$order->trade_no = Helper::guid();
|
||||
$order->total_amount = $request->input('total_amount');
|
||||
|
||||
if ($order->period === 'reset_price') {
|
||||
if (PlanService::getPeriodKey($order->period) === Plan::PERIOD_RESET_TRAFFIC) {
|
||||
$order->type = Order::TYPE_RESET_TRAFFIC;
|
||||
} else if ($user->plan_id !== NULL && $order->plan_id !== $user->plan_id) {
|
||||
$order->type = Order::TYPE_UPGRADE;
|
||||
|
@ -68,71 +68,123 @@ class Server extends Model
|
||||
'updated_at' => 'timestamp'
|
||||
];
|
||||
|
||||
private const DEFAULT_PROTOCOL_SETTINGS = [
|
||||
private const PROTOCOL_CONFIGURATIONS = [
|
||||
self::TYPE_TROJAN => [
|
||||
'allow_insecure' => false,
|
||||
'server_name' => null,
|
||||
'network' => null,
|
||||
'network_settings' => null
|
||||
'allow_insecure' => ['type' => 'boolean', 'default' => false],
|
||||
'server_name' => ['type' => 'string', 'default' => null],
|
||||
'network' => ['type' => 'string', 'default' => null],
|
||||
'network_settings' => ['type' => 'array', 'default' => null]
|
||||
],
|
||||
self::TYPE_VMESS => [
|
||||
'tls' => 0,
|
||||
'network' => null,
|
||||
'rules' => null,
|
||||
'network_settings' => null,
|
||||
'tls_settings' => null
|
||||
'tls' => ['type' => 'integer', 'default' => 0],
|
||||
'network' => ['type' => 'string', 'default' => null],
|
||||
'rules' => ['type' => 'array', 'default' => null],
|
||||
'network_settings' => ['type' => 'array', 'default' => null],
|
||||
'tls_settings' => ['type' => 'array', 'default' => null]
|
||||
],
|
||||
self::TYPE_VLESS => [
|
||||
'tls' => false,
|
||||
'tls_settings' => null,
|
||||
'flow' => null,
|
||||
'network' => null,
|
||||
'network_settings' => null,
|
||||
'tls' => ['type' => 'integer', 'default' => 0],
|
||||
'tls_settings' => ['type' => 'array', 'default' => null],
|
||||
'flow' => ['type' => 'string', 'default' => null],
|
||||
'network' => ['type' => 'string', 'default' => null],
|
||||
'network_settings' => ['type' => 'array', 'default' => null],
|
||||
'reality_settings' => [
|
||||
'allow_insecure' => false,
|
||||
'server_port' => null,
|
||||
'server_name' => null,
|
||||
'public_key' => null,
|
||||
'private_key' => null,
|
||||
'short_id' => null
|
||||
'type' => 'object',
|
||||
'fields' => [
|
||||
'allow_insecure' => ['type' => 'boolean', 'default' => false],
|
||||
'server_port' => ['type' => 'integer', 'default' => null],
|
||||
'server_name' => ['type' => 'string', 'default' => null],
|
||||
'public_key' => ['type' => 'string', 'default' => null],
|
||||
'private_key' => ['type' => 'string', 'default' => null],
|
||||
'short_id' => ['type' => 'string', 'default' => null]
|
||||
]
|
||||
]
|
||||
],
|
||||
self::TYPE_SHADOWSOCKS => [
|
||||
'cipher' => null,
|
||||
'obfs' => null,
|
||||
'obfs_settings' => null
|
||||
'cipher' => ['type' => 'string', 'default' => null],
|
||||
'obfs' => ['type' => 'string', 'default' => null],
|
||||
'obfs_settings' => ['type' => 'array', 'default' => null]
|
||||
],
|
||||
self::TYPE_HYSTERIA => [
|
||||
'version' => 2,
|
||||
'version' => ['type' => 'integer', 'default' => 2],
|
||||
'bandwidth' => [
|
||||
'up' => null,
|
||||
'down' => null
|
||||
'type' => 'object',
|
||||
'fields' => [
|
||||
'up' => ['type' => 'integer', 'default' => null],
|
||||
'down' => ['type' => 'integer', 'default' => null]
|
||||
]
|
||||
],
|
||||
'obfs' => [
|
||||
'open' => false,
|
||||
'type' => 'salamander',
|
||||
'password' => null
|
||||
'type' => 'object',
|
||||
'fields' => [
|
||||
'open' => ['type' => 'boolean', 'default' => false],
|
||||
'type' => ['type' => 'string', 'default' => 'salamander'],
|
||||
'password' => ['type' => 'string', 'default' => null]
|
||||
]
|
||||
],
|
||||
'tls' => [
|
||||
'server_name' => null,
|
||||
'allow_insecure' => false
|
||||
'type' => 'object',
|
||||
'fields' => [
|
||||
'server_name' => ['type' => 'string', 'default' => null],
|
||||
'allow_insecure' => ['type' => 'boolean', 'default' => false]
|
||||
]
|
||||
]
|
||||
],
|
||||
self::TYPE_TUIC => [
|
||||
'congestion_control' => 'cubic',
|
||||
'alpn' => ['h3'],
|
||||
'udp_relay_mode' => 'native',
|
||||
'allow_insecure' => false,
|
||||
'tls_settings' => null
|
||||
'congestion_control' => ['type' => 'string', 'default' => 'cubic'],
|
||||
'alpn' => ['type' => 'array', 'default' => ['h3']],
|
||||
'udp_relay_mode' => ['type' => 'string', 'default' => 'native'],
|
||||
'allow_insecure' => ['type' => 'boolean', 'default' => false],
|
||||
'tls_settings' => ['type' => 'array', 'default' => null]
|
||||
]
|
||||
];
|
||||
|
||||
private function castValueWithConfig($value, array $config)
|
||||
{
|
||||
if ($value === null) {
|
||||
return $config['default'];
|
||||
}
|
||||
|
||||
return match($config['type']) {
|
||||
'integer' => (int) $value,
|
||||
'boolean' => (bool) $value,
|
||||
'string' => (string) $value,
|
||||
'array' => (array) $value,
|
||||
'object' => is_array($value) ?
|
||||
$this->castSettingsWithConfig($value, $config['fields']) :
|
||||
$config['default'],
|
||||
default => $value
|
||||
};
|
||||
}
|
||||
|
||||
private function castSettingsWithConfig(array $settings, array $configs): array
|
||||
{
|
||||
$result = [];
|
||||
foreach ($configs as $key => $config) {
|
||||
$value = $settings[$key] ?? null;
|
||||
$result[$key] = $this->castValueWithConfig($value, $config);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function getDefaultSettings(array $configs): array
|
||||
{
|
||||
$defaults = [];
|
||||
foreach ($configs as $key => $config) {
|
||||
if ($config['type'] === 'object') {
|
||||
$defaults[$key] = $this->getDefaultSettings($config['fields']);
|
||||
} else {
|
||||
$defaults[$key] = $config['default'];
|
||||
}
|
||||
}
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
public function getProtocolSettingsAttribute($value)
|
||||
{
|
||||
$settings = json_decode($value, true) ?? [];
|
||||
$defaultSettings = self::DEFAULT_PROTOCOL_SETTINGS[$this->type] ?? [];
|
||||
|
||||
return array_replace_recursive($defaultSettings, $settings);
|
||||
$configs = self::PROTOCOL_CONFIGURATIONS[$this->type] ?? [];
|
||||
return $this->castSettingsWithConfig($settings, $configs);
|
||||
}
|
||||
|
||||
public function setProtocolSettingsAttribute($value)
|
||||
@ -141,10 +193,10 @@ class Server extends Model
|
||||
$value = json_decode($value, true);
|
||||
}
|
||||
|
||||
$defaultSettings = self::DEFAULT_PROTOCOL_SETTINGS[$this->type] ?? [];
|
||||
$mergedSettings = array_replace_recursive($defaultSettings, $value ?? []);
|
||||
|
||||
$this->attributes['protocol_settings'] = json_encode($mergedSettings);
|
||||
$configs = self::PROTOCOL_CONFIGURATIONS[$this->type] ?? [];
|
||||
$castedSettings = $this->castSettingsWithConfig($value ?? [], $configs);
|
||||
|
||||
$this->attributes['protocol_settings'] = json_encode($castedSettings);
|
||||
}
|
||||
|
||||
public function loadParentCreatedAt(): void
|
||||
|
@ -44,10 +44,10 @@ class OrderService
|
||||
]);
|
||||
}
|
||||
switch ((string) $order->period) {
|
||||
case 'onetime_price':
|
||||
case Plan::PERIOD_ONETIME:
|
||||
$this->buyByOneTime($plan);
|
||||
break;
|
||||
case 'reset_price':
|
||||
case Plan::PERIOD_RESET_TRAFFIC:
|
||||
$this->buyByResetTraffic();
|
||||
break;
|
||||
default:
|
||||
@ -88,7 +88,7 @@ class OrderService
|
||||
public function setOrderType(User $user)
|
||||
{
|
||||
$order = $this->order;
|
||||
if ($order->period === 'reset_price') {
|
||||
if ($order->period === Plan::PERIOD_RESET_TRAFFIC) {
|
||||
$order->type = Order::TYPE_RESET_TRAFFIC;
|
||||
} else if ($user->plan_id !== NULL && $order->plan_id !== $user->plan_id && ($user->expired_at > time() || $user->expired_at === NULL)) {
|
||||
if (!(int) admin_setting('plan_change_enable', 1))
|
||||
@ -170,7 +170,7 @@ class OrderService
|
||||
private function getSurplusValueByOneTime(User $user, Order $order)
|
||||
{
|
||||
$lastOneTimeOrder = Order::where('user_id', $user->id)
|
||||
->where('period', 'onetime_price')
|
||||
->where('period', Plan::PERIOD_ONETIME)
|
||||
->where('status', Order::STATUS_COMPLETED)
|
||||
->orderBy('id', 'DESC')
|
||||
->first();
|
||||
@ -185,7 +185,7 @@ class OrderService
|
||||
$trafficUnitPrice = $paidTotalAmount / $nowUserTraffic;
|
||||
$notUsedTraffic = $nowUserTraffic - (($user->u + $user->d) / 1073741824);
|
||||
$result = $trafficUnitPrice * $notUsedTraffic;
|
||||
$orderModel = Order::where('user_id', $user->id)->where('period', '!=', 'reset_price')->where('status', Order::STATUS_COMPLETED);
|
||||
$orderModel = Order::where('user_id', $user->id)->where('period', '!=', Plan::PERIOD_RESET_TRAFFIC)->where('status', Order::STATUS_COMPLETED);
|
||||
$order->surplus_amount = $result > 0 ? $result : 0;
|
||||
$order->surplus_order_ids = array_column($orderModel->get()->toArray(), 'id');
|
||||
}
|
||||
@ -193,7 +193,7 @@ class OrderService
|
||||
private function getSurplusValueByPeriod(User $user, Order $order)
|
||||
{
|
||||
$orders = Order::where('user_id', $user->id)
|
||||
->whereNotIn('period', ['reset_price', 'onetime_price'])
|
||||
->whereNotIn('period', [Plan::PERIOD_RESET_TRAFFIC, Plan::PERIOD_ONETIME])
|
||||
->where('status', Order::STATUS_COMPLETED)
|
||||
->get()
|
||||
->toArray();
|
||||
@ -272,7 +272,7 @@ class OrderService
|
||||
{
|
||||
$this->user->speed_limit = $speedLimit;
|
||||
}
|
||||
|
||||
|
||||
private function setDeviceLimit($deviceLimit)
|
||||
{
|
||||
$this->user->device_limit = $deviceLimit;
|
||||
|
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Models\Plan;
|
||||
|
||||
return new class extends Migration {
|
||||
/**
|
||||
* 旧的价格字段到新周期的映射关系
|
||||
*/
|
||||
private const PERIOD_MAPPING = [
|
||||
'month_price' => 'monthly',
|
||||
'quarter_price' => 'quarterly',
|
||||
'half_year_price' => 'half_yearly',
|
||||
'year_price' => 'yearly',
|
||||
'two_year_price' => 'two_yearly',
|
||||
'three_year_price' => 'three_yearly',
|
||||
'onetime_price' => 'onetime',
|
||||
'reset_price' => 'reset_traffic'
|
||||
];
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
// 批量更新订单的周期字段
|
||||
foreach (self::PERIOD_MAPPING as $oldPeriod => $newPeriod) {
|
||||
DB::table('v2_order')
|
||||
->where('period', $oldPeriod)
|
||||
->update(['period' => $newPeriod]);
|
||||
}
|
||||
|
||||
// 检查是否还有未转换的记录
|
||||
$unconvertedCount = DB::table('v2_order')
|
||||
->whereNotIn('period', array_values(self::PERIOD_MAPPING))
|
||||
->count();
|
||||
|
||||
if ($unconvertedCount > 0) {
|
||||
\Log::warning("Found {$unconvertedCount} orders with unconverted period values");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
// 回滚操作 - 将新的周期值转换回旧的价格字段名
|
||||
foreach (self::PERIOD_MAPPING as $oldPeriod => $newPeriod) {
|
||||
DB::table('v2_order')
|
||||
->where('period', $newPeriod)
|
||||
->update(['period' => $oldPeriod]);
|
||||
}
|
||||
}
|
||||
};
|
2
public/assets/admin/assets/index.js
vendored
2
public/assets/admin/assets/index.js
vendored
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user