Merge branch 'main' of https://github.com/WDI-Ideas/cheerstothe_season_laravel11 into HritikCheers
This commit is contained in:
@@ -12,6 +12,8 @@ use Carbon\Carbon;
|
||||
use Tymon\JWTAuth\Facades\JWTAuth;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Subscriptions;
|
||||
use Stripe\Subscription;
|
||||
|
||||
class CustomerControllerApi extends Controller
|
||||
{
|
||||
@@ -168,7 +170,42 @@ class CustomerControllerApi extends Controller
|
||||
|
||||
if ($token) {
|
||||
$iamPrincipalId = $token['sub'];
|
||||
$deleteUser = IamPrincipal::find($iamPrincipalId);
|
||||
$stripeSecret = (config('constants.subscription.stripe_secret_key'));
|
||||
// $stripeSecret = env('STRIPE_SECRET');
|
||||
|
||||
$stripe = new \Stripe\StripeClient($stripeSecret);
|
||||
$userId = $iamPrincipalId;
|
||||
|
||||
// dd($id,$stripeSecret);
|
||||
|
||||
$getSubscriptionData = Subscriptions::where('iam_principal_xid', $userId)->where('subscription_status', 'active')->first();
|
||||
if ($getSubscriptionData) {
|
||||
$subscriptionId = $getSubscriptionData->subscription_id;
|
||||
|
||||
$cancelledSubscription = $stripe->subscriptions->update(
|
||||
$subscriptionId,
|
||||
['cancel_at_period_end' => true]
|
||||
);
|
||||
|
||||
$subscriptionFromDatabase = Subscriptions::where('subscription_id', $subscriptionId)->first();
|
||||
$subscriptionFromDatabase->cancelled_at = date('Y-m-d H:i:s', $cancelledSubscription->canceled_at);
|
||||
|
||||
$subscriptionFromDatabase->subscription_status = $cancelledSubscription->status;
|
||||
$subscriptionFromDatabase->is_cancelled_subscription = 1;
|
||||
$subscriptionFromDatabase->status = "cancelled";
|
||||
|
||||
$subscriptionFromDatabase->save();
|
||||
|
||||
|
||||
$getSubscription = $stripe->subscriptions->retrieve($subscriptionFromDatabase->subscription_id, []);
|
||||
|
||||
|
||||
$getSubscribeCustomer = $stripe->customers->retrieve(
|
||||
$subscriptionFromDatabase->stripe_customer_id,
|
||||
[]
|
||||
);
|
||||
}
|
||||
$deleteUser = IamPrincipal::find($userId);
|
||||
$deleteUser->one_signal_player_id = null;
|
||||
$deleteUser->save();
|
||||
|
||||
@@ -189,7 +226,7 @@ class CustomerControllerApi extends Controller
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* Created By : sayli Raut
|
||||
* Created at : 15 July 2024
|
||||
* Use : To get user subscription status.
|
||||
@@ -203,7 +240,6 @@ class CustomerControllerApi extends Controller
|
||||
$customerIamId = $token['sub'];
|
||||
$response = $this->CustomerApiServices->CheckSubscription($customerIamId);
|
||||
return jsonResponseWithSuccessMessageApi(__('auth.data_fetched_successfully'), ['is_subscribed' => $response], 200);
|
||||
|
||||
} else {
|
||||
return jsonResponseWithErrorMessageApi(__('auth.user_deleted'), 409);
|
||||
}
|
||||
|
||||
@@ -28,8 +28,7 @@ class RestaurantApiServices
|
||||
public function getCoordinates($customerIamId)
|
||||
{
|
||||
try {
|
||||
// $perPage = request()->get('per_page', 10000);
|
||||
|
||||
// Fetch all active restaurants
|
||||
$restaurants = ManageRestaurant::with('closedRestaurant')
|
||||
->select(
|
||||
'id',
|
||||
@@ -38,7 +37,8 @@ class RestaurantApiServices
|
||||
'address',
|
||||
'short_id',
|
||||
'latitude',
|
||||
'longtitude'
|
||||
'longtitude',
|
||||
'state_xid'
|
||||
)
|
||||
->where('is_active', '1')->get();
|
||||
|
||||
@@ -110,16 +110,67 @@ class RestaurantApiServices
|
||||
$restaurant['operating_hours'] = "N/A";
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate next redemption time
|
||||
$lastRedeem = RedeemRestaurant::where('iam_principal_xid', $customerIamId)
|
||||
->where('manage_restaurants_xid', $restaurant->id)
|
||||
->where('is_redeem', 1)
|
||||
->orderBy('redeem_date', 'desc')
|
||||
->first();
|
||||
|
||||
$restTime = RestaurantTimeInterval::select('time_hours')->where('manage_restaurants_xid', $restaurant->id)->first();
|
||||
$stateTime = TimeInterval::select('time_hours')->where('manage_state_xid', $restaurant->state_xid)->first();
|
||||
|
||||
$restTimeHours = $restTime ? $restTime->time_hours : 0;
|
||||
$stateTimeHours = $stateTime ? $stateTime->time_hours : 0;
|
||||
|
||||
$restaurant['next_redeem_time'] = "Now";
|
||||
$currentTime = Carbon::now();
|
||||
|
||||
|
||||
if ($lastRedeem) {
|
||||
$lastRedeemTime = Carbon::parse($lastRedeem->redeem_date);
|
||||
|
||||
$restAllowedRedeemTime = $lastRedeemTime->copy()->addHours(intval($restTimeHours));
|
||||
$stateAllowedRedeemTime = $lastRedeemTime->copy()->addHours(intval($stateTimeHours));
|
||||
|
||||
if ($currentTime < $restAllowedRedeemTime) {
|
||||
$restaurant['next_redeem_time'] = $restAllowedRedeemTime->toDateTimeString();
|
||||
} else if ($currentTime < $stateAllowedRedeemTime) {
|
||||
$restaurant['next_redeem_time'] = $stateAllowedRedeemTime->toDateTimeString();
|
||||
}
|
||||
}
|
||||
|
||||
// Include logic for preventing redemption in the same state
|
||||
if ($restaurant['next_redeem_time'] === "Now") {
|
||||
// Fetch the last redeem time for any restaurant in the same state
|
||||
$lastStateRedeem = RedeemRestaurant::where('iam_principal_xid', $customerIamId)
|
||||
->where('state_xid', $restaurant->state_xid)
|
||||
->where('is_redeem', 1)
|
||||
->orderBy('redeem_date', 'desc')
|
||||
->first();
|
||||
|
||||
if ($lastStateRedeem) {
|
||||
$lastStateRedeemTime = Carbon::parse($lastStateRedeem->redeem_date);
|
||||
$stateAllowedRedeemTime = $lastStateRedeemTime->copy()->addHours(intval($stateTimeHours));
|
||||
|
||||
if ($currentTime < $stateAllowedRedeemTime) {
|
||||
$restaurant['next_redeem_time'] = $stateAllowedRedeemTime->toDateTimeString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return jsonResponseWithSuccessMessage(__('auth.data_fetched_successfully'), $restaurants, 200);
|
||||
} catch (Exception $ex) {
|
||||
Log::error('Restaurant Get service failed : ' . $ex->getMessage());
|
||||
return jsonResponseWithErrorMessageApi(__('auth.something_went_wrong'), 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public function addToFavourite($customerIamId, $request)
|
||||
{
|
||||
try {
|
||||
@@ -156,90 +207,90 @@ class RestaurantApiServices
|
||||
|
||||
|
||||
public function listFavRestaurant($customerIamId)
|
||||
{
|
||||
try {
|
||||
// Get list of favorite restaurant IDs
|
||||
$customerFavouriteRestaurants = CustomerFavouriteRestaurant::where('principal_xid', $customerIamId)
|
||||
->pluck('restaurant_xid')
|
||||
->toArray();
|
||||
{
|
||||
try {
|
||||
// Get list of favorite restaurant IDs
|
||||
$customerFavouriteRestaurants = CustomerFavouriteRestaurant::where('principal_xid', $customerIamId)
|
||||
->pluck('restaurant_xid')
|
||||
->toArray();
|
||||
|
||||
// Fetch the restaurant details
|
||||
$restaurants = ManageRestaurant::with('closedRestaurant')->where('is_active', '1')
|
||||
->whereIn('id', $customerFavouriteRestaurants)
|
||||
->get();
|
||||
// Fetch the restaurant details
|
||||
$restaurants = ManageRestaurant::with('closedRestaurant')->where('is_active', '1')
|
||||
->whereIn('id', $customerFavouriteRestaurants)
|
||||
->get();
|
||||
|
||||
$client = new Client();
|
||||
$googlePlaceApiKey = config('constants.googlePlaces.api_key');
|
||||
$promises = [];
|
||||
$client = new Client();
|
||||
$googlePlaceApiKey = config('constants.googlePlaces.api_key');
|
||||
$promises = [];
|
||||
|
||||
foreach ($restaurants as &$res) {
|
||||
$res['image'] = ListingImageUrl('restaurant_images', $res['image']);
|
||||
foreach ($restaurants as &$res) {
|
||||
$res['image'] = ListingImageUrl('restaurant_images', $res['image']);
|
||||
|
||||
$cacheKey = 'restaurant_hours_' . $res->name;
|
||||
if (Cache::has($cacheKey)) {
|
||||
$res['operating_hours'] = Cache::get($cacheKey);
|
||||
} else {
|
||||
// Prepare the first request to get the place_id
|
||||
$promises[$res->name] = $client->getAsync('https://maps.googleapis.com/maps/api/place/findplacefromtext/json', [
|
||||
'query' => [
|
||||
'fields' => 'place_id',
|
||||
'input' => $res->name,
|
||||
'inputtype' => 'textquery',
|
||||
'key' => $googlePlaceApiKey
|
||||
]
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
// Execute all the first requests concurrently
|
||||
$results = Utils::settle($promises)->wait();
|
||||
|
||||
$detailPromises = [];
|
||||
foreach ($restaurants as &$res) {
|
||||
if (isset($results[$res->name]['value'])) {
|
||||
$response = $results[$res->name]['value'];
|
||||
$placeData = json_decode($response->getBody(), true);
|
||||
|
||||
if (isset($placeData['candidates'][0]['place_id'])) {
|
||||
$placeId = $placeData['candidates'][0]['place_id'];
|
||||
|
||||
// Prepare the second request to get the operating hours
|
||||
$detailPromises[$res->name] = $client->getAsync('https://maps.googleapis.com/maps/api/place/details/json', [
|
||||
$cacheKey = 'restaurant_hours_' . $res->name;
|
||||
if (Cache::has($cacheKey)) {
|
||||
$res['operating_hours'] = Cache::get($cacheKey);
|
||||
} else {
|
||||
// Prepare the first request to get the place_id
|
||||
$promises[$res->name] = $client->getAsync('https://maps.googleapis.com/maps/api/place/findplacefromtext/json', [
|
||||
'query' => [
|
||||
'fields' => 'opening_hours',
|
||||
'place_id' => $placeId,
|
||||
'fields' => 'place_id',
|
||||
'input' => $res->name,
|
||||
'inputtype' => 'textquery',
|
||||
'key' => $googlePlaceApiKey
|
||||
]
|
||||
]);
|
||||
} else {
|
||||
$res['operating_hours'] = "N/A";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Execute all the second requests concurrently
|
||||
$detailResults = Utils::settle($detailPromises)->wait();
|
||||
// Execute all the first requests concurrently
|
||||
$results = Utils::settle($promises)->wait();
|
||||
|
||||
foreach ($restaurants as &$res) {
|
||||
if (isset($detailResults[$res->name]['value'])) {
|
||||
$response = $detailResults[$res->name]['value'];
|
||||
$data = json_decode($response->getBody(), true);
|
||||
if (isset($data['result']['opening_hours']['weekday_text'])) {
|
||||
$hours = $data['result']['opening_hours']['weekday_text'];
|
||||
Cache::put('restaurant_hours_' . $res->name, $hours, now()->addHours(24));
|
||||
$res['operating_hours'] = $hours;
|
||||
} else {
|
||||
$res['operating_hours'] = "N/A";
|
||||
$detailPromises = [];
|
||||
foreach ($restaurants as &$res) {
|
||||
if (isset($results[$res->name]['value'])) {
|
||||
$response = $results[$res->name]['value'];
|
||||
$placeData = json_decode($response->getBody(), true);
|
||||
|
||||
if (isset($placeData['candidates'][0]['place_id'])) {
|
||||
$placeId = $placeData['candidates'][0]['place_id'];
|
||||
|
||||
// Prepare the second request to get the operating hours
|
||||
$detailPromises[$res->name] = $client->getAsync('https://maps.googleapis.com/maps/api/place/details/json', [
|
||||
'query' => [
|
||||
'fields' => 'opening_hours',
|
||||
'place_id' => $placeId,
|
||||
'key' => $googlePlaceApiKey
|
||||
]
|
||||
]);
|
||||
} else {
|
||||
$res['operating_hours'] = "N/A";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return jsonResponseWithSuccessMessage(__('auth.data_updated_successfully'), $restaurants, 200);
|
||||
} catch (Exception $ex) {
|
||||
Log::error('List of Favourite Restaurant service failed : ' . $ex->getMessage());
|
||||
return jsonResponseWithErrorMessageApi(__('auth.something_went_wrong'), 500);
|
||||
// Execute all the second requests concurrently
|
||||
$detailResults = Utils::settle($detailPromises)->wait();
|
||||
|
||||
foreach ($restaurants as &$res) {
|
||||
if (isset($detailResults[$res->name]['value'])) {
|
||||
$response = $detailResults[$res->name]['value'];
|
||||
$data = json_decode($response->getBody(), true);
|
||||
if (isset($data['result']['opening_hours']['weekday_text'])) {
|
||||
$hours = $data['result']['opening_hours']['weekday_text'];
|
||||
Cache::put('restaurant_hours_' . $res->name, $hours, now()->addHours(24));
|
||||
$res['operating_hours'] = $hours;
|
||||
} else {
|
||||
$res['operating_hours'] = "N/A";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return jsonResponseWithSuccessMessage(__('auth.data_updated_successfully'), $restaurants, 200);
|
||||
} catch (Exception $ex) {
|
||||
Log::error('List of Favourite Restaurant service failed : ' . $ex->getMessage());
|
||||
return jsonResponseWithErrorMessageApi(__('auth.something_went_wrong'), 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
@@ -543,20 +594,20 @@ class RestaurantApiServices
|
||||
$currentTime = Carbon::now();
|
||||
|
||||
Log::info("stateTimeHours");
|
||||
Log::info("restTimeHours");
|
||||
Log::info("restTimeHours");
|
||||
|
||||
Log::info($stateTimeHours);
|
||||
Log::info($restTimeHours);
|
||||
Log::info($stateTimeHours);
|
||||
Log::info($restTimeHours);
|
||||
|
||||
|
||||
|
||||
$stateAllowedRedeemTime = $lastRedeemTime->copy()->addHours(intval($stateTimeHours));
|
||||
$restAllowedRedeemTime = $lastRedeemTime->copy()->addHours(intval($restTimeHours));
|
||||
Log::info("stateAllowedRedeemTime");
|
||||
Log::info("restAllowedRedeemTime");
|
||||
Log::info("stateAllowedRedeemTime");
|
||||
Log::info("restAllowedRedeemTime");
|
||||
|
||||
Log::info($stateAllowedRedeemTime);
|
||||
Log::info($restAllowedRedeemTime);
|
||||
Log::info($stateAllowedRedeemTime);
|
||||
Log::info($restAllowedRedeemTime);
|
||||
if ($currentTime < $stateAllowedRedeemTime) {
|
||||
$remainingTime = $currentTime->diff($stateAllowedRedeemTime);
|
||||
$hours = $remainingTime->h;
|
||||
@@ -667,7 +718,7 @@ Log::info($restAllowedRedeemTime);
|
||||
public function searchRestaurant($customerIamId, $request)
|
||||
{
|
||||
try {
|
||||
$restaurantsQuery = ManageRestaurant::with('state','closedRestaurant')
|
||||
$restaurantsQuery = ManageRestaurant::with('state', 'closedRestaurant')
|
||||
->where('is_active', '1');
|
||||
|
||||
$searchData = $request->input('search_data');
|
||||
@@ -763,5 +814,4 @@ Log::info($restAllowedRedeemTime);
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user