From 5afe459ce64f33a84f821727b78b2e9b91d361c7 Mon Sep 17 00:00:00 2001 From: Sveneld Date: Thu, 16 May 2024 23:12:22 +0200 Subject: [PATCH] rent system qr code optimize --- actions-qrcode.php | 2 +- scan.php | 6 ++++-- src/Rent/AbstractRentSystem.php | 20 ++++++++++++++++++- src/Rent/RentSystemQR.php | 35 --------------------------------- src/Rent/RentSystemSms.php | 2 +- src/Rent/RentSystemWeb.php | 18 ++++------------- 6 files changed, 29 insertions(+), 54 deletions(-) diff --git a/actions-qrcode.php b/actions-qrcode.php index 3b330d8..bce5727 100644 --- a/actions-qrcode.php +++ b/actions-qrcode.php @@ -8,8 +8,8 @@ function response($message,$error=0,$log=1) $userid = $auth->getUserId(); $number = $user->findPhoneNumber($userid); logresult($number, $message); + $db->commit(); } - $db->commit(); echo '',$systemname,''; echo ''; echo ''; diff --git a/scan.php b/scan.php index b7f8023..5579f27 100644 --- a/scan.php +++ b/scan.php @@ -48,7 +48,8 @@ $bikeno = $parameter; checkbikeno($bikeno); if (!empty($_POST['rent']) && $_POST['rent'] == "yes") { - $rentSystem->rentBike($userid, $bikeno); + $result = $rentSystem->rentBike($userid, $bikeno); + response($result['message'], $result['error'], 0); } else { showrentform($userid, $bikeno); } @@ -57,7 +58,8 @@ logrequest($userid, $action); $stand = $parameter; checkstandname($stand); - $rentSystem->returnBike($userid, 0, $stand); + $result = $rentSystem->returnBike($userid, 0, $stand); + response($result['message'], $result['error'], 0); break; default: unrecognizedqrcode(); diff --git a/src/Rent/AbstractRentSystem.php b/src/Rent/AbstractRentSystem.php index 8a7f9fd..da07265 100644 --- a/src/Rent/AbstractRentSystem.php +++ b/src/Rent/AbstractRentSystem.php @@ -164,6 +164,7 @@ public function rentBike($userId, $bikeId, $force = false) $result = $this->db->query("INSERT INTO history SET userId=$userId,bikeNum=$bikeNum,action='FORCERENT',parameter=$newCode"); //$this->response(_('System override') . ": " . _('Your rented bike') . " " . $bikeNum . " " . _('has been rented by admin') . "."); } + return $this->response($message); } @@ -226,7 +227,19 @@ public function returnBike($userId, $bikeId, $standName, $note = '', $force = fa } abstract protected function getRentSystemType(); - abstract protected function response($message, $error = 0, $additional = '', $log = 1); + + protected function response($message, $error = 0) + { + $userid = $this->auth->getUserId(); + $number = $this->user->findPhoneNumber($userid); + $this->logResult($number, $message); + $this->db->commit(); + + return [ + 'error' => $error, + 'content' => $message, + ]; + } private function checktoomany($userId) { @@ -337,4 +350,9 @@ private function changecreditendrental($bike, $userid) return $creditchange; } } + + private function logResult($number, $message) + { + logresult($number, $message); + } } \ No newline at end of file diff --git a/src/Rent/RentSystemQR.php b/src/Rent/RentSystemQR.php index 10e237a..9f4c203 100644 --- a/src/Rent/RentSystemQR.php +++ b/src/Rent/RentSystemQR.php @@ -40,39 +40,4 @@ public function returnBike($userId, $bikeId, $standName, $note = '', $force = fa protected function getRentSystemType() { return 'qr'; } - - protected function response($message, $error = 0, $additional = '', $log = 1) - { - global $systemname, $systemURL; - - if ($log == 1 and $message) { - $userid = $this->auth->getUserId(); - $number = $this->user->findPhoneNumber($userid); - logresult($number, $message); - } - $this->db->commit(); - echo '',$systemname,''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - if (file_exists("analytics.php")) require("analytics.php"); - echo '
'; - if ($error) - { - echo ''; - } - else - { - echo ''; - } - echo '
'; - exit; - } } \ No newline at end of file diff --git a/src/Rent/RentSystemSms.php b/src/Rent/RentSystemSms.php index 16ded62..2e797aa 100644 --- a/src/Rent/RentSystemSms.php +++ b/src/Rent/RentSystemSms.php @@ -81,7 +81,7 @@ protected function getRentSystemType() { return 'sms'; } - protected function response($message, $error = 0, $additional = '', $log = 1) + protected function response($message, $error = 0) { $this->smsSender->send($this->number, strip_tags($message)); } diff --git a/src/Rent/RentSystemWeb.php b/src/Rent/RentSystemWeb.php index 2ea4d39..7d5b675 100644 --- a/src/Rent/RentSystemWeb.php +++ b/src/Rent/RentSystemWeb.php @@ -8,22 +8,12 @@ protected function getRentSystemType() { return 'web'; } - protected function response($message, $error = 0, $additional = '', $log = 1) + protected function response($message, $error = 0) { - $json = array('error' => $error, 'content' => $message); - if (is_array($additional)) { - foreach ($additional as $key => $value) { - $json[$key] = $value; - } - } - $json = json_encode($json); - if ($log == 1 && $message) { - $userid = $this->auth->getUserId(); + $response = parent::response($message, $error); + + $json = json_encode($response); - $number = $this->user->findPhoneNumber($userid); - logresult($number, $message); - } - $this->db->commit(); echo $json; exit; }