Sync thank card sending logic and validation with specifications

This commit is contained in:
antv
2026-07-15 22:32:24 +07:00
parent 7f059dce86
commit 53fa37d599
2 changed files with 23 additions and 1 deletions
+4
View File
@@ -85,6 +85,10 @@ class UserService implements UserServiceInterface
]); ]);
$sender->card -= $amount; $sender->card -= $amount;
if ($sender->card <= 0) {
$sender->card = 0;
$sender->flag_send = config('constants.FLAG_SEND_DISABLED');
}
$sender->save(); $sender->save();
}); });
} }
+19 -1
View File
@@ -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(){ $submitBtn.addEventListener('click', function(){
if (!validateForm()) { return; } if (!validateForm()) { return; }
const msnv = document.getElementById('receiver').value; 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', 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ư.', 'Đừ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('amount').value = '1';
document.getElementById('confirm_written').checked = false; 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) // Clear local storage for inputs (but not template)
localStorage.removeItem('selectedReceiver'); localStorage.removeItem('selectedReceiver');
localStorage.removeItem('selectedAmount'); localStorage.removeItem('selectedAmount');