Beispiel #1
0
 public function logout()
 {
     try {
         $input = Request::all();
         $userDevice = UserDevice::where(['device_id' => $input['device_id'], 'rest_access_token' => $input['access_token'], 'user_id' => $input['user_id']])->first();
         if ($userDevice) {
             $userDevice->delete();
         }
         return ['code' => 200, 'data' => new \stdClass()];
     } catch (\Exception $e) {
         return response()->json(['message' => 'An application error occured.', 'error' => $e->getMessage()], 500);
     }
 }
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index($statuses, $accessToken)
 {
     try {
         $reservationIdArr = array();
         $reservationArr = array();
         $userDevice = UserDevice::where('rest_access_token', $accessToken)->first();
         $conciergeLocations = VendorLocationContact::where('user_id', $userDevice->user_id)->get();
         $reservationIntAttrArr = ReservationAttributesInteger::statusIn($statuses)->get();
         foreach ($reservationIntAttrArr as $reservationIntAttr) {
             $reservationDetail = ReservationDetail::locationIn($conciergeLocations, $reservationIntAttr->reservation_id)->first();
             if ($reservationDetail) {
                 array_push($reservationIdArr, $reservationIntAttr->reservation_id);
                 if (array_key_exists((string) $reservationIntAttr->reservation_id, $reservationArr)) {
                     $reservation = $reservationArr[(string) $reservationIntAttr->reservation_id];
                 } else {
                     $reservation = array();
                 }
                 $key = 'reservation_id';
                 $value = (string) $reservationIntAttr->reservation_id;
                 $reservation[$key] = $value;
                 $reservationArr[(string) $reservationIntAttr->reservation_id] = $reservation;
             }
         }
         if (sizeof($reservationIdArr) > 0) {
             //Int type
             $reservationIntAttrArr = ReservationAttributesInteger::reservationIdIn($reservationIdArr)->get();
             foreach ($reservationIntAttrArr as $reservationIntAttr) {
                 if (array_key_exists((string) $reservationIntAttr->reservation_id, $reservationArr)) {
                     $reservation = $reservationArr[(string) $reservationIntAttr->reservation_id];
                 } else {
                     $reservation = array();
                 }
                 $key = $reservationIntAttr->attribute->alias;
                 $value = $reservationIntAttr->attribute_value;
                 $reservation[$key] = $value;
                 //Check log for same attribute
                 $reservationStatusLog = ReservationStatusLog::where(['reservation_id' => $reservationIntAttr->reservation_id, 'new_reservation_status_id' => ReservationController::$edited_status_id])->orderBy('created_at', 'DESC')->first();
                 if ($reservationStatusLog != null) {
                     $reservationIntAttrLogArr = ReservationAttributesIntegerLog::where(['reservation_attribute_id' => $reservationIntAttr->attribute->id, 'reservation_status_log_id' => $reservationStatusLog->id])->get();
                     foreach ($reservationIntAttrLogArr as $reservationIntAttrLog) {
                         $key = "old_" . $reservationIntAttrLog->attribute->alias;
                         $value = $reservationIntAttrLog->old_attribute_value;
                         $reservation[$key] = $value;
                     }
                 }
                 $reservationArr[(string) $reservationIntAttr->reservation_id] = $reservation;
             }
             //Float type
             $reservationFloatAttrArr = ReservationAttributesFloat::reservationIdIn($reservationIdArr)->get();
             foreach ($reservationFloatAttrArr as $reservationFloatAttr) {
                 if (array_key_exists((string) $reservationFloatAttr->reservation_id, $reservationArr)) {
                     $reservation = $reservationArr[(string) $reservationFloatAttr->reservation_id];
                 } else {
                     $reservation = array();
                 }
                 $key = $reservationFloatAttr->attribute->alias;
                 $value = $reservationFloatAttr->attribute_value;
                 $reservation[$key] = $value;
                 $reservationArr[(string) $reservationFloatAttr->reservation_id] = $reservation;
             }
             //Date type
             $reservationDateAttrArr = ReservationAttributesDate::reservationIdIn($reservationIdArr)->get();
             foreach ($reservationDateAttrArr as $reservationDateAttr) {
                 if (array_key_exists((string) $reservationDateAttr->reservation_id, $reservationArr)) {
                     $reservation = $reservationArr[(string) $reservationDateAttr->reservation_id];
                 } else {
                     $reservation = array();
                 }
                 $key = $reservationDateAttr->attribute->alias;
                 $value = $reservationDateAttr->attribute_value;
                 $reservation[$key] = $value;
                 //Check log for same attribute
                 $reservationStatusLog = ReservationStatusLog::where(['reservation_id' => $reservationDateAttr->reservation_id, 'new_reservation_status_id' => ReservationController::$edited_status_id])->orderBy('created_at', 'DESC')->first();
                 if ($reservationStatusLog != null) {
                     $reservationDateAttrLogArr = ReservationAttributesDateLog::where(['reservation_attribute_id' => $reservationDateAttr->attribute->id, 'reservation_status_log_id' => $reservationStatusLog->id])->get();
                     foreach ($reservationDateAttrLogArr as $reservationDateAttrLog) {
                         $key = "old_" . $reservationDateAttrLog->attribute->alias;
                         $value = $reservationDateAttrLog->old_attribute_value;
                         $reservation[$key] = $value;
                     }
                 }
                 $reservationArr[(string) $reservationDateAttr->reservation_id] = $reservation;
             }
             //Text type
             $reservationTextAttrArr = ReservationAttributesText::reservationIdIn($reservationIdArr)->get();
             foreach ($reservationTextAttrArr as $reservationTextAttr) {
                 if (array_key_exists((string) $reservationTextAttr->reservation_id, $reservationArr)) {
                     $reservation = $reservationArr[(string) $reservationTextAttr->reservation_id];
                 } else {
                     $reservation = array();
                 }
                 $key = $reservationTextAttr->attribute->alias;
                 $value = $reservationTextAttr->attribute_value;
                 $reservation[$key] = $value;
                 $reservationStatusLog = ReservationStatusLog::where(['reservation_id' => $reservationTextAttr->reservation_id, 'new_reservation_status_id' => ReservationController::$edited_status_id])->orderBy('created_at', 'DESC')->first();
                 if ($reservationStatusLog != null) {
                     $reservationTextAttrLogArr = ReservationAttributesTextLog::where(['reservation_attribute_id' => $reservationTextAttr->attribute->id, 'reservation_status_log_id' => $reservationStatusLog->id])->get();
                     foreach ($reservationTextAttrLogArr as $reservationTextAttrLog) {
                         $key = "old_" . $reservationTextAttrLog->attribute->alias;
                         $value = $reservationTextAttrLog->old_attribute_value;
                         $reservation[$key] = $value;
                     }
                 }
                 $reservationArr[(string) $reservationTextAttr->reservation_id] = $reservation;
             }
             //Boolean type
             $reservationBoolAttrArr = ReservationAttributesBoolean::reservationIdIn($reservationIdArr)->get();
             foreach ($reservationBoolAttrArr as $reservationBoolAttr) {
                 if (array_key_exists((string) $reservationBoolAttr->reservation_id, $reservationArr)) {
                     $reservation = $reservationArr[(string) $reservationBoolAttr->reservation_id];
                 } else {
                     $reservation = array();
                 }
                 $key = $reservationBoolAttr->attribute->alias;
                 $value = $reservationBoolAttr->attribute_value;
                 if ($value == 1) {
                     $reservation[$key] = true;
                 } else {
                     $reservation[$key] = false;
                 }
                 $reservationArr[(string) $reservationBoolAttr->reservation_id] = $reservation;
             }
             //VarChar type
             $reservationVarcharAttrArr = ReservationAttributesVarchar::reservationIdIn($reservationIdArr)->get();
             foreach ($reservationVarcharAttrArr as $reservationVarcharAttr) {
                 if (array_key_exists((string) $reservationVarcharAttr->reservation_id, $reservationArr)) {
                     $reservation = $reservationArr[(string) $reservationVarcharAttr->reservation_id];
                 } else {
                     $reservation = array();
                 }
                 $key = $reservationVarcharAttr->attribute->alias;
                 $value = $reservationVarcharAttr->attribute_value;
                 $reservation[$key] = $value;
                 $reservationArr[(string) $reservationVarcharAttr->reservation_id] = $reservation;
             }
             //Get Customer
             foreach ($reservationIdArr as $reservationId) {
                 $reservationDetail = ReservationDetail::where('id', $reservationId)->first();
                 if ($reservationDetail) {
                     $reservation = $reservationArr[(string) $reservationId];
                     $reservation['reservation_type'] = $reservationDetail->reservation_type;
                     $customer = array();
                     $customer['id'] = $reservationDetail->user->id;
                     if ($reservationDetail->user->is_vip == 1) {
                         $customer['is_vip'] = true;
                     } else {
                         $customer['is_vip'] = false;
                     }
                     $customer['full_name'] = $reservationDetail->user->full_name;
                     $customer['email'] = $reservationDetail->user->email;
                     $customer['phone_number'] = $reservationDetail->user->phone_number;
                     $customer['points_earned'] = $reservationDetail->user->points_earned;
                     $customer['rating'] = UserRating::where('user_id', $reservationDetail->user->id)->avg('rating');
                     if ($customer['rating'] == null) {
                         $customer['rating'] = 0.0;
                     }
                     $customerPreferences = UserAttributesVarChar::where(['user_id' => $reservationDetail->user->id, 'user_attribute_id' => ReservationController::$cust_pref_attr_id])->first();
                     if ($customerPreferences) {
                         $customer['customer_preferences'] = $customerPreferences->attribute_value;
                     }
                     $reservation['customer'] = $customer;
                     $reservationArr[(string) $reservationId] = $reservation;
                 }
             }
             //Get Location
             foreach ($reservationIdArr as $reservationId) {
                 $reservationDetail = ReservationDetail::where('id', $reservationId)->first();
                 if ($reservationDetail) {
                     $reservation = $reservationArr[(string) $reservationId];
                     $location = array();
                     $vendorLocation = VendorLocation::where('id', $reservationDetail->vendor_location_id)->first();
                     $location['location_id'] = $vendorLocation->location_id;
                     $location['location'] = Location::where('id', $vendorLocation->location_id)->first()->name;
                     $reservation['location'] = $location;
                     $reservationArr[(string) $reservationId] = $reservation;
                 }
             }
             //Get Product
             foreach ($reservationIdArr as $reservationId) {
                 $reservationDetail = ReservationDetail::where('id', $reservationId)->first();
                 if ($reservationDetail && $reservationDetail->reservation_type == 'experience') {
                     $reservation = $reservationArr[(string) $reservationId];
                     $product = array();
                     $product['product_id'] = $reservationDetail->product_id;
                     $product['product'] = Product::where('id', $reservationDetail->product_id)->first()->name;
                     $addonsArr = Product::where('product_parent_id', $reservationDetail->product_id)->get();
                     if (sizeof($addonsArr) > 0) {
                         $statusStrArr = explode('~', $statuses);
                         $statusIntArr = [];
                         foreach ($statusStrArr as $statusStr) {
                             array_push($statusIntArr, (int) $statusStr);
                         }
                         $productAddonArr = array();
                         foreach ($addonsArr as $addon) {
                             $addons = array();
                             $addons['addon_id'] = $addon->id;
                             $addons['addon_name'] = $addon->name;
                             $reservationAddonDetail = ReservationAddonsVariantsDetail::whereIn('reservation_status_id', $statusIntArr)->where(['reservation_id' => $reservationId, 'options_id' => $addon->id])->first();
                             if ($reservationAddonDetail != null) {
                                 $addons['no_of_persons'] = $reservationAddonDetail->no_of_persons;
                             }
                             array_push($productAddonArr, $addons);
                         }
                         $product['addons'] = $productAddonArr;
                     }
                     $reservation['product'] = $product;
                     $reservationArr[(string) $reservationId] = $reservation;
                 }
             }
             return response()->json(array_values($reservationArr), 200);
         } else {
             return response()->json(['message' => 'No reservations found.'], 204);
         }
     } catch (\Exception $e) {
         return response()->json(['message' => 'An application error occured.', 'error' => $e->getMessage()], 500);
     }
 }