Add mqtt send event to fulfilled, cancelled and driver arrived #133
This commit is contained in:
parent
f4d4a6e3a0
commit
fbe6c42e50
1 changed files with 40 additions and 4 deletions
|
|
@ -24,6 +24,7 @@ use App\Ramcar\TradeInType;
|
|||
use App\Ramcar\InvoiceStatus;
|
||||
|
||||
use App\Service\InvoiceCreator;
|
||||
use App\Service\MQTTClient;
|
||||
|
||||
use App\Entity\RiderSession;
|
||||
use App\Entity\Customer;
|
||||
|
|
@ -478,14 +479,21 @@ class RAPIController extends Controller
|
|||
$jo->setStatus(JOStatus::CANCELLED);
|
||||
$em->flush();
|
||||
|
||||
// TODO: send mqtt event
|
||||
// send mqtt event
|
||||
$payload = [
|
||||
'event' => 'cancelled',
|
||||
'reason' => 'mobile cancellation',
|
||||
'jo_id' => $jo->getID(),
|
||||
];
|
||||
$mclient->sendEvent($obj, $payload);
|
||||
|
||||
|
||||
// TODO: add event
|
||||
|
||||
return $res->getReturnResponse();
|
||||
}
|
||||
|
||||
public function arrive(Request $req)
|
||||
public function arrive(Request $req, MQTTClient $mclient)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$required_params = ['jo_id'];
|
||||
|
|
@ -499,14 +507,27 @@ class RAPIController extends Controller
|
|||
$jo->setStatus(JOStatus::IN_PROGRESS);
|
||||
$em->flush();
|
||||
|
||||
// TODO: send mqtt event
|
||||
// send mqtt event
|
||||
$rider = $this->session->getRider();
|
||||
$image_url = $req->getScheme() . '://' . $req->getHttpHost() . $req->getBasePath() . '/assets/images/user.gif';
|
||||
if ($rider->getImageFile() != null)
|
||||
$image_url = $req->getScheme() . '://' . $req->getHttpHost() . $req->getBasePath() . '/uploads/' . $rider->getImageFile();
|
||||
|
||||
$payload = [
|
||||
'event' => 'driver_arrived',
|
||||
'jo_id' => $jo->getID(),
|
||||
'driver_image' => $rider->getImage(),
|
||||
'driver_name' => $rider->getFullName(),
|
||||
'driver_id' => $rider->getID(),
|
||||
];
|
||||
$mclient->sendEvent($jo, $payload);
|
||||
|
||||
// TODO: add event
|
||||
|
||||
return $res->getReturnResponse();
|
||||
}
|
||||
|
||||
public function payment(Request $req)
|
||||
public function payment(Request $req, MQTTClient $mclient)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$required_params = ['jo_id'];
|
||||
|
|
@ -522,6 +543,21 @@ class RAPIController extends Controller
|
|||
|
||||
$em->flush();
|
||||
|
||||
// send mqtt event (fulfilled)
|
||||
$rider = $this->session->getRider();
|
||||
$image_url = $req->getScheme() . '://' . $req->getHttpHost() . $req->getBasePath() . '/assets/images/user.gif';
|
||||
if ($rider->getImageFile() != null)
|
||||
$image_url = $req->getScheme() . '://' . $req->getHttpHost() . $req->getBasePath() . '/uploads/' . $rider->getImageFile();
|
||||
$payload = [
|
||||
'event' => 'fulfilled',
|
||||
'jo_id' => $obj->getID(),
|
||||
'driver_image' => $image_url,
|
||||
'driver_name' => $rider->getFullName(),
|
||||
'driver_id' => $rider->getID(),
|
||||
];
|
||||
$mclient->sendEvent($jo, $payload);
|
||||
|
||||
|
||||
// TODO: add event
|
||||
|
||||
return $res->getReturnResponse();
|
||||
|
|
|
|||
Loading…
Reference in a new issue