codes.txt

This commit is contained in:
Mekan1206
2026-06-03 21:24:00 +05:00
parent c74330cfaf
commit fa3202288f
9 changed files with 341 additions and 17 deletions

View File

@@ -3,9 +3,11 @@
namespace App\Http\Controllers;
use App\Enums\OtpVerificationResult;
use App\Exceptions\CouponPoolExhaustedException;
use App\Http\Requests\SendOtpRequest;
use App\Http\Requests\VerifyOtpRequest;
use App\Models\Coupon;
use App\Services\CouponCodePool;
use App\Services\CouponService;
use App\Services\OtpService;
use Illuminate\Contracts\View\View;
@@ -20,6 +22,7 @@ class VerificationController extends Controller
public function __construct(
private OtpService $otpService,
private CouponService $couponService,
private CouponCodePool $couponCodePool,
) {}
public function index(): View|RedirectResponse
@@ -28,6 +31,10 @@ class VerificationController extends Controller
return $redirect;
}
if (! $this->couponCodePool->hasAvailable()) {
return view('verification.promotion-ended');
}
return view('verification.index');
}
@@ -44,6 +51,10 @@ class VerificationController extends Controller
return back()->withErrors(['phone' => 'Bu telefon belgisi eýýäm ulanyldy.'])->withInput();
}
if (! $this->couponCodePool->hasAvailable()) {
return back()->withErrors(['phone' => CouponPoolExhaustedException::MESSAGE])->withInput();
}
if (! $this->otpService->issue($phone)) {
return back()->withErrors(['phone' => 'SMS iberilmedi. Soňrak synanyşyň.'])->withInput();
}
@@ -63,6 +74,12 @@ class VerificationController extends Controller
return redirect()->route('verification.index');
}
$phone = session()->get('verify_phone');
if (! $this->couponCodePool->hasAvailable() && ! Coupon::query()->where('phone', $phone)->exists()) {
return redirect()->route('verification.index');
}
return view('verification.verify', [
'phone' => session()->get('verify_phone'),
]);
@@ -84,6 +101,10 @@ class VerificationController extends Controller
return redirect()->route('verification.congratulations');
}
if (! $this->couponCodePool->hasAvailable()) {
return redirect()->route('verification.index');
}
if (! $this->otpService->issue($phone)) {
return back()->withErrors(['otp' => 'SMS iberilmedi. Soňrak synanyşyň.']);
}
@@ -109,7 +130,11 @@ class VerificationController extends Controller
return back()->withErrors(['otp' => 'Nädogry kod.']);
}
$coupon = $this->couponService->findOrCreateForPhone($phone);
try {
$coupon = $this->couponService->findOrCreateForPhone($phone);
} catch (CouponPoolExhaustedException) {
return back()->withErrors(['otp' => CouponPoolExhaustedException::MESSAGE]);
}
session()->put('coupon_code', $coupon->code);