2020-01-15 23:42:58 -06:00
|
|
|
package Dojo::Model::Vdgproc; use Mojo::File 'path';
|
|
|
|
|
use Mojo::JSON qw(decode_json encode_json);
|
2020-01-20 14:49:59 -06:00
|
|
|
use Dojo::Support qw{ mtxt month_num2txt log dmph} ;
|
2020-01-15 23:42:58 -06:00
|
|
|
use Mojo::Base 'Mojolicious::Controller';
|
|
|
|
|
|
2020-01-20 14:49:59 -06:00
|
|
|
use Email::Valid;
|
|
|
|
|
use Data::Dumper;
|
2020-01-15 23:42:58 -06:00
|
|
|
use File::Basename;
|
|
|
|
|
use Encode qw(decode_utf8 encode_utf8);
|
|
|
|
|
use Text::Markdown qw{ markdown };
|
|
|
|
|
use DBI;
|
|
|
|
|
use Dojo::Conf;
|
|
|
|
|
|
|
|
|
|
sub new { bless {}, shift };
|
|
|
|
|
my $data_path = path('lib/Dojo/Model/Data')->make_path;
|
|
|
|
|
#just for fun
|
|
|
|
|
|
|
|
|
|
|
2020-01-20 14:49:59 -06:00
|
|
|
# Tienda de eventos ===========================================================
|
2020-01-15 23:42:58 -06:00
|
|
|
sub calendar_monthblock {
|
|
|
|
|
my $r = _read ($data_path->child("cal/q1Block.q")->slurp);
|
|
|
|
|
map { $_->{fecha}=month_num2txt($_->{month})." ".$_->{year} } @$r;
|
|
|
|
|
return $r;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub calendar_events {
|
|
|
|
|
my $r = _read ($data_path->child("cal/q3Event.q")->slurp);
|
|
|
|
|
foreach (@$r) { $_->{fecha} = mtxt( $_->{dini},$_->{mini},$_->{dfin},$_->{mfin}) }
|
|
|
|
|
return $r;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub event{
|
|
|
|
|
my ($c,$id)=@_;
|
|
|
|
|
my $r = shift @{ _read ($data_path->child("event/qEvent.q")->slurp,$id)};
|
|
|
|
|
$r->{date} = mtxt( $r->{dini},$r->{mini},$r->{dend},$r->{mend});
|
|
|
|
|
return $r;
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-20 18:19:38 -06:00
|
|
|
sub spay{
|
2020-01-15 23:42:58 -06:00
|
|
|
my ($c,$class,$id) = @_;
|
2020-01-20 18:19:38 -06:00
|
|
|
my $r = shift @{ _read ($data_path->child("spay/qIdStore.q")->slurp,$id)};
|
2020-01-15 23:42:58 -06:00
|
|
|
$r->{fecha} = mtxt( $r->{dini},$r->{mini},$r->{dfin},$r->{mfin});
|
|
|
|
|
return $r;
|
|
|
|
|
}
|
2020-01-20 14:49:59 -06:00
|
|
|
|
|
|
|
|
# Stripe payment process ==============================================================
|
|
|
|
|
# ======================
|
|
|
|
|
# 4000004840000008 3, 6, 9, 12, and 18 month installment plans available
|
|
|
|
|
# "*p4000004840000008
|
|
|
|
|
# 4242424242424242 No installment plans available.
|
|
|
|
|
# ======================
|
|
|
|
|
|
2020-01-15 23:42:58 -06:00
|
|
|
sub intentCreate{
|
|
|
|
|
my ($c,$id) = @_;
|
2020-01-20 14:49:59 -06:00
|
|
|
return _read ($data_path->child("spay/qIntentCreate.q")->slurp,$id)->[0];
|
2020-01-15 23:42:58 -06:00
|
|
|
}
|
2020-01-20 14:49:59 -06:00
|
|
|
|
|
|
|
|
|
2020-01-15 23:42:58 -06:00
|
|
|
sub intentConfirm{
|
2020-01-20 14:49:59 -06:00
|
|
|
my ($c,$data,$r) = @_;
|
|
|
|
|
# cliente_nombre,cliente_correo,cliente_comentario,tienda_evento_id,talla_id,cantidad(1),monto,etapa_id(4),entrega(3),pago_clave,plazo,fecha_pago
|
|
|
|
|
my $mq = $data->{'mq'};
|
|
|
|
|
my $students = $data->{'students'};
|
2020-01-29 03:13:02 -06:00
|
|
|
my $plan = $r->{'payment_method_options'}->{'card'}->{'installments'}->{'plan'}->{'count'} // 0;
|
2020-01-20 14:49:59 -06:00
|
|
|
for (1..$mq){
|
|
|
|
|
_write (
|
|
|
|
|
$data_path->child("/spay/qIntentConfirm.q")->slurp,
|
|
|
|
|
$$students[$_ -1][0],
|
|
|
|
|
$$students[$_ -1][1],
|
|
|
|
|
$$students[$_ -1][2],
|
|
|
|
|
$data->{'tid'},
|
|
|
|
|
$$students[$_ -1][3],
|
|
|
|
|
$data->{'mq'},
|
|
|
|
|
$r->{'amount'},
|
|
|
|
|
4,
|
|
|
|
|
3,
|
|
|
|
|
$r->{'id'},
|
|
|
|
|
$plan
|
|
|
|
|
);
|
|
|
|
|
} # falta plazo
|
|
|
|
|
return ;
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-22 18:22:31 -06:00
|
|
|
sub notify{
|
|
|
|
|
my ($c,$d,$r) = @_;
|
|
|
|
|
my $t =shift @{ _read ($data_path->child("spay/qNotify.q")->slurp,$d->{'tid'})};
|
|
|
|
|
my @ra;
|
2020-01-29 03:13:02 -06:00
|
|
|
my %h=qw/0 na 1 CH 2 M 3 G/;
|
2020-01-29 03:27:24 -06:00
|
|
|
my $plazo = $r->{'payment_method_options'}->{'card'}->{'installments'}->{'plan'}->{'count'}//0;
|
|
|
|
|
my $cant=$r->{'amount'}/100;
|
2020-01-22 18:22:31 -06:00
|
|
|
my $students = $d->{'students'};
|
2020-01-29 03:13:02 -06:00
|
|
|
my $basetxta = "$t->{'cnombre'}
|
|
|
|
|
clave de pago stripe: $r->{'id'}
|
2020-01-22 18:22:31 -06:00
|
|
|
plazo: $plazo meses
|
2020-01-29 03:27:24 -06:00
|
|
|
cantidad: $cant
|
2020-01-22 18:22:31 -06:00
|
|
|
";
|
2020-01-29 03:13:02 -06:00
|
|
|
my $basetxtu = "
|
|
|
|
|
$t->{'cnombre'}
|
|
|
|
|
============================================
|
|
|
|
|
".$t->{'subnombre'}//""."
|
|
|
|
|
/////////////////////////////////////////////
|
|
|
|
|
";
|
2020-01-22 18:22:31 -06:00
|
|
|
|
|
|
|
|
foreach(1 .. $d->{'mq'}) {
|
|
|
|
|
push (@ra, ["
|
|
|
|
|
$basetxtu
|
|
|
|
|
$$students[$_ -1][0]
|
|
|
|
|
$t->{'mmail'}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tu clave de pago es la sigiente. Tenla a la mano para cualquier aclaración
|
2020-01-29 03:13:02 -06:00
|
|
|
==================================
|
|
|
|
|
$r->{'id'}
|
|
|
|
|
==================================
|
2020-01-22 18:22:31 -06:00
|
|
|
", " Inscripción ", $$students[$_ -1][1]]);
|
|
|
|
|
$basetxta .= "
|
|
|
|
|
Nombre: $$students[$_ -1][0]
|
|
|
|
|
Correo: $$students[$_ -1][1]
|
|
|
|
|
Telefono:$$students[$_ -1][0]
|
|
|
|
|
Playera:$h{$$students[$_ -1][3]}
|
|
|
|
|
Comentario:$$students[$_ -1][2]
|
|
|
|
|
=====================
|
|
|
|
|
";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
push (@ra, [$basetxta,"Inscripciones",'david@chaos.foundation']);
|
2020-01-29 03:13:02 -06:00
|
|
|
push (@ra, [$basetxta,"Inscripciones",'benjamuga@gmail.com']);
|
|
|
|
|
push (@ra, [$basetxta,"Inscripciones",'mmunoz@harvest.com']);
|
|
|
|
|
|
2020-01-22 18:22:31 -06:00
|
|
|
return @ra;
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-20 14:49:59 -06:00
|
|
|
# Check payment user info ==============
|
|
|
|
|
# data:
|
|
|
|
|
# ===============
|
|
|
|
|
#'selected_plan' => { 'type' => 'fixed_count', 'count' => 6, 'interval' => 'month' },
|
|
|
|
|
#'mq' => '2', # cantidad de alumnas
|
|
|
|
|
#'req' => 'check',
|
|
|
|
|
#'payment_intent_id' => 'pi_1G1luSFBHoXN2vhnkl3PIiL1',
|
|
|
|
|
#'tid' => 80, #tienda id
|
|
|
|
|
#'students' => [ [ 'User', 'me@me.com', 'obs', 'M' ], [ 'usr2', 'mail2', 'obs', 'G' ], undef, undef, undef, undef, undef, undef, undef, undef ] #arr(10)
|
|
|
|
|
# ===============
|
|
|
|
|
|
|
|
|
|
sub userDataSanity{
|
|
|
|
|
my ($c,$d) = @_;
|
|
|
|
|
return -1 unless (
|
|
|
|
|
defined ($d->{'students'}) && # (nombre,mail,observaciones, talla)
|
|
|
|
|
defined ($d->{'mq'}) &&
|
|
|
|
|
$d->{'mq'} =~/^\d+$/ &&
|
|
|
|
|
$d->{'mq'} < 10
|
|
|
|
|
);
|
2020-01-29 03:13:02 -06:00
|
|
|
|
2020-01-20 14:49:59 -06:00
|
|
|
my %h=qw(n 0 CH 1 M 2 G 3);
|
|
|
|
|
my $mq = $d->{'mq'};
|
|
|
|
|
my $students = $d->{'students'};
|
|
|
|
|
for (1..$mq){
|
|
|
|
|
return $_ unless defined( $$students[$_ -1][0] );
|
|
|
|
|
return $_ unless defined( $$students[$_ -1][1] ) &&
|
|
|
|
|
is_mail($$students[$_ -1][1] );
|
|
|
|
|
$$students[$_ -1][3] = $h{$$students[$_ -1][3] // 'n'};
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub is_mail{
|
|
|
|
|
return Email::Valid->address(shift);
|
2020-01-15 23:42:58 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#==============================================================================
|
|
|
|
|
|
|
|
|
|
# admin evets
|
2020-01-22 18:22:31 -06:00
|
|
|
sub event_del { return _write("delete from curso_tienda where id = ?;",pop);}
|
2020-01-15 23:42:58 -06:00
|
|
|
sub course_del{ return _write("delete from curso where id = ?;",pop); }
|
2020-01-22 18:22:31 -06:00
|
|
|
sub place_del { return _write("delete from curso_lugar where id = ?;",pop); }
|
2020-01-15 23:42:58 -06:00
|
|
|
|
|
|
|
|
sub event_up{
|
|
|
|
|
my ($self,@bind)=@_;
|
|
|
|
|
return _write($data_path->child("/admin/event/add/qEup.q")->slurp,@bind);
|
|
|
|
|
}
|
|
|
|
|
sub course_up{
|
|
|
|
|
my ($self,@bind)=@_;
|
|
|
|
|
return _write($data_path->child("/admin/event/add/qCup.q")->slurp,@bind);
|
|
|
|
|
}
|
|
|
|
|
sub place_up{
|
|
|
|
|
my ($self,@bind)=@_;
|
|
|
|
|
return _write($data_path->child("/admin/event/add/qPup.q")->slurp,@bind);
|
|
|
|
|
}
|
|
|
|
|
sub event_ch{
|
|
|
|
|
my ($self,@bind)=@_;
|
|
|
|
|
return _write($data_path->child("/admin/event/change/qEup.q")->slurp,@bind);
|
|
|
|
|
}
|
|
|
|
|
sub course_ch{
|
|
|
|
|
my ($self,@bind)=@_;
|
|
|
|
|
return _write($data_path->child("/admin/event/change/qCup.q")->slurp,@bind);
|
|
|
|
|
}
|
|
|
|
|
sub place_ch{
|
|
|
|
|
my ($self,@bind)=@_;
|
|
|
|
|
return _write($data_path->child("/admin/event/change/qPup.q")->slurp,@bind);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#==============================================================================
|
2020-01-22 18:22:31 -06:00
|
|
|
sub courses{ return _read("select nombre as name, id from curso;")}
|
|
|
|
|
|
|
|
|
|
sub course { return shift @{_read($data_path->child("/admin/event/json/qCourse.q")->slurp,pop)}}
|
|
|
|
|
|
|
|
|
|
sub places { return _read("select nombre as name, id from curso_lugar;")}
|
|
|
|
|
|
|
|
|
|
sub place { return shift @{_read($data_path->child("/admin/event/json/qPlace.q")->slurp,pop)}}
|
|
|
|
|
|
|
|
|
|
sub events { return _read($data_path->child("/admin/event/qEprev.q")->slurp)}
|
|
|
|
|
|
|
|
|
|
sub eventa { return shift @{_read($data_path->child("/admin/event/json/qEvent.q")->slurp,pop)}}
|
|
|
|
|
|
|
|
|
|
sub eimgList{
|
|
|
|
|
my $dp = path('public/proc/cal/img')->make_path;
|
|
|
|
|
return [ map{ $_->basename} grep{/(jpg|png)$/i}@{$dp->list} ];
|
|
|
|
|
}
|
2020-01-15 23:42:58 -06:00
|
|
|
|
2020-01-20 14:49:59 -06:00
|
|
|
# lower level read =====================================
|
2020-01-15 23:42:58 -06:00
|
|
|
|
|
|
|
|
sub _read{
|
|
|
|
|
my ($q,@bind)=@_;
|
|
|
|
|
my @empty;
|
|
|
|
|
my $dbh = DBI->connect("DBI:mysql:".Dojo::Conf::VDGPROCDB.":".Dojo::Conf::VDGPROCDB_H,Dojo::Conf::VDGPROCDB_UR,Dojo::Conf::VDGPROCDB_URP, {mysql_enable_utf8 => 1});
|
|
|
|
|
return \@empty unless($dbh);
|
|
|
|
|
my $h=$dbh->selectall_arrayref($q,{ Slice => {} },@bind)//"error";
|
|
|
|
|
$dbh->disconnect();
|
|
|
|
|
#((col1=>d1,col2=>d1),(col1=>d2,col2=>d2))
|
|
|
|
|
return $h;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub _write{
|
|
|
|
|
my ($q,@bind)=@_;
|
|
|
|
|
my (@empty);
|
|
|
|
|
my $dbh = DBI->connect("DBI:mysql:".Dojo::Conf::VDGPROCDB.":".Dojo::Conf::VDGPROCDB_H,Dojo::Conf::VDGPROCDB_UW,Dojo::Conf::VDGPROCDB_UWP,{mysql_enable_utf8 => 1} );
|
|
|
|
|
return 0 unless($dbh);
|
|
|
|
|
my $h=$dbh->do($q,{ Slice => {} },@bind)//"error";
|
|
|
|
|
$dbh->disconnect();
|
|
|
|
|
log("db write: $h");
|
|
|
|
|
return $h;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub load_md{
|
|
|
|
|
return "" unless
|
|
|
|
|
my $text = path(shift)->slurp;
|
|
|
|
|
return markdown( decode_utf8($text) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub load_txt{
|
|
|
|
|
return "" unless
|
|
|
|
|
my $text = path(shift)->slurp;
|
|
|
|
|
return decode_utf8($text);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
1;
|
|
|
|
|
|