added vocher validation

This commit is contained in:
franknstayn
2021-12-03 17:43:16 +08:00
parent af5854d256
commit a7c3427fc8

View File

@@ -18,6 +18,7 @@ use App\Traits\CaptchaTrait;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\Redirect;
use Carbon\Carbon;
class TeamStoreController extends Controller
{
@@ -699,7 +700,7 @@ class TeamStoreController extends Controller
);
$getVoucher = $TeamStoreModel->selectVoucher($data);
$now = Carbon::now();
if ($getVoucher) {
$items = $TeamStoreModel->myCart($cartKey);
@@ -711,6 +712,20 @@ class TeamStoreController extends Controller
'message' => 'This voucher is already in used.'
));
}
if ($getVoucher[0]->Status == 'Inactive') {
return response()->json(array(
'success' => false,
'message' => 'This voucher is inactive.'
));
}
if ($getVoucher[0]->VoucherExpiryDate < $now) {
return response()->json(array(
'success' => false,
'message' => 'This voucher has expired.'
));
}
}
// insert vocuher to cart_tmp