refer_swap.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. include_once "../../include/DB.php";
  3. $RiderID="";
  4. $ReturnBatteryID="";
  5. $SwapBatteryID="";
  6. $SwapReferID="";
  7. $TotalReferdSwapCount="";
  8. $UsedReferdSwapCount="";
  9. $AvailableReferdSwapCount="";
  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["SwapReferID"]) && !empty($_POST["SwapReferID"])) {
  20. $SwapReferID=$_POST["SwapReferID"];
  21. }
  22. if (isset($_POST["TotalReferdSwapCount"]) && !empty($_POST["TotalReferdSwapCount"])) {
  23. $TotalReferdSwapCount=$_POST["TotalReferdSwapCount"];
  24. }
  25. if (isset($_POST["UsedReferdSwapCount"]) && !empty($_POST["UsedReferdSwapCount"])) {
  26. $UsedReferdSwapCount=$_POST["UsedReferdSwapCount"];
  27. }
  28. if (isset($_POST["AvailableReferdSwapCount"]) && !empty($_POST["AvailableReferdSwapCount"])) {
  29. $AvailableReferdSwapCount=$_POST["AvailableReferdSwapCount"];
  30. }
  31. $SwapInsertSql = "INSERT INTO swap(RiderID, SwapReferID, ReturnBatterID, SwappedBatterID, IsFreeSwap) VALUES ('$RiderID','$SwapReferID','$ReturnBatteryID','$SwapBatteryID','0')";
  32. $SwapInsertresult = $conn->query($SwapInsertSql);
  33. if ($SwapInsertresult === TRUE) {
  34. $ReferPostData = array(
  35. 'SwapReferID' => $SwapReferID,
  36. 'TotalReferdSwapCount' => $TotalReferdSwapCount,
  37. 'UsedReferdSwapCount' => $UsedReferdSwapCount,
  38. 'AvailableReferdSwapCount' => $AvailableReferdSwapCount,
  39. );
  40. $ReferURL = "http://localhost/cygnusa/batterySwap/api/Admin/Refer";
  41. $ReferCURL = curl_init($ReferURL);
  42. curl_setopt($ReferCURL, CURLOPT_HEADER, false);
  43. curl_setopt($ReferCURL, CURLOPT_RETURNTRANSFER, true);
  44. curl_setopt($ReferCURL, CURLOPT_POST, true);
  45. curl_setopt($ReferCURL, CURLOPT_POSTFIELDS, $ReferPostData);
  46. $ReferJsonResponse = curl_exec($ReferCURL);
  47. $value = array(
  48. "RiderID"=>$RiderID,
  49. "ReturnBatteryID"=>$ReturnBatteryID,
  50. "SwapBatteryID"=>$SwapBatteryID,
  51. "Refer"=>$ReferJsonResponse,
  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();