| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <?php
- include_once "../../include/DB.php";
- $RiderID="";
- $ReturnBatteryID="";
- $SwapBatteryID="";
- $SwapReferID="";
- $TotalReferdSwapCount="";
- $UsedReferdSwapCount="";
- $AvailableReferdSwapCount="";
- if (isset($_POST["RiderID"]) && !empty($_POST["RiderID"])) {
- $RiderID=$_POST["RiderID"];
- }
- if (isset($_POST["ReturnBatteryID"]) && !empty($_POST["ReturnBatteryID"])) {
- $ReturnBatteryID=$_POST["ReturnBatteryID"];
- }
- if (isset($_POST["SwapBatteryID"]) && !empty($_POST["SwapBatteryID"])) {
- $SwapBatteryID=$_POST["SwapBatteryID"];
- }
- if (isset($_POST["SwapReferID"]) && !empty($_POST["SwapReferID"])) {
- $SwapReferID=$_POST["SwapReferID"];
- }
- if (isset($_POST["TotalReferdSwapCount"]) && !empty($_POST["TotalReferdSwapCount"])) {
- $TotalReferdSwapCount=$_POST["TotalReferdSwapCount"];
- }
- if (isset($_POST["UsedReferdSwapCount"]) && !empty($_POST["UsedReferdSwapCount"])) {
- $UsedReferdSwapCount=$_POST["UsedReferdSwapCount"];
- }
- if (isset($_POST["AvailableReferdSwapCount"]) && !empty($_POST["AvailableReferdSwapCount"])) {
- $AvailableReferdSwapCount=$_POST["AvailableReferdSwapCount"];
- }
- $SwapInsertSql = "INSERT INTO swap(RiderID, SwapReferID, ReturnBatterID, SwappedBatterID, IsFreeSwap) VALUES ('$RiderID','$SwapReferID','$ReturnBatteryID','$SwapBatteryID','0')";
- $SwapInsertresult = $conn->query($SwapInsertSql);
- if ($SwapInsertresult === TRUE) {
- $ReferPostData = array(
- 'SwapReferID' => $SwapReferID,
- 'TotalReferdSwapCount' => $TotalReferdSwapCount,
- 'UsedReferdSwapCount' => $UsedReferdSwapCount,
- 'AvailableReferdSwapCount' => $AvailableReferdSwapCount,
- );
- $ReferURL = "http://localhost/cygnusa/batterySwap/api/Admin/Refer";
- $ReferCURL = curl_init($ReferURL);
- curl_setopt($ReferCURL, CURLOPT_HEADER, false);
- curl_setopt($ReferCURL, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ReferCURL, CURLOPT_POST, true);
- curl_setopt($ReferCURL, CURLOPT_POSTFIELDS, $ReferPostData);
- $ReferJsonResponse = curl_exec($ReferCURL);
- $value = array(
- "RiderID"=>$RiderID,
- "ReturnBatteryID"=>$ReturnBatteryID,
- "SwapBatteryID"=>$SwapBatteryID,
- "Refer"=>$ReferJsonResponse,
- "Message"=>"Swap Data saved successfully",
- );
- // Use json_encode() function
- $json = json_encode($value);
- }else {
- http_response_code(404);
- $errorMesage= $conn->error;
- // Declare an array with error message
- $value = array(
- "Message"=>"Something went wrong",
- "Error"=>$errorMesage
- );
- // Use json_encode() function
- $json = json_encode($value);
- }
- // Display the output
- echo ($json);
- $conn->close();
|