2017-12-14 20:30:44 +00:00
|
|
|
package Pear::LocalLoop::Controller::Api::V1::Customer::Pies;
|
|
|
|
use Mojo::Base 'Mojolicious::Controller';
|
|
|
|
|
|
|
|
sub index {
|
|
|
|
my $c = shift;
|
|
|
|
|
|
|
|
my $entity = $c->stash->{api_user}->entity;
|
|
|
|
|
2017-12-15 14:59:38 +00:00
|
|
|
my $purchase_rs = $entity->purchases;
|
|
|
|
my $local_org_local_purchase = $purchase_rs->search({
|
|
|
|
"me.distance" => { '<', 20000 },
|
|
|
|
'organisation.is_local' => 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
join => { 'seller' => 'organisation' },
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
my $local_org_non_local_purchase = $purchase_rs->search({
|
|
|
|
"me.distance" => { '>=', 20000 },
|
|
|
|
'organisation.is_local' => 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
join => { 'seller' => 'organisation' },
|
|
|
|
}
|
|
|
|
);
|
2017-12-14 20:30:44 +00:00
|
|
|
|
2017-12-15 14:59:38 +00:00
|
|
|
my $non_local_org_local_purchase = $purchase_rs->search({
|
|
|
|
"me.distance" => { '<', 20000 },
|
|
|
|
'organisation.is_local' => 0,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
join => { 'seller' => 'organisation' },
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
my $non_local_org_non_local_purchase = $purchase_rs->search({
|
|
|
|
"me.distance" => { '>=', 20000 },
|
|
|
|
'organisation.is_local' => 0,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
join => { 'seller' => 'organisation' },
|
|
|
|
}
|
|
|
|
);
|
2017-12-14 20:30:44 +00:00
|
|
|
|
2018-04-05 16:19:53 +00:00
|
|
|
my $data = {
|
2017-12-15 14:59:38 +00:00
|
|
|
'Local shop local purchaser' => $local_org_local_purchase->count,
|
|
|
|
'Local shop non-local purchaser' => $local_org_non_local_purchase->count,
|
|
|
|
'Non-local shop local purchaser' => $non_local_org_local_purchase->count,
|
|
|
|
'Non-local shop non-local purchaser' => $non_local_org_non_local_purchase->count,
|
|
|
|
};
|
2018-03-26 13:44:03 +00:00
|
|
|
|
2017-12-14 20:30:44 +00:00
|
|
|
return $c->render(
|
|
|
|
json => {
|
|
|
|
success => Mojo::JSON->true,
|
2018-04-05 16:19:53 +00:00
|
|
|
pie => $data,
|
2017-12-14 20:30:44 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|