增加会员查看
This commit is contained in:
@@ -13,11 +13,16 @@
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
use App\Models\VipLevel;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
/**
|
||||
* 后台 VIP 会员等级管理控制器
|
||||
* 负责会员等级维护,以及查看各等级下的会员名单。
|
||||
*/
|
||||
class VipController extends Controller
|
||||
{
|
||||
/**
|
||||
@@ -51,7 +56,10 @@ class VipController extends Controller
|
||||
*/
|
||||
public function index(): View
|
||||
{
|
||||
$levels = VipLevel::orderBy('sort_order')->get();
|
||||
$levels = VipLevel::query()
|
||||
->withCount('users')
|
||||
->orderBy('sort_order')
|
||||
->get();
|
||||
|
||||
return view('admin.vip.index', [
|
||||
'levels' => $levels,
|
||||
@@ -60,6 +68,64 @@ class VipController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看某个会员等级下的会员名单。
|
||||
*
|
||||
* @param Request $request 当前筛选请求
|
||||
* @param VipLevel $vip 当前会员等级
|
||||
*/
|
||||
public function members(Request $request, VipLevel $vip): View
|
||||
{
|
||||
$query = User::query()->where('vip_level_id', $vip->id);
|
||||
$now = now();
|
||||
|
||||
if ($request->filled('keyword')) {
|
||||
$keyword = trim((string) $request->input('keyword'));
|
||||
|
||||
// 支持后台按用户名快速筛选某个等级下的会员。
|
||||
$query->where('username', 'like', '%'.$keyword.'%');
|
||||
}
|
||||
|
||||
if ($request->input('status') === 'active') {
|
||||
// 当前有效会员:永久会员或到期时间仍在未来。
|
||||
$query->where(function ($builder) use ($now): void {
|
||||
$builder->whereNull('hy_time')->orWhere('hy_time', '>', $now);
|
||||
});
|
||||
}
|
||||
|
||||
if ($request->input('status') === 'expired') {
|
||||
// 已过期会员:到期时间存在且已经早于当前时间。
|
||||
$query->whereNotNull('hy_time')->where('hy_time', '<=', $now);
|
||||
}
|
||||
|
||||
$members = $query
|
||||
->select(['id', 'username', 'sex', 'vip_level_id', 'hy_time', 'created_at'])
|
||||
->orderByRaw('CASE WHEN hy_time IS NULL THEN 0 WHEN hy_time > ? THEN 1 ELSE 2 END', [$now])
|
||||
->orderByRaw('hy_time IS NULL DESC')
|
||||
->orderByDesc('hy_time')
|
||||
->orderBy('username')
|
||||
->paginate(20)
|
||||
->withQueryString();
|
||||
|
||||
$totalAssignedCount = User::query()
|
||||
->where('vip_level_id', $vip->id)
|
||||
->count();
|
||||
|
||||
$activeCount = User::query()
|
||||
->where('vip_level_id', $vip->id)
|
||||
->where(function ($builder) use ($now): void {
|
||||
$builder->whereNull('hy_time')->orWhere('hy_time', '>', $now);
|
||||
})
|
||||
->count();
|
||||
|
||||
return view('admin.vip.members', [
|
||||
'vip' => $vip,
|
||||
'members' => $members,
|
||||
'totalAssignedCount' => $totalAssignedCount,
|
||||
'activeCount' => $activeCount,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增会员等级
|
||||
*/
|
||||
|
||||
@@ -125,7 +125,7 @@
|
||||
</div>
|
||||
<div class="flex justify-between">
|
||||
<span class="text-gray-500">当前会员</span>
|
||||
<span class="font-bold text-indigo-600">{{ $level->users()->count() }} 人</span>
|
||||
<span class="font-bold text-indigo-600">{{ $level->users_count }} 人</span>
|
||||
</div>
|
||||
<div class="flex justify-between">
|
||||
<span class="text-gray-500">进场特效</span>
|
||||
@@ -143,6 +143,10 @@
|
||||
</div>
|
||||
|
||||
<div class="border-t bg-gray-50 px-5 py-3 flex justify-end space-x-2">
|
||||
<a href="{{ route('admin.vip.members', $level->id) }}"
|
||||
class="text-xs bg-emerald-50 text-emerald-600 font-bold px-3 py-1.5 rounded hover:bg-emerald-600 hover:text-white transition">
|
||||
查看会员
|
||||
</a>
|
||||
<button
|
||||
@click="openEdit({
|
||||
id: {{ $level->id }},
|
||||
|
||||
@@ -0,0 +1,143 @@
|
||||
{{--
|
||||
文件功能:后台 VIP 等级会员列表页面
|
||||
用于查看某个会员等级下有哪些用户,以及对应会员到期日期和当前状态
|
||||
--}}
|
||||
|
||||
@extends('admin.layouts.app')
|
||||
|
||||
@section('title', $vip->name . ' 会员列表')
|
||||
|
||||
@section('content')
|
||||
<div class="space-y-6">
|
||||
<div class="flex flex-col gap-4 rounded-2xl border border-gray-200 bg-white p-6 shadow-sm lg:flex-row lg:items-center lg:justify-between">
|
||||
<div>
|
||||
<div class="flex items-center gap-3">
|
||||
<span class="text-3xl">{{ $vip->icon }}</span>
|
||||
<div>
|
||||
<h2 class="text-xl font-bold" style="color: {{ $vip->color }}">{{ $vip->name }} 会员列表</h2>
|
||||
<p class="mt-1 text-sm text-gray-500">查看该等级下的会员用户名、当前状态与会员到期日期</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-4 flex flex-wrap gap-3 text-sm">
|
||||
<span class="inline-flex items-center rounded-full bg-indigo-50 px-3 py-1 font-semibold text-indigo-600">
|
||||
总分配人数:{{ $totalAssignedCount }}
|
||||
</span>
|
||||
<span class="inline-flex items-center rounded-full bg-emerald-50 px-3 py-1 font-semibold text-emerald-600">
|
||||
当前有效会员:{{ $activeCount }}
|
||||
</span>
|
||||
<span class="inline-flex items-center rounded-full bg-amber-50 px-3 py-1 font-semibold text-amber-600">
|
||||
等级时长:{{ $vip->duration_days ?: '永久' }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex gap-3">
|
||||
<a href="{{ route('admin.vip.index') }}"
|
||||
class="inline-flex items-center justify-center rounded-lg border border-gray-300 px-4 py-2 text-sm font-semibold text-gray-600 transition hover:bg-gray-50">
|
||||
返回等级列表
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="rounded-2xl border border-gray-200 bg-white p-5 shadow-sm">
|
||||
<form action="{{ route('admin.vip.members', $vip->id) }}" method="GET" class="flex flex-wrap items-end gap-4">
|
||||
<div class="min-w-[180px] flex-1">
|
||||
<label class="mb-1.5 block text-xs font-semibold uppercase tracking-wider text-gray-500">用户名</label>
|
||||
<input type="text" name="keyword" value="{{ request('keyword') }}"
|
||||
class="w-full rounded-lg border-gray-300 px-3 py-2 text-sm shadow-sm focus:border-indigo-500 focus:ring-indigo-500"
|
||||
placeholder="支持模糊搜索用户名">
|
||||
</div>
|
||||
<div class="w-44">
|
||||
<label class="mb-1.5 block text-xs font-semibold uppercase tracking-wider text-gray-500">会员状态</label>
|
||||
<select name="status"
|
||||
class="w-full rounded-lg border-gray-300 px-3 py-2 text-sm shadow-sm focus:border-indigo-500 focus:ring-indigo-500">
|
||||
<option value="">全部状态</option>
|
||||
<option value="active" @selected(request('status') === 'active')>当前有效</option>
|
||||
<option value="expired" @selected(request('status') === 'expired')>已过期</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="flex gap-2">
|
||||
<button type="submit"
|
||||
class="rounded-lg bg-indigo-600 px-5 py-2 text-sm font-semibold text-white transition hover:bg-indigo-700">
|
||||
查询
|
||||
</button>
|
||||
<a href="{{ route('admin.vip.members', $vip->id) }}"
|
||||
class="rounded-lg border border-gray-300 px-4 py-2 text-sm font-semibold text-gray-600 transition hover:bg-gray-50">
|
||||
重置
|
||||
</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="overflow-hidden rounded-2xl border border-gray-200 bg-white shadow-sm">
|
||||
<div class="overflow-x-auto">
|
||||
<table class="min-w-full text-left">
|
||||
<thead class="bg-gray-50 text-xs font-semibold uppercase tracking-wider text-gray-500">
|
||||
<tr>
|
||||
<th class="px-6 py-4">用户ID</th>
|
||||
<th class="px-6 py-4">用户名</th>
|
||||
<th class="px-6 py-4">性别</th>
|
||||
<th class="px-6 py-4">会员状态</th>
|
||||
<th class="px-6 py-4">到期日期</th>
|
||||
<th class="px-6 py-4">注册时间</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="divide-y divide-gray-100 text-sm text-gray-700">
|
||||
@forelse ($members as $member)
|
||||
@php
|
||||
$status = $member->hy_time === null ? 'permanent' : ($member->hy_time->isFuture() ? 'active' : 'expired');
|
||||
$statusLabel = match ($status) {
|
||||
'permanent' => '永久会员',
|
||||
'active' => '当前有效',
|
||||
default => '已过期',
|
||||
};
|
||||
$statusClass = match ($status) {
|
||||
'permanent' => 'bg-purple-50 text-purple-600',
|
||||
'active' => 'bg-emerald-50 text-emerald-600',
|
||||
default => 'bg-rose-50 text-rose-600',
|
||||
};
|
||||
$sexLabel = match ((int) $member->sex) {
|
||||
1 => '男',
|
||||
2 => '女',
|
||||
default => '未知',
|
||||
};
|
||||
@endphp
|
||||
<tr class="transition hover:bg-gray-50">
|
||||
<td class="px-6 py-4 font-mono text-xs text-gray-500">#{{ $member->id }}</td>
|
||||
<td class="px-6 py-4">
|
||||
<div class="font-semibold text-gray-800">{{ $member->username }}</div>
|
||||
</td>
|
||||
<td class="px-6 py-4 text-gray-500">{{ $sexLabel }}</td>
|
||||
<td class="px-6 py-4">
|
||||
<span class="inline-flex rounded-full px-2.5 py-1 text-xs font-semibold {{ $statusClass }}">
|
||||
{{ $statusLabel }}
|
||||
</span>
|
||||
</td>
|
||||
<td class="px-6 py-4 text-gray-600">
|
||||
@if ($member->hy_time)
|
||||
{{ $member->hy_time->format('Y-m-d H:i') }}
|
||||
@else
|
||||
永久
|
||||
@endif
|
||||
</td>
|
||||
<td class="px-6 py-4 text-gray-500">{{ $member->created_at?->format('Y-m-d H:i') }}</td>
|
||||
</tr>
|
||||
@empty
|
||||
<tr>
|
||||
<td colspan="6" class="px-6 py-12 text-center text-sm text-gray-400">
|
||||
当前条件下暂无该等级会员记录
|
||||
</td>
|
||||
</tr>
|
||||
@endforelse
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
@if ($members->hasPages())
|
||||
<div class="border-t border-gray-200 px-6 py-4">
|
||||
{{ $members->links() }}
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
@@ -434,6 +434,7 @@ Route::middleware(['chat.auth', 'chat.has_position'])->prefix('admin')->name('ad
|
||||
|
||||
// VIP 会员等级(含新增/编辑/删除)
|
||||
Route::get('/vip', [\App\Http\Controllers\Admin\VipController::class, 'index'])->name('vip.index');
|
||||
Route::get('/vip/{vip}/members', [\App\Http\Controllers\Admin\VipController::class, 'members'])->name('vip.members');
|
||||
Route::post('/vip', [\App\Http\Controllers\Admin\VipController::class, 'store'])->name('vip.store');
|
||||
Route::put('/vip/{vip}', [\App\Http\Controllers\Admin\VipController::class, 'update'])->name('vip.update');
|
||||
Route::delete('/vip/{vip}', [\App\Http\Controllers\Admin\VipController::class, 'destroy'])->name('vip.destroy');
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:后台 VIP 管理功能测试
|
||||
* 校验管理员可以查看某个会员等级下的会员名单与会员状态。
|
||||
*/
|
||||
|
||||
namespace Tests\Feature\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Models\VipLevel;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* 后台 VIP 管理功能测试
|
||||
* 负责验证会员等级成员列表页的展示结果。
|
||||
*/
|
||||
class AdminVipControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* 测试超级管理员可以查看某个会员等级下的会员名单。
|
||||
*/
|
||||
public function test_admin_can_view_vip_level_members_page(): void
|
||||
{
|
||||
$admin = User::factory()->create([
|
||||
'user_level' => 100,
|
||||
]);
|
||||
|
||||
$vipLevel = VipLevel::create([
|
||||
'name' => '黄金会员',
|
||||
'icon' => '👑',
|
||||
'color' => '#f59e0b',
|
||||
'exp_multiplier' => 1.5,
|
||||
'jjb_multiplier' => 1.2,
|
||||
'sort_order' => 1,
|
||||
'price' => 100,
|
||||
'duration_days' => 30,
|
||||
'join_effect' => 'none',
|
||||
'leave_effect' => 'none',
|
||||
'join_banner_style' => 'aurora',
|
||||
'leave_banner_style' => 'farewell',
|
||||
'allow_custom_messages' => true,
|
||||
]);
|
||||
|
||||
User::factory()->create([
|
||||
'username' => 'active_member',
|
||||
'vip_level_id' => $vipLevel->id,
|
||||
'hy_time' => now()->addDays(10),
|
||||
]);
|
||||
|
||||
User::factory()->create([
|
||||
'username' => 'permanent_member',
|
||||
'vip_level_id' => $vipLevel->id,
|
||||
'hy_time' => null,
|
||||
]);
|
||||
|
||||
User::factory()->create([
|
||||
'username' => 'expired_member',
|
||||
'vip_level_id' => $vipLevel->id,
|
||||
'hy_time' => now()->subDay(),
|
||||
]);
|
||||
|
||||
User::factory()->create([
|
||||
'username' => 'other_level_member',
|
||||
]);
|
||||
|
||||
$response = $this->actingAs($admin)->get(route('admin.vip.members', $vipLevel->id));
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertSee('黄金会员 会员列表');
|
||||
$response->assertSee('active_member');
|
||||
$response->assertSee('permanent_member');
|
||||
$response->assertSee('expired_member');
|
||||
$response->assertDontSee('other_level_member');
|
||||
$response->assertSee('当前有效');
|
||||
$response->assertSee('永久会员');
|
||||
$response->assertSee('已过期');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user