API
This commit is contained in:
@@ -62,4 +62,25 @@ class RedeemControllerApi extends Controller
|
||||
return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Created By : sayli Raut
|
||||
* Created at : 11 June 2024
|
||||
* Use : Search Redemption coupon.
|
||||
*/
|
||||
// public function searchRedemption(Request $request)
|
||||
// {
|
||||
// try {
|
||||
// $token = readRestHeaderToken();
|
||||
// if ($token) {
|
||||
// $restIamId = $token['sub'];
|
||||
// return $this->RedeemApiService->searchRedemption($restIamId, $request);
|
||||
// } else {
|
||||
// return jsonResponseWithErrorMessageApi(__('auth.user_deleted'), 409);
|
||||
// }
|
||||
// } catch (\Exception $e) {
|
||||
// Log::error("An error occurred in " . __METHOD__ . ": " . $e->getMessage(), ['exception' => $e]);
|
||||
// return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -20,52 +20,145 @@ class RedeemApiService
|
||||
$rest = IamPrincipal::findOrFail($restIamId);
|
||||
$data['user_detail'] = IamPrincipal::select('id', 'first_name', 'last_name', 'email_address', 'phone_number', 'date_of_birth')->find($rest->id);
|
||||
|
||||
$restaurantRoles = IamPrincipalRestaurantRole::select('id', 'principal_xid', 'restaurant_xid', 'role')->where('principal_xid', $rest->id)->first();
|
||||
$restaurantRoles = IamPrincipalRestaurantRole::select('id', 'principal_xid', 'restaurant_xid', 'role')
|
||||
->where('principal_xid', $rest->id)
|
||||
->first();
|
||||
|
||||
$restDetail = RedeemRestaurant::with('customer')->select('id', 'iam_principal_xid', 'manage_restaurants_xid', 'redeem_date', 'is_active', 'count')
|
||||
|
||||
$restDetail = RedeemRestaurant::with([
|
||||
'customer:id,first_name,last_name,profile_photo',
|
||||
'restaurant:id,image,name'
|
||||
])
|
||||
->select('id', 'iam_principal_xid', 'manage_restaurants_xid', 'redeem_date', 'is_active', 'count')
|
||||
->where('manage_restaurants_xid', $restaurantRoles->restaurant_xid)
|
||||
->where('is_redeem', 1)
|
||||
->get()
|
||||
->toArray();
|
||||
|
||||
|
||||
$restDetail = RedeemRestaurant::with('customer')->select('id', 'iam_principal_xid', 'manage_restaurants_xid', 'redeem_date', 'is_active', 'count')
|
||||
->where('manage_restaurants_xid', $restaurantRoles->restaurant_xid)
|
||||
->where('is_redeem', 1)
|
||||
->get()
|
||||
->toArray();
|
||||
->get();
|
||||
|
||||
foreach ($restDetail as $detail) {
|
||||
if ($detail->customer) {
|
||||
if ($detail->customer->profile_photo) {
|
||||
$detail->customer->profile_photo = ListingImageUrl('profile_image', $detail->customer->profile_photo);
|
||||
$detail->customer->profile_photo = $detail->customer->profile_photo
|
||||
? ListingImageUrl('profile_image', $detail->customer->profile_photo)
|
||||
: asset('public/assets/img/blankProfile.png');
|
||||
}
|
||||
|
||||
if ($detail->restaurant) {
|
||||
// Check if the image is already a URL
|
||||
if (!filter_var($detail->restaurant->image, FILTER_VALIDATE_URL)) {
|
||||
$detail->restaurant->image = ListingImageUrl('restaurant_images', $detail->restaurant->image);
|
||||
} else {
|
||||
$detail->customer->profile_photo = asset('public/assets/img/blankProfile.png');
|
||||
// Fallback if the image is already a URL
|
||||
$detail->restaurant->image = $detail->restaurant->image
|
||||
? $detail->restaurant->image
|
||||
: asset('public/assets/img/blankProfile.png');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dd($restDetail);
|
||||
$restDetailArray = $restDetail->toArray();
|
||||
|
||||
|
||||
|
||||
$restaurantDetail['redeemed_vouchers'] = $restDetail;
|
||||
$restaurantDetail['redemption_undone_vouchers'] = $redemptionUndoneVouchers;
|
||||
$restundoresumptionDetail = RedeemRestaurant::with([
|
||||
'customer:id,first_name,last_name,profile_photo',
|
||||
'restaurant:id,image,name'
|
||||
])
|
||||
->select('id', 'iam_principal_xid', 'manage_restaurants_xid', 'redeem_date', 'is_active', 'count', 'redeemption_undone_date')
|
||||
->where('manage_restaurants_xid', $restaurantRoles->restaurant_xid)
|
||||
->where('is_redeemption_undone', 1)
|
||||
->get();
|
||||
|
||||
foreach ($restundoresumptionDetail as $detail) {
|
||||
if ($detail->customer) {
|
||||
$detail->customer->profile_photo = $detail->customer->profile_photo
|
||||
? ListingImageUrl('profile_image', $detail->customer->profile_photo)
|
||||
: asset('public/assets/img/blankProfile.png');
|
||||
}
|
||||
|
||||
if ($detail->restaurant) {
|
||||
// Check if the image is already a URL
|
||||
if (!filter_var($detail->restaurant->image, FILTER_VALIDATE_URL)) {
|
||||
$detail->restaurant->image = ListingImageUrl('restaurant_images', $detail->restaurant->image);
|
||||
} else {
|
||||
// Fallback if the image is already a URL
|
||||
$detail->restaurant->image = $detail->restaurant->image
|
||||
? $detail->restaurant->image
|
||||
: asset('public/assets/img/blankProfile.png');
|
||||
}
|
||||
}
|
||||
}
|
||||
$restundoRedumption = $restundoresumptionDetail->toArray();
|
||||
|
||||
|
||||
$restaurantDetail = [
|
||||
'redeemed_vouchers' => $restDetailArray,
|
||||
'redemption_undone_vouchers' => $restundoRedumption,
|
||||
];
|
||||
|
||||
return jsonResponseWithSuccessMessageApi(__('auth.User_details_fetch'), $restaurantDetail, 200);
|
||||
} catch (Exception $ex) {
|
||||
Log::error('Restaurant Get data service failed : ' . $ex->getMessage());
|
||||
Log::error('Restaurant Get data service failed: ' . $ex->getMessage());
|
||||
return jsonResponseWithErrorMessageApi(__('auth.something_went_wrong'), 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public function undoRedemption($restIamId, $request)
|
||||
{
|
||||
try {
|
||||
$rest = ManageRestaurant::where('short_id', $request->voucher_id)->first();
|
||||
$voucherDetail = RedeemRestaurant::where('id', $request->voucher_id)->first();
|
||||
$rest = ManageRestaurant::where('id', $voucherDetail->manage_restaurants_xid)->first();
|
||||
if ($voucherDetail) {
|
||||
$voucherDetail->update([
|
||||
'is_redeem' => 0,
|
||||
'redeem_date' => null,
|
||||
'is_redeemption_undone' => 1,
|
||||
'redeemption_undone_date' => now(),
|
||||
|
||||
]);
|
||||
$imagePath = ListingImageUrl('restaurant_images', $rest->image);
|
||||
$customerTitle = "Your voucher was successfully undo redemption for " . $rest->name;
|
||||
$customerMessage = $rest->name . " Voucher Undo Redemption Successfully";
|
||||
$customerContentType = 'Voucher_UndoRedemption';
|
||||
$customerImageUrl = $imagePath;
|
||||
$customerData = IamPrincipal::where('id', $voucherDetail->iam_principal_xid)->where('notification_status', 1)->where('principal_type_xid', 3)->first();
|
||||
if ($customerData) {
|
||||
$pushNotificationToCustomer = onesignalhelper::sendNotificationApi(
|
||||
$customerData->one_signal_player_id,
|
||||
$customerTitle,
|
||||
$customerMessage,
|
||||
$customerContentType,
|
||||
$customerImageUrl,
|
||||
$id = null
|
||||
);
|
||||
|
||||
onesignalhelper::StoreNotificationDetails($customerData->id, $customerContentType, $customerTitle, $customerImageUrl);
|
||||
}
|
||||
$restUser = IamPrincipal::where('id', $restIamId)->where('notification_status', 1)->where('principal_type_xid', 4)->first();
|
||||
if ($restUser) {
|
||||
$restImagePath = ListingImageUrl('voucher_images', $rest->image);
|
||||
$restTitle = "voucher Undo redemption successful for " . $rest->name;
|
||||
$restMessage = $rest->image . " Voucher Undo Redemption Successfully";
|
||||
$restContentType = 'Voucher_UndoRedemption';
|
||||
$restImageUrl = $restImagePath;
|
||||
|
||||
$pushNotificationToCustomer = onesignalhelper::restSendNotificationApi(
|
||||
$restUser->one_signal_player_id,
|
||||
$restTitle,
|
||||
$restMessage,
|
||||
$restContentType,
|
||||
$restImageUrl,
|
||||
$id = null
|
||||
);
|
||||
|
||||
onesignalhelper::StoreNotificationDetails($restUser->id, $restContentType, $restTitle, $restImageUrl);
|
||||
}
|
||||
return jsonResponseWithSuccessMessageApi(__('auth.data_updated_successfully'), 200);
|
||||
} else {
|
||||
return jsonResponseWithErrorMessageApi(__('auth.voucher_not_found'), 404);
|
||||
}
|
||||
} catch (Exception $ex) {
|
||||
Log::error('Restaurant update profile service failed: ' . $ex->getMessage());
|
||||
return jsonResponseWithErrorMessageApi(__('auth.something_went_wrong'), 500);
|
||||
@@ -73,6 +166,124 @@ class RedeemApiService
|
||||
}
|
||||
|
||||
|
||||
public function getRedemedData(Request $request)
|
||||
{
|
||||
try {
|
||||
$restIamId = $request->input('restIamId');
|
||||
$rest = IamPrincipal::findOrFail($restIamId);
|
||||
$data['user_detail'] = IamPrincipal::select('id', 'first_name', 'last_name', 'email_address', 'phone_number', 'date_of_birth')->find($rest->id);
|
||||
|
||||
$restaurantRoles = IamPrincipalRestaurantRole::select('id', 'principal_xid', 'restaurant_xid', 'role')
|
||||
->where('principal_xid', $rest->id)
|
||||
->first();
|
||||
|
||||
$query = RedeemRestaurant::with([
|
||||
'customer:id,first_name,last_name,profile_photo',
|
||||
'restaurant:id,image,name'
|
||||
])
|
||||
->select('id', 'iam_principal_xid', 'manage_restaurants_xid', 'redeem_date', 'is_active', 'count')
|
||||
->where('manage_restaurants_xid', $restaurantRoles->restaurant_xid)
|
||||
->where('is_redeem', 1);
|
||||
|
||||
// Apply filters based on query parameters
|
||||
if ($request->has('customer_first_name')) {
|
||||
$query->whereHas('customer', function ($q) use ($request) {
|
||||
$q->where('first_name', 'like', '%' . $request->input('customer_first_name') . '%');
|
||||
});
|
||||
}
|
||||
|
||||
if ($request->has('customer_last_name')) {
|
||||
$query->whereHas('customer', function ($q) use ($request) {
|
||||
$q->where('last_name', 'like', '%' . $request->input('customer_last_name') . '%');
|
||||
});
|
||||
}
|
||||
|
||||
if ($request->has('redeem_date')) {
|
||||
$query->whereDate('redeem_date', $request->input('redeem_date'));
|
||||
}
|
||||
|
||||
$restDetail = $query->get();
|
||||
|
||||
foreach ($restDetail as $detail) {
|
||||
if ($detail->customer) {
|
||||
$detail->customer->profile_photo = $detail->customer->profile_photo
|
||||
? ListingImageUrl('profile_image', $detail->customer->profile_photo)
|
||||
: asset('public/assets/img/blankProfile.png');
|
||||
}
|
||||
|
||||
if ($detail->restaurant) {
|
||||
if (!filter_var($detail->restaurant->image, FILTER_VALIDATE_URL)) {
|
||||
$detail->restaurant->image = ListingImageUrl('restaurant_images', $detail->restaurant->image);
|
||||
} else {
|
||||
$detail->restaurant->image = $detail->restaurant->image
|
||||
? $detail->restaurant->image
|
||||
: asset('public/assets/img/blankProfile.png');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$restDetailArray = $restDetail->toArray();
|
||||
|
||||
// For redemption undone vouchers
|
||||
$queryUndo = RedeemRestaurant::with([
|
||||
'customer:id,first_name,last_name,profile_photo',
|
||||
'restaurant:id,image,name'
|
||||
])
|
||||
->select('id', 'iam_principal_xid', 'manage_restaurants_xid', 'redeem_date', 'is_active', 'count', 'redeemption_undone_date')
|
||||
->where('manage_restaurants_xid', $restaurantRoles->restaurant_xid)
|
||||
->where('is_redeemption_undone', 1);
|
||||
|
||||
// Apply filters based on query parameters
|
||||
if ($request->has('customer_first_name')) {
|
||||
$queryUndo->whereHas('customer', function ($q) use ($request) {
|
||||
$q->where('first_name', 'like', '%' . $request->input('customer_first_name') . '%');
|
||||
});
|
||||
}
|
||||
|
||||
if ($request->has('customer_last_name')) {
|
||||
$queryUndo->whereHas('customer', function ($q) use ($request) {
|
||||
$q->where('last_name', 'like', '%' . $request->input('customer_last_name') . '%');
|
||||
});
|
||||
}
|
||||
|
||||
if ($request->has('redeemption_undone_date')) {
|
||||
$queryUndo->whereDate('redeemption_undone_date', $request->input('redeemption_undone_date'));
|
||||
}
|
||||
|
||||
$restundoresumptionDetail = $queryUndo->get();
|
||||
|
||||
foreach ($restundoresumptionDetail as $detail) {
|
||||
if ($detail->customer) {
|
||||
$detail->customer->profile_photo = $detail->customer->profile_photo
|
||||
? ListingImageUrl('profile_image', $detail->customer->profile_photo)
|
||||
: asset('public/assets/img/blankProfile.png');
|
||||
}
|
||||
|
||||
if ($detail->restaurant) {
|
||||
if (!filter_var($detail->restaurant->image, FILTER_VALIDATE_URL)) {
|
||||
$detail->restaurant->image = ListingImageUrl('restaurant_images', $detail->restaurant->image);
|
||||
} else {
|
||||
$detail->restaurant->image = $detail->restaurant->image
|
||||
? $detail->restaurant->image
|
||||
: asset('public/assets/img/blankProfile.png');
|
||||
}
|
||||
}
|
||||
}
|
||||
$restundoRedumption = $restundoresumptionDetail->toArray();
|
||||
|
||||
$restaurantDetail = [
|
||||
'redeemed_vouchers' => $restDetailArray,
|
||||
'redemption_undone_vouchers' => $restundoRedumption,
|
||||
];
|
||||
|
||||
return jsonResponseWithSuccessMessageApi(__('auth.User_details_fetch'), $restaurantDetail, 200);
|
||||
} catch (Exception $ex) {
|
||||
Log::error('Restaurant Get data service failed: ' . $ex->getMessage());
|
||||
return jsonResponseWithErrorMessageApi(__('auth.something_went_wrong'), 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// public function searchRedemption($restIamId, $request)
|
||||
// {
|
||||
// try {
|
||||
|
||||
Reference in New Issue
Block a user