社交操作补充 user_currency_logs 流水记录

- sendFlower 送鲜花:发送方 gold 用 SEND_GIFT 记录,接收方 charm 用 RECV_GIFT 记录
- giftGold 赠送金币:发送方用 GIFT_SENT 记录,接收方用 GOLD_GIFT_RECV 记录
- grantChatCharm 聊天魅力奖励:用 CHAT_CHARM 记录发送方魅力值变动
- CurrencySource 新增 GOLD_GIFT_RECV、CHAT_CHARM 两个来源枚举
This commit is contained in:
pllx
2026-05-28 13:18:52 +08:00
parent dce0a52750
commit 2ea84ed93e
2 changed files with 18 additions and 14 deletions
+10 -14
View File
@@ -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 = [