mirror of
https://gitlab.com/t6353/sharee.bike.git
synced 2025-05-13 23:26:29 +02:00
changing rental freed_time to once a day and A-A message
This commit is contained in:
parent
63380dfbe0
commit
94fcafaff3
7 changed files with 82 additions and 37 deletions
|
@ -18,6 +18,7 @@ use Digest::SHA qw(sha256_base64);
|
|||
use Scalar::Util qw(looks_like_number);
|
||||
use DateTime;
|
||||
use DateTime::Format::Pg;
|
||||
use Date::Calc qw(Add_Delta_YMD);
|
||||
use URI::Encode;
|
||||
use Config::General;
|
||||
|
||||
|
@ -885,18 +886,17 @@ sub service_work {
|
|||
}#end service_work
|
||||
|
||||
|
||||
#2022-04-05 refactored bike reservation
|
||||
#bike reservation
|
||||
sub booking_request(){
|
||||
my $self = shift;
|
||||
my $q = shift;
|
||||
my $varenv = shift;
|
||||
my $auth = shift;#app API auth
|
||||
my $bike = shift || "";#app API request
|
||||
my $bike = shift || 0;#app API request
|
||||
my $ct_bike = shift || {};
|
||||
my $ct_tariff = shift;
|
||||
my $owner = shift || "";
|
||||
my $gps = shift || "";
|
||||
my $ct_tariff = shift || {};
|
||||
my $sig_book = shift || {};
|
||||
my $owner = shift || 0;
|
||||
|
||||
my $state = $q->escapeHTML($q->param('state')) || "";
|
||||
my $lock_state = $q->escapeHTML($q->param('lock_state')) || "";
|
||||
|
@ -928,6 +928,32 @@ sub booking_request(){
|
|||
close_time => "is::null",
|
||||
};
|
||||
|
||||
#for free rental
|
||||
#depends on operator, only 1 rental get freed_time
|
||||
my $pref_pos = {
|
||||
table => "contenttranspos",
|
||||
fetch => "all",
|
||||
keyfield => "c_id",
|
||||
ca_id => "$auth->{c_id}",
|
||||
};
|
||||
if($dbt->{operator}->{$varenv->{dbname}}->{project} eq "Konstanz"){
|
||||
$pref_pos->{int10} = "IN::(2,3)";
|
||||
}else{
|
||||
my $day = strftime "%d", localtime;
|
||||
my $mon = strftime "%m", localtime;
|
||||
my $year = strftime "%Y", localtime;
|
||||
my ($nyear,$nmon,$nday) = Add_Delta_YMD($year,$mon,$day, 0,0,1);
|
||||
$pref_pos->{time_range} = "start_time >= '$year-$mon-$day' and start_time < '$nyear-$nmon-$nday'";
|
||||
}
|
||||
my $record_pos = $dbt->fetch_tablerecord($dbh,$pref_pos);
|
||||
|
||||
my $activ_count=1;#+1 because counting before insert.
|
||||
foreach my $pid (sort { $record_pos->{$a}->{c_id} <=> $record_pos->{$b}->{c_id} } keys (%$record_pos)){
|
||||
$activ_count++;
|
||||
}
|
||||
if($activ_count > 1){
|
||||
delete $ct_tariff->{time02};
|
||||
}
|
||||
|
||||
#if bike and tariff
|
||||
if($ct_bike->{barcode} && $ct_tariff->{barcode}){
|
||||
|
@ -962,7 +988,7 @@ sub booking_request(){
|
|||
if($ctt->{c_id}){
|
||||
|
||||
#2 = "requested"
|
||||
$pos_id = $dbt->insert_pos($dbh,$ctt->{c_id},$ct_bike,$ct_station,$auth,$ct_tariff,$now_dt,$bike,"2",$owner,$sig_book);
|
||||
$pos_id = $dbt->insert_pos($dbh,$ctt->{c_id},$ct_bike,$ct_station,$auth,$ct_tariff,$now_dt,$bike,"2",$owner,$sig_book,$activ_count);
|
||||
$bw->log("booking_request insert_pos:",$pos_id,"");
|
||||
|
||||
if($pos_id){
|
||||
|
@ -981,12 +1007,12 @@ sub booking_request(){
|
|||
}
|
||||
}
|
||||
}elsif($rentable_check == 1){
|
||||
$response_state="Failure 1006: There is no valid payment methode";
|
||||
$response_state="Failure 1006: rental is prohibited because of user profil";
|
||||
$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_state="Failure 1005: user-account deactivated because of user profil";
|
||||
$response_text="Bitte überprüfen Sie Ihre Profildaten auf Vollständigkeit, nur dann können wir das Mietradsystem für Sie freischalten";
|
||||
}
|
||||
|
||||
|
@ -1223,13 +1249,14 @@ sub booking_update(){
|
|||
my $geo_distance_next = 100000;
|
||||
my $station_next = 0;
|
||||
my $geo_debug="";
|
||||
my $rows_end = 0;
|
||||
my ($stations,$stations_raw) = $self->stations_available($q,$varenv,$auth,$record_pos,"");
|
||||
|
||||
foreach my $id (sort { $stations_raw->{$a}->{barcode} <=> $stations_raw->{$b}->{barcode} } keys (%$stations_raw)){
|
||||
my $latitude_station = $1 if($stations_raw->{$id}->{txt06} =~ /^(\d+\.\d+)/);
|
||||
my $longitude_station = $1 if($stations_raw->{$id}->{txt06} =~ /(\d+\.\d+)$/);
|
||||
if((!looks_like_number($gps_data->{latitude}) || !looks_like_number($gps_data->{longitude})) && ($record_pos->{int11} != 3)){
|
||||
$geo_debug .= "ERROR no user GPS: $stations_raw->{$id}->{barcode}|$gps_data->{latitude},$gps_data->{longitude},$latitude_station,$longitude_station --> $gps_data->{geo_distance} Meter\n";
|
||||
$geo_debug .= "ERROR no user GPS: $stations_raw->{$id}->{int04}|$gps_data->{latitude},$gps_data->{longitude},$latitude_station,$longitude_station --> $gps_data->{geo_distance} Meter\n";
|
||||
}elsif((looks_like_number($gps_data->{latitude}) && looks_like_number($gps_data->{longitude}) && looks_like_number($latitude_station) && looks_like_number($longitude_station)) || ($record_pos->{int11} == 3)){
|
||||
$update_pos->{owner_end} = "$owner";
|
||||
$update_pos->{end_time} = "now()";
|
||||
|
@ -1264,9 +1291,9 @@ sub booking_update(){
|
|||
$update_pos->{int40} = "$counting->{int40}" if(looks_like_number($counting->{int40}));
|
||||
$update_pos->{int41} = "$counting->{int41}" if(looks_like_number($counting->{int41}));
|
||||
|
||||
$rows = $dbt->update_record($dbh,$update_pos,$record_pos);
|
||||
$rows_end = $dbt->update_record($dbh,$update_pos,$record_pos);
|
||||
|
||||
if($rows > 0){
|
||||
if($rows_end > 0){
|
||||
$update_cc->{int10} = 1;
|
||||
$booking_values->{response_state} = "OK: available bike " . $q->param('bike');
|
||||
$booking_values->{response_text} = "Danke! Die Miete Fahrrad Nr. " . $q->param('bike') . " wurde beendet.";
|
||||
|
@ -1298,18 +1325,24 @@ sub booking_update(){
|
|||
$update_pos->{int40} = "$counting->{int40}" if(looks_like_number($counting->{int40}));
|
||||
$update_pos->{int41} = "$counting->{int41}" if(looks_like_number($counting->{int41}));
|
||||
|
||||
$rows = $dbt->update_record($dbh,$update_pos,$record_pos);
|
||||
$rows_end = $dbt->update_record($dbh,$update_pos,$record_pos);
|
||||
|
||||
$geo_debug .= "Out of station distance: $stations_raw->{$id}->{barcode}|$gps_data->{latitude},$gps_data->{longitude},$latitude_station,$longitude_station --> $geo_distance_next Meter ($geo_distance_next <= $gps_data->{geo_distance}) station_next: $station_next\n";
|
||||
$geo_debug .= "Out of station distance: $stations_raw->{$id}->{int04}|$gps_data->{latitude},$gps_data->{longitude},$latitude_station,$longitude_station --> $geo_distance_next Meter ($geo_distance_next <= $gps_data->{geo_distance}) station_next: $station_next\n";
|
||||
|
||||
$booking_values->{response_state} = "Failure 2178: bike " . $q->param('bike') . " out of GEO fencing. $geo_distance_next meter distance to next station $station_next .";
|
||||
$booking_values->{response_text} = "Achtung! Ihr aktueller Standort liegt außerhalb einer Fahrradstation. Die Miete Fahrrad Nr. " . $q->param('bike') . " kann nicht $state_text werden. $geo_distance_next Meter Entfernung zur nächsten Station $station_next . Falls Sie sich doch an einer Station befinden, dann wiederholen Sie \"Miete beenden\".";
|
||||
}
|
||||
|
||||
}else{
|
||||
$geo_debug .= "ERROR no station GPS: $stations_raw->{$id}->{barcode}|$gps_data->{latitude},$gps_data->{longitude},$latitude_station,$longitude_station --> $gps_data->{geo_distance} Meter\n";
|
||||
$geo_debug .= "ERROR no station GPS: $stations_raw->{$id}->{int04}|$gps_data->{latitude},$gps_data->{longitude},$latitude_station,$longitude_station --> $gps_data->{geo_distance} Meter\n";
|
||||
}
|
||||
}
|
||||
#$geo_distance_next == 100000 defaults to if no station in stations_raw
|
||||
if($record_pos->{int42} == 0 && !$rows_end && $geo_distance_next == 100000){
|
||||
$geo_distance_next = "undefined";
|
||||
$booking_values->{response_state} = "Failure 2244: this bike not accepted on A-A station, state change forbidden.";
|
||||
$booking_values->{response_text} = "Ein Mietende mit diesem Rad ist an dieser Station nicht erlaubt, da es sich hier um eine sog. A-A Station handelt. An A-A Stationen dürfen nur Mieträder zurück gegeben werden die von dort gemietet wurden.";
|
||||
}
|
||||
$booking_values->{geo_distance} = "$geo_distance_next";
|
||||
#print "$geo_debug\n";
|
||||
$bw->log("GEOfencing geo_debug:$geo_debug",$q,"");
|
||||
|
@ -1633,8 +1666,8 @@ sub user_rentals_history(){
|
|||
}
|
||||
foreach my $sharee_operator (keys (%operator_hash)){
|
||||
my $dbh_operator = $dbt->dbconnect_extern("$sharee_operator");
|
||||
my $record = $dbt->collect_post($dbh_operator,$pref);
|
||||
$record_all = { %$record_all, %$record };
|
||||
my $cttpos = $dbt->collect_post($dbh_operator,$pref);
|
||||
$record_all = { %$record_all, %$cttpos };
|
||||
}
|
||||
}
|
||||
}else{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue