added voucher validation

This commit is contained in:
franknstayn
2021-12-03 18:00:27 +08:00
parent 0b8856d3a0
commit 729d0e72e6

View File

@@ -13,6 +13,7 @@ use App\Models\user\UserModel;
// use Mail;
use Illuminate\Support\Facades\Mail;
use Analytics;
use Carbon\Carbon;
class TeamStoreController extends Controller
@@ -680,7 +681,7 @@ class TeamStoreController extends Controller
);
$getVoucher = $TeamStoreModel->selectVoucher($data);
$now = Carbon::now();
if ($getVoucher) {
$items = $TeamStoreModel->myCart($cartKey);
@@ -692,6 +693,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