recharge_swap.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. include_once "../../include/DB.php";
  3. $RiderID="";
  4. $ReturnBatteryID="";
  5. $SwapBatteryID="";
  6. $SwapRechargeID="";
  7. $TotalRechargedSwapCount="";
  8. $UsedRechargedSwapCount="";
  9. $AvailableRechargedSwapCount="";
  10. if (isset($_POST["RiderID"]) && !empty($_POST["RiderID"])) {
  11. $RiderID=$_POST["RiderID"];
  12. }
  13. if (isset($_POST["ReturnBatteryID"]) && !empty($_POST["ReturnBatteryID"])) {
  14. $ReturnBatteryID=$_POST["ReturnBatteryID"];
  15. }
  16. if (isset($_POST["SwapBatteryID"]) && !empty($_POST["SwapBatteryID"])) {
  17. $SwapBatteryID=$_POST["SwapBatteryID"];
  18. }
  19. if (isset($_POST["SwapRechargeID"]) && !empty($_POST["SwapRechargeID"])) {
  20. $SwapRechargeID=$_POST["SwapRechargeID"];
  21. }
  22. if (isset($_POST["TotalRechargedSwapCount"]) && !empty($_POST["TotalRechargedSwapCount"])) {
  23. $TotalRechargedSwapCount=$_POST["TotalRechargedSwapCount"];
  24. }
  25. if (isset($_POST["UsedRechargedSwapCount"]) && !empty($_POST["UsedRechargedSwapCount"])) {
  26. $UsedRechargedSwapCount=$_POST["UsedRechargedSwapCount"];
  27. }
  28. if (isset($_POST["AvailableRechargedSwapCount"]) && !empty($_POST["AvailableRechargedSwapCount"])) {
  29. $AvailableRechargedSwapCount=$_POST["AvailableRechargedSwapCount"];
  30. }
  31. $SwapInsertSql = "INSERT INTO swap(RiderID, SwapRechargeID, ReturnBatterID, SwappedBatterID,IsFreeSwap) VALUES ('$RiderID','$SwapRechargeID','$ReturnBatteryID','$SwapBatteryID','0')";
  32. $SwapInsertresult = $conn->query($SwapInsertSql);
  33. if ($SwapInsertresult === TRUE) {
  34. $RechargePostData = array(
  35. 'SwapRechargeID' => $SwapRechargeID,
  36. 'TotalRechargedSwapCount' => $TotalRechargedSwapCount,
  37. 'UsedRechargedSwapCount' => $UsedRechargedSwapCount,
  38. 'AvailableRechargedSwapCount' => $AvailableRechargedSwapCount,
  39. );
  40. $RechargeURL = "http://localhost/cygnusa/batterySwap/api/Admin/Recharge/";
  41. $RechargeCURL = curl_init($RechargeURL);
  42. curl_setopt($RechargeCURL, CURLOPT_HEADER, false);
  43. curl_setopt($RechargeCURL, CURLOPT_RETURNTRANSFER, true);
  44. curl_setopt($RechargeCURL, CURLOPT_POST, true);
  45. curl_setopt($RechargeCURL, CURLOPT_POSTFIELDS, $RechargePostData);
  46. $RechargeJsonResponse = curl_exec($RechargeCURL);
  47. $value = array(
  48. "RiderID"=>$RiderID,
  49. "ReturnBatteryID"=>$ReturnBatteryID,
  50. "SwapBatteryID"=>$SwapBatteryID,
  51. "Recharge"=>$RechargeJsonResponse,
  52. "Message"=>"Swap Data saved successfully",
  53. );
  54. // Use json_encode() function
  55. $json = json_encode($value);
  56. }else {
  57. http_response_code(404);
  58. $errorMesage= $conn->error;
  59. // Declare an array with error message
  60. $value = array(
  61. "Message"=>"Something went wrong",
  62. "Error"=>$errorMesage
  63. );
  64. // Use json_encode() function
  65. $json = json_encode($value);
  66. }
  67. // Display the output
  68. echo ($json);
  69. $conn->close();