This commit is contained in:
antv
2026-07-16 16:01:15 +07:00
parent 939287d9b3
commit 9c20a25111
10 changed files with 123 additions and 180 deletions
@@ -61,6 +61,25 @@ class UserController extends Controller
return view('user.send', compact('users'));
}
/**
* Get statistics for a specific recipient.
*/
public function getRecipientStats(Request $request): JsonResponse
{
$receiverMsnv = (string) $request->query('receiver');
if (empty($receiverMsnv)) {
return response()->json(['success' => false, 'message' => 'Receiver is required'], 400);
}
$sender = Auth::user();
$sentCount = $this->userService->getSentCardsToUserThisMonth($sender, $receiverMsnv);
return response()->json([
'success' => true,
'sent_count' => $sentCount,
]);
}
public function storeThankcards(SendThankCardRequest $request): JsonResponse
{
try {
@@ -91,10 +110,15 @@ class UserController extends Controller
}
}
$sender = Auth::user();
$newRecipientSentCount = $this->userService->getSentCardsToUserThisMonth($sender, (string) $request->input('receiver'));
return response()->json([
'success' => true,
'message' => __('messages.thank_card_send_success'),
'receiver_email' => $receiverUser ? $receiverUser->mail : '',
'new_balance' => (int) $sender->card,
'new_recipient_sent_count' => $newRecipientSentCount,
]);
}
@@ -20,4 +20,6 @@ interface UserServiceInterface
public function getRankingList(string $type, string $selectedMonth, User $currentUser): array;
public function updateProfile(User $user, array $data, ?\Illuminate\Http\UploadedFile $avatarFile = null): void;
public function getSentCardsToUserThisMonth(User $sender, string $receiverMsnv): int;
}
+11
View File
@@ -275,4 +275,15 @@ class UserService implements UserServiceInterface
$user->save();
}
public function getSentCardsToUserThisMonth(User $sender, string $receiverMsnv): int
{
$startOfMonth = Carbon::now()->startOfMonth();
$endOfMonth = Carbon::now()->endOfMonth();
return (int) Administration::where('msnv', $sender->msnv)
->where('receiver', $receiverMsnv)
->whereBetween('date', [$startOfMonth, $endOfMonth])
->sum('sent');
}
}