first commit
This commit is contained in:
25
Xboard/app/Http/Resources/ComissionLogResource.php
Normal file
25
Xboard/app/Http/Resources/ComissionLogResource.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class ComissionLogResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
"id"=> $this['id'],
|
||||
"order_amount" => $this['order_amount'],
|
||||
"trade_no" => $this['trade_no'],
|
||||
"get_amount" => $this['get_amount'],
|
||||
"created_at" => $this['created_at']
|
||||
];
|
||||
}
|
||||
}
|
||||
38
Xboard/app/Http/Resources/CouponResource.php
Normal file
38
Xboard/app/Http/Resources/CouponResource.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use App\Models\Coupon;
|
||||
use App\Services\CouponService;
|
||||
use App\Services\PlanService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
/**
|
||||
* 优惠券资源类
|
||||
*
|
||||
* @property array|null $limit_plan_ids 限制可用的套餐ID列表
|
||||
*/
|
||||
class CouponResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* 将资源转换为数组
|
||||
*
|
||||
* @param Request $request 请求实例
|
||||
* @return array<string, mixed> 转换后的数组
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
...$this->resource->toArray(),
|
||||
'limit_plan_ids' => empty($this->limit_plan_ids) ? null : collect($this->limit_plan_ids)
|
||||
->map(fn(mixed $id): string => (string) $id)
|
||||
->values()
|
||||
->all(),
|
||||
'limit_period' => empty($this->limit_period) ? null : collect($this->limit_period)
|
||||
->map(fn(mixed $period): string => (string) PlanService::convertToLegacyPeriod($period))
|
||||
->values()
|
||||
->all(),
|
||||
];
|
||||
}
|
||||
}
|
||||
28
Xboard/app/Http/Resources/InviteCodeResource.php
Normal file
28
Xboard/app/Http/Resources/InviteCodeResource.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class InviteCodeResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
$data = [
|
||||
"user_id" => $this['user_id'],
|
||||
"code" => $this['code'],
|
||||
"pv" => $this['pv'],
|
||||
"status" => $this['status'],
|
||||
"created_at" => $this['created_at'],
|
||||
"updated_at" => $this['updated_at']
|
||||
];
|
||||
if(!config('hidden_features.enable_exposed_user_count_fix')) $data['user_id']= $this['user_id'];
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
28
Xboard/app/Http/Resources/KnowledgeResource.php
Normal file
28
Xboard/app/Http/Resources/KnowledgeResource.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use App\Services\Plugin\HookManager;
|
||||
|
||||
class KnowledgeResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
$data = [
|
||||
'id' => $this['id'],
|
||||
'category' => $this['category'],
|
||||
'title' => $this['title'],
|
||||
'body' => $this->when(isset($this['body']), $this['body']),
|
||||
'updated_at' => $this['updated_at'],
|
||||
];
|
||||
|
||||
return HookManager::filter('user.knowledge.resource', $data, $request, $this);
|
||||
}
|
||||
}
|
||||
26
Xboard/app/Http/Resources/MessageResource.php
Normal file
26
Xboard/app/Http/Resources/MessageResource.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class MessageResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
"id" => $this['id'],
|
||||
"ticket_id" => $this['ticket_id'],
|
||||
"is_me" => $this['is_from_user'],
|
||||
"message" => $this["message"],
|
||||
"created_at" => $this['created_at'],
|
||||
"updated_at" => $this['updated_at']
|
||||
];
|
||||
}
|
||||
}
|
||||
29
Xboard/app/Http/Resources/NodeResource.php
Normal file
29
Xboard/app/Http/Resources/NodeResource.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class NodeResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this['id'],
|
||||
'type' => $this['type'],
|
||||
'version' => $this['version'] ?? null,
|
||||
'name' => $this['name'],
|
||||
'rate' => $this['rate'],
|
||||
'tags' => $this['tags'],
|
||||
'is_online' => $this['is_online'],
|
||||
'cache_key' => $this['cache_key'],
|
||||
'last_check_at' => $this['last_check_at']
|
||||
];
|
||||
}
|
||||
}
|
||||
28
Xboard/app/Http/Resources/OrderResource.php
Normal file
28
Xboard/app/Http/Resources/OrderResource.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use App\Models\Order;
|
||||
use App\Services\PlanService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
/**
|
||||
* @mixin Order
|
||||
*/
|
||||
class OrderResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
...parent::toArray($request),
|
||||
'period' => PlanService::getLegacyPeriod((string)$this->period),
|
||||
'plan' => $this->whenLoaded('plan', fn() => PlanResource::make($this->plan)),
|
||||
];
|
||||
}
|
||||
}
|
||||
122
Xboard/app/Http/Resources/PlanResource.php
Normal file
122
Xboard/app/Http/Resources/PlanResource.php
Normal file
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use App\Models\Plan;
|
||||
use App\Services\PlanService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class PlanResource extends JsonResource
|
||||
{
|
||||
private const PRICE_MULTIPLIER = 100;
|
||||
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->resource['id'],
|
||||
'group_id' => $this->resource['group_id'],
|
||||
'name' => $this->resource['name'],
|
||||
'tags' => $this->resource['tags'],
|
||||
'content' => $this->formatContent(),
|
||||
...$this->getPeriodPrices(),
|
||||
'capacity_limit' => $this->getFormattedCapacityLimit(),
|
||||
'transfer_enable' => $this->resource['transfer_enable'],
|
||||
'speed_limit' => $this->resource['speed_limit'],
|
||||
'device_limit' => $this->resource['device_limit'],
|
||||
'show' => (bool) $this->resource['show'],
|
||||
'sell' => (bool) $this->resource['sell'],
|
||||
'renew' => (bool) $this->resource['renew'],
|
||||
'reset_traffic_method' => $this->resource['reset_traffic_method'],
|
||||
'sort' => $this->resource['sort'],
|
||||
'created_at' => $this->resource['created_at'],
|
||||
'updated_at' => $this->resource['updated_at']
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get transformed period prices using Plan mapping
|
||||
*
|
||||
* @return array<string, float|null>
|
||||
*/
|
||||
protected function getPeriodPrices(): array
|
||||
{
|
||||
return collect(Plan::LEGACY_PERIOD_MAPPING)
|
||||
->mapWithKeys(function (string $newPeriod, string $legacyPeriod): array {
|
||||
$price = $this->resource['prices'][$newPeriod] ?? null;
|
||||
return [
|
||||
$legacyPeriod => $price !== null
|
||||
? (float) $price * self::PRICE_MULTIPLIER
|
||||
: null
|
||||
];
|
||||
})
|
||||
->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get formatted capacity limit value
|
||||
*
|
||||
* @return int|string|null
|
||||
*/
|
||||
protected function getFormattedCapacityLimit(): int|string|null
|
||||
{
|
||||
$limit = $this->resource['capacity_limit'];
|
||||
|
||||
return match (true) {
|
||||
$limit === null => null,
|
||||
$limit <= 0 => __('Sold out'),
|
||||
default => (int) $limit,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Format content with template variables
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function formatContent(): string
|
||||
{
|
||||
$content = $this->resource['content'] ?? '';
|
||||
|
||||
$replacements = [
|
||||
'{{transfer}}' => $this->resource['transfer_enable'],
|
||||
'{{speed}}' => $this->resource['speed_limit'] === NULL ? __('No Limit') : $this->resource['speed_limit'],
|
||||
'{{devices}}' => $this->resource['device_limit'] === NULL ? __('No Limit') : $this->resource['device_limit'],
|
||||
'{{reset_method}}' => $this->getResetMethodText(),
|
||||
];
|
||||
|
||||
return str_replace(
|
||||
array_keys($replacements),
|
||||
array_values($replacements),
|
||||
$content
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get reset method text
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getResetMethodText(): string
|
||||
{
|
||||
$method = $this->resource['reset_traffic_method'];
|
||||
|
||||
if ($method === Plan::RESET_TRAFFIC_FOLLOW_SYSTEM) {
|
||||
$method = admin_setting('reset_traffic_method', Plan::RESET_TRAFFIC_MONTHLY);
|
||||
}
|
||||
return match ($method) {
|
||||
Plan::RESET_TRAFFIC_FIRST_DAY_MONTH => __('First Day of Month'),
|
||||
Plan::RESET_TRAFFIC_MONTHLY => __('Monthly'),
|
||||
Plan::RESET_TRAFFIC_NEVER => __('Never'),
|
||||
Plan::RESET_TRAFFIC_FIRST_DAY_YEAR => __('First Day of Year'),
|
||||
Plan::RESET_TRAFFIC_YEARLY => __('Yearly'),
|
||||
default => __('Monthly')
|
||||
};
|
||||
}
|
||||
}
|
||||
31
Xboard/app/Http/Resources/TicketResource.php
Normal file
31
Xboard/app/Http/Resources/TicketResource.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class TicketResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
$data = [
|
||||
"id" => $this['id'],
|
||||
"level" => $this['level'],
|
||||
"reply_status" => $this['reply_status'],
|
||||
"status" => $this['status'],
|
||||
"subject" => $this['subject'],
|
||||
"message" => array_key_exists('message',$this->additional) ? MessageResource::collection($this['message']) : null,
|
||||
"created_at" => $this['created_at'],
|
||||
"updated_at" => $this['updated_at']
|
||||
];
|
||||
if(!config('hidden_features.enable_exposed_user_count_fix')) $data['user_id']= $this['user_id'];
|
||||
return $data;
|
||||
|
||||
}
|
||||
}
|
||||
26
Xboard/app/Http/Resources/TrafficLogResource.php
Normal file
26
Xboard/app/Http/Resources/TrafficLogResource.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class TrafficLogResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
$data = [
|
||||
"d" => $this['d'],
|
||||
"u" => $this['u'],
|
||||
"record_at" => $this['record_at'],
|
||||
"server_rate" => $this['server_rate'],
|
||||
];
|
||||
if(!config('hidden_features.enable_exposed_user_count_fix')) $data['user_id']= $this['user_id'];
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user