- 新建 vip_levels 表(名称、图标、颜色、经验/金币倍率、专属进入/离开模板) - 默认4个等级种子:白银🥈(×1.5)、黄金🥇(×2.0)、钻石💎(×3.0)、至尊👑(×5.0) - 后台 VIP 等级 CRUD 管理(新增/编辑/删除,配置模板和倍率) - 后台用户编辑弹窗支持设置 VIP 等级和到期时间 - ChatController 心跳经验按 VIP 倍率加成 - FishingController 正向奖励按 VIP 倍率加成(负面惩罚不变) - 在线名单显示 VIP 图标和管理员🛡️标识 - VIP 用户进入/离开使用专属颜色和标题 - 后台侧栏新增「👑 VIP 会员等级」入口
124 lines
3.7 KiB
PHP
124 lines
3.7 KiB
PHP
<?php
|
||
|
||
/**
|
||
* 文件功能:后台 VIP 会员等级管理控制器
|
||
* 提供会员等级的 CRUD(增删改查)功能
|
||
* 后台可自由创建、修改、删除会员等级
|
||
*
|
||
* @author ChatRoom Laravel
|
||
*
|
||
* @version 1.0.0
|
||
*/
|
||
|
||
namespace App\Http\Controllers\Admin;
|
||
|
||
use App\Http\Controllers\Controller;
|
||
use App\Models\VipLevel;
|
||
use Illuminate\Http\RedirectResponse;
|
||
use Illuminate\Http\Request;
|
||
use Illuminate\View\View;
|
||
|
||
class VipController extends Controller
|
||
{
|
||
/**
|
||
* 会员等级管理列表页
|
||
*/
|
||
public function index(): View
|
||
{
|
||
$levels = VipLevel::orderBy('sort_order')->get();
|
||
|
||
return view('admin.vip.index', compact('levels'));
|
||
}
|
||
|
||
/**
|
||
* 新增会员等级
|
||
*/
|
||
public function store(Request $request): RedirectResponse
|
||
{
|
||
$data = $request->validate([
|
||
'name' => 'required|string|max:50',
|
||
'icon' => 'required|string|max:20',
|
||
'color' => 'required|string|max:10',
|
||
'exp_multiplier' => 'required|numeric|min:1|max:99',
|
||
'jjb_multiplier' => 'required|numeric|min:1|max:99',
|
||
'sort_order' => 'required|integer|min:0',
|
||
'price' => 'required|integer|min:0',
|
||
'duration_days' => 'required|integer|min:0',
|
||
'join_templates' => 'nullable|string',
|
||
'leave_templates' => 'nullable|string',
|
||
]);
|
||
|
||
// 将文本框的多行模板转为 JSON 数组
|
||
$data['join_templates'] = $this->textToJson($data['join_templates'] ?? '');
|
||
$data['leave_templates'] = $this->textToJson($data['leave_templates'] ?? '');
|
||
|
||
VipLevel::create($data);
|
||
|
||
return redirect()->route('admin.vip.index')->with('success', '会员等级创建成功!');
|
||
}
|
||
|
||
/**
|
||
* 更新会员等级
|
||
*
|
||
* @param int $id 等级ID
|
||
*/
|
||
public function update(Request $request, int $id): RedirectResponse
|
||
{
|
||
$level = VipLevel::findOrFail($id);
|
||
|
||
$data = $request->validate([
|
||
'name' => 'required|string|max:50',
|
||
'icon' => 'required|string|max:20',
|
||
'color' => 'required|string|max:10',
|
||
'exp_multiplier' => 'required|numeric|min:1|max:99',
|
||
'jjb_multiplier' => 'required|numeric|min:1|max:99',
|
||
'sort_order' => 'required|integer|min:0',
|
||
'price' => 'required|integer|min:0',
|
||
'duration_days' => 'required|integer|min:0',
|
||
'join_templates' => 'nullable|string',
|
||
'leave_templates' => 'nullable|string',
|
||
]);
|
||
|
||
$data['join_templates'] = $this->textToJson($data['join_templates'] ?? '');
|
||
$data['leave_templates'] = $this->textToJson($data['leave_templates'] ?? '');
|
||
|
||
$level->update($data);
|
||
|
||
return redirect()->route('admin.vip.index')->with('success', '会员等级更新成功!');
|
||
}
|
||
|
||
/**
|
||
* 删除会员等级(关联用户的 vip_level_id 会自动置 null)
|
||
*
|
||
* @param int $id 等级ID
|
||
*/
|
||
public function destroy(int $id): RedirectResponse
|
||
{
|
||
$level = VipLevel::findOrFail($id);
|
||
$level->delete();
|
||
|
||
return redirect()->route('admin.vip.index')->with('success', '会员等级已删除!');
|
||
}
|
||
|
||
/**
|
||
* 将多行文本转为 JSON 数组字符串
|
||
* 每行一个模板,空行忽略
|
||
*
|
||
* @param string $text 多行文本
|
||
* @return string|null JSON 字符串
|
||
*/
|
||
private function textToJson(string $text): ?string
|
||
{
|
||
$lines = array_filter(
|
||
array_map('trim', explode("\n", $text)),
|
||
fn ($line) => $line !== ''
|
||
);
|
||
|
||
if (empty($lines)) {
|
||
return null;
|
||
}
|
||
|
||
return json_encode(array_values($lines), JSON_UNESCAPED_UNICODE);
|
||
}
|
||
}
|