= 0) && ($bytes < $kb)) { return $bytes . ' B'; } elseif (($bytes >= $kb) && ($bytes < $mb)) { return ceil($bytes / $kb) . ' KB'; } elseif (($bytes >= $mb) && ($bytes < $gb)) { return ceil($bytes / $mb) . ' MB'; } elseif (($bytes >= $gb) && ($bytes < $tb)) { return ceil($bytes / $gb) . ' GB'; } elseif ($bytes >= $tb) { return ceil($bytes / $tb) . ' TB'; } else { return $bytes . ' B'; } } public static function generateRequestID($user_id){ return date('Ymdhis').'-'.$user_id; } public static function authenticate_token($token){ $user = ApiTokens::where('api_token',$token)->first(); if($user->users->is_active=="0" || $user->users->is_active==0){ //dd($user->users->is_active); $response = [ 'type' => 'error', 'message' => 'Account is inative, contact to administrator!', 'code' =>'X003' ]; echo json_encode($response); exit; } return $user; } public static function sendResponse($result, $message) { $response = [ 'type' => "success", 'data' => $result, 'message' => $message, ]; return response()->json($response, 200,[],JSON_UNESCAPED_UNICODE); } public static function sendError($error, $errorMessages = [], $code = 404) { $response = [ 'type' => 'error', 'message' => $error, 'code' =>$code ]; if(!empty($errorMessages)){ $response['data'] = $errorMessages; } return response()->json($response, 400); } public static function idFormat($restoId,$id){ return str_pad($restoId,4,0, STR_PAD_LEFT).'-'.str_pad($id,6,0, STR_PAD_LEFT); } public static function idFormatItem($restoId,$order_id,$id){ return str_pad($restoId,4,0, STR_PAD_LEFT).'-'.str_pad($order_id,6,0, STR_PAD_LEFT).'-'.str_pad($id,6,0, STR_PAD_LEFT); } public static function uploadFileToAWSCDN($budketName, $restoID ,$restoName ,$sourceFile,$fileName ){ $s3 = new S3Client([ 'version' => 'latest', 'region' => env('AWS_DEFAULT_REGION') ]); $bucket = $budketName; $image = ""; try { // Upload data. $result = $s3->putObject([ 'Bucket' => $bucket, 'Key' => env('BUCKET_FOLDER')."/".$restoID.'-'.\Illuminate\Support\Str::slug($restoName)."/".$fileName , 'SourceFile' => $sourceFile, 'Body' => 'Hello, world!', 'ACL' => 'public-read' ]); // Print the URL to the object. $image = $result['ObjectURL']; $result = array('type'=>'success','url'=>$image); return $result; } catch (S3Exception $e) { $result = array('type'=>'error','message'=>$e->getMessage()); return $result; } } public static function getRestuarantID(){ // return 110; if(Auth::user()->role=='administrator') return Auth::id(); else if(Auth::user()->role=='restaurant') return Auth::user()->restaurants->id; else if(Auth::user()->role=='admin_user') return Auth::user()->admin_users->id; else return Auth::user()->resto_users->resto_id; } public static function changeImageLinkAWStoImgix($aws_image_link,$imgix, $width,$height,$quality){ return str_replace(env('AWS_URL_API'),$imgix,$aws_image_link).'?fm=webp&h='.$width.'&w='.$height.'&q='.$quality.'&fit=center&crop=center'; } public static function getRestoMetas(Restaurants $restaurants){ // $resto_metas = \Illuminate\Support\Facades\Cookie::get($restaurants->resto_unique_name.'_resto_metas'); // if(!isset($resto_metas)){ if(1){ $resto_meta = isset($restaurants->resto_metas)?$restaurants->resto_metas:null; //dump($resto_meta); $resto_metas = []; $billing = []; if(isset($resto_meta)){ foreach($resto_meta as $meta){ if($meta->outlet_id!=""){ continue; } $index_name = isset($meta->resto_meta_defs->parents)?$meta->resto_meta_defs->parents->meta_def_name:$meta->resto_meta_defs->meta_def_name; // dump($meta->resto_meta_defs); if($index_name=="BILLING_GATEWAY"){ // dump($meta->resto_meta_defs->meta_def_name); // $resto_metas['BILLING_GATEWAY'][] = $meta->meta_val; $billing[] = array('id'=>$meta->meta_id,'value'=>$meta->meta_val); } $resto_metas[$index_name] = $meta->meta_val; } } $resto_metas['BILLING_GATEWAY'] = $billing; //\Illuminate\Support\Facades\Cookie::queue($restaurants->resto_unique_name.'_resto_metas',json_encode($resto_metas),'3600'); return $resto_metas; }else{ $resto_metas = json_decode($resto_metas,true); return $resto_metas; } } public static function getIPBasedInfo($ip = NULL, $purpose = "location", $deep_detect = TRUE) { $output = NULL; if (filter_var($ip, FILTER_VALIDATE_IP) === FALSE) { $ip = $_SERVER["REMOTE_ADDR"]; if ($deep_detect) { if (filter_var(@$_SERVER['HTTP_X_FORWARDED_FOR'], FILTER_VALIDATE_IP)) $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; if (filter_var(@$_SERVER['HTTP_CLIENT_IP'], FILTER_VALIDATE_IP)) $ip = $_SERVER['HTTP_CLIENT_IP']; } } $purpose = str_replace(array("name", "\n", "\t", " ", "-", "_"), NULL, strtolower(trim($purpose))); $support = array("country", "countrycode", "state", "region", "city", "location", "address"); $continents = array( "AF" => "Africa", "AN" => "Antarctica", "AS" => "Asia", "EU" => "Europe", "OC" => "Australia (Oceania)", "NA" => "North America", "SA" => "South America" ); if (filter_var($ip, FILTER_VALIDATE_IP) && in_array($purpose, $support)) { $ipdat = @json_decode(file_get_contents("http://www.geoplugin.net/json.gp?ip=" . $ip)); if (@strlen(trim($ipdat->geoplugin_countryCode)) == 2) { switch ($purpose) { case "location": $output = array( "city" => @$ipdat->geoplugin_city, "state" => @$ipdat->geoplugin_regionName, "country" => @$ipdat->geoplugin_countryName, "country_code" => @$ipdat->geoplugin_countryCode, "continent" => @$continents[strtoupper($ipdat->geoplugin_continentCode)], "continent_code" => @$ipdat->geoplugin_continentCode, 'currency' => @$ipdat->geoplugin_currencyCode ); break; case "address": $address = array($ipdat->geoplugin_countryName); if (@strlen($ipdat->geoplugin_regionName) >= 1) $address[] = $ipdat->geoplugin_regionName; if (@strlen($ipdat->geoplugin_city) >= 1) $address[] = $ipdat->geoplugin_city; $output = implode(", ", array_reverse($address)); break; case "city": $output = @$ipdat->geoplugin_city; break; case "state": $output = @$ipdat->geoplugin_regionName; break; case "region": $output = @$ipdat->geoplugin_regionName; break; case "country": $output = @$ipdat->geoplugin_countryName; break; case "countrycode": $output = @$ipdat->geoplugin_countryCode; break; } } } return $output; } }