File: /home/durgeshpandey215/www/zeeroprice.skilladders.com/ajax_showprice.php
<? require_once "application_top.php";
$userid = isset($_SESSION['useridsess'])?$_SESSION['useridsess']:"0";
$id = isset($_REQUEST['id'])? decode($_REQUEST['id']) : "";
$error = "";
$freePoints = "";
if(!$userid){
$error = "<a href='".HTTP_SERVER."login.php' class='btn'>Login <br/>to View Zeero Price.</a>";
$objret = array("error"=>$error);
echo json_encode($objret);
exit;
}
//Get products details
$db->where('istatus',1);
$db->where('qty',0,'>');
$db->where('pid',$id);
$db->where('tilldate',CURDATE,'>=');
$rowprd = $db->getOne('products');
if(!$rowprd){
$error = "Product is sold out.";
$objret = array("error"=>$error);
echo json_encode($objret);
exit;
}
if($rowprd['reducedPrice']==0){
$error = "Product is sold out as Free.";
$objret = array("error"=>$error);
echo json_encode($objret);
exit;
}
$prdCurrency = $rowprd["currency"];
$pointstocut = PointsFromMRP($rowprd["mrp"]);
//Reduce price of products
$oldreducedprice = floatval(finalcost($rowprd["reducedPrice"]));
$cop = floatval(costofPoints($pointstocut));
$newcollectedprice = floatval($rowprd["collectedprice"]+$cop);
$newreducedPrice = floatval($oldreducedprice - $cop);
//get user details
$db->where('userid',$_SESSION['useridsess']);
$rowu = $db->getOne('register');
//Check if user have sufficient balance
if((!$rowu['points'])||($rowu['points'] < $pointstocut) ){
$error = "You don't have sufficient".POINTS.".<br/><a href='".HTTP_SERVER."wallet.php' class='btn'>Click To Recharge.</a>";
$objret = array("error"=>$error);
echo json_encode($objret);exit;
};
// check if newreducedPrice matches minprice
$isPrdFree = 0;
if($rowprd["minprice"] <= $newcollectedprice){
$isPrdFree = 1;
$newreducedPrice =0;
}
$updateArr = array();
$updateArr['reducedPrice']= $newreducedPrice;
$updateArr['collectedprice']= $newcollectedprice;
$db->where('pid',$rowprd["pid"]);
$db->update('products',$updateArr);
$orderid = $rowprd['sellerid'].date('YHis');
//entry in pointsTransaction table
$insertdata = array('orderid'=>$orderid,
'userid'=>$_SESSION['useridsess'],
'pid'=> $rowprd["pid"],
'sellerid'=> $rowprd["sellerid"],
'mrp'=> finalcost($rowprd["mrp"]),
'reducedPrice'=> $newreducedPrice,
'points'=> $pointstocut,
'postedon'=> CURDATETIME
);
$db->insert('pointstransaction',$insertdata);
//cut points from users wallet
// + give him 4x free coins
$pointsRemain = $rowu["points"]- $pointstocut;
$freePoints = $rowu["freePoints"]+(4*$pointstocut);
$updateaArr = array(
'points' => $pointsRemain,
'freePoints' => $freePoints
);
$db->where('userid',$_SESSION['useridsess']);
if($db->update('register',$updateaArr)){
//create Session
$_SESSION['walletSess'] = $pointsRemain;
$_SESSION['freeCoins'] = $freePoints;
}
$objret = array("pid"=>encode($id),"orderid"=>$orderid,"reducedPrice"=>$newreducedPrice,"pointsRemain"=>$pointsRemain,"NewFreePoints"=>$freePoints);
echo json_encode($objret);
?>