From 53fa37d59992c9598211a57b0f3658a62d16f5ac Mon Sep 17 00:00:00 2001 From: antv Date: Wed, 15 Jul 2026 22:32:24 +0700 Subject: [PATCH] Sync thank card sending logic and validation with specifications --- app/Services/User/UserService.php | 4 ++++ resources/views/user/send.blade.php | 20 +++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/app/Services/User/UserService.php b/app/Services/User/UserService.php index 5d194ed..d8c046a 100644 --- a/app/Services/User/UserService.php +++ b/app/Services/User/UserService.php @@ -85,6 +85,10 @@ class UserService implements UserServiceInterface ]); $sender->card -= $amount; + if ($sender->card <= 0) { + $sender->card = 0; + $sender->flag_send = config('constants.FLAG_SEND_DISABLED'); + } $sender->save(); }); } diff --git a/resources/views/user/send.blade.php b/resources/views/user/send.blade.php index 994c81f..14dc6a7 100644 --- a/resources/views/user/send.blade.php +++ b/resources/views/user/send.blade.php @@ -451,11 +451,22 @@ document.addEventListener('DOMContentLoaded', function() { } } + // User state for client-side validation + let userCard = {{ (int) auth()->user()->card }}; + let userFlagSend = {{ (int) auth()->user()->flag_send }}; + $submitBtn.addEventListener('click', function(){ if (!validateForm()) { return; } const msnv = document.getElementById('receiver').value; - const amount = document.getElementById('amount').value; + const amount = parseInt(document.getElementById('amount').value, 10); + + if (userCard < 0 || userFlagSend === 0) { + showModal('Lỗi gửi thẻ', + 'Bạn không đủ điều kiện gửi thẻ (Số thẻ < 0 hoặc quyền gửi thẻ bị khóa). Vui lòng liên hệ Admin để được cấp thêm.', + false); + return; + } showModal('Xác nhận gửi Thank Card', 'Đừng quên hoàn thành Thank Card của bạn nhé!\n Chúng mình sẽ gửi thông báo đến người nhận\nđể họ đến khu vực nhận thư.', @@ -477,6 +488,13 @@ document.addEventListener('DOMContentLoaded', function() { document.getElementById('amount').value = '1'; document.getElementById('confirm_written').checked = false; + // Update local JS state + userCard -= amount; + if (userCard <= 0) { + userCard = 0; + userFlagSend = 0; + } + // Clear local storage for inputs (but not template) localStorage.removeItem('selectedReceiver'); localStorage.removeItem('selectedAmount');