fix: correct know file issues

This commit is contained in:
xboard 2025-01-12 21:10:52 +08:00
parent 0de998dc25
commit 51664a4da0
17 changed files with 291 additions and 123 deletions

View File

@ -12,8 +12,8 @@ class NoticeController extends Controller
{
$current = $request->input('current') ? $request->input('current') : 1;
$pageSize = 5;
$model = Notice::orderBy('created_at', 'DESC')
->where('show', 1);
$model = Notice::orderBy('sort', 'ASC')
->where('show', true);
$total = $model->count();
$res = $model->forPage($current, $pageSize)
->get();

View File

@ -7,12 +7,17 @@ use App\Http\Controllers\Controller;
use App\Http\Requests\Admin\NoticeSave;
use App\Models\Notice;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class NoticeController extends Controller
{
public function fetch(Request $request)
{
return $this->success(Notice::orderBy('id', 'DESC')->get());
return $this->success(
Notice::orderBy('sort', 'ASC')
->orderBy('id', 'DESC')
->get()
);
}
public function save(NoticeSave $request)
@ -72,4 +77,25 @@ class NoticeController extends Controller
}
return $this->success(true);
}
public function sort(Request $request)
{
$params = $request->validate([
'ids' => 'required|array'
]);
try {
DB::beginTransaction();
foreach ($params['ids'] as $k => $v) {
$notice = Notice::findOrFail($v);
$notice->update(['sort' => $k + 1]);
}
DB::commit();
return $this->success(true);
} catch (\Exception $e) {
DB::rollBack();
\Log::error($e);
return $this->fail([500, '排序保存失败']);
}
}
}

View File

