sms and update admin

changes
This commit is contained in:
2026-06-12 12:57:23 +05:45
parent 3b529327bf
commit 85e87beaf6
8 changed files with 519 additions and 13 deletions
+35
View File
@@ -0,0 +1,35 @@
<?php
if (! function_exists('sendSMS')) {
function sendSMS(string $destination, string $message): bool
{
$key = env('SMS_API') ?: '';
$sender = env('SMS_SENDER') ?: 'SMSBit';
$url = env('SMS_URL') ?: 'https://sms.bibhutisolutions.com/smsapi/index';
$params = http_build_query([
'key' => $key,
'contacts' => $destination,
'senderid' => $sender,
'msg' => $message,
'responsetype' => 'json',
]);
$separator = parse_url($url, PHP_URL_QUERY) ? '&' : '?';
$url_final = $url . $separator . $params;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url_final);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($response === false || $httpCode >= 400) {
return false;
}
return true;
}
}
+1
View File
@@ -71,6 +71,7 @@ class HomeController extends Controller
$data['registrations'] = $query;
$data['search'] = $search;
$data['total'] = Registration::count();
$data['todayTotal'] = $query->total();
$data['played'] = $registrations->filter(fn($r) => !empty($r['today_goals']) && count($r['today_goals']) >= 3)->count();
$data['topScore'] = $registrations->max('total_score') ?? 0;
$data['countries'] = Country::where('status', 1)->orderBy('title')->get(['id','title','country_flag']);
@@ -8,6 +8,8 @@ use App\Models\GameShot;
use App\Models\Registration;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Mail;
class RegistrationController extends Controller
{
@@ -64,6 +66,15 @@ class RegistrationController extends Controller
'score' => 0,
]);
if ($request->filled('email')) {
dispatch(function () use ($registration) {
Mail::send('emails.welcome', ['registration' => $registration], function ($message) use ($registration) {
$message->to($registration->email)
->subject('Welcome to the Score & Win Challenge 2026! ⚽');
});
})->afterResponse();
}
return response()->json([
'status' => 'session_created',
'registration' => [
@@ -95,9 +106,11 @@ class RegistrationController extends Controller
Cache::put("otp_$phone", $otp, now()->addMinutes(2));
sendSMS($phone, "Your OTP for Score & Win Challenge 2026 is: $otp. It is valid for 2 minutes.");
return response()->json([
'status' => true,
'otp' => $otp // remove in production
// 'otp' => $otp // remove in production
]);
}
@@ -263,6 +276,16 @@ class RegistrationController extends Controller
$registration = $session->registration;
$registration->update(['total_score' => $registration->sessions()->sum('score')]);
if ($registration->email && $request->shot_number == 3) {
dispatch(function () use ($registration) {
Mail::send('emails.score', ['registration' => $registration], function ($message) use ($registration) {
$message->to($registration->email)
->subject('Your Score Update for the Score & Win Challenge 2026! ⚽');
});
})->afterResponse();
}
return response()->json([
'status' => 'ok',
'total_score' => $registration->fresh()->total_score,