| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366 |
- <?php
- namespace App\Module\Game\AdminControllers;
- use App\Module\Game\AdminControllers\Actions\ViewTempDataAction;
- use App\Module\Game\Services\FundTempService;
- use App\Module\Game\Services\HouseTempService;
- use App\Module\Game\Services\ItemTempService;
- use App\Module\Game\Services\LandTempService;
- use App\Module\Game\Services\PetTempService;
- use App\Module\User\Models\User;
- use Dcat\Admin\Grid;
- use Dcat\Admin\Layout\Content;
- use Dcat\Admin\Widgets\Card;
- use Illuminate\Support\Facades\Log;
- use Spatie\RouteAttributes\Attributes\Get;
- use Spatie\RouteAttributes\Attributes\Prefix;
- use UCore\DcatAdmin\AdminController;
- /**
- * 暂存数据管理控制器
- *
- * 用于查看用户的各种暂存数据,包括物品、土地、房屋、宠物和资金等
- */
- class TempDataController extends AdminController
- {
- /**
- * 页面标题
- *
- * @var string
- */
- protected $title = '暂存数据管理';
- /**
- * 各种暂存服务
- */
- protected $itemTempService;
- protected $landTempService;
- protected $houseTempService;
- protected $petTempService;
- protected $fundTempService;
- /**
- * 构造函数
- */
- public function __construct()
- {
- $this->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', '用户名');
- });
- });
- }
- }
|