From d7a575d8c8f7b230de21d642a6633c097e971aec Mon Sep 17 00:00:00 2001 From: lkddi Date: Wed, 18 Mar 2026 20:31:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=93=B6=E8=A1=8C=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=EF=BC=9A=E5=AD=98=E5=8F=96=E9=87=91=E5=B8=81=E3=80=81?= =?UTF-8?q?=E6=B5=81=E6=B0=B4=E8=AE=B0=E5=BD=95=E3=80=81PC/=E6=89=8B?= =?UTF-8?q?=E6=9C=BA=E7=AB=AF=E5=8F=8C=E5=85=A5=E5=8F=A3=EF=BC=9B=E8=BF=81?= =?UTF-8?q?=E7=A7=BB=20bank=5Fjjb=20=E5=AD=97=E6=AE=B5=E5=92=8C=20bank=5Fl?= =?UTF-8?q?ogs=20=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/BankController.php | 128 +++++++ app/Models/BankLog.php | 46 +++ ..._18_202706_add_bank_jjb_to_users_table.php | 34 ++ ...26_03_18_202708_create_bank_logs_table.php | 40 ++ .../partials/layout/mobile-drawer.blade.php | 2 +- .../chat/partials/layout/toolbar.blade.php | 352 +++++++++++++++++- routes/web.php | 5 + 7 files changed, 605 insertions(+), 2 deletions(-) create mode 100644 app/Http/Controllers/BankController.php create mode 100644 app/Models/BankLog.php create mode 100644 database/migrations/2026_03_18_202706_add_bank_jjb_to_users_table.php create mode 100644 database/migrations/2026_03_18_202708_create_bank_logs_table.php diff --git a/app/Http/Controllers/BankController.php b/app/Http/Controllers/BankController.php new file mode 100644 index 0000000..4707e85 --- /dev/null +++ b/app/Http/Controllers/BankController.php @@ -0,0 +1,128 @@ +id) + ->latest() + ->limit(20) + ->get(['type', 'amount', 'balance_after', 'created_at']); + + return response()->json([ + 'status' => 'success', + 'jjb' => $user->jjb ?? 0, + 'bank_jjb' => $user->bank_jjb ?? 0, + 'logs' => $logs, + ]); + } + + /** + * 存款:从流通金币(jjb)转入银行(bank_jjb) + * + * 请求参数:amount(正整数) + */ + public function deposit(Request $request): JsonResponse + { + $request->validate([ + 'amount' => 'required|integer|min:1|max:9999999', + ]); + + $amount = $request->integer('amount'); + $user = Auth::user(); + + if (($user->jjb ?? 0) < $amount) { + return response()->json([ + 'status' => 'error', + 'message' => '流通金币不足!当前余额 '.($user->jjb ?? 0)." 枚,无法存入 {$amount} 枚。", + ]); + } + + DB::transaction(function () use ($user, $amount): void { + $user->decrement('jjb', $amount); + $user->increment('bank_jjb', $amount); + + BankLog::create([ + 'user_id' => $user->id, + 'type' => 'deposit', + 'amount' => $amount, + 'balance_after' => $user->fresh()->bank_jjb, + ]); + }); + + $fresh = $user->fresh(); + + return response()->json([ + 'status' => 'success', + 'message' => "成功存入 {$amount} 枚金币!", + 'jjb' => $fresh->jjb, + 'bank_jjb' => $fresh->bank_jjb, + ]); + } + + /** + * 取款:从银行(bank_jjb)转回流通金币(jjb) + * + * 请求参数:amount(正整数) + */ + public function withdraw(Request $request): JsonResponse + { + $request->validate([ + 'amount' => 'required|integer|min:1|max:9999999', + ]); + + $amount = $request->integer('amount'); + $user = Auth::user(); + + if (($user->bank_jjb ?? 0) < $amount) { + return response()->json([ + 'status' => 'error', + 'message' => '银行余额不足!当前存款 '.($user->bank_jjb ?? 0)." 枚,无法取出 {$amount} 枚。", + ]); + } + + DB::transaction(function () use ($user, $amount): void { + $user->decrement('bank_jjb', $amount); + $user->increment('jjb', $amount); + + BankLog::create([ + 'user_id' => $user->id, + 'type' => 'withdraw', + 'amount' => $amount, + 'balance_after' => $user->fresh()->bank_jjb, + ]); + }); + + $fresh = $user->fresh(); + + return response()->json([ + 'status' => 'success', + 'message' => "成功取出 {$amount} 枚金币!", + 'jjb' => $fresh->jjb, + 'bank_jjb' => $fresh->bank_jjb, + ]); + } +} diff --git a/app/Models/BankLog.php b/app/Models/BankLog.php new file mode 100644 index 0000000..af06bee --- /dev/null +++ b/app/Models/BankLog.php @@ -0,0 +1,46 @@ + + */ + protected $fillable = [ + 'user_id', + 'type', + 'amount', + 'balance_after', + ]; + + /** + * 字段类型转换 + */ + protected function casts(): array + { + return [ + 'amount' => 'integer', + 'balance_after' => 'integer', + ]; + } + + /** + * 所属用户 + */ + public function user(): BelongsTo + { + return $this->belongsTo(User::class); + } +} diff --git a/database/migrations/2026_03_18_202706_add_bank_jjb_to_users_table.php b/database/migrations/2026_03_18_202706_add_bank_jjb_to_users_table.php new file mode 100644 index 0000000..290c408 --- /dev/null +++ b/database/migrations/2026_03_18_202706_add_bank_jjb_to_users_table.php @@ -0,0 +1,34 @@ +integer('bank_jjb')->default(0)->after('frozen_jjb')->comment('银行存款金币(与流通金币隔离)'); + }); + } + + /** + * 回滚迁移 + */ + public function down(): void + { + Schema::table('users', function (Blueprint $table): void { + $table->dropColumn('bank_jjb'); + }); + } +}; diff --git a/database/migrations/2026_03_18_202708_create_bank_logs_table.php b/database/migrations/2026_03_18_202708_create_bank_logs_table.php new file mode 100644 index 0000000..d856454 --- /dev/null +++ b/database/migrations/2026_03_18_202708_create_bank_logs_table.php @@ -0,0 +1,40 @@ +id(); + $table->unsignedBigInteger('user_id')->comment('操作用户ID'); + $table->enum('type', ['deposit', 'withdraw'])->comment('操作类型:存款/取款'); + $table->integer('amount')->comment('操作金额(正数)'); + $table->integer('balance_after')->comment('操作后 bank_jjb 余额'); + $table->timestamps(); + + $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); + $table->index(['user_id', 'created_at']); + }); + } + + /** + * 回滚迁移 + */ + public function down(): void + { + Schema::dropIfExists('bank_logs'); + } +}; diff --git a/resources/views/chat/partials/layout/mobile-drawer.blade.php b/resources/views/chat/partials/layout/mobile-drawer.blade.php index 2cac2b4..55c5b05 100644 --- a/resources/views/chat/partials/layout/mobile-drawer.blade.php +++ b/resources/views/chat/partials/layout/mobile-drawer.blade.php @@ -34,7 +34,7 @@
🛒
商店
💾
存点
🎮
娱乐
-
🏦
银行
+
🏦
银行
💍
婚姻
👫
好友
🖼️
头像
diff --git a/resources/views/chat/partials/layout/toolbar.blade.php b/resources/views/chat/partials/layout/toolbar.blade.php index 6e304ca..a1c9088 100644 --- a/resources/views/chat/partials/layout/toolbar.blade.php +++ b/resources/views/chat/partials/layout/toolbar.blade.php @@ -18,7 +18,7 @@
商店
存点
娱乐
-
银行
+
银行
婚姻
好友
头像
@@ -1568,3 +1568,353 @@ })(); + +{{-- ═══════════ 银行弹窗 ═══════════ --}} + + +
+
+ {{-- 标题栏 --}} +
+ 🏦 金币银行 + × +
+ + {{-- 余额展示 --}} +
+
+
💰 流通金币
+
+
+
+
🏦 银行存款
+
+
+
+ + {{-- 操作区 --}} +
+ {{-- 存款 --}} +
+ 存 款 + + +
+ {{-- 取款 --}} +
+ 取 款 + + +
+ +
+ + {{-- 流水记录 --}} +
+
加载中...
+
+
+
+ + diff --git a/routes/web.php b/routes/web.php index cb4b284..c570e6a 100644 --- a/routes/web.php +++ b/routes/web.php @@ -294,6 +294,11 @@ Route::middleware(['chat.auth'])->group(function () { Route::post('/shop/buy', [\App\Http\Controllers\ShopController::class, 'buy'])->name('shop.buy'); Route::post('/shop/rename', [\App\Http\Controllers\ShopController::class, 'rename'])->name('shop.rename'); + // ---- 银行(存取金币)---- + Route::get('/bank', [\App\Http\Controllers\BankController::class, 'info'])->name('bank.info'); + Route::post('/bank/deposit', [\App\Http\Controllers\BankController::class, 'deposit'])->name('bank.deposit'); + Route::post('/bank/withdraw', [\App\Http\Controllers\BankController::class, 'withdraw'])->name('bank.withdraw'); + // ---- 开发日志(独立前台页面 /changelog)---- Route::get('/changelog', [ChangelogController::class, 'index'])->name('changelog.index'); // 懒加载接口:scroll 到底追加更多日志