itemTempService = new ItemTempService(); $this->landTempService = new LandTempService(); $this->houseTempService = new HouseTempService(); $this->petTempService = new PetTempService(); $this->fundTempService = new FundTempService(); } /** * 用户列表页面 * * @param Content $content * @return Content */ #[Get('game-temp-data', name: 'dcat.admin.game-temp-data')] public function index(Content $content) { return $content ->title($this->title) ->description('查看用户的暂存数据') ->body($this->grid()); } /** * 查看指定用户的暂存数据 * * @param int $userId 用户ID * @param Content $content * @return Content */ #[Get('game-temp-data/{userId}', name: 'dcat.admin.game-temp-data.show')] public function show($userId, Content $content) { // 查找用户 $user = User::find($userId); if (!$user) { admin_error('错误', '用户不存在'); return redirect()->route('dcat.admin.game-temp-data'); } // 用户信息卡片 $userCard = new Card('用户信息', "ID: {$user->id} | 用户名: {$user->username}"); // 获取所有暂存数据 $itemChanges = $this->itemTempService->getUserItemChanges($userId); $landChanges = $this->landTempService->getUserLandChanges($userId); $houseChange = $this->houseTempService->getUserHouseChange($userId); $petUpdates = $this->petTempService->getUserPetUpdates($userId); $petStatus = $this->petTempService->getUserPetStatus($userId); $fundChanges = $this->fundTempService->getUserFundChanges($userId); // 检查是否有任何暂存数据 $hasAnyData = !empty($itemChanges) || !empty($landChanges) || $houseChange !== null || !empty($petUpdates) || !empty($petStatus) || !empty($fundChanges); // 构建统一的暂存数据视图 $unifiedView = view('admin.temp-data.unified-view', [ 'userId' => $userId, 'username' => $user->username, 'itemChanges' => $itemChanges, 'landChanges' => $landChanges, 'houseChange' => $houseChange, 'petUpdates' => $petUpdates, 'petStatus' => $petStatus, 'fundChanges' => $fundChanges, 'hasAnyData' => $hasAnyData ]); return $content ->title("用户 {$user->username} 的暂存数据") ->description('查看用户的所有暂存数据') ->body($userCard) ->body($unifiedView) ->body(view('admin.temp-data.clear-buttons', ['userId' => $userId])); } /** * 清除用户的物品暂存数据 * * @param int $userId 用户ID * @return \Illuminate\Http\RedirectResponse */ #[Get('game-temp-data/{userId}/clear-item', name: 'dcat.admin.game-temp-data.clear-item')] public function clearItem($userId) { try { // 查找用户 $user = User::find($userId); if (!$user) { admin_error('错误', '用户不存在'); return redirect()->route('dcat.admin.game-temp-data'); } // 清除用户的物品暂存数据 $result = $this->itemTempService->clearUserItemChanges($userId); if ($result) { admin_success('成功', "已清除用户 {$user->username} 的物品暂存数据"); } else { admin_error('错误', "清除用户 {$user->username} 的物品暂存数据失败"); } } catch (\Exception $e) { Log::error('清除用户物品暂存数据失败', [ 'user_id' => $userId, 'error' => $e->getMessage(), ]); admin_error('错误', '清除用户物品暂存数据失败: ' . $e->getMessage()); } return redirect()->route('dcat.admin.game-temp-data.show', ['userId' => $userId]); } /** * 清除用户的土地暂存数据 * * @param int $userId 用户ID * @return \Illuminate\Http\RedirectResponse */ #[Get('game-temp-data/{userId}/clear-land', name: 'dcat.admin.game-temp-data.clear-land')] public function clearLand($userId) { try { // 查找用户 $user = User::find($userId); if (!$user) { admin_error('错误', '用户不存在'); return redirect()->route('dcat.admin.game-temp-data'); } // 清除用户的土地暂存数据 $this->landTempService->clearUserAllLandTemp($userId); admin_success('成功', "已清除用户 {$user->username} 的土地暂存数据"); } catch (\Exception $e) { Log::error('清除用户土地暂存数据失败', [ 'user_id' => $userId, 'error' => $e->getMessage(), ]); admin_error('错误', '清除用户土地暂存数据失败: ' . $e->getMessage()); } return redirect()->route('dcat.admin.game-temp-data.show', ['userId' => $userId]); } /** * 清除用户的房屋暂存数据 * * @param int $userId 用户ID * @return \Illuminate\Http\RedirectResponse */ #[Get('game-temp-data/{userId}/clear-house', name: 'dcat.admin.game-temp-data.clear-house')] public function clearHouse($userId) { try { // 查找用户 $user = User::find($userId); if (!$user) { admin_error('错误', '用户不存在'); return redirect()->route('dcat.admin.game-temp-data'); } // 清除用户的房屋暂存数据 $this->houseTempService->clearUserHouseChange($userId); admin_success('成功', "已清除用户 {$user->username} 的房屋暂存数据"); } catch (\Exception $e) { Log::error('清除用户房屋暂存数据失败', [ 'user_id' => $userId, 'error' => $e->getMessage(), ]); admin_error('错误', '清除用户房屋暂存数据失败: ' . $e->getMessage()); } return redirect()->route('dcat.admin.game-temp-data.show', ['userId' => $userId]); } /** * 清除用户的宠物暂存数据 * * @param int $userId 用户ID * @return \Illuminate\Http\RedirectResponse */ #[Get('game-temp-data/{userId}/clear-pet', name: 'dcat.admin.game-temp-data.clear-pet')] public function clearPet($userId) { try { // 查找用户 $user = User::find($userId); if (!$user) { admin_error('错误', '用户不存在'); return redirect()->route('dcat.admin.game-temp-data'); } // 清除用户的宠物暂存数据 $this->petTempService->clearUserAllPetTemp($userId); admin_success('成功', "已清除用户 {$user->username} 的宠物暂存数据"); } catch (\Exception $e) { Log::error('清除用户宠物暂存数据失败', [ 'user_id' => $userId, 'error' => $e->getMessage(), ]); admin_error('错误', '清除用户宠物暂存数据失败: ' . $e->getMessage()); } return redirect()->route('dcat.admin.game-temp-data.show', ['userId' => $userId]); } /** * 清除用户的资金暂存数据 * * @param int $userId 用户ID * @return \Illuminate\Http\RedirectResponse */ #[Get('game-temp-data/{userId}/clear-fund', name: 'dcat.admin.game-temp-data.clear-fund')] public function clearFund($userId) { try { // 查找用户 $user = User::find($userId); if (!$user) { admin_error('错误', '用户不存在'); return redirect()->route('dcat.admin.game-temp-data'); } // 清除用户的资金暂存数据 $this->fundTempService->clearUserFundChanges($userId); admin_success('成功', "已清除用户 {$user->username} 的资金暂存数据"); } catch (\Exception $e) { Log::error('清除用户资金暂存数据失败', [ 'user_id' => $userId, 'error' => $e->getMessage(), ]); admin_error('错误', '清除用户资金暂存数据失败: ' . $e->getMessage()); } return redirect()->route('dcat.admin.game-temp-data.show', ['userId' => $userId]); } /** * 清除用户的所有暂存数据 * * @param int $userId 用户ID * @return \Illuminate\Http\RedirectResponse */ #[Get('game-temp-data/{userId}/clear-all', name: 'dcat.admin.game-temp-data.clear-all')] public function clearAll($userId) { try { // 查找用户 $user = User::find($userId); if (!$user) { admin_error('错误', '用户不存在'); return redirect()->route('dcat.admin.game-temp-data'); } // 清除用户的所有暂存数据 $this->itemTempService->clearUserItemChanges($userId); $this->landTempService->clearUserAllLandTemp($userId); $this->houseTempService->clearUserHouseChange($userId); $this->petTempService->clearUserAllPetTemp($userId); $this->fundTempService->clearUserFundChanges($userId); admin_success('成功', "已清除用户 {$user->username} 的所有暂存数据"); } catch (\Exception $e) { Log::error('清除用户所有暂存数据失败', [ 'user_id' => $userId, 'error' => $e->getMessage(), ]); admin_error('错误', '清除用户所有暂存数据失败: ' . $e->getMessage()); } return redirect()->route('dcat.admin.game-temp-data.show', ['userId' => $userId]); } /** * 用户列表网格 * * @return Grid */ protected function grid() { return Grid::make(User::class, function (Grid $grid) { $grid->column('id', 'ID')->sortable(); $grid->column('username', '用户名'); $grid->column('created_at', '创建时间'); $grid->column('updated_at', '更新时间'); // 添加查看暂存数据操作 $grid->actions(function (Grid\Displayers\Actions $actions) { // 禁用默认操作按钮 $actions->disableDelete(); $actions->disableEdit(); $actions->disableQuickEdit(); $actions->disableView(); // 添加查看暂存数据操作 $actions->append(new ViewTempDataAction()); }); // 禁用创建按钮 $grid->disableCreateButton(); // 禁用批量操作 $grid->disableBatchActions(); // 添加搜索 $grid->filter(function (Grid\Filter $filter) { $filter->equal('id', '用户ID'); $filter->like('username', '用户名'); }); }); } }