我必须在我的项目中实现通知功能,该功能是在CodeIgniter中实现的。
情景就好了,我的设备中有两个应用程序,即驱动程序和乘客应用程序。我在控制器文件中创建了一个函数,并尝试向这两个应用程序发送通知。但我只收到一个驱动程序应用程序的通知。
以下是我的控制器功能。请建议我在哪里犯错 -
public function tripNotStartedCron() {
try {
$allTripsdata = $this->trip->getAllTripsCron();
echo "<pre>";print_r($allTripsdata);
$allCancelTripsdata = $this->trip->getAllTripsCron(1);
print_r($allCancelTripsdata);
// Send notification for trip notification after 30 min
foreach ($allTripsdata as $tripsData) {
/* Time calculation */
$buggyTimeZones = array('19800' => 'Asia/Calcutta');
if (array_key_exists($tripsData['timezone'], $buggyTimeZones)) {
$pickUpLocationTimeZone = $buggyTimeZones[$tripsData['timezone']];
} else {
$pickUpLocationTimeZone = timezone_name_from_abbr('', $tripsData['timezone'], 0);
}
$date = new DateTime('NOW', new DateTimeZone($pickUpLocationTimeZone));
$tripsData['pickupdatetime'] = date('Y-m-d H:i:s', strtotime($tripsData['pickupdatetime'] . ' +' . CONFIRMED_CANCELLED_TRIP . ' minutes'));
$tripDateTime = new DateTime($tripsData['pickupdatetime'], new DateTimeZone($pickUpLocationTimeZone));
/* End time calculation */
$driverId = $tripsData['fkdriverid'];
$rideId = $tripsData['rideid'];
$asap = $tripsData['is_pickup_as_soon'];
$tripStatusId = TRIP_STATUS_DRIVERCONFIRMED;
//$message = 'You have a trip that was scheduled to start more than ' . CONFIRMED_CANCELLED_TRIP . ' minutes ago, if you do not start it within ' . DRIVER_TRIP_CANCELLED_SECOND_WARING . ' minutes it will be automatically cancelled.';
$message = 'You have a trip that was scheduled to start more than 1 hour ago, if you do not start it within ' . DRIVER_TRIP_CANCELLED_SECOND_WARING . ' minutes it will be automatically cancelled.';
//echo date($date->format('U'))."----------".date($tripDateTime->format('U'));
if ($date->format('U') > $tripDateTime->format('U')) {
if ($driverId > 0) {
/* * ** Send push notificaion on ios *** */
$iosDeviceDetailArr = $this->profile->getIosNotificationStatus($driverId, DRIVER_ROLE, IOS);
$tripCompleteDetail = $this->trip->getOrderDetailForARide($rideId);
$driverDetails = $this->profile->getDriverDetails($driverId);
$driverBUserId = $driverDetails[0]->id ? $driverDetails[0]->id : 0;
$driverCurrentUserId = $driverId;
$driverCurrentRoleId = DRIVER_ROLE;
$additionalDetail = array();
if (!empty($driverBUserId)) {
$additionalDetail = array('bUserId' => $driverBUserId, 'currentUserId' => $driverCurrentUserId, 'currentRoleId' => $driverCurrentRoleId);
}
/* store notification detail in db start */
$dataDictionary = array(
'alert' => $message,
'ondemand' => $asap,
'ridedetail' => $tripCompleteDetail,
'rideid' => $rideId,
'type' => "trip_cancel_reminder",
'userdetail' => $additionalDetail
);
$dataToSave = array(
'buserid' => $additionalDetail['bUserId'],
'currentuserid' => $additionalDetail['currentUserId'],
'currentroleid' => $additionalDetail['currentRoleId'],
'datadictionary' => json_encode($dataDictionary),
'rideid' => $rideId,
'notificationlabel' => 'Trip Scheduling Alert',
'createddate' => date('Y-m-d H:i:s'),
'modifydate' => date('Y-m-d H:i:s')
);
$notificationId = $this->common->saveDetails(TBL_PUSH_NOTIFICATIONS, $dataToSave);
if ($notificationId) {
updateNotificationStatus(array('currentuserid' => $additionalDetail['currentUserId'], 'rideid' => $rideId, 'notificationid !=' => $notificationId), 'trip_cancel_reminder');
}
$tripCompleteDetail[0]['notificationId'] = (isset($notificationId) && $notificationId) ? $notificationId : 0;
/* store notification detail in db start */
$res = member_notification_ios($iosDeviceDetailArr, $message, $rideId, $asap, $tripCompleteDetail, $additionalDetail, 'trip_cancel_reminder');
/* * ** Send push notificaion on antroid device *** */
$androidDeviceDetailArr = $this->profile->getIosNotificationStatus($driverId, DRIVER_ROLE, ANTROID);
if (is_array($androidDeviceDetailArr) && count($androidDeviceDetailArr) > 0)
foreach ($androidDeviceDetailArr as $deviceDetail) {
/* * ** Code for send push notification *** */
$deviceToken = isset($deviceDetail['devicetoken']) ? $deviceDetail['devicetoken'] : '';
$deviceToken = get_device_token($deviceToken);
if (isset($deviceToken) && !empty($deviceToken))
$androidRes = member_notification_antroid($deviceDetail['devicetoken'], $message, $rideId, $asap, $tripCompleteDetail, $additionalDetail, 'trip_cancel_reminder');
}
/* Update notification status in TBL_TRIPS_ASSIGNEDDRIVER table */
$data = array('notificationflag' => 1);
$condition = array('fkdriverid' => $driverId, 'rideid' => $rideId, 'tripstatusid' => $tripStatusId);
$updateResult = $this->common->saveDetails(TBL_TRIPS_ASSIGNEDDRIVER, $data, $condition);
/* * ** End of code for push notification *** */
}
}
}
// Send notification for trip cancelation after 35 min
foreach ($allCancelTripsdata as $canceltripsData) {
/* Time calculation */
$buggyTimeZones = array('19800' => 'Asia/Calcutta');
if (array_key_exists($canceltripsData['timezone'], $buggyTimeZones)) {
$pickUpLocationTimeZone = $buggyTimeZones[$canceltripsData['timezone']];
} else {
$pickUpLocationTimeZone = timezone_name_from_abbr('', $canceltripsData['timezone'], 0);
}
$date = new DateTime('NOW', new DateTimeZone($pickUpLocationTimeZone));
$canceltripsData['pickupdatetime'] = date('Y-m-d H:i:s', strtotime($canceltripsData['pickupdatetime'] . ' +' . CONFIRMED_CANCELLED_TRIP_FINAL . ' minutes'));
$tripDateTime = new DateTime($canceltripsData['pickupdatetime'], new DateTimeZone($pickUpLocationTimeZone));
$driverId = $canceltripsData['fkdriverid'];
$rideId = $canceltripsData['rideid'];
$asap = $canceltripsData['is_pickup_as_soon'];
$tripStatusId = TRIP_STATUS_DRIVERCONFIRMED;
//$message = 'Your trip has been cancelled because it was never started.';
$messagePassenger = 'Your trip has been cancelled because the driver did not show up to the location.';
$messageDriver = 'Your trip has been cancelled because you did not show up to the location.';
if ($date->format('U') > $tripDateTime->format('U')) {
if ($driverId > 0) {
/** ** Send push notificaion on ios *** */
$tripCompleteDetail = $this->trip->getOrderDetailForARide($rideId);
$iosDeviceDetailArrDriver = $this->profile->getIosNotificationStatus($driverId, DRIVER_ROLE, IOS);
//echo "<pre>";print_r($iosDeviceDetailArr);die(' ll');
$driverDetails = $this->profile->getDriverDetails($driverId);
$driverBUserId = $driverDetails[0]->id ? $driverDetails[0]->id : 0;
$driverCurrentUserId = $driverId;
$driverCurrentRoleId = DRIVER_ROLE;
$additionalDetailDriver = array();
$additionalDetailPassenger = array();
if (!empty($driverBUserId)) {
$additionalDetailDriver = array('bUserId' => $driverBUserId, 'currentUserId' => $driverCurrentUserId, 'currentRoleId' => $driverCurrentRoleId);
}
/* store notification detail in db start */
$dataDictionaryDriver = array(
'alert' => $messageDriver,
'ondemand' => $asap,
'ridedetail' => $tripCompleteDetail,
'rideid' => $rideId,
'type' => "trip_cancel_notification_driver",
'userdetail' => $additionalDetailDriver
);
$dataToSaveDriver = array(
'buserid' => $additionalDetailDriver['bUserId'],
'currentuserid' => $additionalDetailDriver['currentUserId'],
'currentroleid' => $additionalDetailDriver['currentRoleId'],
'datadictionary' => json_encode($dataDictionaryDriver),
'rideid' => $rideId,
'notificationlabel' => 'Trip Cancelled',
'forlisting' => 0,
'createddate' => date('Y-m-d H:i:s'),
'modifydate' => date('Y-m-d H:i:s')
);
$notificationIdDriver = $this->common->saveDetails(TBL_PUSH_NOTIFICATIONS, $dataToSaveDriver);
if ($notificationIdDriver) {
updateNotificationStatus(array('currentuserid' => $additionalDetailDriver['currentUserId'], 'rideid' => $rideId, 'notificationid !=' => $notificationIdDriver), 'trip_cancel_notification_driver');
}
$tripCompleteDetail[0]['notificationId'] = (isset($notificationIdDriver) && $notificationIdDriver) ? $notificationIdDriver : 0;
/* store notification detail in db start */
$res = member_notification_ios($iosDeviceDetailArrDriver, $messageDriver, $rideId, $asap, $tripCompleteDetail, $additionalDetailDriver, 'trip_cancel_notification_driver');
$androidDeviceDetailArrDriver = $this->profile->getIosNotificationStatus($driverId, DRIVER_ROLE, ANTROID);
if (is_array($androidDeviceDetailArrDriver) && count($androidDeviceDetailArrDriver) > 0) {
foreach ($androidDeviceDetailArrDriver as $deviceDetail) {
/* * ** Code for send push notification *** */
$deviceToken = isset($deviceDetail['devicetoken']) ? $deviceDetail['devicetoken'] : '';
$deviceToken = get_device_token($deviceToken);
if (isset($deviceToken) && !empty($deviceToken))
$androidRes = member_notification_antroid($deviceDetail['devicetoken'], $messageDriver, $rideId, $asap, $tripCompleteDetail, $additionalDetailDriver, 'trip_cancel_notification_driver');
}
}
/*********************************************************/
$iosDeviceDetailArrPassenger = $this->profile->getIosNotificationStatus($tripCompleteDetail[0]['currentuserid'], USER_ROLE, IOS);
$userRecord = $this->common->getData(TBL_USE_AS, array('use_driverfy_as' => $tripCompleteDetail[0]['currentuserid']), 'array', 'userid', 'rows');
if (!empty($userRecord)) {
$additionalDetailPassenger = array('bUserId' => $userRecord[0]['userid'], 'currentUserId' => $tripCompleteDetail[0]['currentuserid'], 'currentRoleId' => USER_ROLE);
}
$dataDictionaryPassenger = array(
'alert' => $messagePassenger,
'ondemand' => $asap,
'ridedetail' => $tripCompleteDetail,
'rideid' => $rideId,
'type' => "trip_cancel_notification_passenger",
'userdetail' => $additionalDetailPassenger
);
$dataToSavePassenger = array(
'buserid' => $additionalDetailPassenger['bUserId'],
'currentuserid' => $additionalDetailPassenger['currentUserId'],
'currentroleid' => $additionalDetailPassenger['currentRoleId'],
'datadictionary' => json_encode($dataDictionaryPassenger),
'rideid' => $rideId,
'notificationlabel' => 'Trip Cancelled',
'forlisting' => 0,
'createddate' => date('Y-m-d H:i:s'),
'modifydate' => date('Y-m-d H:i:s')
);
$notificationIdPassenger = $this->common->saveDetails(TBL_PUSH_NOTIFICATIONS, $dataToSavePassenger);
if ($notificationIdPassenger) {
updateNotificationStatus(array('currentuserid' => $additionalDetailPassenger['currentUserId'], 'rideid' => $rideId, 'notificationid !=' => $notificationIdPassenger), 'trip_cancel_notification_passenger');
}
$tripCompleteDetail[0]['notificationId'] = (isset($notificationIdPassenger) && $notificationIdPassenger) ? $notificationIdPassenger : 0;
/* store notification detail in db start */
$res = member_notification_ios($iosDeviceDetailArrPassenger, $messagePassenger, $rideId, $asap, $tripCompleteDetail, $additionalDetailPassenger, 'trip_cancel_notification_passenger', '', USER_ROLE);
die("tt");
/** ** Send push notificaion on antroid device *** */
$androidDeviceDetailArrPassenger = $this->profile->getIosNotificationStatus($tripCompleteDetail[0]['currentuserid'], USER_ROLE, ANTROID);
if (is_array($androidDeviceDetailArrPassenger) && count($androidDeviceDetailArrPassenger) > 0) {
foreach ($androidDeviceDetailArrPassenger as $deviceDetail) {
/* * ** Code for send push notification *** */
$deviceToken = isset($deviceDetail['devicetoken']) ? $deviceDetail['devicetoken'] : '';
$deviceToken = get_device_token($deviceToken);
if (isset($deviceToken) && !empty($deviceToken))
$androidRes = member_notification_antroid($deviceDetail['devicetoken'], $messagePassenger, $rideId, $asap, $tripCompleteDetail, $additionalDetailPassenger, 'trip_cancel_notification_passenger');
}
}
/* * ** End Send push notificaion on antroid device *** */
/* Update notification status in TBL_TRIPS_ASSIGNEDDRIVER table */
$cancelData = array('tripstatusid' => TRIP_STATUS_CANCEL_RUN);
$conditionCancel = array('fkdriverid' => $driverId, 'rideid' => $rideId, 'tripstatusid' => $tripStatusId);
$updateResult = $this->common->saveDetails(TBL_TRIPS_ASSIGNEDDRIVER, $cancelData, $conditionCancel);
/* * ** End of code for push notification *** */
/* Code for void authorized amount of cancel trip */
$orderResultedData = $this->common->getData(TBL_RS_ORDER, array('bookingid' => $canceltripsData['bookingid']), 'array', 'orderid');
//echo 'orderId=>'.$orderResultedData['orderid']; echo "<br/>";
$tripAuthorizationDetails = $this->common->getRowDetails(TBL_RS_ORDER_AUTHORIZATION, array('orderid' => $orderResultedData['orderid'], 'authorization_status' => 'hold', 'is_edit_charge' => 0, 'is_cancel_charge' => 0), '', 1);
//print_r($tripAuthorizationDetails);
if (count($tripAuthorizationDetails) > 0) {
foreach ($tripAuthorizationDetails as $key => $value) {
$brainTreeAuthorizationId = base64_decode($value['braintree_authorization_id']);
$orderAuthorizationId = $value['id'];
/* Here we will void all amount and maintain records in tables for future */
$this->load->library("braintreelib");
$rsltVoidSucc = $this->braintreelib->voidTransactionCustomer($brainTreeAuthorizationId);
if ($rsltVoidSucc->success) {
/* Insert records in escrow details table */
$tableName = TBL_ORDER_ESCROW_DETAIL;
$condition = array();
$dataToSave = array(
'escrow_status' => VOID_ALL_AMOUNT,
'order_id' => $orderResultedData['orderid'],
'final_trip_amount' => 0,
'created_date' => date('Y-m-d H:i:s'),
'braintree_escrow_id' => $brainTreeAuthorizationId,
'order_authorization_id' => $orderAuthorizationId
);
$insertData = $this->common->saveDetails($tableName, $dataToSave, $condition);
if ($insertData) {
$updateData = $this->common->saveDetails(TBL_RS_ORDER_AUTHORIZATION, array('authorization_status' => 'amount_void'), array('id' => $value['id']));
} else {
$this->data['status'] = faLSE;
$this->data['data'] = '';
$this->data['errorMessages'] = 'Your trip is cancel, but amount is not refund. Please contact to admin.';
}
/* End */
} else {
$errorFound = '';
foreach ($rsltVoidSucc->errors->deepAll() as $error) {
echo $errorFound = $error->message;
}
die();
}
}
}
/* End code for void authorized amount of cancel trip */
}
}
}
} catch (Exception $e) {
echo $e->getMessage() . "<br>" . $e->getFile() . "<br>" . $e->getLine();
}
}