Compare commits
2
Commits
ce6d71a4f2
...
2ea84ed93e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2ea84ed93e | ||
|
|
dce0a52750 |
@@ -17,6 +17,7 @@
|
||||
/.agents
|
||||
/.codex
|
||||
/.hermes
|
||||
/.reasonix
|
||||
/auth.json
|
||||
/node_modules
|
||||
/public/build
|
||||
|
||||
@@ -164,6 +164,18 @@ enum CurrencySource: string
|
||||
/** 猜谜活动奖励 */
|
||||
case GAME_REWARD = 'game_reward';
|
||||
|
||||
/** 收到用户赠送的金币 */
|
||||
case GOLD_GIFT_RECV = 'gold_gift_recv';
|
||||
|
||||
/** 聊天互动魅力奖励 */
|
||||
case CHAT_CHARM = 'chat_charm';
|
||||
|
||||
/** 存入银行(jjb → bank_jjb) */
|
||||
case BANK_DEPOSIT = 'bank_deposit';
|
||||
|
||||
/** 从银行取款(bank_jjb → jjb) */
|
||||
case BANK_WITHDRAW = 'bank_withdraw';
|
||||
|
||||
/**
|
||||
* 返回该来源的中文名称,用于后台统计展示。
|
||||
*/
|
||||
@@ -218,6 +230,10 @@ enum CurrencySource: string
|
||||
self::MSG_DECORATION_BUY => '消息装扮购买(旧)',
|
||||
self::AVATAR_FRAME_BUY => '头像框购买',
|
||||
self::GAME_REWARD => '猜谜活动奖励',
|
||||
self::GOLD_GIFT_RECV => '收到赠送金币',
|
||||
self::CHAT_CHARM => '聊天魅力奖励',
|
||||
self::BANK_DEPOSIT => '存入银行',
|
||||
self::BANK_WITHDRAW => '银行取款',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,9 +13,12 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Enums\CurrencySource;
|
||||
use App\Models\BankLog;
|
||||
use App\Models\Sysparam;
|
||||
use App\Models\User;
|
||||
use App\Models\UserCurrencyLog;
|
||||
use App\Services\UserCurrencyService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
@@ -26,6 +29,9 @@ use Illuminate\Support\Facades\DB;
|
||||
*/
|
||||
class BankController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly UserCurrencyService $currencyService,
|
||||
) {}
|
||||
/**
|
||||
* 查询银行余额及最近20条流水记录
|
||||
*/
|
||||
@@ -107,7 +113,8 @@ class BankController extends Controller
|
||||
}
|
||||
|
||||
DB::transaction(function () use ($user, $amount): void {
|
||||
$user->decrement('jjb', $amount);
|
||||
$this->currencyService->change($user, 'gold', -$amount, CurrencySource::BANK_DEPOSIT, "存入银行 {$amount} 金币");
|
||||
|
||||
$user->increment('bank_jjb', $amount);
|
||||
|
||||
BankLog::create([
|
||||
@@ -151,7 +158,8 @@ class BankController extends Controller
|
||||
|
||||
DB::transaction(function () use ($user, $amount): void {
|
||||
$user->decrement('bank_jjb', $amount);
|
||||
$user->increment('jjb', $amount);
|
||||
|
||||
$this->currencyService->change($user, 'gold', $amount, CurrencySource::BANK_WITHDRAW, "取出银行存款 {$amount} 金币");
|
||||
|
||||
BankLog::create([
|
||||
'user_id' => $user->id,
|
||||
|
||||
@@ -1091,12 +1091,9 @@ class ChatController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
// 扣除金币、增加对方魅力
|
||||
$user->jjb = ($user->jjb ?? 0) - $totalCost;
|
||||
$user->save();
|
||||
|
||||
$toUser->meili = ($toUser->meili ?? 0) + $totalCharm;
|
||||
$toUser->save();
|
||||
// 扣除金币、增加对方魅力(含流水日志)
|
||||
$this->currencyService->change($user, 'gold', -$totalCost, CurrencySource::SEND_GIFT, "送花:送给 {$toUsername} {$count} 份【{$gift->name}】,魅力 +{$totalCharm}", $roomId);
|
||||
$this->currencyService->change($toUser, 'charm', $totalCharm, CurrencySource::RECV_GIFT, "收到 {$user->username} 赠送的 {$count} 份【{$gift->name}】", $roomId);
|
||||
|
||||
// 构建礼物图片 URL
|
||||
$giftImageUrl = $gift->image ? "/images/gifts/{$gift->image}" : '';
|
||||
@@ -1128,8 +1125,8 @@ class ChatController extends Controller
|
||||
'status' => 'success',
|
||||
'message' => "送花成功!花费 {$totalCost} 金币,{$toUsername} 魅力 +{$totalCharm}",
|
||||
'data' => [
|
||||
'my_jjb' => $user->jjb,
|
||||
'target_charm' => $toUser->meili,
|
||||
'my_jjb' => $user->fresh()->jjb,
|
||||
'target_charm' => $toUser->fresh()->meili,
|
||||
],
|
||||
]);
|
||||
}
|
||||
@@ -1182,9 +1179,8 @@ class ChatController extends Controller
|
||||
return;
|
||||
}
|
||||
|
||||
// 发送者获得魅力
|
||||
$sender->meili = ($sender->meili ?? 0) + $charmGain;
|
||||
$sender->save();
|
||||
// 发送者获得魅力(含流水日志)
|
||||
$this->currencyService->change($sender, 'charm', $charmGain, CurrencySource::CHAT_CHARM, "与 {$toUsername} 聊天获得魅力奖励");
|
||||
|
||||
// 更新 Redis 计数器(1 小时过期)
|
||||
Redis::incrby($capKey, $charmGain);
|
||||
@@ -1407,9 +1403,9 @@ class ChatController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
// 执行转账(直接操作字段,与 sendFlower 保持一致风格)
|
||||
$sender->decrement('jjb', $amount);
|
||||
$receiver->increment('jjb', $amount);
|
||||
// 执行转账(含流水日志)
|
||||
$this->currencyService->change($sender, 'gold', -$amount, CurrencySource::GIFT_SENT, "赠送金币给 {$toName}", $roomId);
|
||||
$this->currencyService->change($receiver, 'gold', $amount, CurrencySource::GOLD_GIFT_RECV, "收到 {$sender->username} 赠送的金币", $roomId);
|
||||
|
||||
// 写入真正的私聊消息,避免其他旁观用户在公屏看到赠金币通知。
|
||||
$giftMsg = [
|
||||
|
||||
@@ -10,10 +10,13 @@
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Enums\CurrencySource;
|
||||
use App\Events\MessageSent;
|
||||
use App\Jobs\SaveMessageJob;
|
||||
use App\Models\BankLog;
|
||||
use App\Models\User;
|
||||
use App\Models\UserCurrencyLog;
|
||||
use App\Services\UserCurrencyService;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
/**
|
||||
@@ -41,6 +44,7 @@ class AiFinanceService
|
||||
*/
|
||||
public function __construct(
|
||||
private readonly ChatStateService $chatState,
|
||||
private readonly UserCurrencyService $currencyService,
|
||||
) {}
|
||||
|
||||
/**
|
||||
@@ -107,15 +111,15 @@ class AiFinanceService
|
||||
$depositAmount = $walletGold - self::AVAILABLE_GOLD_RESERVE;
|
||||
|
||||
// 只把超过 100 万的部分转入银行,手上保留不高于 100 万的常规活动资金。
|
||||
$lockedUser->jjb = self::AVAILABLE_GOLD_RESERVE;
|
||||
$lockedUser->bank_jjb = $bankBefore + $depositAmount;
|
||||
$lockedUser->save();
|
||||
$this->currencyService->change($lockedUser, 'gold', -$depositAmount, CurrencySource::BANK_DEPOSIT, "自动存入银行 {$depositAmount} 金币");
|
||||
|
||||
$lockedUser->increment('bank_jjb', $depositAmount);
|
||||
|
||||
BankLog::create([
|
||||
'user_id' => $lockedUser->id,
|
||||
'type' => 'deposit',
|
||||
'amount' => $depositAmount,
|
||||
'balance_after' => (int) $lockedUser->bank_jjb,
|
||||
'balance_after' => (int) $lockedUser->fresh()->bank_jjb,
|
||||
]);
|
||||
|
||||
return array_values(array_filter(
|
||||
@@ -162,15 +166,15 @@ class AiFinanceService
|
||||
}
|
||||
|
||||
// 优先把银行金币提回手上,保证 AI 的即时可用余额尽量回到目标线。
|
||||
$lockedUser->jjb = $walletGold + $withdrawAmount;
|
||||
$lockedUser->bank_jjb = $bankGold - $withdrawAmount;
|
||||
$lockedUser->save();
|
||||
$this->currencyService->change($lockedUser, 'gold', $withdrawAmount, CurrencySource::BANK_WITHDRAW, "从银行自动取款 {$withdrawAmount} 金币");
|
||||
|
||||
$lockedUser->decrement('bank_jjb', $withdrawAmount);
|
||||
|
||||
BankLog::create([
|
||||
'user_id' => $lockedUser->id,
|
||||
'type' => 'withdraw',
|
||||
'amount' => $withdrawAmount,
|
||||
'balance_after' => (int) $lockedUser->bank_jjb,
|
||||
'balance_after' => (int) $lockedUser->fresh()->bank_jjb,
|
||||
]);
|
||||
|
||||
return (int) $lockedUser->jjb >= $targetWalletGold;
|
||||
|
||||
Reference in New Issue
Block a user