mirror of
https://gitlab.com/t6353/sharee.bike.git
synced 2025-02-22 11:46:27 +01:00
sigo api reserve and rental
This commit is contained in:
parent
5870071d1b
commit
9c0e5f78e8
7 changed files with 444 additions and 68 deletions
|
@ -6,7 +6,7 @@ package APIfunc;
|
|||
#Server methods for sharee API
|
||||
#
|
||||
#perl -cw
|
||||
#use lib qw(/var/www/copri4/tinkdms/src);
|
||||
#use lib qw(/var/www/copri-bike/shareeapp-operator/src);
|
||||
#
|
||||
use strict;
|
||||
use warnings;
|
||||
|
@ -25,6 +25,7 @@ use Mod::DBtank;
|
|||
use Mod::Callib;
|
||||
use Mod::Basework;
|
||||
use Mod::Pricing;
|
||||
#use Mod::APIsigoclient;#no!
|
||||
use Data::Dumper;
|
||||
use Sys::Hostname;
|
||||
my $hostname = hostname;
|
||||
|
@ -35,6 +36,7 @@ my $dbt = new DBtank;
|
|||
my $cal = new Callib;
|
||||
my $bw = new Basework;
|
||||
my $pri = new Pricing;
|
||||
#my $si = new APIsigoclient;
|
||||
|
||||
sub new {
|
||||
my $class = shift;
|
||||
|
@ -768,7 +770,223 @@ sub service_work {
|
|||
}#end service_work
|
||||
|
||||
|
||||
#check and set user-bike rental tarif
|
||||
sub fetch_bike_tariff {
|
||||
my $self = shift;
|
||||
my $varenv = shift;
|
||||
my $auth = shift;
|
||||
my $bike = shift;
|
||||
my $owner = shift;
|
||||
|
||||
my $bike_id = "";
|
||||
$bike_id = $1 if($bike =~ /(\d+)/);
|
||||
|
||||
my $main_ids = "";
|
||||
my ($bike_group,$user_group,$tariff_content,$user_tour) = $self->fetch_tariff($varenv->{dbname},$auth,"");
|
||||
$main_ids = join(",",@{$bike_group});
|
||||
$main_ids =~ s/[a-z_]+//ig;
|
||||
my $ct_bike = {};
|
||||
my $pref_cc = {
|
||||
table => "content",
|
||||
fetch => "one",
|
||||
main_id => "IN::($main_ids)",
|
||||
barcode => $bike_id,
|
||||
#int10 => 1,
|
||||
};
|
||||
|
||||
$ct_bike = $dbt->fetch_record($dbh,$pref_cc) if($main_ids);
|
||||
|
||||
#$tariff_nr in contentadr are saved by copri or user tarif-select!!!
|
||||
my $tariff_nr = "";
|
||||
my @adr_tariff = ();
|
||||
if($auth->{txt30}){
|
||||
@adr_tariff = ("$auth->{txt30}");
|
||||
@adr_tariff = split(/\s+/,$auth->{txt30}) if($auth->{txt30} =~ /\w\s+\w/);
|
||||
}
|
||||
|
||||
#This is the automatic user tariff setter
|
||||
if(ref($ct_bike) eq "HASH" && $ct_bike->{main_id}){
|
||||
foreach my $id (keys (%$tariff_content)){
|
||||
foreach(@adr_tariff){
|
||||
$bw->log("booking_request adr_tariff array form $auth->{txt30}",$_,"");
|
||||
if($tariff_content->{$id}->{int12} && $tariff_content->{$id}->{int12} == $ct_bike->{main_id} && $tariff_content->{$id}->{barcode} && $_ == $tariff_content->{$id}->{barcode}){
|
||||
$bw->log("booking_request tariff loop matches:",$tariff_content->{$id}->{barcode},"");
|
||||
$tariff_nr = $tariff_content->{$id}->{barcode};
|
||||
}
|
||||
}
|
||||
}
|
||||
#if no tarif then update user account to fallback default public or private or hidden tarif
|
||||
if(!$tariff_nr){
|
||||
|
||||
my $update_adr = {
|
||||
table => "contentadr",
|
||||
mtime => "now()",
|
||||
owner => "$owner",
|
||||
c_id => "$auth->{c_id}",
|
||||
};
|
||||
|
||||
my @txt30 = ();
|
||||
foreach my $id (keys (%$tariff_content)){
|
||||
#</sharing_type>
|
||||
if($tariff_content->{$id}->{int18} && ($tariff_content->{$id}->{int18} == 2 || $tariff_content->{$id}->{int18} == 3 || $tariff_content->{$id}->{int18} == 4)){
|
||||
|
||||
#auto set tarif if requested bike matches flot
|
||||
if($tariff_content->{$id}->{int12} && $tariff_content->{$id}->{int12} == $ct_bike->{main_id} && $tariff_content->{$id}->{barcode}){
|
||||
$bw->log("booking_request tariff loop matches:",$tariff_content->{$id}->{barcode},"");
|
||||
$tariff_nr = $tariff_content->{$id}->{barcode};
|
||||
push(@txt30, "$tariff_content->{$id}->{barcode}");
|
||||
}
|
||||
#add also other public tarif
|
||||
elsif($tariff_content->{$id}->{int18} && $tariff_content->{$id}->{int18} == 2 && $tariff_content->{$id}->{int12} && $tariff_content->{$id}->{barcode}){
|
||||
push(@txt30, "$tariff_content->{$id}->{barcode}");
|
||||
}
|
||||
}
|
||||
}
|
||||
$bw->log("booking_request NO user tariff defined, update user account to fallback default public or private or hidden",\@txt30,"");
|
||||
$dbt->update_one($dbh,$update_adr,"txt30='@txt30'");
|
||||
}else{
|
||||
$bw->log("booking_request user tariff selected",$tariff_nr,"");
|
||||
}
|
||||
}
|
||||
|
||||
$bw->log("booking_request fetch_bike_tariff result ---> bike $ct_bike->{barcode} matching by bike_group: @{$bike_group} main_ids:$main_ids | user_group:@{$user_group} | Tarif selected: $tariff_nr",$tariff_content->{$tariff_nr},"");
|
||||
|
||||
return ($ct_bike,$tariff_content->{$tariff_nr});
|
||||
}
|
||||
|
||||
#2022-04-05 refactored bike reservation
|
||||
sub booking_request(){
|
||||
my $self = shift;
|
||||
my $varenv = shift;
|
||||
my $auth = shift;#app API auth
|
||||
my $bike = shift || "";#app API request
|
||||
my $ct_bike = shift || {};
|
||||
my $ct_tariff = shift;
|
||||
my $owner = shift || "";
|
||||
my $gps = shift || "";
|
||||
my $reserveid = shift || "";
|
||||
|
||||
my $dbh = "";
|
||||
my $bike_id = "";
|
||||
$bike_id = $1 if($bike =~ /(\d+)/);
|
||||
|
||||
my $pos_id="";
|
||||
my $now_dt = strftime "%Y-%m-%d %H:%M", localtime;
|
||||
my $response_state = "OK";
|
||||
my $response_text = "";
|
||||
|
||||
$bw->log("booking_request ct_bike $ct_bike->{barcode}, auth $auth->{c_id}, tarif $ct_tariff->{barcode}, requested bike:",$bike,"");
|
||||
|
||||
my $update_adr = {
|
||||
table => "contentadr",
|
||||
mtime => "now()",
|
||||
owner => "$owner",
|
||||
c_id => "$auth->{c_id}",
|
||||
};
|
||||
|
||||
my $pref = {
|
||||
table => "contenttrans",
|
||||
fetch => "one",
|
||||
main_id => 300008,
|
||||
template_id => 218,
|
||||
#ca_id => "$auth->{c_id}",#future change
|
||||
int10 => "$auth->{c_id}",
|
||||
state => "null",
|
||||
close_time => "is::null",
|
||||
};
|
||||
|
||||
my $booking_pos = {
|
||||
table => "contenttranspos",
|
||||
fetch => "one",
|
||||
barcode => "$bike_id",
|
||||
int10 => "IN::('2','3')",
|
||||
ca_id => "$auth->{c_id}",
|
||||
};
|
||||
|
||||
|
||||
#if bike and tariff
|
||||
if($ct_bike->{barcode} && $ct_tariff->{barcode}){
|
||||
my $ctt = {};
|
||||
my $rentable_check=0;
|
||||
$rentable_check = $self->isuser_rentable($auth,$varenv);
|
||||
|
||||
$bw->log("booking_request isuser_rentable:",$rentable_check,"");
|
||||
|
||||
if($rentable_check == 2){
|
||||
|
||||
#get invoice
|
||||
$ctt = $dbt->fetch_record($dbh,$pref);
|
||||
if(!$ctt->{c_id}){
|
||||
my $ct_id = $dbt->insert_contenttrans($dbh,$auth,"300008","218","----","$owner");
|
||||
$pref->{c_id} = $ct_id;
|
||||
$ctt = $dbt->fetch_record($dbh,$pref) if($pref->{c_id});
|
||||
}
|
||||
$bw->log("booking_request used invoice c_id:",$ctt->{c_id},"");
|
||||
|
||||
#if invoice exist
|
||||
if($ctt->{c_id}){
|
||||
|
||||
#2 = "requested"
|
||||
$pos_id = $dbt->insert_pos($dbh,$ctt->{c_id},$ct_bike,$auth,$ct_tariff,$now_dt,$bike,"2",$owner,$reserveid);
|
||||
$bw->log("booking_request insert_pos:",$pos_id,"");
|
||||
|
||||
if($pos_id){
|
||||
$response_state = "OK, bike " . $bike . " succesfully requested";
|
||||
$response_text = "Fahrrad Nr. $bike wurde erfolgreich für 15 Min. reserviert";
|
||||
$bw->log("booking_request insert contenttranspos pos_id: $pos_id\n","","");
|
||||
|
||||
my $update_ctt = {
|
||||
table => "contenttrans",
|
||||
c_id => $ctt->{c_id},
|
||||
};
|
||||
$dbt->update_one($dbh,$update_ctt,"start_time='$now_dt'");
|
||||
}else{
|
||||
$response_state="Failure 1007: booking request fails";
|
||||
$response_text="Entschuldigung, es ist ein Fehler aufgetreten. Bitte kontaktieren Sie unsere hotline damit wir das Problem lösen können";
|
||||
}
|
||||
}
|
||||
}elsif($rentable_check == 1){
|
||||
$response_state="Failure 1006: There is no valid payment methode";
|
||||
$response_text="Bitte überprüfen Sie Ihre Profildaten auf Vollständigkeit, nur dann können wir das Mietradsystem für Sie freischalten";
|
||||
}else{
|
||||
my $vde = $auth->{int12} || 1;
|
||||
$dbt->update_one($dbh,$update_adr,"int12=$vde");
|
||||
$response_state="Failure 1005: user-account deactivated because of failing data";
|
||||
$response_text="Bitte überprüfen Sie Ihre Profildaten auf Vollständigkeit, nur dann können wir das Mietradsystem für Sie freischalten";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
my $return = {
|
||||
bike => "$bike",
|
||||
state => "requested",
|
||||
response_state => "$response_state",
|
||||
response_text => "$response_text"
|
||||
};
|
||||
$bw->log("booking_request response_state:",$return,"");
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
#int03=1 if sepa, 2=CC
|
||||
#int04==1 if email Ack
|
||||
#int13==1 if sms Ack
|
||||
#int12!=1|2|3 if Vde
|
||||
#int14==1 if AGB
|
||||
sub isuser_rentable {
|
||||
my $self = shift;
|
||||
my $auth = shift;
|
||||
my $varenv = shift;
|
||||
|
||||
my $rentable_check=0;
|
||||
if(($auth->{int03} == 1 && $auth->{ct_name} =~ /\w{2}-\d+/ && $auth->{ct_name} !~ /LV-\d+/) || ($auth->{int03} == 2 && length($auth->{ct_name}) >= 19) || ($auth->{int03} == 1 && $varenv->{dbname} eq "sharee_lv" && $auth->{ct_name} =~ /LV-\d+/)){
|
||||
$rentable_check=1;
|
||||
if($auth->{txt08} && $auth->{int04} == 1 && $auth->{int13} == 1 && !$auth->{int12} && $auth->{int14}){
|
||||
$rentable_check=2;
|
||||
}
|
||||
}
|
||||
return $rentable_check;
|
||||
}
|
||||
|
||||
#booking_cancel changed to booking_update
|
||||
sub booking_update(){
|
||||
|
@ -777,6 +995,8 @@ sub booking_update(){
|
|||
my $varenv = shift;
|
||||
my $auth = shift;
|
||||
my $owner = shift || 0;
|
||||
my $rentalid = shift || "";
|
||||
|
||||
my $state = $q->escapeHTML($q->param('state')) || "";
|
||||
my $lock_state = $q->escapeHTML($q->param('lock_state')) || "";
|
||||
my $station_state = $q->escapeHTML($q->param('station_state')) || "";
|
||||
|
@ -920,6 +1140,7 @@ sub booking_update(){
|
|||
$update_pos->{owner} = "$owner";
|
||||
|
||||
$update_pos->{int10} = "$state_key";
|
||||
$update_pos->{txt11} = "$rentalid";
|
||||
$rows = $dbt->update_record($dbh,$update_pos,$record_pos);
|
||||
|
||||
if($rows > 0){
|
||||
|
@ -938,6 +1159,7 @@ sub booking_update(){
|
|||
$update_pos->{int03} = "$pricing->{computed_hours}" if(looks_like_number($pricing->{computed_hours}));
|
||||
|
||||
$update_pos->{int10} = "$state_key";
|
||||
$update_pos->{txt11} = "$rentalid";
|
||||
$rows = $dbt->update_record($dbh,$update_pos,$record_pos);
|
||||
|
||||
$booking_values->{response_state} = "OK: available bike " . $q->param('bike') . ", still locked";
|
||||
|
@ -973,6 +1195,7 @@ sub booking_update(){
|
|||
$update_cc->{int04} = "$stations_raw->{$id}->{int04}";
|
||||
$update_pos->{int24} = "1";
|
||||
$update_pos->{int10} = "$state_key";
|
||||
$update_pos->{txt11} = "$rentalid";
|
||||
$update_cc->{txt06} = "$gps";#end content coordinates
|
||||
$update_pos->{txt06} = "$gps";#end pos coordinates
|
||||
$update_pos->{int21} = "$gps_age_minutes";
|
||||
|
@ -2459,3 +2682,4 @@ sub authcookie_manager {
|
|||
}
|
||||
|
||||
1;
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ sub handler {
|
|||
my $jsc = new APIjsonclient;
|
||||
my $si = new APIsigoclient;
|
||||
|
||||
|
||||
my $dbh = "";
|
||||
my %varenv = $cf->envonline();
|
||||
my $oprefix = $dbt->{operator}->{$varenv{dbname}}->{oprefix};
|
||||
my $now_dt = strftime "%Y-%m-%d %H:%M:%S", localtime;
|
||||
|
@ -190,14 +190,25 @@ elsif($q->param('request') eq "booking_request"){
|
|||
my ($auth,$authraw) = $apif->auth_verify($q);
|
||||
$response = { %$response, %$auth };
|
||||
if(ref($auth) eq "HASH" && $auth->{authcookie}){
|
||||
if($q->param('bike')){
|
||||
#check count of occcupied/requested bikes
|
||||
my $record = $apif->user_bikes_occupied($q,$authraw);
|
||||
my $bikes_occupied = $apif->rentals($record,$authraw,"1");
|
||||
my $count=0;
|
||||
foreach my $id (keys(%$bikes_occupied)){
|
||||
my $bike = $q->escapeHTML($q->param('bike')) || "";
|
||||
if($bike){
|
||||
my $bike_id = "";
|
||||
$bike_id = $1 if($bike =~ /(\d+)/);
|
||||
|
||||
#check count of occcupied/requested bikes
|
||||
my $record = $apif->user_bikes_occupied($q,$authraw);
|
||||
my $count=0;
|
||||
my $still_requested = 0;
|
||||
foreach my $id (keys(%$record)){
|
||||
$count++;
|
||||
}
|
||||
if($bike_id && $bike_id == $record->{$id}->{barcode}){
|
||||
$still_requested = 1;
|
||||
$response->{response_state} = "OK, bike " . $bike . " already requested or occupied";
|
||||
$response->{response_text} = "Fahrrad Nr. " . $bike . " ist bereits reserviert";
|
||||
}
|
||||
}
|
||||
|
||||
if(!$still_requested){
|
||||
#only if not debug
|
||||
if(!$authraw->{int11} && $count >= 3){
|
||||
$response->{response_state} = "Failure: booking_request declined. max count of 3 occupied bikes has been reached";
|
||||
|
@ -222,40 +233,66 @@ elsif($q->param('request') eq "booking_request"){
|
|||
$longitude = $1 if($longitude_in =~ /(\d+\.\d+)/);
|
||||
$gps = "$latitude,$longitude" if($latitude && $longitude);
|
||||
}
|
||||
|
||||
my $response_book = {};
|
||||
#2022-04-07 refactored booking_request
|
||||
#if($varenv{syshost} eq "shareeapp-sx"){
|
||||
my $ct_bike = {};
|
||||
my $ct_tariff = {};
|
||||
($ct_bike,$ct_tariff) = $apif->fetch_bike_tariff(\%varenv,$authraw,$bike,$aowner);
|
||||
|
||||
if($ct_bike->{barcode} && $ct_tariff->{barcode}){
|
||||
my $reserveid = "";
|
||||
if($ct_bike->{int11} == 3){
|
||||
my $sigo_book = $si->sigo_booking(\%varenv,$auth,$ct_bike,"reserve");
|
||||
$reserveid = $sigo_book->{reservationId} if($sigo_book->{reservationId});
|
||||
}
|
||||
$response_book = $apif->booking_request(\%varenv,$authraw,$bike,$ct_bike,$ct_tariff,$aowner,$gps,$reserveid);
|
||||
}elsif(!$ct_tariff->{barcode}){
|
||||
$response->{response_state} = "Failure 2089: booking bike $bike fails, no user tariff available";
|
||||
$response->{response_text} = "Reservierungsfehler Fahrrad Nr. $bike. Es konnte kein Mietrad Tarif gefunden werden.";
|
||||
}elsif(!$ct_bike->{barcode}){
|
||||
$response->{response_state} = "Failure 2001: booking bike $bike fails, bike not available";
|
||||
$response->{response_text} = "Fahrrad Nr. $bike ist leider nicht verfügbar. Ist die Mietrad Flotte für sie freigeschaltet? Bitte überprüfen Sie Ihre Profildaten auf Vollständigkeit";
|
||||
}
|
||||
#}else{
|
||||
#2022-04-05 should be obsolet, use booking_request @all
|
||||
#$response_book = $tk->net_booking($authraw,$q->param('bike'),$aowner,$gps);
|
||||
#}
|
||||
|
||||
my $response_book = $tk->net_booking($authraw,$q->param('bike'),$aowner,$gps);
|
||||
|
||||
#just in time booking
|
||||
if(ref($response_book) eq "HASH" && $response_book->{response_state} =~ /OK/ && $q->param('state') && $q->param('state') =~ /occupied/){
|
||||
(my $rows, my $booking_values) = $apif->booking_update($q,\%varenv,$authraw,$aowner);
|
||||
$response = {%$response, %$booking_values};
|
||||
my $ctpos = {};
|
||||
my $booking_pos = {
|
||||
table => "contenttranspos",
|
||||
fetch => "one",
|
||||
barcode => "$bike_id",
|
||||
int10 => "IN::('2','3')",
|
||||
ca_id => "$authraw->{c_id}",
|
||||
};
|
||||
my $dbh = "";
|
||||
$ctpos = $dbt->fetch_tablerecord($dbh,$booking_pos);
|
||||
my $rentalid = "";
|
||||
if($ctpos->{int11} == 3){
|
||||
my $sigo_book = $si->sigo_booking(\%varenv,$auth,$ctpos,"rental");
|
||||
$rentalid = $sigo_book->{rentalId} if($sigo_book->{rentalId});
|
||||
}
|
||||
|
||||
(my $rows, my $booking_values) = $apif->booking_update($q,\%varenv,$authraw,$aowner,$rentalid);
|
||||
$response = {%$response, %$booking_values};
|
||||
}else{
|
||||
$response = {%$response, %$response_book};
|
||||
$response = {%$response, %$response_book};
|
||||
}
|
||||
}
|
||||
|
||||
$record = $apif->user_bikes_occupied($q,$authraw);
|
||||
$bikes_occupied = $apif->rentals($record,$authraw,"1");
|
||||
|
||||
foreach my $id (keys(%$bikes_occupied)){
|
||||
if($bikes_occupied->{$id}->{bike} eq $q->param('bike')){
|
||||
if($bikes_occupied->{$id}->{int10} == 2){
|
||||
$response->{response_state} = "OK, bike " . $q->param('bike') . " requested";
|
||||
$response->{response_text} = "Fahrrad Nr. " . $q->param('bike') . " ist reserviert";
|
||||
}elsif($bikes_occupied->{$id}->{int10} == 3){
|
||||
$response->{response_state} = "OK, bike " . $q->param('bike') . " requested and occupied";
|
||||
$response->{response_text} = "Fahrrad Nr. " . $q->param('bike') . " ist gemietet";
|
||||
}
|
||||
}
|
||||
}
|
||||
#return list of occupied/requested bikes
|
||||
$record = $apif->user_bikes_occupied($q,$authraw);
|
||||
$response->{bikes_occupied} = $apif->rentals($record,$authraw,"1");#returns JSON rental values
|
||||
|
||||
}#end still_requested
|
||||
}else{
|
||||
$response->{response_state} = "Failure: no bike defined";
|
||||
$response->{response_text} = "Abbruch, es wurde kein Fahrrad ausgewählt";
|
||||
$response->{timeCode} = 0;#if fails
|
||||
}
|
||||
}else{
|
||||
$response->{response_state} = "Failure 1001: authcookie not defined";
|
||||
|
@ -278,12 +315,36 @@ elsif($q->param('request') eq "booking_cancel" || $q->param('request') eq "booki
|
|||
$response = { %$response, %$auth };
|
||||
|
||||
if(ref($auth) eq "HASH" && $auth->{authcookie}){
|
||||
if($q->param('bike')){
|
||||
my $bike = $q->escapeHTML($q->param('bike')) || "";
|
||||
if($bike){
|
||||
my $bike_id = "";
|
||||
$bike_id = $1 if($bike =~ /(\d+)/);
|
||||
|
||||
my $ctpos = {};
|
||||
my $booking_pos = {
|
||||
table => "contenttranspos",
|
||||
fetch => "one",
|
||||
barcode => "$bike_id",
|
||||
int10 => "IN::('2','3')",
|
||||
ca_id => "$authraw->{c_id}",
|
||||
};
|
||||
$ctpos = $dbt->fetch_tablerecord($dbh,$booking_pos);
|
||||
|
||||
if($q->param('request') eq "booking_update" && $q->param('state') && $q->param('state') =~ /canceled/){
|
||||
|
||||
#TODO sigo request
|
||||
($rows, my $booking_values) = $apif->booking_update($q,\%varenv,$authraw,$aowner);
|
||||
$response = {%$response, %$booking_values};
|
||||
}elsif($q->param('request') eq "booking_update" && (($q->param('state') && $q->param('state') =~ /occupied|available/) || ($q->param('lock_state') && $q->param('lock_state') =~ /locking|locked|unlocking|unlocked/))){
|
||||
($rows, my $booking_values) = $apif->booking_update($q,\%varenv,$authraw,$aowner);
|
||||
|
||||
|
||||
my $rentalid = "";
|
||||
if($ctpos->{int11} == 3){
|
||||
my $sigo_book = $si->sigo_booking(\%varenv,$auth,$ctpos,"cancel");
|
||||
$rentalid = $sigo_book->{rentalId} if($sigo_book->{rentalId});
|
||||
}
|
||||
|
||||
($rows, my $booking_values) = $apif->booking_update($q,\%varenv,$authraw,$aowner,$rentalid);
|
||||
$response = {%$response, %$booking_values};
|
||||
|
||||
#keep in mind, it works on operator dependency
|
||||
|
@ -346,7 +407,6 @@ elsif($q->param('request') eq "booking_cancel" || $q->param('request') eq "booki
|
|||
atime => "now()",
|
||||
owner => "198",
|
||||
};
|
||||
my $dbh = "";
|
||||
my $rows = $dbt->update_record($dbh,$update_op,$authraw);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,17 +70,23 @@ sub sigo_available {
|
|||
$authed = 1 if(ref($auth) eq "HASH" && $auth->{c_id} && $auth->{c_id} > 0);
|
||||
(my $bike_group,my $user_group,$tariff_content,my $user_tour) = $apif->fetch_tariff($varenv->{dbname},$auth,$q->param('authcookie'));
|
||||
|
||||
my $hotline_hash = {
|
||||
table => "contentuser",
|
||||
fetch => "one",
|
||||
template_id => 197,
|
||||
c_id => "1",
|
||||
};
|
||||
my $hotline_data = $dbt->fetch_record($dbh,$hotline_hash);
|
||||
|
||||
open(FILE,">>$varenv->{logdir}/APIsigo_client.log");
|
||||
print FILE "\n*** $now_dt 'sigo client' \n";
|
||||
print FILE "\n*** $now_dt 'sigo_available' \n";
|
||||
|
||||
#my $endpoint = "https://sigo.dev.sigo.green/api/v1/bikes";
|
||||
my $endpoint = "$dbt->{operator}->{$varenv->{dbname}}->{endpoint}/bikes";
|
||||
|
||||
|
||||
my $response_out = {};
|
||||
my $return2copri = {};
|
||||
my $rest_json = "";
|
||||
my $ret_json = get_sigo("$endpoint",$rest_json);
|
||||
my $ret_json = $self->get_sigo("$endpoint",$rest_json);
|
||||
eval {
|
||||
$response_in = decode_json($ret_json);
|
||||
print FILE "<--- station_and_bikes response_in:\n";
|
||||
|
@ -112,7 +118,20 @@ sub sigo_available {
|
|||
}elsif($resp->{site}->{status} eq "OFFLINE"){
|
||||
$response_out->{$station}->{state} = "defect";
|
||||
}
|
||||
$response_out->{$station}->{operator_data} = {};
|
||||
$response_out->{$station}->{operator_data} = {
|
||||
"operator_name" => "",
|
||||
"operator_hours" => "",
|
||||
"operator_color" => "",
|
||||
"operator_logo" => "",
|
||||
"operator_phone" => "",
|
||||
"operator_email" => "",
|
||||
};
|
||||
$response_out->{$station}->{operator_data}->{operator_name} = Encode::encode('utf-8', Encode::decode('iso-8859-1',$hotline_data->{txt01})) if($hotline_data->{txt01});
|
||||
$response_out->{$station}->{operator_data}->{operator_hours} = Encode::encode('utf-8', Encode::decode('iso-8859-1',$hotline_data->{txt84})) if($hotline_data->{txt84});
|
||||
$response_out->{$station}->{operator_data}->{operator_color} = $hotline_data->{txt85} if($hotline_data->{txt85});
|
||||
$response_out->{$station}->{operator_data}->{operator_logo} = $hotline_data->{img01} if($hotline_data->{img01});
|
||||
$response_out->{$station}->{operator_data}->{operator_phone} = $hotline_data->{txt07} if($hotline_data->{txt07});
|
||||
$response_out->{$station}->{operator_data}->{operator_email} = $hotline_data->{txt08} if($hotline_data->{txt08});
|
||||
|
||||
#just like caching
|
||||
$return2copri->{$station}->{barcode} = $1 if($response_out->{$station}->{station} =~ /(\d+)/);#new on station context
|
||||
|
@ -134,7 +153,7 @@ sub sigo_available {
|
|||
|
||||
#bike (mainly using sigojson state object)
|
||||
my $bike = "SX$resp->{mobile_bike_id}";
|
||||
if($bike && looks_like_number($resp->{mobile_bike_id}) && $resp->{status} eq "ACTIVE" && looks_like_number($resp->{site}->{id})){
|
||||
if($bike && looks_like_number($resp->{mobile_bike_id}) && looks_like_number($resp->{site}->{id})){
|
||||
print FILE "Bike: $bike\n";
|
||||
$response_out->{$bike}->{bike} = "$bike";
|
||||
$response_out->{$bike}->{authed} = "$authed";
|
||||
|
@ -180,6 +199,7 @@ sub sigo_available {
|
|||
#just like caching
|
||||
$return2copri->{$bike}->{int11} = 3;
|
||||
$return2copri->{$bike}->{barcode} = $1 if($response_out->{$bike}->{bike} =~ /(\d+)/);
|
||||
$return2copri->{$bike}->{txt22} = $resp->{id};#bike id like 380116b5-0522-43da-ab66-477744a731a3
|
||||
$return2copri->{$bike}->{int04} = $1 if($response_out->{$bike}->{station} =~ /(\d+)/);
|
||||
$return2copri->{$bike}->{txt01} = "$response_out->{$bike}->{description}";
|
||||
$return2copri->{$bike}->{txt06} = "$response_out->{$bike}->{gps}->{latitude},$response_out->{$bike}->{gps}->{longitude}";
|
||||
|
@ -194,6 +214,7 @@ sub sigo_available {
|
|||
$return2copri->{$bike}->{int20} = $key;
|
||||
}
|
||||
}
|
||||
delete $response_out->{$bike} if($resp->{status} ne "ACTIVE");#don't view not active bikes
|
||||
}
|
||||
}#end bikes_available
|
||||
|
||||
|
@ -205,14 +226,70 @@ sub sigo_available {
|
|||
warn $@;
|
||||
}
|
||||
|
||||
print FILE "response_out from response_in\n" . Dumper($response_out) . "\n";
|
||||
print FILE "sigo_available response_out from response_in\n" . Dumper($response_out) . "\n";
|
||||
close(FILE);
|
||||
|
||||
return ($response_out,$return2copri);
|
||||
}#end sigo_available
|
||||
|
||||
#POST resverve, rental, ...
|
||||
sub sigo_booking {
|
||||
my $self = shift;
|
||||
my $varenv = shift || {};
|
||||
my $auth = shift || {};
|
||||
my $ct_bike = shift || {};
|
||||
my $todo = shift || "";
|
||||
|
||||
my $dbh = "";
|
||||
my $owner = 169;
|
||||
my $sigo_book = {};
|
||||
|
||||
open(FILE,">>$varenv->{logdir}/APIsigo_client.log");
|
||||
print FILE "\n*** $now_dt 'sigo_post $todo' \n";
|
||||
|
||||
my $endpoint = "$dbt->{operator}->{$varenv->{dbname}}->{endpoint}/";
|
||||
my %json = ();
|
||||
|
||||
if($todo eq "reserve"){
|
||||
$endpoint .= "bikes/reserve";
|
||||
%json = (
|
||||
bikeId => "$ct_bike->{txt22}",
|
||||
email => "r.guempelein\@sharee.bike"
|
||||
);
|
||||
}
|
||||
|
||||
if($todo eq "rental"){
|
||||
$endpoint .= "rental";
|
||||
%json = (
|
||||
bikeId => "$ct_bike->{txt22}",
|
||||
email => "r.guempelein\@sharee.bike"
|
||||
);
|
||||
}
|
||||
|
||||
my $rest_json = encode_json(\%json);
|
||||
|
||||
my $ret_json = $self->post_sigo($endpoint,$rest_json);
|
||||
#
|
||||
eval {
|
||||
$sigo_book = decode_json($ret_json);
|
||||
print FILE "<--- sigo_post $todo response_in:\n" . Dumper($sigo_book);
|
||||
#print $ret_json . "\n";
|
||||
|
||||
};
|
||||
if ($@){
|
||||
print FILE "<--- failure sigo_post $todo raw response_in:\n" . Dumper($ret_json) . "\n";
|
||||
#warn $@;
|
||||
print FILE "warn:" . $@ . "\n";
|
||||
}
|
||||
|
||||
close(FILE);
|
||||
return $sigo_book;
|
||||
}
|
||||
|
||||
|
||||
#main GET
|
||||
sub get_sigo {
|
||||
my $self = shift;
|
||||
my $endpoint = shift || "";
|
||||
my $rest_json = shift || "";
|
||||
my $sigo_request = "$endpoint";
|
||||
|
@ -234,8 +311,9 @@ sub get_sigo {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
#main POST
|
||||
sub post_sigo {
|
||||
my $self = shift;
|
||||
my $endpoint = shift || "";
|
||||
my $rest_json = shift || "";
|
||||
my $sigo_request = "$endpoint";
|
||||
|
|
|
@ -794,7 +794,7 @@ sub update_one(){
|
|||
my $self = shift;
|
||||
my $dbh = shift || $dbh_intern;
|
||||
my $update = shift;
|
||||
my $one = shift;
|
||||
my $one_in = shift || "";
|
||||
my $c_id = shift || "";
|
||||
|
||||
my $source = $dbh->get_info( $GetInfoType{SQL_DATABASE_NAME} );
|
||||
|
@ -819,6 +819,7 @@ sub update_one(){
|
|||
$where = "where rel_id = $update->{rel_id}";
|
||||
}
|
||||
|
||||
my $one = $one_in;
|
||||
if($update->{table} =~ /^users|relation|node/){
|
||||
$one .= ",change='now()'";
|
||||
}else{
|
||||
|
@ -826,7 +827,8 @@ sub update_one(){
|
|||
}
|
||||
$one .= ",owner=$update->{owner}" if($update->{owner});
|
||||
|
||||
if($where){
|
||||
#only update if input
|
||||
if($where && $one_in){
|
||||
my $sql = "UPDATE $update->{table} set $one $where";
|
||||
my $sth = $dbh->prepare($sql);
|
||||
$rows = $sth->execute();
|
||||
|
@ -844,7 +846,7 @@ sub update_record(){
|
|||
my $record = shift;
|
||||
my $source = $dbh->get_info( $GetInfoType{SQL_DATABASE_NAME} );
|
||||
my $where = "";
|
||||
my $set = "set";
|
||||
my $set = "";
|
||||
my $rows = 0;
|
||||
|
||||
#print Dumper($update);
|
||||
|
@ -885,12 +887,13 @@ sub update_record(){
|
|||
}
|
||||
}
|
||||
}
|
||||
$set =~ s/,$//;
|
||||
my $sql = "UPDATE $update->{table} $set $where";
|
||||
my $sth = $dbh->prepare($sql);
|
||||
$rows = $sth->execute();
|
||||
$bw->log("DBtank update_record $source: $rows",$sql,"") if($debug);
|
||||
|
||||
if($set){
|
||||
$set =~ s/,$//;
|
||||
my $sql = "UPDATE $update->{table} set $set $where";
|
||||
my $sth = $dbh->prepare($sql);
|
||||
$rows = $sth->execute();
|
||||
$bw->log("DBtank update_record $source: $rows",$sql,"") if($debug);
|
||||
}
|
||||
return $rows;
|
||||
}#update_record
|
||||
|
||||
|
@ -1247,11 +1250,12 @@ sub insert_pos(){
|
|||
my $ctadr = shift;
|
||||
my $ct_tariff = shift || "";
|
||||
my $endRental = shift || "0000-00-00";
|
||||
my $artikelnr = shift;
|
||||
my $status = shift;
|
||||
my $owner = shift;
|
||||
my $ct_name = shift || "";
|
||||
my $status = shift || "";
|
||||
my $owner = shift || "";
|
||||
my $reserveid = shift || "";
|
||||
|
||||
$artikelnr = $ct->{barcode} if(!$artikelnr);#RadID
|
||||
$ct_name = $ct->{barcode} if(!$ct_name);#artikelnr or bikenr
|
||||
my $user_name = $ctadr->{txt01};
|
||||
$user_name = $ctadr->{txt08} if(!$user_name || $user_name eq "no name");
|
||||
my $staff = 0;
|
||||
|
@ -1271,7 +1275,7 @@ sub insert_pos(){
|
|||
my $free_hours = 0;
|
||||
my $sharing_type = 0;
|
||||
my $menge = 0;
|
||||
if(ref($ct_tariff) eq "HASH"){
|
||||
if(ref($ct_tariff) eq "HASH" && $ct_tariff->{barcode}){
|
||||
$rabatt = $ctadr->{int07} || 0;
|
||||
$unit_price = $ct_tariff->{int02} || 0;
|
||||
$tariff_nr = $ct_tariff->{barcode} || 0;
|
||||
|
@ -1285,9 +1289,9 @@ sub insert_pos(){
|
|||
my $sth;
|
||||
#Verleihräder
|
||||
if($ct->{template_id} && $ct->{template_id} == 205){#Leihrad_list
|
||||
$sth = $dbh->prepare("INSERT INTO contenttranspos (ct_id,cc_id,ca_id,ct_name,barcode,txt01,txt08,txt02,txt09,itime,start_time,end_time,int02,int03,int06,int04,txt05,txt06,txt07,int10,int12,int13,owner,int07,txt04,int09,int17,int15,int16,int11,int18,int19,txt17,txt18,int20,int25,int34) VALUES ('$ctt_id','$ct->{c_id}','$ctadr->{c_id}','$artikelnr','$ct->{barcode}','$ct->{txt01}','$user_name','$ct->{txt02}','$ctadr->{txt09}',now(),now(),'$endRental','$unit_price','$menge','$station','$station','$ct->{txt06}','$ct->{txt06}','$ct->{txt07}','$status','$from_main_id','$deviceId','$owner','$rabatt','$tariff_desc','$tariff_nr','$day_maxprice','$abo_price','$free_hours','$ct->{int11}','$sharing_type','$bike_charge','$ct->{txt17}','$ct->{txt18}','$ct->{int20}','$trackon','$staff') RETURNING c_id");
|
||||
$sth = $dbh->prepare("INSERT INTO contenttranspos (ct_id,cc_id,ca_id,ct_name,barcode,txt01,txt08,txt02,txt09,itime,start_time,end_time,int02,int03,int06,int04,txt05,txt06,txt07,int10,int12,int13,owner,int07,txt04,int09,int17,int15,int16,int11,int18,int19,txt17,txt18,int20,int25,int34,txt22,txt10) VALUES ('$ctt_id','$ct->{c_id}','$ctadr->{c_id}','$ct_name','$ct->{barcode}','$ct->{txt01}','$user_name','$ct->{txt02}','$ctadr->{txt09}',now(),now(),'$endRental','$unit_price','$menge','$station','$station','$ct->{txt06}','$ct->{txt06}','$ct->{txt07}','$status','$from_main_id','$deviceId','$owner','$rabatt','$tariff_desc','$tariff_nr','$day_maxprice','$abo_price','$free_hours','$ct->{int11}','$sharing_type','$bike_charge','$ct->{txt17}','$ct->{txt18}','$ct->{int20}','$trackon','$staff','$ct->{txt22}','$reserveid') RETURNING c_id");
|
||||
}else{
|
||||
$sth = $dbh->prepare("INSERT INTO contenttranspos (ct_id,cc_id,ca_id,ct_name,barcode,txt08,txt09,itime,int02,int03,txt01,txt06,txt07,int10,int12,owner) VALUES ('$ctt_id','$ct->{c_id}','$ctadr->{c_id}','$artikelnr','0','$user_name','$ctadr->{txt09}',now(),'$unit_price','1','$ct->{txt01}','$ct->{txt06}','$ct->{txt07}','0','$from_main_id','$owner') RETURNING c_id");
|
||||
$sth = $dbh->prepare("INSERT INTO contenttranspos (ct_id,cc_id,ca_id,ct_name,barcode,txt08,txt09,itime,int02,int03,txt01,txt06,txt07,int10,int12,owner) VALUES ('$ctt_id','$ct->{c_id}','$ctadr->{c_id}','$ct_name','0','$user_name','$ctadr->{txt09}',now(),'$unit_price','1','$ct->{txt01}','$ct->{txt06}','$ct->{txt07}','0','$from_main_id','$owner') RETURNING c_id");
|
||||
}
|
||||
my $rows = $sth->execute();
|
||||
my $last_id;
|
||||
|
|
|
@ -747,7 +747,7 @@ sub save_transact(){
|
|||
|
||||
|
||||
#online net bike booking
|
||||
#Used by APP API
|
||||
#deprecated, use apif->booking_request
|
||||
sub net_booking(){
|
||||
my $self = shift;
|
||||
my $auth = shift;#API auth
|
||||
|
@ -755,15 +755,12 @@ sub net_booking(){
|
|||
my $owner = shift;
|
||||
my $gps = shift || "";
|
||||
|
||||
my $c_id = $auth->{c_id};
|
||||
my %varenv = $cf->envonline();
|
||||
$bikeIDin =~ s/\s//g;
|
||||
my $bikeID = $q->escapeHTML($bikeIDin) if($bikeIDin =~ /\d+$/);
|
||||
my $db_bike = $bikeID;
|
||||
$db_bike = $1 if($db_bike =~ /(\d+)/);
|
||||
|
||||
my %varenv = $cf->envonline();
|
||||
my $ctf = $db->get_content1("contentuser",$dbt->{shareedms_conf}->{parent_id});
|
||||
|
||||
my $pos_id="";
|
||||
my $return=0;
|
||||
my $now_dt = strftime "%Y-%m-%d %H:%M", localtime;
|
||||
|
@ -771,7 +768,7 @@ sub net_booking(){
|
|||
my $response_state = "OK";
|
||||
my $response_text = "";
|
||||
|
||||
$bw->log("net_booking booking_request bikeIDin $bikeIDin, authID $auth->{c_id}","","");
|
||||
$bw->log("net_booking booking_request bikeIDin $bikeIDin, authID $auth->{c_id}",$bikeIDin,"");
|
||||
|
||||
my $ctadr = $db->get_contentrow("contentadr",$auth->{c_id});
|
||||
|
||||
|
@ -997,7 +994,8 @@ sub net_booking(){
|
|||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
}#end net_booking
|
||||
|
||||
|
||||
#Send sms after payable check and !int13
|
||||
sub smsack(){
|
||||
|
|
|
@ -3,7 +3,9 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
# Copyright (c) Rainer Gümpelein, TeilRad GmbH
|
||||
#
|
||||
# sudo su www-data -c "./src/scripts/sigo_client.pl shareedms-fr01 get_bikes"
|
||||
# sudo su www-data -c "./src/scripts/sigo_client.pl shareeapp-sx sigo_available"
|
||||
#
|
||||
# sudo su www-data -c "./src/scripts/sigo_client.pl shareeapp-sx sigo_reserve"
|
||||
#
|
||||
use vars qw($syshost);
|
||||
|
||||
|
@ -30,10 +32,20 @@ my $now_dt = strftime "%Y-%m-%d %H:%M:%S", localtime;
|
|||
my $todo = $ARGV[1];
|
||||
|
||||
|
||||
if($todo eq "get_bikes"){
|
||||
if($todo eq "sigo_available"){
|
||||
$q->param(-name=>'request',-value=>"bikes_available");
|
||||
my $auth = { c_id => 0 };
|
||||
my $return = $si->sigo_available($q,\%varenv,$auth);
|
||||
print $0 . Dumper($return) . "\n";
|
||||
}
|
||||
|
||||
if($todo eq "sigo_reserve"){
|
||||
my $auth = { c_id => 1842 };
|
||||
#my $bikeId = "380116b5-0522-43da-ab66-477744a731a3";# bike 1150
|
||||
my $bike = "SX1150";# bike 1150 from app booking_request
|
||||
my $return = $si->sigo_reserve(\%varenv,$auth,$bike);
|
||||
print $0 . Dumper($return) . "\n";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -123,7 +123,7 @@ sub tpl(){
|
|||
|
||||
print "</div>\n";
|
||||
print $q->end_form,"\n";
|
||||
print $q->span({-style=>'color:white;'},"merchant_id:$varenv->{merchant_id}"),"\n";
|
||||
#print $q->span({-style=>'color:white;'},"merchant_id:$varenv->{merchant_id}"),"\n";
|
||||
print "</div>";
|
||||
|
||||
exit 0;
|
||||
|
@ -253,13 +253,13 @@ sub tpl(){
|
|||
my $big2menu="";
|
||||
#while (my ($key, $value) = each %{ $dbt->{operator} }) {
|
||||
foreach my $key (sort keys (%{ $dbt->{operator} })) {
|
||||
$big2menu .= $but->lia_button("$dbt->{operator}->{$key}->{operatorDMS}?merchant_id=$dbt->{operator}->{$key}->{merchant_id}","DMS $key","","","color:#$dbt->{operator}->{$key}->{bgcolor1};","") if($dbt->{operator}->{$key}->{merchant_id});
|
||||
$big2menu .= $but->lia_button("$dbt->{operator}->{$key}->{operatorDMS}","DMS $key","","","color:#$dbt->{operator}->{$key}->{bgcolor1};","") if($dbt->{operator}->{$key}->{merchant_id});
|
||||
}
|
||||
foreach my $key (sort keys (%{ $dbt->{website} })) {
|
||||
$big2menu .= $but->lia_button("$dbt->{website}->{$key}->{operatorWeb}","Web $key","","","color:#$dbt->{website}->{$key}->{bgcolor1};","") if($dbt->{website}->{$key}->{merchant_id});
|
||||
}
|
||||
foreach my $key (sort keys (%{ $dbt->{appsframe} })) {
|
||||
$big2menu .= $but->lia_button("$dbt->{primary}->{sharee_primary}->{primaryApp}?request=authorization&authcookie=$dbt->{appsframe}->{$key}->{merchant_id}","App $key","","","color:#$dbt->{merchant_ids}->{$dbt->{appsframe}->{$key}->{merchant_id}}->{bgcolor1};","");
|
||||
$big2menu .= $but->lia_button("$dbt->{primary}->{sharee_primary}->{primaryApp}?sessionid=$dbt->{appsframe}->{$key}->{merchant_id}","App $key","","","color:#$dbt->{merchant_ids}->{$dbt->{appsframe}->{$key}->{merchant_id}}->{bgcolor1};","");
|
||||
}
|
||||
|
||||
print $q->div({-style=>'width:100%;margin:0;padding-top:70px;color:white;'}, ""),"\n";
|
||||
|
|
Loading…
Add table
Reference in a new issue