$RiderID ); ////////////////////////////////////////////////////////////////////////////////////////////////////// $CheckRaidertURL = "http://localhost/cygnusa/batterySwap/api/User/"; $CheckRaidertCURL = curl_init($CheckRaidertURL); curl_setopt($CheckRaidertCURL, CURLOPT_HEADER, false); curl_setopt($CheckRaidertCURL, CURLOPT_RETURNTRANSFER, true); curl_setopt($CheckRaidertCURL, CURLOPT_POST, true); curl_setopt($CheckRaidertCURL, CURLOPT_POSTFIELDS, $RaiderPostData); $CheckRaidertJsonResponse = curl_exec($CheckRaidertCURL); $RaiderResult = json_decode($CheckRaidertJsonResponse, true); $AvailableRemainingSwapCount=$RaiderResult["SwapData"]["RemainingData"]["Available"]; $AvailableFreeSwapCount=$RaiderResult["SwapData"]["FreeData"]["Available"]; $TotalRechargedSwapCount=$RaiderResult["SwapData"]["RechargeData"]["Total"]; $UsedRechargedSwapCount=$RaiderResult["SwapData"]["RechargeData"]["Used"]; $AvailableRechargedSwapCount=$RaiderResult["SwapData"]["RechargeData"]["Available"]; $SwapRechargeID=$RaiderResult["SwapData"]["RechargeData"]["SwapRechargeID"]; $TotalReferSwapCount=$RaiderResult["SwapData"]["ReferData"]["Total"]; $UsedReferSwapCount=$RaiderResult["SwapData"]["ReferData"]["Used"]; $AvailableReferSwapCount=$RaiderResult["SwapData"]["ReferData"]["Available"]; $SwapReferID=$RaiderResult["SwapData"]["ReferData"]["SwapReferID"]; if ($AvailableRemainingSwapCount>0) { if ($AvailableFreeSwapCount>0) { $FreeSwapPostData = array( 'RiderID' => $RiderID, 'ReturnBatteryID' => $ReturnBatteryID, 'SwapBatteryID' => $SwapBatteryID, ); $FreeSwapBatteryURL = "http://localhost/cygnusa/batterySwap/api/Admin/Swap/free_swap.php"; $FreeSwapBatteryCURL = curl_init($FreeSwapBatteryURL); curl_setopt($FreeSwapBatteryCURL, CURLOPT_HEADER, false); curl_setopt($FreeSwapBatteryCURL, CURLOPT_RETURNTRANSFER, true); curl_setopt($FreeSwapBatteryCURL, CURLOPT_POST, true); curl_setopt($FreeSwapBatteryCURL, CURLOPT_POSTFIELDS, $FreeSwapPostData); $SwapBatteryJsonResponse = curl_exec($FreeSwapBatteryCURL); } else if ($AvailableReferSwapCount>0){ $ReferSwapPostData = array( 'RiderID' => $RiderID, 'ReturnBatteryID' => $ReturnBatteryID, 'SwapBatteryID' => $SwapBatteryID, 'SwapReferID' => $SwapReferID, 'TotalReferSwapCount' => ($TotalReferSwapCount), 'UsedReferSwapCount' => ($UsedReferSwapCount+1), 'AvailableReferSwapCount' => ($AvailableReferSwapCount-1), ); $ReferSwapBatteryURL = "http://localhost/cygnusa/batterySwap/api/Admin/Swap/refer_swap.php"; $ReferSwapBatteryCURL = curl_init($ReferSwapBatteryURL); curl_setopt($ReferSwapBatteryCURL, CURLOPT_HEADER, false); curl_setopt($ReferSwapBatteryCURL, CURLOPT_RETURNTRANSFER, true); curl_setopt($ReferSwapBatteryCURL, CURLOPT_POST, true); curl_setopt($ReferSwapBatteryCURL, CURLOPT_POSTFIELDS, $ReferSwapPostData); $SwapBatteryJsonResponse = curl_exec($ReferSwapBatteryCURL); } else if ($AvailableRechargedSwapCount>0){ $RechargeSwapPostData = array( 'RiderID' => $RiderID, 'ReturnBatteryID' => $ReturnBatteryID, 'SwapBatteryID' => $SwapBatteryID, 'SwapRechargeID' => $SwapRechargeID, 'TotalRechargedSwapCount' => ($TotalRechargedSwapCount), 'UsedRechargedSwapCount' => ($UsedRechargedSwapCount+1), 'AvailableRechargedSwapCount' => ($AvailableRechargedSwapCount-1), ); $RechargeSwapBatteryURL = "http://localhost/cygnusa/batterySwap/api/Admin/Swap/Recharge_swap.php"; $RechargeSwapBatteryCURL = curl_init($RechargeSwapBatteryURL); curl_setopt($RechargeSwapBatteryCURL, CURLOPT_HEADER, false); curl_setopt($RechargeSwapBatteryCURL, CURLOPT_RETURNTRANSFER, true); curl_setopt($RechargeSwapBatteryCURL, CURLOPT_POST, true); curl_setopt($RechargeSwapBatteryCURL, CURLOPT_POSTFIELDS, $RechargeSwapPostData); $SwapBatteryJsonResponse = curl_exec($RechargeSwapBatteryCURL); } ////////////////////////////////////////////////////////////////////////////////////////////////////// $ReturnBatteryPostData = array( 'AssetID' => $ReturnBatteryID, "IsInServiceCenter"=>1, ); $ChangeReturnBatteryAssetURL = "http://localhost/cygnusa/batterySwap/api/Admin/Asset/change_asset.php"; $ChangeReturnBatteryAssetCURL = curl_init($ChangeReturnBatteryAssetURL); curl_setopt($ChangeReturnBatteryAssetCURL, CURLOPT_HEADER, false); curl_setopt($ChangeReturnBatteryAssetCURL, CURLOPT_RETURNTRANSFER, true); curl_setopt($ChangeReturnBatteryAssetCURL, CURLOPT_POST, true); curl_setopt($ChangeReturnBatteryAssetCURL, CURLOPT_POSTFIELDS, $ReturnBatteryPostData); $ReturnBatteryAssetJsonResponse = curl_exec($ChangeReturnBatteryAssetCURL); ///////////////////////////////////////////////////////////////////////////////////////////////////// $SwapBatteryPostData = array( 'AssetID' => $SwapBatteryID, "IsInServiceCenter"=>0, ); $ChangeSwapBatteryAssetURL = "http://localhost/cygnusa/batterySwap/api/Admin/Asset/change_asset.php"; $ChangeSwapBatteryAssetCURL = curl_init($ChangeSwapBatteryAssetURL); curl_setopt($ChangeSwapBatteryAssetCURL, CURLOPT_HEADER, false); curl_setopt($ChangeSwapBatteryAssetCURL, CURLOPT_RETURNTRANSFER, true); curl_setopt($ChangeSwapBatteryAssetCURL, CURLOPT_POST, true); curl_setopt($ChangeSwapBatteryAssetCURL, CURLOPT_POSTFIELDS, $SwapBatteryPostData); $SwapBatteryAssetJsonResponse = curl_exec($ChangeSwapBatteryAssetCURL); $value = array( "SwapResult"=>json_decode($SwapBatteryJsonResponse), "ReturnBatteryResult"=>json_decode($ReturnBatteryAssetJsonResponse), "SwapBatteryResult"=>json_decode($SwapBatteryAssetJsonResponse), "Message"=>"Swap done", ); // Use json_encode() function $json = json_encode($value); }else { $value = array( "Message"=>"Swap failed. Please recharge to swap", "Error"=>"Please recharge to swap" ); // Use json_encode() function $json = json_encode($value); } // Display the output echo($json); $conn->close();