feat(admin-frontend): 补齐活跃筛选与支付快照能力
新增用户管理“活跃状态”高级筛选,并在后端支持 activity_status 复合规则,支持按活跃与非活跃筛选用户。 补齐订单支付成功快照落库与后台展示,保存支付渠道、 支付方法、实付金额和支付 IP,并在订单详情中优先展示。 同时增强节点页在线/离线筛选与批量删除、仪表盘快捷入口, 并修复已关闭工单再次回复后自动重开的统一语义。 附带同步测试、迁移、CI 工作流命名及知识库记录
This commit is contained in:
@@ -23,7 +23,7 @@ class PaymentController extends Controller
|
||||
return $this->fail([422, 'verify error']);
|
||||
}
|
||||
HookManager::call('payment.notify.verified', $verify);
|
||||
if (!$this->handle($verify['trade_no'], $verify['callback_no'])) {
|
||||
if (!$this->handle($verify)) {
|
||||
return $this->fail([400, 'handle error']);
|
||||
}
|
||||
return (isset($verify['custom_result']) ? $verify['custom_result'] : 'success');
|
||||
@@ -33,8 +33,17 @@ class PaymentController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
private function handle($tradeNo, $callbackNo)
|
||||
/**
|
||||
* @param array<string, mixed> $verify
|
||||
*/
|
||||
private function handle(array $verify)
|
||||
{
|
||||
$tradeNo = (string) ($verify['trade_no'] ?? '');
|
||||
$callbackNo = (string) ($verify['callback_no'] ?? '');
|
||||
if ($tradeNo === '') {
|
||||
return false;
|
||||
}
|
||||
|
||||
$order = Order::where('trade_no', $tradeNo)->first();
|
||||
if (!$order) {
|
||||
return $this->fail([400202, 'order is not found']);
|
||||
@@ -42,7 +51,7 @@ class PaymentController extends Controller
|
||||
if ($order->status !== Order::STATUS_PENDING)
|
||||
return true;
|
||||
$orderService = new OrderService($order);
|
||||
if (!$orderService->paid($callbackNo)) {
|
||||
if (!$orderService->paid($callbackNo, $verify)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -67,9 +67,6 @@ class TicketController extends Controller
|
||||
if (!$ticket) {
|
||||
return $this->fail([400, __('Ticket does not exist')]);
|
||||
}
|
||||
if ($ticket->status) {
|
||||
return $this->fail([400, __('The ticket is closed and cannot be replied')]);
|
||||
}
|
||||
if ((int) admin_setting('ticket_must_wait_reply', 0) && $request->user()->id == $this->getLastMessage($ticket->id)->user_id) {
|
||||
return $this->fail(codeResponse: [400, __('Please wait for the technical enginneer to reply')]);
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ class OrderController extends Controller
|
||||
|
||||
public function detail(Request $request)
|
||||
{
|
||||
$order = Order::with(['user', 'plan', 'commission_log', 'invite_user'])->find($request->input('id'));
|
||||
$order = Order::with(['user', 'plan', 'commission_log', 'invite_user', 'payment'])->find($request->input('id'));
|
||||
if (!$order)
|
||||
return $this->fail([400202, '订单不存在']);
|
||||
if ($order->surplus_order_ids) {
|
||||
|
||||
@@ -70,6 +70,14 @@ class UserController extends Controller
|
||||
// Build one filter query condition.
|
||||
private function buildFilterQuery(Builder|QueryBuilder $query, string $field, mixed $value): void
|
||||
{
|
||||
if ($field === 'activity_status') {
|
||||
$activityStatus = $this->resolveActivityStatusValue($value);
|
||||
if ($activityStatus !== null) {
|
||||
$this->applyActivityStatusFilter($query, $activityStatus);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// 处理关联查询
|
||||
if (str_contains($field, '.')) {
|
||||
if (!method_exists($query, 'whereHas')) {
|
||||
@@ -119,6 +127,60 @@ class UserController extends Controller
|
||||
$this->applyQueryCondition($query, $queryField, $operator, $filterValue);
|
||||
}
|
||||
|
||||
private function resolveActivityStatusValue(mixed $value): ?bool
|
||||
{
|
||||
if (is_bool($value)) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
if (is_numeric($value)) {
|
||||
$numericValue = (int) $value;
|
||||
return match ($numericValue) {
|
||||
1 => true,
|
||||
0 => false,
|
||||
default => null,
|
||||
};
|
||||
}
|
||||
|
||||
if (!is_string($value)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$normalized = trim($value);
|
||||
if (str_contains($normalized, ':')) {
|
||||
[$operator, $normalized] = explode(':', $normalized, 2);
|
||||
if (strtolower($operator) !== 'eq') {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return match (strtolower(trim($normalized))) {
|
||||
'1', 'true', 'active', 'yes' => true,
|
||||
'0', 'false', 'inactive', 'no' => false,
|
||||
default => null,
|
||||
};
|
||||
}
|
||||
|
||||
private function applyActivityStatusFilter(Builder|QueryBuilder $query, bool $active): void
|
||||
{
|
||||
$threshold = now()->subMonths(6);
|
||||
|
||||
if ($active) {
|
||||
$query->whereNotNull('plan_id')
|
||||
->whereRaw('COALESCE(transfer_enable, 0) > COALESCE(u, 0) + COALESCE(d, 0)')
|
||||
->whereNotNull('last_online_at')
|
||||
->where('last_online_at', '>=', $threshold);
|
||||
return;
|
||||
}
|
||||
|
||||
$query->where(function ($activityQuery) use ($threshold) {
|
||||
$activityQuery->whereNull('plan_id')
|
||||
->orWhereRaw('COALESCE(transfer_enable, 0) <= COALESCE(u, 0) + COALESCE(d, 0)')
|
||||
->orWhereNull('last_online_at')
|
||||
->orWhere('last_online_at', '<', $threshold);
|
||||
});
|
||||
}
|
||||
|
||||
// Apply sorting rules to the query builder.
|
||||
private function applySorting(Request $request, Builder|QueryBuilder $builder): void
|
||||
{
|
||||
|
||||
@@ -13,10 +13,13 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
* @property int $user_id
|
||||
* @property int $plan_id
|
||||
* @property int|null $payment_id
|
||||
* @property string|null $payment_channel
|
||||
* @property string|null $payment_method
|
||||
* @property string $period
|
||||
* @property string $trade_no
|
||||
* @property int $total_amount
|
||||
* @property int|null $handling_amount
|
||||
* @property int|null $payment_amount
|
||||
* @property int|null $balance_amount
|
||||
* @property int|null $refund_amount
|
||||
* @property int|null $surplus_amount
|
||||
@@ -35,6 +38,7 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
* @property int|null $discount_amount
|
||||
* @property int|null $paid_at
|
||||
* @property string|null $callback_no
|
||||
* @property string|null $payment_ip
|
||||
*
|
||||
* @property-read Plan $plan
|
||||
* @property-read Payment|null $payment
|
||||
@@ -50,7 +54,8 @@ class Order extends Model
|
||||
'created_at' => 'timestamp',
|
||||
'updated_at' => 'timestamp',
|
||||
'surplus_order_ids' => 'array',
|
||||
'handling_amount' => 'integer'
|
||||
'handling_amount' => 'integer',
|
||||
'payment_amount' => 'integer',
|
||||
];
|
||||
|
||||
const STATUS_PENDING = 0; // 待支付
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace App\Services;
|
||||
use App\Exceptions\ApiException;
|
||||
use App\Jobs\OrderHandleJob;
|
||||
use App\Models\Order;
|
||||
use App\Models\Payment;
|
||||
use App\Models\Plan;
|
||||
use App\Models\TrafficResetLog;
|
||||
use App\Models\User;
|
||||
@@ -283,7 +284,7 @@ class OrderService
|
||||
}
|
||||
}
|
||||
|
||||
public function paid(string $callbackNo)
|
||||
public function paid(string $callbackNo, array $paymentSnapshot = [])
|
||||
{
|
||||
$order = $this->order;
|
||||
if ($order->status !== Order::STATUS_PENDING)
|
||||
@@ -291,6 +292,7 @@ class OrderService
|
||||
$order->status = Order::STATUS_PROCESSING;
|
||||
$order->paid_at = time();
|
||||
$order->callback_no = $callbackNo;
|
||||
$order->fill($this->buildPaymentSnapshot($paymentSnapshot));
|
||||
if (!$order->save())
|
||||
return false;
|
||||
try {
|
||||
@@ -302,6 +304,82 @@ class OrderService
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $paymentSnapshot
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function buildPaymentSnapshot(array $paymentSnapshot): array
|
||||
{
|
||||
/** @var Payment|null $payment */
|
||||
$payment = $this->order->relationLoaded('payment')
|
||||
? $this->order->payment
|
||||
: $this->order->payment()->first();
|
||||
|
||||
$channel = $this->normalizeSnapshotText(
|
||||
$paymentSnapshot['payment_channel'] ?? $payment?->name ?? $payment?->payment
|
||||
);
|
||||
$method = $this->normalizeSnapshotText(
|
||||
$paymentSnapshot['payment_method'] ?? $this->resolvePaymentMethod($payment)
|
||||
);
|
||||
$amount = $this->normalizeSnapshotAmount($paymentSnapshot['payment_amount'] ?? null);
|
||||
$ip = $this->normalizeSnapshotText($paymentSnapshot['payment_ip'] ?? null);
|
||||
|
||||
return array_filter([
|
||||
'payment_channel' => $channel,
|
||||
'payment_method' => $method,
|
||||
'payment_amount' => $amount,
|
||||
'payment_ip' => $ip,
|
||||
], static fn($value) => $value !== null && $value !== '');
|
||||
}
|
||||
|
||||
private function resolvePaymentMethod(?Payment $payment): ?string
|
||||
{
|
||||
if (!$payment) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$config = $payment->config;
|
||||
if (is_string($config)) {
|
||||
$decoded = json_decode($config, true);
|
||||
$config = is_array($decoded) ? $decoded : [];
|
||||
}
|
||||
|
||||
if (!is_array($config)) {
|
||||
$config = [];
|
||||
}
|
||||
|
||||
return $this->normalizeSnapshotText(
|
||||
data_get($config, 'token_pay_currency') ?? $payment->payment ?? $payment->name
|
||||
);
|
||||
}
|
||||
|
||||
private function normalizeSnapshotText(mixed $value): ?string
|
||||
{
|
||||
if (!is_scalar($value)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$text = trim((string) $value);
|
||||
return $text !== '' ? $text : null;
|
||||
}
|
||||
|
||||
private function normalizeSnapshotAmount(mixed $value): ?int
|
||||
{
|
||||
if ($value === null || $value === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
$normalized = is_string($value)
|
||||
? str_replace(',', '', trim($value))
|
||||
: $value;
|
||||
|
||||
if (!is_numeric($normalized)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (int) round(((float) $normalized) * 100);
|
||||
}
|
||||
|
||||
public function cancel(): bool
|
||||
{
|
||||
$order = $this->order;
|
||||
|
||||
@@ -22,11 +22,7 @@ class TicketService
|
||||
'ticket_id' => $ticket->id,
|
||||
'message' => $message
|
||||
]);
|
||||
$isAdmin = $userId !== $ticket->user_id;
|
||||
$ticket->reply_status = $isAdmin
|
||||
? Ticket::REPLY_STATUS_REPLIED
|
||||
: Ticket::REPLY_STATUS_WAITING;
|
||||
$ticket->last_reply_user_id = $userId;
|
||||
$this->applyReplyState($ticket, (int) $userId);
|
||||
if (!$ticketMessage || !$ticket->save()) {
|
||||
throw new \Exception();
|
||||
}
|
||||
@@ -52,6 +48,24 @@ class TicketService
|
||||
$this->sendEmailNotify($ticket, $ticketMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies the unified reply state to a ticket.
|
||||
*
|
||||
* @param Ticket $ticket The target ticket.
|
||||
* @param int $userId The replying user ID.
|
||||
* @return void
|
||||
*/
|
||||
private function applyReplyState(Ticket $ticket, int $userId): void
|
||||
{
|
||||
$isAdmin = $userId !== $ticket->user_id;
|
||||
|
||||
$ticket->status = Ticket::STATUS_OPENING;
|
||||
$ticket->reply_status = $isAdmin
|
||||
? Ticket::REPLY_STATUS_REPLIED
|
||||
: Ticket::REPLY_STATUS_WAITING;
|
||||
$ticket->last_reply_user_id = $userId;
|
||||
}
|
||||
|
||||
public function createTicket($userId, $subject, $level, $message)
|
||||
{
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user