@ -14,6 +14,7 @@ use App\Services\UserService;
use App\Utils\Helper;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Database\Eloquent\Builder;
class OrderController extends Controller
{
@ -57,24 +58,80 @@ class OrderController extends Controller
);
}
private function applyFiltersAndSorts(Request $request, $builder)
private function applyFiltersAndSorts(Request $request, Builder $builder): void
{
$request->collect('filter')->each(function ($filter) use ($builder) {
$key = $filter['id'];
$this->applyFilters($request, $builder);
$this->applySorting($request, $builder);
}
private function applyFilters(Request $request, Builder $builder): void
{
if (!$request->has('filter')) {
return;
}
collect($request->input('filter'))->each(function ($filter) use ($builder) {
$field = $filter['id'];
$value = $filter['value'];
$builder->where(function ($query) use ($key, $value) {
is_array($value)
? $query->whereIn($key, $value)
: $query->where($key, 'like', "%{$value}%");
$builder->where(function ($query) use ($field, $value) {
$this->buildFilterQuery($query, $field, $value);
});
});
}
$request->collect('sort')->each(function ($sort) use ($builder) {
$builder->orderBy(
$sort['id'],
$sort['desc'] ? 'DESC' : 'ASC'
);
private function buildFilterQuery(Builder $query, string $field, mixed $value): void
{
// Handle array values for 'in' operations
if (is_array($value)) {
$query->whereIn($field, $value);
return;
}
// Handle operator-based filtering
if (!is_string($value) || !str_contains($value, ':')) {
$query->where($field, 'like', "%{$value}%");
return;
}
[$operator, $filterValue] = explode(':', $value, 2);
// Convert numeric strings to appropriate type
if (is_numeric($filterValue)) {
$filterValue = strpos($filterValue, '.') !== false
? (float) $filterValue
: (int) $filterValue;
}
// Apply operator
$query->where($field, match (strtolower($operator)) {
'eq' => '=',
'gt' => '>',
'gte' => '>=',
'lt' => '<',
'lte' => '<=',
'like' => 'like',
'notlike' => 'not like',
'null' => static fn($q) => $q->whereNull($queryField),
'notnull' => static fn($q) => $q->whereNotNull($queryField),
default => 'like'
}, match (strtolower($operator)) {
'like', 'notlike' => "%{$filterValue}%",
'null', 'notnull' => null,
default => $filterValue
});
}
private function applySorting(Request $request, Builder $builder): void
{
if (!$request->has('sort')) {
return;
}
collect($request->input('sort'))->each(function ($sort) use ($builder) {
$field = $sort['id'];
$direction = $sort['desc'] ? 'DESC' : 'ASC';
$builder->orderBy($field, $direction);
});
}

View File

@ -139,6 +139,7 @@ class AdminRoute
$router->post('/update', [NoticeController::class, 'update']);
$router->post('/drop', [NoticeController::class, 'drop']);
$router->post('/show', [NoticeController::class, 'show']);
$router->post('/sort', [NoticeController::class, 'sort']);
});
// Ticket

View File

@ -14,6 +14,5 @@ class Notice extends Model
'updated_at' => 'timestamp',
'tags' => 'array',
'show' => 'boolean',
];
}

View File

@ -166,10 +166,10 @@ class Clash implements ProtocolInterface
break;
case 'ws':
$array['network'] = 'ws';
$array['ws-opts'] = [
'path' => data_get($protocol_settings, 'network_settings.path'),
'headers' => ['Host' => data_get($protocol_settings, 'network_settings.headers.Host')]
];
$array['ws-opts']['path'] = data_get($protocol_settings, 'network_settings.path', '/');
if ($host = data_get($protocol_settings, 'network_settings.headers.Host')) {
$array['ws-opts']['headers'] = ['Host' => $host];
}
break;
case 'grpc':
$array['network'] = 'grpc';
@ -200,10 +200,10 @@ class Clash implements ProtocolInterface
break;
case 'ws':
$array['network'] = 'ws';
$array['ws-opts'] = [
'path' => data_get($protocol_settings, 'network_settings.path'),
'headers' => ['Host' => data_get($protocol_settings, 'network_settings.headers.Host')]
];
$array['ws-opts']['path'] = data_get($protocol_settings, 'network_settings.path', '/');
if ($host = data_get($protocol_settings, 'network_settings.headers.Host')) {
$array['ws-opts']['headers'] = ['Host' => $host];
}
break;
case 'grpc':
$array['network'] = 'grpc';

View File

@ -167,7 +167,7 @@ class ClashMeta implements ProtocolInterface
$array['network'] = 'ws';
$array['ws-opts'] = [
'path' => data_get($protocol_settings, 'network_settings.path'),
'headers' => ['Host' => data_get($protocol_settings, 'network_settings.headers.Host')]
'headers' => ['Host' => data_get($protocol_settings, 'network_settings.headers.Host', $server['host'])]
];
break;
case 'grpc':
@ -221,10 +221,10 @@ class ClashMeta implements ProtocolInterface
switch (data_get($protocol_settings, 'network')) {
case 'ws':
$array['network'] = 'ws';
$array['ws-opts'] = [
'path' => data_get($protocol_settings, 'network_settings.path'),
'headers' => ['Host' => data_get($protocol_settings, 'network_settings.headers.Host')]
];
$array['ws-opts']['path'] = data_get($protocol_settings, 'network_settings.path', '/');
if ($host = data_get($protocol_settings, 'network_settings.headers.Host')) {
$array['ws-opts']['headers'] = ['Host' => $host];
}
break;
case 'grpc':
$array['network'] = 'grpc';
@ -248,7 +248,7 @@ class ClashMeta implements ProtocolInterface
public static function buildTrojan($password, $server)
{
$settings = data_get($server, 'protocol_settings', []);
$protocol_settings = data_get($server, 'protocol_settings', []);
$array = [
'name' => $server['name'],
'type' => 'trojan',
@ -256,23 +256,23 @@ class ClashMeta implements ProtocolInterface
'port' => $server['port'],
'password' => $password,
'udp' => true,
'sni' => data_get($settings, 'server_name'),
'skip-cert-verify' => (bool) data_get($settings, 'allow_insecure', false)
'sni' => data_get($protocol_settings, 'server_name'),
'skip-cert-verify' => (bool) data_get($protocol_settings, 'allow_insecure', false)
];
switch (data_get($settings, 'network')) {
switch (data_get($protocol_settings, 'network')) {
case 'grpc':
$array['network'] = 'grpc';
$array['grpc-opts'] = [
'grpc-service-name' => data_get($settings, 'network_settings.serviceName')
'grpc-service-name' => data_get($protocol_settings, 'network_settings.serviceName')
];
break;
case 'ws':
$array['network'] = 'ws';
$array['ws-opts'] = [
'path' => data_get($settings, 'network_settings.path'),
'headers' => ['Host' => data_get($settings, 'network_settings.headers.Host')]
];
$array['ws-opts']['path'] = data_get($protocol_settings, 'network_settings.path', '/');
if ($host = data_get($protocol_settings, 'network_settings.headers.Host')) {
$array['ws-opts']['headers'] = ['Host' => $host];
}
break;
default:
break;

View File

@ -83,13 +83,15 @@ class General implements ProtocolInterface
switch ($protocol_settings['network']) {
case 'tcp':
$config['type'] = 'http';
$config['path'] = \Arr::random(data_get($protocol_settings, 'network_settings.header.request.path', []));
$config['host'] = data_get($protocol_settings, 'network_settings.headers.Host') ? \Arr::random(data_get($protocol_settings, 'network_settings.headers.Host')) : null;
$config['path'] = \Arr::random(data_get($protocol_settings, 'network_settings.header.request.path', ['/']));
$config['host'] = data_get($protocol_settings, 'network_settings.headers.Host') ? \Arr::random(data_get($protocol_settings, 'network_settings.headers.Host'),['/']) : null;
break;
case 'ws':
$config['type'] = 'ws';
$config['path'] = data_get($protocol_settings, 'network_settings.path');
$config['host'] = data_get($protocol_settings, 'network_settings.headers.Host') ? \Arr::random(data_get($protocol_settings, 'network_settings.headers.Host')) : null;
if ($host = data_get($protocol_settings, 'network_settings.headers.Host')) {
$config['host'] = $host;
}
break;
case 'grpc':
$config['type'] = 'grpc';
@ -137,7 +139,9 @@ class General implements ProtocolInterface
switch ($server['protocol_settings']['network']) {
case 'ws':
$config['path'] = data_get($protocol_settings, 'network_settings.path');
$config['host'] = data_get($protocol_settings, 'network_settings.headers.Host');
if ($host = data_get($protocol_settings, 'network_settings.headers.Host')) {
$config['host'] = $host;
}
break;
case 'grpc':
$config['serviceName'] = data_get($protocol_settings, 'network_settings.serviceName');
@ -148,11 +152,11 @@ class General implements ProtocolInterface
break;
case 'httpupgrade':
$config['path'] = data_get($protocol_settings, 'network_settings.path');
$config['host'] = data_get($protocol_settings, 'network_settings.headers.Host');
$config['host'] = data_get($protocol_settings, 'network_settings.headers.Host', $server['host']);
break;
case 'xhttp':
$config['path'] = data_get($protocol_settings, 'network_settings.path');
$config['host'] = data_get($protocol_settings, 'network_settings.headers.Host');
$config['host'] = data_get($protocol_settings, 'network_settings.headers.Host', $server['host']);
$config['mode'] = data_get($protocol_settings, 'network_settings.mode', 'auto');
$config['extra'] = data_get($protocol_settings, 'network_settings.extra') ? Helper::encodeURIComponent(data_get($protocol_settings, 'network_settings.extra')) : null;
break;

View File

@ -102,7 +102,9 @@ class Shadowrocket implements ProtocolInterface
case 'ws':
$config['obfs'] = "websocket";
$config['path'] = data_get($protocol_settings, 'network_settings.path');
$config['obfsParam'] = data_get($protocol_settings, 'network_settings.headers.Host');
if ($host = data_get($protocol_settings, 'network_settings.headers.Host')) {
$config['obfsParam'] = $host;
}
break;
case 'grpc':
$config['obfs'] = "grpc";
@ -159,12 +161,14 @@ class Shadowrocket implements ProtocolInterface
case 'tcp':
$config['obfs'] = data_get($protocol_settings, 'network_settings.header.type');
$config['path'] = \Arr::random(data_get($protocol_settings, 'network_settings.header.request.path', ['/']));
$config['obfsParam'] = \Arr::random(data_get($protocol_settings, 'network_settings.header.request.headers.Host', ['']));
$config['obfsParam'] = \Arr::random(data_get($protocol_settings, 'network_settings.header.request.headers.Host', ['/']));
break;
case 'ws':
$config['obfs'] = "websocket";
$config['path'] = data_get($protocol_settings, 'network_settings.path');
$config['obfsParam'] = data_get($protocol_settings, 'network_settings.headers.Host');
if ($host = data_get($protocol_settings, 'network_settings.headers.Host')) {
$config['obfsParam'] = $host;
}
break;
case 'grpc':
$config['obfs'] = "grpc";

View File

@ -135,12 +135,12 @@ class SingBox implements ProtocolInterface
$transport = match ($protocol_settings['network']) {
'tcp' => [
'type' => 'http',
'path' => \Arr::random(data_get($protocol_settings, 'network_settings.header.request.path', []))
'path' => \Arr::random(data_get($protocol_settings, 'network_settings.header.request.path', ['/']))
],
'ws' => [
'type' => 'ws',
'path' => data_get($protocol_settings, 'network_settings.path'),
'headers' => data_get($protocol_settings, 'network_settings.headers.Host') ? ['Host' => data_get($protocol_settings, 'network_settings.headers.Host')] : null,
'headers' => ($host = data_get($protocol_settings, 'network_settings.headers.Host')) ? ['Host' => $host] : null,
'max_early_data' => 2048,
'early_data_header_name' => 'Sec-WebSocket-Protocol'
],
@ -196,13 +196,13 @@ class SingBox implements ProtocolInterface
'type' => 'http',
'path' => data_get($protocol_settings, 'network_settings.header.request.path')
] : null,
'ws' => [
'ws' => array_filter([
'type' => 'ws',
'path' => data_get($protocol_settings, 'network_settings.path'),
'headers' => data_get($protocol_settings, 'network_settings.headers.Host') ? ['Host' => [data_get($protocol_settings, 'network_settings.headers.Host')]] : null,
'headers' => ($host = data_get($protocol_settings, 'network_settings.headers.Host')) ? ['Host' => $host] : null,
'max_early_data' => 2048,
'early_data_header_name' => 'Sec-WebSocket-Protocol'
],
], fn($value) => !is_null($value)),
'grpc' => [
'type' => 'grpc',
'service_name' => data_get($protocol_settings, 'network_settings.serviceName')
@ -215,7 +215,7 @@ class SingBox implements ProtocolInterface
'httpupgrade' => [
'type' => 'httpupgrade',
'path' => data_get($protocol_settings, 'network_settings.path'),
'host' => data_get($protocol_settings, 'network_settings.headers.Host'),
'host' => data_get($protocol_settings, 'network_settings.headers.Host', $server['host']),
'headers' => data_get($protocol_settings, 'network_settings.headers')
],
default => null

View File

@ -152,7 +152,9 @@ class Stash implements ProtocolInterface
case 'ws':
$array['network'] = 'ws';
$array['ws-opts']['path'] = data_get($protocol_settings, 'network_settings.path');
$array['ws-opts']['headers'] = data_get($protocol_settings, 'network_settings.headers.Host') ? ['Host' => data_get($protocol_settings, 'network_settings.headers.Host')] : null;
if ($host = data_get($protocol_settings, 'network_settings.headers.Host')) {
$array['ws-opts']['headers'] = ['Host' => $host];
}
break;
case 'grpc':
$array['network'] = 'grpc';
@ -205,7 +207,9 @@ class Stash implements ProtocolInterface
case 'ws':
$array['network'] = 'ws';
$array['ws-opts']['path'] = data_get($protocol_settings, 'network_settings.path');
$array['ws-opts']['headers'] = data_get($protocol_settings, 'network_settings.headers.Host') ? ['Host' => data_get($protocol_settings, 'network_settings.headers.Host')] : null;
if ($host = data_get($protocol_settings, 'network_settings.headers.Host')) {
$array['ws-opts']['headers'] = ['Host' => $host];
}
break;
case 'grpc':
$array['network'] = 'grpc';

View File

@ -67,6 +67,7 @@ class OrderService
}
$this->setSpeedLimit($plan->speed_limit);
$this->setDeviceLimit($plan->device_limit);
if (!$this->user->save()) {
throw new \Exception('用户信息保存失败');
@ -271,6 +272,11 @@ class OrderService
{
$this->user->speed_limit = $speedLimit;
}
private function setDeviceLimit($deviceLimit)
{
$this->user->device_limit = $deviceLimit;
}
private function buyByResetTraffic()
{

View File

@ -0,0 +1,30 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('v2_notice', function (Blueprint $table) {
$table->integer('sort')->nullable()->after('id')->index();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('v2_notice', function (Blueprint $table) {
$table->dropColumn('sort');
});
}
};

View File

@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
DB::table('v2_order')->where('commission_status', null)->update([
'commission_status' => 0
]);
Schema::table('v2_order', function (Blueprint $table) {
$table->boolean('commission_status')->default(value: 0)->comment('0待确认1发放中2有效3无效')->change();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('v2_order', function (Blueprint $table) {
$table->boolean('commission_status')->nullable()->comment('0待确认1发放中2有效3无效')->change();
});
}
};

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