Skip to content

Instantly share code, notes, and snippets.

@ahelord
Created February 10, 2021 03:11
Show Gist options
  • Save ahelord/5d9c8b220279b384fba11281194f8e87 to your computer and use it in GitHub Desktop.
Save ahelord/5d9c8b220279b384fba11281194f8e87 to your computer and use it in GitHub Desktop.
//Versión original del problema de refactor de Rappi en HackerRanks
<?php
class Controller {
public function post_confirm() {
$id = Input::get('service_id');
$servicio = Service::find($id);
//dd($servicio);
if ($servicio != NULL) {
if ($servicio->status_id == '6') {
return Response::json(array('error' => '2'));
}
if ($servicio->driver_id == NULL && $servcio->status_id == '1') {
$servicio = Service::update($id, array(
'driver_id' => Input::get('driver_id'),
'status_id' => '2'
//Up Carro
//,'pwd' => me5(Input::get('pwd'))
));
Driver::update(Input::get('driver_id'), array(
"available" => '0'
));
$driverTmp = Driver::find(Input::get('driver_id'));
Service::update($id, array(
'car_id' => $driverTmp->car_id
//Up Carro
//,'pwd' => md5(Input::get('pwd'))
));
//Notificar a usuario!
$pushMessage = 'Tu servicio ha sido confirmado!';
/* $servicio = Service::find($id);
$push = Push::make();
if ($servicio->user->type == '1') { //iPhone
$pushAns = $push->ios($servicio->user-->uuid, $pushMessage);
} else {
$pushAns = $push->android($servicio->user-->uuid, $pushMessage);
} */
$servicio = Service::find($id);
$push = Push::make();
if ($servcio->user->uuid == '') {
return Response::json(array('error' => '0'));
}
if ($servicio->user->type == '1') { //Iphone
$result = $push->ios($servicio->user->uuid, $pushMessage, 1, 'honk.wav', 'Open', array('serviceId' => $servicio->id));
} else {
$result = $push->android2($servicio->user->uuid, $pushMessage, 1, 'default', 'Open', array('serviceId' => $servicio->id));
}
return Response::json(array('error' => '0'));
} else {
return Response::json(array('error' => '1'));
}
} else {
return Response::json(array('error' => '3'));
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment