コード例 #1
0
 public function create_manual_request()
 {
     $latitude = Input::get('latitude');
     $longitude = Input::get('longitude');
     $d_latitude = Input::get('d_latitude');
     $d_longitude = Input::get('d_longitude');
     $type = Input::get('type');
     $provider = Input::get('provider');
     $user_id = Session::get('user_id');
     $time = date("Y-m-d H:i:s");
     $provider_details = Walker::where('id', '=', $provider)->first();
     $user = Owner::where('id', '=', $user_id)->first();
     $request = new Requests();
     $request->owner_id = $user_id;
     $request->request_start_time = $time;
     $request->confirmed_walker = $provider;
     if ($d_longitude != '' && $d_latitude != '') {
         $request->D_latitude = $d_latitude;
         $request->D_longitude = $d_longitude;
     }
     $request->current_walker = $provider;
     $request->status = 1;
     $request->save();
     $reqid = $request->id;
     $request_service = new RequestServices();
     $request_service->type = $type;
     $request_service->request_id = $request->id;
     $request_service->save();
     $owner = Owner::find($user_id);
     $owner->latitude = $latitude;
     $owner->longitude = $longitude;
     $owner->save();
     $walkerlocation = new WalkLocation();
     $walkerlocation->request_id = $request->id;
     $walkerlocation->distance = 0.0;
     $walkerlocation->latitude = $latitude;
     $walkerlocation->longitude = $longitude;
     $walkerlocation->save();
     if ($request->save()) {
         $current_request = Requests::where('id', '=', $reqid)->first();
         return Redirect::to('/user/request-trip');
     }
 }
コード例 #2
0
 public function create_request_later()
 {
     $token = Input::get('token');
     $owner_id = Input::get('id');
     $latitude = Input::get('latitude');
     $longitude = Input::get('longitude');
     $date_time = Input::get('datetime');
     // dd(date('Y-m-d h:i:s', strtotime("$date_time + 2 hours")));
     $validator = Validator::make(array('token' => $token, 'owner_id' => $owner_id, 'latitude' => $latitude, 'longitude' => $longitude, 'datetime' => $date_time), array('token' => 'required', 'owner_id' => 'required|integer', 'latitude' => 'required', 'longitude' => 'required', 'datetime' => 'required'));
     if ($validator->fails()) {
         $error_messages = $validator->messages()->all();
         $response_array = array('success' => false, 'error' => 'Invalid Input', 'error_code' => 401, 'error_messages' => $error_messages);
         $response_code = 200;
     } else {
         $is_admin = $this->isAdmin($token);
         if ($owner_data = $this->getOwnerData($owner_id, $token, $is_admin)) {
             // check for token validity
             if (is_token_active($owner_data->token_expiry) || $is_admin) {
                 // Do necessary operations
                 if ($owner_data->debt > 0) {
                     $response_array = array('success' => false, 'error' => "You are already in \${$owner->debt} debt", 'error_code' => 417);
                     $response_code = 200;
                     $response = Response::json($response_array, $response_code);
                     return $response;
                 }
                 if (Input::has('type')) {
                     $type = Input::get('type');
                     if (!$type) {
                         // choose default type
                         $provider_type = ProviderType::where('is_default', 1)->first();
                         if (!$provider_type) {
                             $type = 1;
                         } else {
                             $type = $provider_type->id;
                         }
                     }
                     $typequery = "SELECT distinct provider_id from walker_services where type IN({$type})";
                     $typewalkers = DB::select(DB::raw($typequery));
                     Log::info('typewalkers = ' . print_r($typewalkers, true));
                     foreach ($typewalkers as $key) {
                         $types[] = $key->provider_id;
                     }
                     $typestring = implode(",", $types);
                     Log::info('typestring = ' . print_r($typestring, true));
                     if ($typestring == '') {
                         /* $driver = Keywords::where('id', 1)->first();
                            $response_array = array('success' => false, 'error' => 'No ' . $driver->keyword . ' found matching the service type.', 'error_code' => 405); */
                         $response_array = array('success' => false, 'error' => 'No ' . Config::get('app.generic_keywords.Provider') . ' found matching the service type.', 'error_code' => 405);
                         $response_code = 200;
                         return Response::json($response_array, $response_code);
                     }
                     $settings = Settings::where('key', 'default_search_radius')->first();
                     $distance = $settings->value;
                     $settings = Settings::where('key', 'default_distance_unit')->first();
                     $unit = $settings->value;
                     if ($unit == 0) {
                         $multiply = 1.609344;
                     } elseif ($unit == 1) {
                         $multiply = 1;
                     }
                     $query1 = "SELECT walker.id, ROUND(" . $multiply . " * 3956 * acos( cos( radians('{$latitude}') ) * cos( radians(latitude) ) * cos( radians(longitude) - radians('{$longitude}') ) + sin( radians('{$latitude}') ) * sin( radians(latitude) ) ) ,8) as distance from walker where is_available = 1 and is_active = 1 and is_approved = 1 and ROUND((" . $multiply . " * 3956 * acos( cos( radians('{$latitude}') ) * cos( radians(latitude) ) * cos( radians(longitude) - radians('{$longitude}') ) + sin( radians('{$latitude}') ) * sin( radians(latitude) ) ) ) ,8) <= {$distance} and walker.id IN({$typestring});";
                     $ssstrings = DB::select(DB::raw($query1));
                     foreach ($ssstrings as $ssstrin) {
                         $ssstri[] = $ssstrin->id;
                     }
                     $ssstring = implode(",", $ssstri);
                     $datewant = new DateTime($date_time);
                     $datetime = $datewant->format('Y-m-d H:i:s');
                     $dategiven = $datewant->sub(new DateInterval('P0Y0M0DT1H59M59S'))->format('Y-m-d H:i:s');
                     $end_time = $datewant->add(new DateInterval('P0Y0M0DT1H59M59S'))->format('Y-m-d H:i:s');
                     /* $setting = Settings::where('key', 'allow_calendar')->first();
                        if ($setting->value == 1)
                        $pvquery = "SELECT distinct provider_id from provider_availability where start <= '" . $datetime . "' and end >= '" . $datetime . "' and provider_id IN($ssstring) and provider_id NOT IN(SELECT confirmed_walker FROM request where request_start_time>='" . $dategiven . "' and request_start_time<='" . $end_time . "');";
                        else */
                     $pvquery = "SELECT id from walker where id IN({$ssstring}) and id NOT IN(SELECT confirmed_walker FROM request where request_start_time>='" . $dategiven . "' and request_start_time<='" . $end_time . "');";
                     $pvques = DB::select(DB::raw($pvquery));
                     //  dd($pvques);
                     $ssstr = array();
                     foreach ($pvques as $ssstn) {
                         $ssstr[] = $ssstn->provider_id;
                     }
                     $pvque = implode(",", $ssstr);
                     $walkers = array();
                     if ($pvque) {
                         $settings = Settings::where('key', 'default_distance_unit')->first();
                         $unit = $settings->value;
                         if ($unit == 0) {
                             $multiply = 1.609344;
                         } elseif ($unit == 1) {
                             $multiply = 1;
                         }
                         $query = "SELECT walker.id, ROUND(" . $multiply . " * 3956 * acos( cos( radians('{$latitude}') ) * cos( radians(latitude) ) * cos( radians(longitude) - radians('{$longitude}') ) + sin( radians('{$latitude}') ) * sin( radians(latitude) ) ) ,8) as distance from walker where is_available = 1 and is_active = 1 and is_approved = 1 and ROUND((" . $multiply . " * 3956 * acos( cos( radians('{$latitude}') ) * cos( radians(latitude) ) * cos( radians(longitude) - radians('{$longitude}') ) + sin( radians('{$latitude}') ) * sin( radians(latitude) ) ) ) ,8) <= {$distance} and walker.id IN({$typestring}) and id IN({$pvque}) order by distance;";
                         $walkers = DB::select(DB::raw($query));
                     }
                     $walker_list = array();
                     $owner = Owner::find($owner_id);
                     $owner->latitude = $latitude;
                     $owner->longitude = $longitude;
                     $owner->save();
                     $request = new Requests();
                     $request->owner_id = $owner_id;
                     $request->request_start_time = $datetime;
                     $request->later = 1;
                     if (Input::has('cod')) {
                         if (Input::get('cod') == 1) {
                             $request->cod = 1;
                         } else {
                             $request->cod = 0;
                         }
                     }
                     $request->save();
                     $reqserv = new RequestServices();
                     $reqserv->request_id = $request->id;
                     $reqserv->type = $type;
                     $reqserv->save();
                 } else {
                     $settings = Settings::where('key', 'default_search_radius')->first();
                     $distance = $settings->value;
                     $settings = Settings::where('key', 'default_distance_unit')->first();
                     $unit = $settings->value;
                     if ($unit == 0) {
                         $multiply = 1.609344;
                     } elseif ($unit == 1) {
                         $multiply = 1;
                     }
                     $query1 = "SELECT walker.id, ROUND(" . $multiply . " * 3956 * acos( cos( radians('{$latitude}') ) * cos( radians(latitude) ) * cos( radians(longitude) - radians('{$longitude}') ) + sin( radians('{$latitude}') ) * sin( radians(latitude) ) ) ,8) as distance from walker where is_available = 1 and is_active = 1 and is_approved = 1 and ROUND((" . $multiply . " * 3956 * acos( cos( radians('{$latitude}') ) * cos( radians(latitude) ) * cos( radians(longitude) - radians('{$longitude}') ) + sin( radians('{$latitude}') ) * sin( radians(latitude) ) ) ) ,8) <= {$distance};";
                     $ssstrings = DB::select(DB::raw($query1));
                     foreach ($ssstrings as $ssstrin) {
                         $ssstri[] = $ssstrin->id;
                     }
                     $ssstring = implode(",", $ssstri);
                     $datewant = new DateTime($date_time);
                     $datetime = $datewant->format('Y-m-d H:i:s');
                     $dategiven = $datewant->sub(new DateInterval('P0Y0M0DT1H59M59S'))->format('Y-m-d H:i:s');
                     $end_time = $datewant->add(new DateInterval('P0Y0M0DT1H59M59S'))->format('Y-m-d H:i:s');
                     /* $setting = Settings::where('key', 'allow_calendar')->first();
                        if ($setting->value == 1)
                        $pvquery = "SELECT distinct provider_id from provider_availability where start <= '" . $datetime . "' and end >= '" . $datetime . "' and provider_id IN($ssstring) and provider_id NOT IN(SELECT confirmed_walker FROM request where request_start_time>='" . $dategiven . "' and request_start_time<='" . $end_time . "');";
                        else */
                     $pvquery = "SELECT id from walker where id IN({$ssstring}) and id NOT IN(SELECT confirmed_walker FROM request where request_start_time>='" . $dategiven . "' and request_start_time<='" . $end_time . "');";
                     $pvques = DB::select(DB::raw($pvquery));
                     $ssstr = array();
                     foreach ($pvques as $ssstn) {
                         $ssstr[] = $ssstn->provider_id;
                     }
                     $pvque = implode(",", $ssstr);
                     $walkers = array();
                     if ($pvque) {
                         $settings = Settings::where('key', 'default_distance_unit')->first();
                         $unit = $settings->value;
                         if ($unit == 0) {
                             $multiply = 1.609344;
                         } elseif ($unit == 1) {
                             $multiply = 1;
                         }
                         $query = "SELECT walker.id, ROUND(" . $multiply . " * 3956 * acos( cos( radians('{$latitude}') ) * cos( radians(latitude) ) * cos( radians(longitude) - radians('{$longitude}') ) + sin( radians('{$latitude}') ) * sin( radians(latitude) ) ) ,8) as distance from walker where is_available = 1 and is_active = 1 and is_approved = 1 and ROUND((" . $multiply . " * 3956 * acos( cos( radians('{$latitude}') ) * cos( radians(latitude) ) * cos( radians(longitude) - radians('{$longitude}') ) + sin( radians('{$latitude}') ) * sin( radians(latitude) ) ) ) ,8) <= {$distance} and id IN({$pvque}) order by distance;";
                         $walkers = DB::select(DB::raw($query));
                     }
                     $walker_list = array();
                     $owner = Owner::find($owner_id);
                     $owner->latitude = $latitude;
                     $owner->longitude = $longitude;
                     $owner->save();
                     $request = new Requests();
                     $request->owner_id = $owner_id;
                     $request->request_start_time = $datetime;
                     $request->save();
                     $reqserv = new RequestServices();
                     $reqserv->request_id = $request->id;
                     $reqserv->save();
                 }
                 $i = 0;
                 $first_walker_id = 0;
                 if ($walkers) {
                     foreach ($walkers as $walker) {
                         $request_meta = new RequestMeta();
                         $request_meta->request_id = $request->id;
                         $request_meta->walker_id = $walker->id;
                         if ($i == 0) {
                             $first_walker_id = $walker->id;
                             $i++;
                         }
                         $request_meta->save();
                     }
                     $req = Requests::find($request->id);
                     $req->current_walker = $first_walker_id;
                     $req->save();
                 }
                 $settings = Settings::where('key', 'provider_timeout')->first();
                 $time_left = $settings->value;
                 // Send Notification
                 $walker = Walker::find($first_walker_id);
                 if ($walker) {
                     $msg_array = array();
                     $msg_array['unique_id'] = 3;
                     $msg_array['request_id'] = $request->id;
                     $msg_array['time_left_to_respond'] = $time_left;
                     $owner = Owner::find($owner_id);
                     $request_data = array();
                     $request_data['owner'] = array();
                     $request_data['owner']['name'] = $owner->first_name . " " . $owner->last_name;
                     $request_data['owner']['picture'] = $owner->picture;
                     $request_data['owner']['phone'] = $owner->phone;
                     $request_data['owner']['address'] = $owner->address;
                     $request_data['owner']['latitude'] = $owner->latitude;
                     $request_data['owner']['longitude'] = $owner->longitude;
                     $request_data['owner']['rating'] = $owner->rate;
                     $request_data['owner']['num_rating'] = $owner->rate_count;
                     /* $request_data['owner']['rating'] = DB::table('review_dog')->where('owner_id', '=', $owner->id)->avg('rating') ? : 0;
                        $request_data['owner']['num_rating'] = DB::table('review_dog')->where('owner_id', '=', $owner->id)->count(); */
                     $date_want = new DateTime($date_time);
                     $datetime1 = $date_want->format('Y-m-d H:i:s');
                     $request_data['datetime'] = $datetime1;
                     $request_data['dog'] = array();
                     if ($dog = Dog::find($owner->dog_id)) {
                         $request_data['dog']['name'] = $dog->name;
                         $request_data['dog']['age'] = $dog->age;
                         $request_data['dog']['breed'] = $dog->breed;
                         $request_data['dog']['likes'] = $dog->likes;
                         $request_data['dog']['picture'] = $dog->image_url;
                     }
                     $msg_array['request_data'] = $request_data;
                     $title = "New Request";
                     $message = $msg_array;
                     Log::info('first_walker_id = ' . print_r($first_walker_id, true));
                     Log::info('New request = ' . print_r($message, true));
                     /* don't do json_encode in above line because if */
                     send_notifications($first_walker_id, "walker", $title, $message);
                 }
                 // Send SMS
                 $settings = Settings::where('key', 'sms_request_created')->first();
                 $pattern = $settings->value;
                 $pattern = str_replace('%user%', $owner_data->first_name . " " . $owner_data->last_name, $pattern);
                 $pattern = str_replace('%id%', $request->id, $pattern);
                 $pattern = str_replace('%user_mobile%', $owner_data->phone, $pattern);
                 sms_notification(1, 'admin', $pattern);
                 // send email
                 /* $settings = Settings::where('key', 'email_new_request')->first();
                    $pattern = $settings->value;
                    $pattern = str_replace('%id%', $request->id, $pattern);
                    $pattern = str_replace('%url%', web_url() . "/admin/request/map/" . $request->id, $pattern);
                    $subject = "New Request Created";
                    email_notification(1, 'admin', $pattern, $subject); */
                 $settings = Settings::where('key', 'admin_email_address')->first();
                 $admin_email = $settings->value;
                 $follow_url = web_url() . "/user/signin";
                 $pattern = array('admin_eamil' => $admin_email, 'trip_id' => $request->id, 'follow_url' => $follow_url);
                 $subject = "Ride Booking Request";
                 email_notification(1, 'admin', $pattern, $subject, 'new_request', null);
                 $response_array = array('success' => true, 'request_id' => $request->id);
                 $response_code = 200;
             } else {
                 $response_array = array('success' => false, 'error' => 'Token Expired', 'error_code' => 405);
                 $response_code = 200;
             }
         } else {
             if ($is_admin) {
                 /* $var = Keywords::where('id', 2)->first();
                    $response_array = array('success' => false, 'error' => '' . $var->keyword . ' ID not Found', 'error_code' => 410); */
                 $response_array = array('success' => false, 'error' => '' . Config::get('app.generic_keywords.User') . ' ID not Found', 'error_code' => 410);
             } else {
                 $response_array = array('success' => false, 'error' => 'Not a valid token', 'error_code' => 406);
             }
             $response_code = 200;
         }
     }
     $response = Response::json($response_array, $response_code);
     return $response;
 }
コード例 #3
0
 public function get_providers()
 {
     $token = Input::get('token');
     $owner_id = Input::get('id');
     $latitude = Input::get('latitude');
     $longitude = Input::get('longitude');
     $type = Input::get('type');
     $validator = Validator::make(array('token' => $token, 'owner_id' => $owner_id, 'latitude' => $latitude, 'longitude' => $longitude), array('token' => 'required', 'owner_id' => 'required|integer', 'latitude' => 'required', 'longitude' => 'required'));
     if ($validator->fails()) {
         $error_messages = $validator->messages()->all();
         $response_array = array('success' => false, 'error' => 'Invalid Input', 'error_code' => 401, 'error_messages' => $error_messages);
         $response_code = 200;
     } else {
         $is_admin = $this->isAdmin($token);
         if ($owner_data = $this->getOwnerData($owner_id, $token, $is_admin)) {
             // check for token validity
             if (is_token_active($owner_data->token_expiry) || $is_admin) {
                 // Do necessary operations
                 if (!$type) {
                     // choose default type
                     $provider_type = ProviderType::where('is_default', 1)->first();
                     if (!$provider_type) {
                         $type = 1;
                     } else {
                         $type = $provider_type->id;
                     }
                 }
                 foreach ($type as $key) {
                     $typ[] = $key;
                 }
                 $ty = implode(",", $typ);
                 $typequery = "SELECT distinct provider_id from walker_services where type IN({$ty})";
                 $typewalkers = DB::select(DB::raw($typequery));
                 Log::info('typewalkers = ' . print_r($typewalkers, true));
                 foreach ($typewalkers as $key) {
                     $types[] = $key->provider_id;
                 }
                 $typestring = implode(",", $types);
                 Log::info('typestring = ' . print_r($typestring, true));
                 if ($typestring == '') {
                     $response_array = array('success' => false, 'error' => 'No provider found matching the service type.', 'error_code' => 405);
                     $response_code = 200;
                     return Response::json($response_array, $response_code);
                 }
                 $settings = Settings::where('key', 'default_search_radius')->first();
                 $distance = $settings->value;
                 $query = "SELECT walker.id, 1.609344 * 3956 * acos( cos( radians('{$latitude}') ) * cos( radians(latitude) ) * cos( radians(longitude) - radians('{$longitude}') ) + sin( radians('{$latitude}') ) * sin( radians(latitude) ) ) as distance from walker where is_available = 1 and is_active = 1 and is_approved = 1 and (1.609344 * 3956 * acos( cos( radians('{$latitude}') ) * cos( radians(latitude) ) * cos( radians(longitude) - radians('{$longitude}') ) + sin( radians('{$latitude}') ) * sin( radians(latitude) ) ) ) <= {$distance} and walker.id IN({$typestring}) order by distance";
                 $walkers = DB::select(DB::raw($query));
                 Log::info('walkers = ' . print_r($walkers, true));
                 if ($walkers != NULL) {
                     $owner = Owner::find($owner_id);
                     $owner->latitude = $latitude;
                     $owner->longitude = $longitude;
                     $owner->save();
                     $request = new Requests();
                     $request->owner_id = $owner_id;
                     $request->request_start_time = date("Y-m-d H:i:s");
                     $request->save();
                     foreach ($type as $key) {
                         $reqserv = new RequestServices();
                         $reqserv->request_id = $request->id;
                         $reqserv->type = $key;
                         $reqserv->save();
                     }
                     $response_array = array('success' => true, 'request_id' => $request->id, 'walkers' => $walkers);
                     $response_code = 200;
                 } else {
                     $response_array = array('success' => false, 'error' => 'No walker found');
                     $response_code = 200;
                 }
             } else {
                 $response_array = array('success' => false, 'error' => 'Token Expired', 'error_code' => 405);
                 $response_code = 200;
             }
         } else {
             if ($is_admin) {
                 $response_array = array('success' => false, 'error' => 'Owner ID not Found', 'error_code' => 410);
             } else {
                 $response_array = array('success' => false, 'error' => 'Not a valid token', 'error_code' => 406);
             }
             $response_code = 200;
         }
     }
     $response = Response::json($response_array, $response_code);
     return $response;
 }
コード例 #4
0
 public function saveUserRequestTrip()
 {
     Session::forget('skipReview');
     $latitude = Input::get('latitude');
     $longitude = Input::get('longitude');
     $d_latitude = Input::get('d_latitude');
     $d_longitude = Input::get('d_longitude');
     $type = Input::get('type');
     $owner_id = Session::get('user_id');
     $payment_type = Input::get('payment_type');
     if ($type == "") {
         $message = "Please Select the Service Type";
         $type = "warning";
         return Redirect::route('userrequestTrip')->with('message', $message)->with('type', $type);
     } else {
         if (Input::has('promo_code')) {
             $promo_code = Input::get('promo_code');
             $code_check = PromoCodes::where('coupon_code', $promo_code)->first();
             if ($code_check == NULL) {
                 $message = "Invalid Promo Code";
                 $type = "error";
                 return Redirect::route('userrequestTrip')->with('message', $message)->with('type', $type);
             } else {
                 if ($code_check->state == 1 && date('Y-m-d H:i:s', strtotime($code_check->expiry)) > date('Y-m-d H:i:s')) {
                     $code_id = $code_check->id;
                 } else {
                     $message = "Invalid Promo Code";
                     $type = "error";
                     return Redirect::route('userrequestTrip')->with('message', $message)->with('type', $type);
                 }
             }
         } else {
             $code_id = NULL;
         }
         $owner_data = Owner::find($owner_id);
         $settings = Settings::where('key', 'default_search_radius')->first();
         $distance = $settings->value;
         if (Input::has('type')) {
             $type = Input::get('type');
             if (!$type) {
                 // choose default type
                 $provider_type = ProviderType::where('is_default', 1)->first();
                 if (!$provider_type) {
                     $type = 1;
                 } else {
                     $type = $provider_type->id;
                 }
             }
         }
         $typequery = "SELECT distinct provider_id from walker_services where type IN({$type})";
         $typewalkers = DB::select(DB::raw($typequery));
         /* $var = Keywords::where('id', 1)->first(); */
         if (empty($typewalkers)) {
             /* $message = "No " . $var->keyword . " found matching the service type."; */
             $message = "No " . Config::get('app.generic_keywords.Provider') . " found matching the service type.";
         } else {
             Log::info('typewalkers = ' . print_r($typewalkers, true));
             foreach ($typewalkers as $key) {
                 $types[] = $key->provider_id;
             }
             $typestring = implode(",", $types);
             Log::info('typestring = ' . print_r($typestring, true));
             if ($typestring == '') {
                 /* $message = "No " . $var->keyword . " found matching the service type."; */
                 $message = "No " . Config::get('app.generic_keywords.Provider') . " found matching the service type.";
             }
             $settings = Settings::where('key', 'default_search_radius')->first();
             $distance = $settings->value;
             $settings = Settings::where('key', 'default_distance_unit')->first();
             $unit = $settings->value;
             if ($unit == 0) {
                 $multiply = 1.609344;
             } elseif ($unit == 1) {
                 $multiply = 1;
             }
             $query = "SELECT walker.*, ROUND(" . $multiply . " * 3956 * acos( cos( radians('{$latitude}') ) * cos( radians(latitude) ) * cos( radians(longitude) - radians('{$longitude}') ) + sin( radians('{$latitude}') ) * sin( radians(latitude) ) ) ,8) as distance from walker where is_available = 1 and is_active = 1 and is_approved = 1 and ROUND((" . $multiply . " * 3956 * acos( cos( radians('{$latitude}') ) * cos( radians(latitude) ) * cos( radians(longitude) - radians('{$longitude}') ) + sin( radians('{$latitude}') ) * sin( radians(latitude) ) ) ) ,8) <= {$distance} and walker.deleted_at IS NULL and walker.id IN({$typestring}) order by distance";
             $walkers = DB::select(DB::raw($query));
             $walker_list = array();
             $owner = Owner::find($owner_id);
             $owner->latitude = $latitude;
             $owner->longitude = $longitude;
             $owner->save();
             $user_timezone = $owner->timezone;
             $default_timezone = Config::get('app.timezone');
             $offset = $this->get_timezone_offset($default_timezone, $user_timezone);
             $request = new Requests();
             $request->owner_id = $owner_id;
             if ($d_longitude != '' && $d_latitude != '') {
                 $request->D_latitude = $d_latitude;
                 $request->D_longitude = $d_longitude;
             }
             $request->request_start_time = date("Y-m-d H:i:s", strtotime(date("Y-m-d H:i:s")) + $offset);
             $request->save();
             $request_service = new RequestServices();
             $request_service->type = $type;
             $request_service->request_id = $request->id;
             $request_service->save();
             $i = 0;
             $first_walker_id = 0;
             foreach ($walkers as $walker) {
                 $request_meta = new RequestMeta();
                 $request_meta->request_id = $request->id;
                 $request_meta->walker_id = $walker->id;
                 if ($i == 0) {
                     $first_walker_id = $walker->id;
                     $i++;
                 }
                 $request_meta->save();
             }
             $req = Requests::find($request->id);
             $req->current_walker = $first_walker_id;
             $req->confirmed_walker = 0;
             $req->payment_mode = $payment_type;
             $req->promo_code = $code_id;
             $req->save();
             $settings = Settings::where('key', 'provider_timeout')->first();
             $time_left = $settings->value;
             /* $var = Keywords::where('id', 1)->first();
             
                               $message = "Your Request is successful. Please wait while we are finding a nearest " . $var->keyword . " for you."; */
             $message = "Your Request is successful. Please wait while we are finding a nearest " . Config::get('app.generic_keywords.Provider') . " for you.";
             $type = "success";
         }
         return Redirect::to('/user/request-trip')->with('message', $message)->with('type', $type);
         // Send Notification
         $walker = Walker::find($first_walker_id);
         if ($walker) {
             $msg_array = array();
             $msg_array['unique_id'] = 1;
             $msg_array['request_id'] = $request->id;
             $msg_array['time_left_to_respond'] = $time_left;
             $owner = Owner::find($owner_id);
             $request_data = array();
             $request_data['owner'] = array();
             $request_data['owner']['name'] = $owner->first_name . " " . $owner->last_name;
             $request_data['owner']['picture'] = $owner->picture;
             $request_data['owner']['phone'] = $owner->phone;
             $request_data['owner']['address'] = $owner->address;
             $request_data['owner']['latitude'] = $owner->latitude;
             $request_data['owner']['longitude'] = $owner->longitude;
             /* $request_data['owner']['rating'] = DB::table('review_dog')->where('owner_id', '=', $owner->id)->avg('rating') ? : 0; */
             $request_data['owner']['rating'] = $owner->rate;
             /* $request_data['owner']['num_rating'] = DB::table('review_dog')->where('owner_id', '=', $owner->id)->count(); */
             $request_data['owner']['num_rating'] = $owner->rate_count;
             $request_data['dog'] = array();
             if ($dog = Dog::find($owner->dog_id)) {
                 $request_data['dog']['name'] = $dog->name;
                 $request_data['dog']['age'] = $dog->age;
                 $request_data['dog']['breed'] = $dog->breed;
                 $request_data['dog']['likes'] = $dog->likes;
                 $request_data['dog']['picture'] = $dog->image_url;
             }
             $msg_array['request_data'] = $request_data;
             $title = "New Request";
             $message = json_encode($msg_array);
             send_notifications($first_walker_id, "walker", $title, $message);
         }
         // Send SMS
         $settings = Settings::where('key', 'sms_request_created')->first();
         $pattern = $settings->value;
         $pattern = str_replace('%user%', $owner_data->first_name . " " . $owner_data->last_name, $pattern);
         $pattern = str_replace('%id%', $request->id, $pattern);
         $pattern = str_replace('%user_mobile%', $owner_data->phone, $pattern);
         sms_notification(1, 'admin', $pattern);
         // send email
         /* $settings = Settings::where('key', 'email_new_request')->first();
            $pattern = $settings->value;
            $pattern = str_replace('%id%', $request->id, $pattern);
            $pattern = str_replace('%url%', web_url() . "/admin/request/map/" . $request->id, $pattern);
            $subject = "New Request Created";
            email_notification(1, 'admin', $pattern, $subject); */
         $settings = Settings::where('key', 'admin_email_address')->first();
         $admin_email = $settings->value;
         $follow_url = web_url() . "/user/signin";
         $pattern = array('admin_eamil' => $admin_email, 'trip_id' => $request->id, 'follow_url' => $follow_url);
         $subject = "Ride Booking Request";
         email_notification(1, 'admin', $pattern, $subject, 'new_request', null);
         return Redirect::to('/user/request-trip')->with('message', $message)->with('type', $type);
     }
 }