补充补签聊天室播报
This commit is contained in:
@@ -121,6 +121,10 @@ class DailySignInController extends Controller
|
|||||||
$presencePayload = $this->presenceService->build($freshUser);
|
$presencePayload = $this->presenceService->build($freshUser);
|
||||||
$this->refreshOnlinePresence($freshUser, $presencePayload);
|
$this->refreshOnlinePresence($freshUser, $presencePayload);
|
||||||
|
|
||||||
|
if ($roomId !== null && $this->chatState->isUserInRoom($roomId, $freshUser->username)) {
|
||||||
|
$this->broadcastSignInNotice($freshUser, $refreshedSignIn, $roomId, $currentStreakDays);
|
||||||
|
}
|
||||||
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'status' => 'success',
|
'status' => 'success',
|
||||||
'message' => '补签成功,'.$refreshedSignIn?->sign_in_date?->format('Y-m-d').' 已补签,当前连续签到 '.$currentStreakDays.' 天。',
|
'message' => '补签成功,'.$refreshedSignIn?->sign_in_date?->format('Y-m-d').' 已补签,当前连续签到 '.$currentStreakDays.' 天。',
|
||||||
@@ -145,14 +149,14 @@ class DailySignInController extends Controller
|
|||||||
/**
|
/**
|
||||||
* 方法功能:向当前聊天室广播签到成功通知。
|
* 方法功能:向当前聊天室广播签到成功通知。
|
||||||
*/
|
*/
|
||||||
private function broadcastSignInNotice(User $user, DailySignIn $dailySignIn, int $roomId): void
|
private function broadcastSignInNotice(User $user, DailySignIn $dailySignIn, int $roomId, ?int $currentStreakDays = null): void
|
||||||
{
|
{
|
||||||
$message = [
|
$message = [
|
||||||
'id' => $this->chatState->nextMessageId($roomId),
|
'id' => $this->chatState->nextMessageId($roomId),
|
||||||
'room_id' => $roomId,
|
'room_id' => $roomId,
|
||||||
'from_user' => '签到播报',
|
'from_user' => '签到播报',
|
||||||
'to_user' => '大家',
|
'to_user' => '大家',
|
||||||
'content' => $this->buildNoticeContent($user, $dailySignIn),
|
'content' => $this->buildNoticeContent($user, $dailySignIn, $currentStreakDays),
|
||||||
'is_secret' => false,
|
'is_secret' => false,
|
||||||
'font_color' => '#0f766e',
|
'font_color' => '#0f766e',
|
||||||
'action' => '',
|
'action' => '',
|
||||||
@@ -166,13 +170,21 @@ class DailySignInController extends Controller
|
|||||||
/**
|
/**
|
||||||
* 方法功能:生成聊天室内的签到播报内容。
|
* 方法功能:生成聊天室内的签到播报内容。
|
||||||
*/
|
*/
|
||||||
private function buildNoticeContent(User $user, DailySignIn $dailySignIn): string
|
private function buildNoticeContent(User $user, DailySignIn $dailySignIn, ?int $currentStreakDays = null): string
|
||||||
{
|
{
|
||||||
$rewardText = $this->buildRewardText($dailySignIn);
|
$rewardText = $this->buildRewardText($dailySignIn);
|
||||||
$identityText = $dailySignIn->identity_badge_name
|
$identityText = $dailySignIn->identity_badge_name
|
||||||
? ',获得身份 '.e($dailySignIn->identity_badge_name)
|
? ',获得身份 '.e($dailySignIn->identity_badge_name)
|
||||||
: '';
|
: '';
|
||||||
|
|
||||||
|
if ($dailySignIn->is_makeup) {
|
||||||
|
$signInDate = $dailySignIn->sign_in_date?->format('Y-m-d') ?? '漏签日期';
|
||||||
|
$streakDays = $currentStreakDays ?? (int) $dailySignIn->streak_days;
|
||||||
|
|
||||||
|
return '【'.e($user->username).'】使用补签卡补签 '.$signInDate
|
||||||
|
.',当前连续签到 '.$streakDays.' 天,获得 '.$rewardText.$identityText.'。';
|
||||||
|
}
|
||||||
|
|
||||||
$quickButton = '<button type="button" onclick="window.quickDailySignIn && window.quickDailySignIn()" '
|
$quickButton = '<button type="button" onclick="window.quickDailySignIn && window.quickDailySignIn()" '
|
||||||
.'style="display:inline-block;margin-left:6px;padding:1px 8px;border:none;border-radius:999px;'
|
.'style="display:inline-block;margin-left:6px;padding:1px 8px;border:none;border-radius:999px;'
|
||||||
.'background:#ccfbf1;color:#0f766e;font-size:10px;font-weight:bold;cursor:pointer;vertical-align:middle;">'
|
.'background:#ccfbf1;color:#0f766e;font-size:10px;font-weight:bold;cursor:pointer;vertical-align:middle;">'
|
||||||
|
|||||||
@@ -303,7 +303,10 @@ class DailySignInControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function test_user_can_makeup_missed_day_with_sign_repair_card(): void
|
public function test_user_can_makeup_missed_day_with_sign_repair_card(): void
|
||||||
{
|
{
|
||||||
|
Event::fake([MessageSent::class, UserStatusUpdated::class]);
|
||||||
|
|
||||||
$user = User::factory()->create(['jjb' => 0]);
|
$user = User::factory()->create(['jjb' => 0]);
|
||||||
|
$room = Room::create(['room_name' => '补签通知房', 'door_open' => true]);
|
||||||
SignInRewardRule::query()->updateOrCreate(['streak_days' => 1], [
|
SignInRewardRule::query()->updateOrCreate(['streak_days' => 1], [
|
||||||
'streak_days' => 1,
|
'streak_days' => 1,
|
||||||
'gold_reward' => 10,
|
'gold_reward' => 10,
|
||||||
@@ -333,9 +336,12 @@ class DailySignInControllerTest extends TestCase
|
|||||||
'sign_in_date' => '2026-04-24',
|
'sign_in_date' => '2026-04-24',
|
||||||
'streak_days' => 1,
|
'streak_days' => 1,
|
||||||
]);
|
]);
|
||||||
|
Redis::hset("room:{$room->id}:users", $user->username, json_encode(['username' => $user->username], JSON_UNESCAPED_UNICODE));
|
||||||
|
Redis::setex("room:{$room->id}:alive:{$user->username}", 90, 1);
|
||||||
|
|
||||||
$response = $this->actingAs($user)->postJson(route('daily-sign-in.makeup'), [
|
$response = $this->actingAs($user)->postJson(route('daily-sign-in.makeup'), [
|
||||||
'target_date' => '2026-04-23',
|
'target_date' => '2026-04-23',
|
||||||
|
'room_id' => $room->id,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$response->assertOk()
|
$response->assertOk()
|
||||||
@@ -368,6 +374,17 @@ class DailySignInControllerTest extends TestCase
|
|||||||
'source' => CurrencySource::SIGN_IN->value,
|
'source' => CurrencySource::SIGN_IN->value,
|
||||||
'remark' => '补签 2026-04-23:当前连续签到 3 天',
|
'remark' => '补签 2026-04-23:当前连续签到 3 天',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
$rawMessage = Redis::lindex("room:{$room->id}:messages", -1);
|
||||||
|
$message = json_decode((string) $rawMessage, true);
|
||||||
|
$this->assertSame('签到播报', $message['from_user']);
|
||||||
|
$this->assertStringContainsString('使用补签卡补签 2026-04-23', $message['content']);
|
||||||
|
$this->assertStringContainsString('当前连续签到 3 天', $message['content']);
|
||||||
|
|
||||||
|
Event::assertDispatched(MessageSent::class, function (MessageSent $event) use ($room): bool {
|
||||||
|
return $event->roomId === $room->id
|
||||||
|
&& str_contains((string) ($event->message['content'] ?? ''), '使用补签卡补签 2026-04-23');
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user