update flat voucher

This commit is contained in:
franknstayn
2021-12-23 22:01:02 +08:00
parent 0973ea08b2
commit 9917f8b33e
4 changed files with 66 additions and 23 deletions

View File

@@ -321,10 +321,15 @@ class PaypalController extends Controller
$m->updateVoucherValueInCart($data, $item_id);
} else {
$voucherData = array(
'totalValue' => $totalValue,
'type' => 'Flat'
$data = array(
'Price' => round($totalValue * -1, 2)
);
$m->updateVoucherValueInCart($data, $item_id);
// $voucherData = array(
// 'totalValue' => $totalValue,
// 'type' => 'Flat'
// );
}
}

View File

@@ -590,18 +590,14 @@ class TeamStoreController extends Controller
$UserModel = new UserModel;
$array_address_book = null;
if(!Auth::guest()){
if (!Auth::guest()) {
$userId = Auth::user()->id;
$array_address_book = $UserModel->selectAddresBook('UserId', $userId);
if (count($array_address_book) <= 0) {
$array_address_book = null;
}
$array_address_book = $UserModel->selectAddresBook('UserId', $userId);
if (count($array_address_book) <= 0) {
$array_address_book = null;
}
}
$cartKey = $request->session()->get('cartkey');
$items = $m->myCart($cartKey);
$getSubtotal = $m->getSubtotal($cartKey);
@@ -651,15 +647,17 @@ class TeamStoreController extends Controller
$finalSubTotal = $getSubtotal[0]->Subtotal - $getDiscountValue;
} else {
//Flat voucher computation here..
$finalSubTotal = $getSubtotal[0]->Subtotal - $voucherData['totalValue'];
// var_dump($voucherData['totalValue']);
}
} else {
$finalSubTotal = $getSubtotal[0]->Subtotal;
}
if($cartKey != null) {
if ($cartKey != null) {
$shippingFee = app(\App\Http\Controllers\paypal\PaypalController::class)->getShippingFee($cartKey);
$tax = app(\App\Http\Controllers\paypal\PaypalController::class)->getTax($cartKey);
}else{
} else {
$shippingFee = 0;
$tax = [];
}
@@ -680,6 +678,7 @@ class TeamStoreController extends Controller
public function addVoucher(Request $request)
{
$cartKey = $request->session()->get('cartkey');
$userId = Auth::user()->id;
if ($cartKey == "") {
return false;
@@ -694,6 +693,14 @@ class TeamStoreController extends Controller
$store_array = $TeamStoreModel->selectTeamStore('Id', $grouped_item[0]->StoreId);
$getSubtotal = $TeamStoreModel->getSubtotal($cartKey);
if ($cartKey != null) {
$shippingFee = app(\App\Http\Controllers\paypal\PaypalController::class)->getShippingFee($cartKey);
$tax = app(\App\Http\Controllers\paypal\PaypalController::class)->getTax($cartKey);
} else {
$shippingFee = 0;
$tax = [];
}
$data = array(
'store_id' => $store_id,
'voucher' => $vocher
@@ -726,6 +733,25 @@ class TeamStoreController extends Controller
'message' => 'This voucher has expired.'
));
}
if ($getVoucher[0]->VoucherType === "Flat") {
$isUsed = $TeamStoreModel->checkVoucher($userId, $getVoucher[0]->Id);
if (count($isUsed) >= 1) {
return response()->json(array(
'success' => false,
'message' => 'You already used this voucher.',
));
}
if ($getSubtotal[0]->Subtotal <= $getVoucher[0]->VoucherValue) {
return response()->json(array(
'success' => false,
'message' => 'Please add more item to redeem this voucher.',
));
}
}
}
// insert vocuher to cart_tmp
@@ -770,12 +796,13 @@ class TeamStoreController extends Controller
}
}
// voucher computation
if ($voucherData['type'] == "Percentage") {
$getPercentageValue = $voucherData['totalValue'] / 100;
$getDiscountValue = ($getSubtotal[0]->Subtotal * $getPercentageValue);
$finalSubTotal = $getSubtotal[0]->Subtotal - $getDiscountValue;
} else {
//Flat voucher computation here..
$finalSubTotal = $getSubtotal[0]->Subtotal - $voucherData['totalValue'];
}
} else {
$finalSubTotal = $getSubtotal[0]->Subtotal;
@@ -787,6 +814,8 @@ class TeamStoreController extends Controller
$offData = $getVoucher[0]->VoucherValue . ' ' . $store_array[0]->StoreCurrency;
}
$message = '<div class="btn-group mb-2">
<button type="button" class="btn btn-black btn-sm dropdown-toggle" data-bs-toggle="dropdown">' . $getVoucher[0]->VoucherCode . ' ' . $offData . ' OFF</button>
<ul class="dropdown-menu">
@@ -798,7 +827,7 @@ class TeamStoreController extends Controller
return response()->json(array(
'success' => true,
'message' => $message,
'subtotal' => number_format($finalSubTotal, 2)
'subtotal' => number_format($finalSubTotal + $shippingFee + $tax["tax"], 2)
));
} else {

View File

@@ -252,14 +252,14 @@ class TeamStoreModel extends Model
function selectFeaturedProducts($store_id = 0)
{
if($store_id == 0){
if ($store_id == 0) {
$i = DB::select("SELECT t.StoreUrl, tp.ProductName, tp.ProductPrice, tp.ProductURL, tpt.Image FROM teamstores AS t
INNER JOIN teamstore_products AS tp ON tp.TeamStoreId = t.Id
INNER JOIN teamstore_product_thumbnails as tpt ON tp.Id = tpt.ProductId
WHERE t.Password IS NULL AND t.IsHibernated IS NULL AND tpt.ImageClass = 'active' AND tp.PrivacyStatus = 'public'
ORDER BY RAND()
LIMIT 6");
} else{
} else {
$i = DB::select("SELECT t.StoreUrl, tp.ProductName, tp.ProductPrice, tp.ProductURL, tpt.Image FROM teamstores AS t
INNER JOIN teamstore_products AS tp ON tp.TeamStoreId = t.Id
INNER JOIN teamstore_product_thumbnails as tpt ON tp.Id = tpt.ProductId
@@ -270,4 +270,13 @@ class TeamStoreModel extends Model
return $i;
}
function checkVoucher($userid, $voucherid)
{
$i = DB::select("SELECT *
FROM payment_details AS pd
INNER JOIN orders AS o ON pd.CartKey = o.CartKey
WHERE pd.UserId = $userid AND o.VoucherId = $voucherid");
return $i;
}
}

View File

@@ -327,7 +327,7 @@
<small>{{ number_format($tax['tax'], 2) . ' ' . $store_array[0]->StoreCurrency }}</small>
</h5>
<hr>
<h3>Total: <span id="my_subtotal">{{ number_format($tax['order_grandtotal'] + $shipping_fee + $tax['tax'], 2) }}</span>
<h3>Total: <span id="my_subtotal">{{ number_format($getSubtotal + $shipping_fee + $tax['tax'], 2) }}</span>
<small>{{ $store_array[0]->StoreCurrency }}</small>
</h3>