cleaning the house

This commit is contained in:
mynah
2020-01-20 14:49:59 -06:00
parent 252ec865b3
commit 7dfd107c04
81 changed files with 426 additions and 958 deletions

View File

@@ -0,0 +1,82 @@
package Dojo::Controller::Admin;
use Mojo::File 'path';
use Mojo::JSON qw(decode_json encode_json);
use Mojo::Base 'Mojolicious::Controller';
use Dojo::Support qw{ log };
# pagina y mensajes ===========================================================
sub admin{
my $c=shift;
my $n=$c->param("dreq")//"";
my $json = {status => "304"};
$json = ($c->dbv->rmsgid ($c->param('id')))[0] if ($n =~m/^mensajes$/);
$json = ($c->dbv->ecourse($c->param('id')))[0] if ($n =~m/^ecourse$/);
$json = ($c->dbv->qcourse($c->param('id')))[0] if ($n =~m/^qcourse$/);
$json = ($c->dbv->qplace ($c->param('id')))[0] if ($n =~m/^qplace$/);
$c->render(json=>$json);
}
# Eventos =====================================================================
sub admin_eventos{
my $c=shift;
if ( (my $t=$c->param('type') // "") =~/[ecp]/){
my $id=$c->param('id');
my $req=$c->param('req');
if ( $req eq "Eliminar"){
$c->dbv->event_del($id) if ($t eq 'e');
$c->dbv->course_del($id) if ($t eq 'c');
$c->dbv->place_del($id) if ($t eq 'p');
}
elsif( $req eq "Aceptar"){
if($t eq 'e'){
my @list=map{$c->param($_)}qw/eplace yini mini dini yend mend dend cost promo pen ecourse eimg een id/;
$c->dbv->event_up(@list) if ($id ==0);
$c->dbv->event_ch(@list) if ($id >0);
}
if($t eq 'c'){
my @list=map{$c->param($_)}qw/cname csubjects cservices cen id/;
$c->dbv->course_up(@list) if ($id ==0);
$c->dbv->course_ch(@list) if ($id >0);
}
if($t eq 'p'){
my @list=map{$c->param($_)}qw/pname paddr pobs pto pst pco plat plng pen id/;
$c->dbv->place_up(@list) if ($id ==0);
$c->dbv->place_ch(@list) if ($id >0);
}
}
$c->redirect_to("/admin/eventos");
}
$c->stash(
courses=>$c->dbv->courses,
places=>$c->dbv->places,
months=>$c->dbv->months,
events=>$c->dbv->events,
img=>$c->dbv->eimgList,
);
$c->stash(template=>"home/admin/event");
$c->stash(layout=>"admin");
}
sub admin_tienda{
my $c=shift;
$c->stash(u=>$c->dbv->user_heads);
$c->stash(s=>$c->dbv->store_heads);
$c->stash(template=>"home/admin/tienda");
$c->stash(layout=>"admin");
}
# Funciones auxiliares ========================================================
sub admin_json{
my $c=shift;
my $id = $c->param('id');
my $req = $c->param('dreq');
my $json = "304";
$json = $c->dbv->astore($id) if $req=~/tienda/;
$json = $c->dbv->course($id) if $req=~/course/;
$json = $c->dbv->place($id) if $req=~/place/;
$json = $c->dbv->eventa($id) if $req=~/event/;
$c->render(json=>$json);
}

View File

@@ -8,6 +8,7 @@ use Net::Telnet;
my $server_name = "";
our $t; #telnet server object
my $data_path = path('lib/Dojo/Model/Data')->make_path;
sub simple{
my $c=shift;
my $n=$c->param("dreq")//"";
@@ -18,16 +19,6 @@ sub simple{
$c->render(json=>$json);
}
sub admin{
my $c=shift;
my $n=$c->param("dreq")//"";
my $json = {status => "304"};
$json = ($c->dbv->rmsgid ($c->param('id')))[0] if ($n =~m/^mensajes$/);
$json = ($c->dbv->ecourse($c->param('id')))[0] if ($n =~m/^ecourse$/);
$json = ($c->dbv->qcourse($c->param('id')))[0] if ($n =~m/^qcourse$/);
$json = ($c->dbv->qplace ($c->param('id')))[0] if ($n =~m/^qplace$/);
$c->render(json=>$json);
}
#==== candy =====================================================
sub candy{
my $c=shift;
@@ -43,32 +34,36 @@ sub candy{
$c->render(json => {a=>$r});
}
sub turnOff{
grep(/Result: true/,join('',sendT('host:deactivate("'.$server_name.'")')))?1:0
unless (isOn()==0);
}
sub turnOn{
grep(/Result: true/,join('',sendT('host:activate("'.$server_name.'")')))?1:0
unless (isOn()==1);
sub turnOff{
grep(/Result: true/,join('',sendT('host:deactivate("'.$server_name.'")')))?1:0
unless (isOn()==0);
}
sub turnOn{
grep(/Result: true/,join('',sendT('host:activate("'.$server_name.'")')))?1:0
unless (isOn()==1);
}
sub isOn{return grep(/\s$server_name/,sendT("host:list()"))? 1:0; }
sub isOn{return grep(/\s$server_name/,sendT("host:list()"))? 1:0; }
sub sendT{
commandT(shift);
my @r = $t->getlines(All=>0);
return @r
}
sub connectT{
$t = new Net::Telnet ( Port=>5582, Timeout=>1, Errmode=>'return' );
# $t = new Net::Telnet ( Port=>5582, Timeout=>1, Errmode=>'die' );
return 1 if $t->open();
return 0;
}
sub commandT{
$t->getlines(All=>0);#empty buffer
$t->print(shift); #run istruction
}
sub disconnectT{ $t->close();}
#=========================================================

View File

@@ -1,12 +0,0 @@
package Dojo::Controller::Example;
use Mojo::Base 'Mojolicious::Controller';
# This action will render a template
sub welcome {
my $self = shift;
# Render template "example/welcome.html.ep" with message
$self->render(msg => 'Welcome to the Mojolicious real-time web framework!');
}
1;

View File

@@ -1,107 +0,0 @@
package Dojo::Controller::Misc;
use Mojo::Base 'Mojolicious::Controller';
use Mojo::Template;
use Dojo::Support qw{ log get_names};
# estos son paypal=======:w
use LWP::UserAgent;
use HTTP::Request::Common;
use JSON;
use Data::Dumper;
# 4000004840000008 3, 6, 9, 12, and 18 month installment plans available
# "*p4000004840000008
# 4242424242424242 No installment plans available.
my $sky='sk_test_GXWsfsoxy5336LrSw7SgTXNC00TV9O4Dbq';
my $api_create_path='https://api.stripe.com/v1/payment_intents';
sub stripe {
my $self = shift;
my $request = defined ($self->req->json)? $self->req->json->{'req'}:"start";
# item info ======================
my $header = "Beijing Wisdom </br> Healing Center";
my $title = "Retiro Curso de Tercer método de ZhiNengQiGong";
my $subtitle = "Una experiencia de instrucción del tercer método y profundización con los instructores ZhangQing (Helen) y QiuFuChun (Karl).";
my ($amount,$description,$max_time) = (1417500,"Tercer método",9);
# ==============================
if( $request eq "precheck" ){
my $pmi=$self->req->json->{'payment_method_id'} // 0;
my $t = intentCreate( $pmi, $amount, $description, $max_time);
$self->render(json=>$t);
}
elsif( $request eq "check" ){
my $pii = $self->req->json->{'payment_intent_id'};
my $plan = $self->req->json->{'selected_plan'}//0;
unless ($plan==0) {if ($plan->{count} > $max_time) {
log("\n\n max time instalment attempt\n\n");
$self->render(json=>{'error'=>'max time error'});
return 0;
}}
my $r = intentConfirm($pii,$plan);
$self->render(json=>$r);
}
else {
$self->stash(header=>$header);
$self->stash(title=>$title);
$self->stash(subtitle=>$subtitle);
$self->stash(layout=>'xpay');
}
}
#stripe appi functions
sub intentCreate{
my ($pmi,$amount,$descriptor,$max_time) = @_;
my $payment_info=[
'payment_method'=>$pmi,
'amount'=>$amount,
'currency'=>'mxn',
'description'=>$descriptor,
'payment_method_options[card][installments][enabled]'=>'true'
];
my $r=stripeAppi($api_create_path,$payment_info);
my $t->{intent_id}=$r->{id};
foreach (@{$r->{payment_method_options}{card}{installments}{available_plans}}){
push (@{$t->{available_plans}}, $_) unless ($_->{count}>$max_time);
}
return $t;
}
sub intentConfirm{
my ($pii,$plan) = @_;
my $api_confirm_path = "https://api.stripe.com/v1/payment_intents/$pii/confirm";
my $cplan=0;
$cplan = [
'payment_method_options[card][installments][plan][type]'=>'fixed_count',
'payment_method_options[card][installments][plan][interval]'=>'month',
'payment_method_options[card][installments][plan][count]'=>$plan->{count},
]
unless ($plan==0);
my $r = stripeAppi($api_confirm_path,$cplan);
my $rtt = {
'status'=>$r->{'status'},
'plan' => $r->{'payment_method_options'}{'card'}{'installments'}{'plan'},
};
return $rtt;
}
sub stripeAppi{
my ($path,$data) = @_;
my $req = POST $path, $data;
$req->authorization_basic($sky,'');
$req->content_type('application/x-www-form-urlencoded');
my $ua = LWP::UserAgent->new;
my $res=$ua->request($req);
unless ($res->is_success){
log("stripe error! path=$path\n data=".Dumper($data)."\n $res->status_line ");
return 0;
}
my $json = JSON->new->utf8;
return $json->decode($res->decoded_content);
}
1;

View File

@@ -2,55 +2,14 @@ package Dojo::Controller::Proc;
use Mojo::Base 'Mojolicious::Controller';
use Mojo::Template;
use Dojo::Support qw{ log get_names};
# estos son paypal=======:w
use LWP::UserAgent;
use HTTP::Request::Common;
use JSON;
use Data::Dumper;
#=========================
sub tst{
my $c=shift;
if( defined($c->req->json) ){
my $oid = $c->req->json->{'orderID'} //0;
log( $oid );
#credentials====
my $client='AQdZ1JJL-GNBgGTI3W6cXChmj6MnZsInRGlWeHw1kbGiE_49eTtZ2fPvEq9ersU2y6O5WpxccdsyAQw7';
my $secter='EBn8CNOCrJbVZ_fNllXB7oUIm9_vhtqrJMm2zSBGbxSyiiych3cHOIWOLAD5NVw4Z3dmNhmsHQwPsrZ0';
my $pauth='https://api.sandbox.paypal.com/v1/oauth2/token/';
my $porder='https://api.sandbox.paypal.com/v2/checkout/orders/';
#=================
#pre auth ====
my $ua = LWP::UserAgent->new;
my $req=POST $pauth, ["grant_type"=>"client_credentials"];
$req->authorization_basic($client,$secter);
$req->content_type('application/x-www-form-urlencoded');
my $res=$ua->request($req);
log("paypal pre auth error! $res->status_line") unless ($res->is_success );
my $json = JSON->new->utf8;
my $r=$json->decode($res->decoded_content);
#==============
#order details ====
my $ub = LWP::UserAgent->new;
$ub->default_header('Content-Type'=> 'application/json' );
$ub->default_header('Authorization'=> 'Bearer ' . $r->{access_token} );
my $resb=$ub->get($porder.$oid);
log("paypal checkout error!") unless ($resb->is_success );
my $jsonb = JSON->new->utf8;
my $s=$jsonb->decode($resb->decoded_content);
#===================
$c->rendered(200); #es default,nomas para enfatizar que puede ser 400 o 500
# interesan create time, id, payer: email address, shippng address
}
else{
my $data=$c->dbg->store_id($c->param('id'));
$c->redirect_to('store') unless ($data->{'id'});
$c->stash($data);
$c->stash(layout=>'default');
}
#$c->render(text=> $c->config->{radio}{'channel'});
}
# User ========================================================================
sub cal {
@@ -71,67 +30,13 @@ sub event{
$c->stash(layout=> "defaultContact");
}
sub store{
my $c = shift;
$c->stash( r=>$c->dbg->store);
$c->stash(layout=> "defaultContact");
}
sub storep{
my $c=shift;
if( defined($c->req->json) ){
my $oid = $c->req->json->{'orderID'} //0;
log( $oid );
#credentials====
my $client='AQdZ1JJL-GNBgGTI3W6cXChmj6MnZsInRGlWeHw1kbGiE_49eTtZ2fPvEq9ersU2y6O5WpxccdsyAQw7';
my $secter='EBn8CNOCrJbVZ_fNllXB7oUIm9_vhtqrJMm2zSBGbxSyiiych3cHOIWOLAD5NVw4Z3dmNhmsHQwPsrZ0';
my $pauth='https://api.sandbox.paypal.com/v1/oauth2/token/';
my $porder='https://api.sandbox.paypal.com/v2/checkout/orders/';
#=================
#pre auth ====
my $ua = LWP::UserAgent->new;
my $req=POST $pauth, ["grant_type"=>"client_credentials"];
$req->authorization_basic($client,$secter);
$req->content_type('application/x-www-form-urlencoded');
my $res=$ua->request($req);
log("paypal pre auth error! $res->status_line") unless ($res->is_success );
my $json = JSON->new->utf8;
my $r=$json->decode($res->decoded_content);
#==============
#order details ====
my $ub = LWP::UserAgent->new;
$ub->default_header('Content-Type'=> 'application/json' );
$ub->default_header('Authorization'=> 'Bearer ' . $r->{access_token} );
my $resb=$ub->get($porder.$oid);
log("paypal checkout error!") unless ($resb->is_success );
my $jsonb = JSON->new->utf8;
my $s=$jsonb->decode($resb->decoded_content);
#===================
$c->rendered(200); #es default,nomas para enfatizar que puede ser 400 o 500
# interesan create time, id, payer: email address, shippng address
}
else{
my $data=$c->dbg->store_id($c->param('id'));
$c->redirect_to('cal') if ($c->param('id')==4);
$c->redirect_to('store') unless ($data->{'id'});
$c->stash($data);
$c->stash(layout=>'default');
}
}
sub spay{
my $c = shift;
my $data=$c->mproc->store_id($c->param('class'),$c->param('id'));
$c->stash($data);
if( ($c->param('id') <= 86) && ($c->param('id') >= 80) )
{ $c->stash(layout=>'xpay');}
else {$c->stash(layout=>'default');}
}
#stripe appi functions
#stripe appi function =============================================================================
sub intentCreate{
my $c = shift;
unless (defined ($c->req->json)){
@@ -139,21 +44,28 @@ sub intentCreate{
$c->render(template=>'home/not_found', status=>404);
return 0;
}
my $pmi=$c->req->json->{'payment_method_id'} // 0;
my $data=$c->mproc->intentCreate($c->req->json->{'tid'});
my ($amount,$description,$max_time) = ($data->{'precio'},$data->{'nombre'},9);
# if(!@$data){ intentError($c,"event not found",1); return;};
my $pmi=$c->req->json->{'payment_method_id'} // 0;
my $amount = $data->{'precio'} * $c->req->json->{'mq'} ;
my $description = $data->{'nombre'};
my $max_time = 9;
my $api_create_path='https://api.stripe.com/v1/payment_intents';
my $payment_info=[
'payment_method'=>$pmi,
'amount'=>$amount,
'amount'=>$amount*100,
'currency'=>'mxn',
'description'=>$description,
'payment_method_options[card][installments][enabled]'=>'true'
];
my $r=stripeAppi($api_create_path,$payment_info);
if ($r==0){intentError($c,"api create error",1); return;}
my $t->{intent_id}=$r->{id};
foreach (@{$r->{payment_method_options}{card}{installments}{available_plans}}){
push (@{$t->{available_plans}}, $_) unless ($_->{count}>$max_time);
push (@{$t->{available_plans}}, $_) unless ($_->{count} > $max_time);
}
$c->render(json=>$t);
return 0;
@@ -162,30 +74,49 @@ sub intentCreate{
sub intentConfirm{
my $c = shift;
my $max_time = 9;
unless (defined ($c->req->json)){
$c->stash(layout=>'clean');
$c->render(template=>'home/not_found', status=>404);
return;
return;
}
my $pii = $c->req->json->{'payment_intent_id'};
my $plan = $c->req->json->{'selected_plan'}//0;
unless ($c->mproc->intentSanity($c->req->json) == 0 ){
intentError($c,"sanity failed",0); return; }
my $data = $c->req->json;
my $pii = $data->{'payment_intent_id'};
my $plan = $data->{'selected_plan'} // 0;
my $api_confirm_path = "https://api.stripe.com/v1/payment_intents/$pii/confirm";
unless ($plan==0) {if ($plan->{count} > $max_time) {
log("\n\n max time instalment attempt\n\n");
$c->render(json=>{'error'=>'max time error'});
my $cplan = 0;
if ($plan != 0){
if ($plan->{count} > $max_time) {
intentError($c,'max time installment attempt error',3);
return 0;
}}
my $cplan=0;
}
$cplan = [
'payment_method_options[card][installments][plan][type]'=>'fixed_count',
'payment_method_options[card][installments][plan][interval]'=>'month',
'payment_method_options[card][installments][plan][count]'=>$plan->{count},
]
}
if (
intentCheck(
$c,
$data->{'payment_intent_id'},
$data->{'tid'},
$data->{'mq'}
) == -1) {
intentError($c,"api confirm error pre",2); return;
}
$cplan = [
'payment_method_options[card][installments][plan][type]'=>'fixed_count',
'payment_method_options[card][installments][plan][interval]'=>'month',
'payment_method_options[card][installments][plan][count]'=>$plan->{count},
]
unless ($plan==0);
my $r = stripeAppi($api_confirm_path,$cplan);
my $data=$c->mproc->intentCreate($c->req->json->{'tid'});
if ($r==0){intentError($c,"api confirm error post",2); return;}
if ($r->{'status'} ne "succeeded" ){intentError($c,"payment not completed,2"); return;}
$c->mproc->intentConfirm($data,$r);
my $rtt = {
'status'=>$r->{'status'},
'plan' => $r->{'payment_method_options'}{'card'}{'installments'}{'plan'},
@@ -194,11 +125,33 @@ sub intentConfirm{
return 0;
}
sub intentError{ # e: error msg, stage: 0-userinfo, 1 icreate. 2 iconfirm
my $c = shift;
$c->render(json => { 'e'=>shift, 'stage'=>shift });
return 0;
}
sub userCheck{
my $c=shift;
my $r = { 'userst' => $c->mproc->userDataSanity($c->req->json)};
$c->render(json=>$r);
return 0;
}
sub intentCheck{
my ($c, $cid, $tid, $mq) = @_;
my $stripe = stripeAppi("https://api.stripe.com/v1/payment_intents/$cid",0);
my $data=$c->mproc->intentCreate($tid);
return -1 unless ( $stripe->{'amount'} == ($data->{'precio'} * $mq)*100);
return 0;
}
sub stripeAppi{
my $sky='sk_test_GXWsfsoxy5336LrSw7SgTXNC00TV9O4Dbq';
my ($path,$data) = @_;
my $req = POST $path, $data;
$req->authorization_basic($sky,'');
my $req;
if ($data == 0 ) { $req = POST $path;} # -.-
else { $req = POST $path, $data;}
$req->authorization_basic(Dojo::Conf::STRIPE_SK,'');
$req->content_type('application/x-www-form-urlencoded');
my $ua = LWP::UserAgent->new;
my $res=$ua->request($req);
@@ -210,71 +163,49 @@ sub stripeAppi{
return $json->decode($res->decoded_content);
}
# Admin =======================================================================
sub admin_eventos{
my $c=shift;
if ( (my $t=$c->param('type') // "") =~/[ecp]/){
my $id=$c->param('id');
my $req=$c->param('req');
if ( $req eq "Eliminar"){
$c->dbv->event_del($id) if ($t eq 'e');
$c->dbv->course_del($id) if ($t eq 'c');
$c->dbv->place_del($id) if ($t eq 'p');
}
elsif( $req eq "Aceptar"){
if($t eq 'e'){
my @list=map{$c->param($_)}qw/eplace yini mini dini yend mend dend cost promo pen ecourse eimg een id/;
$c->dbv->event_up(@list) if ($id ==0);
$c->dbv->event_ch(@list) if ($id >0);
}
if($t eq 'c'){
my @list=map{$c->param($_)}qw/cname csubjects cservices cen id/;
$c->dbv->course_up(@list) if ($id ==0);
$c->dbv->course_ch(@list) if ($id >0);
}
if($t eq 'p'){
my @list=map{$c->param($_)}qw/pname paddr pobs pto pst pco plat plng pen id/;
$c->dbv->place_up(@list) if ($id ==0);
$c->dbv->place_ch(@list) if ($id >0);
}
}
$c->redirect_to("/admin/eventos");
}
# Not used but maybe later ======================================================
$c->stash(
courses=>$c->dbv->courses,
places=>$c->dbv->places,
months=>$c->dbv->months,
events=>$c->dbv->events,
img=>$c->dbv->eimgList,
);
$c->stash(template=>"home/admin/event");
$c->stash(layout=>"admin");
}
sub admin_tienda{
my $c=shift;
$c->stash(u=>$c->dbv->user_heads);
$c->stash(s=>$c->dbv->store_heads);
$c->stash(template=>"home/admin/tienda");
$c->stash(layout=>"admin");
}
sub admin_json{
my $c=shift;
my $id = $c->param('id');
my $req = $c->param('dreq');
my $json = "304";
$json = $c->dbv->astore($id) if $req=~/tienda/;
$json = $c->dbv->course($id) if $req=~/course/;
$json = $c->dbv->place($id) if $req=~/place/;
$json = $c->dbv->eventa($id) if $req=~/event/;
$c->render(json=>$json);
}
#==============================================================================
#sub storeppl{
#my $c=shift;
#if( defined($c->req->json) ){
#my $oid = $c->req->json->{'orderID'} //0;
#log( $oid );
##credentials====
#my $client='AQdZ1JJL-GNBgGTI3W6cXChmj6MnZsInRGlWeHw1kbGiE_49eTtZ2fPvEq9ersU2y6O5WpxccdsyAQw7';
#my $secter='EBn8CNOCrJbVZ_fNllXB7oUIm9_vhtqrJMm2zSBGbxSyiiych3cHOIWOLAD5NVw4Z3dmNhmsHQwPsrZ0';
#my $pauth='https://api.sandbox.paypal.com/v1/oauth2/token/';
#my $porder='https://api.sandbox.paypal.com/v2/checkout/orders/';
##=================
##pre auth ====
#my $ua = LWP::UserAgent->new;
#my $req=POST $pauth, ["grant_type"=>"client_credentials"];
#$req->authorization_basic($client,$secter);
#$req->content_type('application/x-www-form-urlencoded');
#my $res=$ua->request($req);
#log("paypal pre auth error! $res->status_line") unless ($res->is_success );
#my $json = JSON->new->utf8;
#my $r=$json->decode($res->decoded_content);
##==============
##order details ====
#my $ub = LWP::UserAgent->new;
#$ub->default_header('Content-Type'=> 'application/json' );
#$ub->default_header('Authorization'=> 'Bearer ' . $r->{access_token} );
#my $resb=$ub->get($porder.$oid);
#log("paypal checkout error!") unless ($resb->is_success );
#my $jsonb = JSON->new->utf8;
#my $s=$jsonb->decode($resb->decoded_content);
##===================
#$c->rendered(200); #es default,nomas para enfatizar que puede ser 400 o 500
## interesan create time, id, payer: email address, shippng address
#}
#else{
#my $data=$c->dbg->store_id($c->param('id'));
#$c->redirect_to('cal') if ($c->param('id')==4);
#$c->redirect_to('store') unless ($data->{'id'});
#$c->stash($data);
#$c->stash(layout=>'default');
#}
#}
1;

View File

@@ -0,0 +1,19 @@
insert into caja_evento
(
cliente_nombre,
cliente_correo,
cliente_comentario,
tienda_evento_id,
talla_id,
cantidad,
monto,
etapa_id,
entrega_id,
pago_clave,
plazo,
fecha_pago
)
values (?,?,?,?,?,?,?,?,?,?,?,now())
;

View File

@@ -0,0 +1,10 @@
select
t.precio as precio,
c.nombre as nombre
from
tienda_evento as t
inner join
curso as c on t.curso_id=c.id
where
t.id = ?
;

View File

@@ -1,30 +0,0 @@
select
t.id as tid,
c.nombre as nombre,
c.subnombre as subnombre,
c.descripcion as descripcion,
c.maestro as maestro,
c.imagen_a as cimga,
c.imagen_b as cimgb,
c.imagen_c as cimgc,
day(t.fecha_inicio) as dini,
month(t.fecha_inicio) as mini,
day(t.fecha_fin) as dfin,
month(t.fecha_fin) as mfin,
t.precio as precio,
t.promocion as promo,
t.promo_estado as promo_estado,
t.playera_estado as playera_estado,
t.cupo as cupo,
l.nombre as lnombre,
l.federativa as federativa,
l.pais as pais,
l.municipio as municipio
from tienda_evento as t
join curso as c on c.id = t.curso_id
join lugar as l on l.id = t.lugar_id
where t.id=? and t.estado =1
;

View File

@@ -1,10 +0,0 @@
select
id,
objeto as "objeto",
nombre as "nombre",
precio as "precio",
subnombre as "subnombre",
promocion as "promocion",
imagen as "imagen"
from tienda where activo =1;

View File

@@ -1,9 +1,10 @@
package Dojo::Model::Vdgproc; use Mojo::File 'path';
use Mojo::JSON qw(decode_json encode_json);
use Dojo::Support qw{month_num2txt log dmph} ;
use Dojo::Support qw{ mtxt month_num2txt log dmph} ;
use Mojo::Base 'Mojolicious::Controller';
use Email::Valid;
use Data::Dumper;
use File::Basename;
use Encode qw(decode_utf8 encode_utf8);
use Text::Markdown qw{ markdown };
@@ -15,24 +16,13 @@ my $data_path = path('lib/Dojo/Model/Data')->make_path;
#just for fun
# Tienda de eventos ===========================================================
sub calendar_monthblock {
my $r = _read ($data_path->child("cal/q1Block.q")->slurp);
map { $_->{fecha}=month_num2txt($_->{month})." ".$_->{year} } @$r;
return $r;
}
sub mtxt {
my ($di, $mi, $df, $mf)=@_; # dini,mini,dfin,mfin
my $txt;
if ($mi == $mf){
if ($di == $df){ $txt = "$di de ".month_num2txt($mi);}
else{ $txt = "Del $di al $df de ".month_num2txt($mi);}
}
else{
$txt = "Del $di de ".month_num2txt($mi)." al $df de ".month_num2txt($mf);
}
return $txt;
}
sub calendar_events {
my $r = _read ($data_path->child("cal/q3Event.q")->slurp);
foreach (@$r) { $_->{fecha} = mtxt( $_->{dini},$_->{mini},$_->{dfin},$_->{mfin}) }
@@ -48,29 +38,103 @@ sub event{
sub spay {
my ($c,$class,$id) = @_;
return _read ($data_path->child("/store/qIdStore.q")->slurp,$id)->[0];
return _read ($data_path->child("spay/qIdStore.q")->slurp,$id)->[0];
}
# 4000004840000008 3, 6, 9, 12, and 18 month installment plans available
# "*p4000004840000008
# 4242424242424242 No installment plans available.
#==============================================================================
sub store_id {
my ($c,$class,$id) = @_;
my $r = _read ($data_path->child("/store/qEstore.q")->slurp,$id)->[0];
my $r = _read ($data_path->child("store/qEstore.q")->slurp,$id)->[0];
$r->{fecha} = mtxt( $r->{dini},$r->{mini},$r->{dfin},$r->{mfin});
return $r;
}
# Stripe payment process ==============================================================
# ======================
# 4000004840000008 3, 6, 9, 12, and 18 month installment plans available
# "*p4000004840000008
# 4242424242424242 No installment plans available.
# ======================
sub intentCreate{
my ($c,$id) = @_;
my $q="select t.precio as precio, c.nombre as nombre from tienda_evento as t inner join curso as c on t.curso_id=c.id where t.id = ? ;";
return _read ($q,$id)->[0];
return _read ($data_path->child("spay/qIntentCreate.q")->slurp,$id)->[0];
}
sub intentConfirm{
my ($c,$id) = @_;
my $q="select t.precio as precio, c.nombre as nombre from tienda_evento as t inner join curso as c on t.curso_id=c.id where t.id = ? ;";
return _read ($q,$id)->[0];
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'};
my $plan = 0;
if (defined $data->{'selected_plan'}){
$plan = $data->{'selected_plan'}->{'count'};
}
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 ;
}
# 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 intentSanity{
my ($c,$d)=@_;
if (defined $d->{'selected_plan'} ){
return -1 unless defined ($d->{'selected_plan'}{'type'});
return -1 unless defined ($d->{'selected_plan'}{'count'});
return -1 unless defined ($d->{'selected_plan'}{'interval'});
}
return -1 unless defined ($d->{'tid'}) && $d->{'tid'} =~ /^\d+$/ ;
return -1 unless defined ($d->{'req'}) && $d->{'req'} eq 'check';
return -1 unless defined ($d->{'payment_intent_id'});
return userDataSanity($c,$d) ;
}
sub userDataSanity{
my ($c,$d) = @_;
return -1 unless (
defined ($d->{'students'}) && # (nombre,mail,observaciones, talla)
defined ($d->{'mq'}) &&
$d->{'mq'} =~/^\d+$/ &&
$d->{'mq'} < 10
);
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);
}
#==============================================================================
@@ -107,16 +171,7 @@ sub place_ch{
#==============================================================================
#ayudas =====================================
sub tst{
my $c=shift;
my $d=$c->param('n');
log("------log-------");
log("$d");
log("------log-------");
return 0;
}
# lower level read =====================================
sub _read{
my ($q,@bind)=@_;

View File

@@ -2,7 +2,7 @@ package Dojo::Support;
use strict;
use warnings;
use Exporter 'import';
our @EXPORT = qw/ commify month_num2txt log dmph merge_hash load_module get_names /;
our @EXPORT = qw/ mtxt commify month_num2txt log dmph merge_hash load_module get_names /;
use Mojo::Base 'Mojolicious';
use File::Basename;
@@ -17,6 +17,7 @@ sub log{
my $log = Mojo::Log->new;
$log->debug("============ ".shift." ===========");
}
sub get_names{
my $dir = shift;
my @file_name;
@@ -36,13 +37,26 @@ sub merge_hash{
my $merger = Hash::Merge->new('LEFT_PRECEDENT');
foreach (@_){
$h= $merger->merge($h,$_);
}
return $h;
}
return $h;
}
sub month_num2txt{
return ("enero febrero marzo abril mayo junio julio agosto septiembre octubre noviembre diciembre" =~ m/\w+/g)[shift (@_) -1];
}
sub mtxt {
my ($di, $mi, $df, $mf)=@_; # dini,mini,dfin,mfin
my $txt;
if ($mi == $mf){
if ($di == $df){ $txt = "$di de ".month_num2txt($mi);}
else{ $txt = "Del $di al $df de ".month_num2txt($mi);}
}
else{
$txt = "Del $di de ".month_num2txt($mi)." al $df de ".month_num2txt($mf);
}
return $txt;
}
#put comas on price numbers
sub commify {