@@ -5,8 +5,11 @@ namespace App\Services\APIs\CustomerAPIs;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Models\CustomerFavouriteRestaurant;
|
||||
use App\Models\IamPrincipal;
|
||||
use App\Models\IamPrincipalRestaurantRole;
|
||||
use App\Models\ManageRestaurant;
|
||||
use App\Models\RedeemRestaurant;
|
||||
use App\Helpers\onesignalhelper;
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
@@ -249,6 +252,54 @@ class RestaurantApiServices
|
||||
$redeemRestaurant->redeemption_undone_date = null;
|
||||
$redeemRestaurant->save();
|
||||
|
||||
|
||||
|
||||
$imagePath = ListingImageUrl('restaurant_images', $restaurant->image);
|
||||
|
||||
$customerTitle = "Your Redemption was successful for " . $restaurant->name;
|
||||
$customerMessage = $restaurant->name . " Voucher Redeemed Successfully";
|
||||
$customerContentType = 'Voucher_Redemption';
|
||||
$customerImageUrl = $imagePath;
|
||||
|
||||
$customerData = IamPrincipal::where('id', $customerIamId)->where('notification_status', 1)->where('principal_type_xid', 3)->first();
|
||||
$restaurants = IamPrincipalRestaurantRole::select('id', 'principal_xid')->where('restaurant_xid', $restaurant->id)->get();
|
||||
|
||||
foreach ($restaurants as $restaurant) {
|
||||
$restUser = IamPrincipal::where('id', $restaurant->principal_xid)->where('notification_status', 1)->where('principal_type_xid', 4)->first();
|
||||
|
||||
if ($restUser) {
|
||||
$restImagePath = ListingImageUrl('restaurant_images', $restaurant->image);
|
||||
$restTitle = "New redemption for " . $restaurant->name;
|
||||
$restMessage = $restaurant->name . " new voucher Redeemed Successfully";
|
||||
$restContent_type = 'Voucher_Redemption';
|
||||
$restImageUrl = $restImagePath;
|
||||
|
||||
// Sending notification to restaurant
|
||||
$pushNotificationToRestaurant = onesignalhelper::restSendNotificationApi(
|
||||
$restUser->one_signal_player_id,
|
||||
$restTitle,
|
||||
$restMessage,
|
||||
$restContent_type,
|
||||
$restImageUrl,
|
||||
$id = null
|
||||
);
|
||||
onesignalhelper::StoreNotificationDetails($restUser->id, $restContent_type, $restTitle, $restImageUrl);
|
||||
}
|
||||
}
|
||||
|
||||
if ($customerData) {
|
||||
// Sending notification to customer
|
||||
$pushNotificationToCustomer = onesignalhelper::sendNotificationApi(
|
||||
$customerData->one_signal_player_id,
|
||||
$customerTitle,
|
||||
$customerMessage,
|
||||
$customerContentType,
|
||||
$customerImageUrl,
|
||||
$id = null
|
||||
);
|
||||
|
||||
onesignalhelper::StoreNotificationDetails($customerData->id, $customerContentType, $customerTitle, $customerImageUrl);
|
||||
}
|
||||
return jsonResponseWithSuccessMessageApi(__('success.restaurant_redeem'), $redeemRestaurant, 200);
|
||||
} catch (Exception $ex) {
|
||||
Log::error('Restaurant Redeem service failed: ' . $ex->getMessage());
|
||||
|
||||
Reference in New Issue
Block a user