23-01-2026
This commit is contained in:
parent
a939cd51ef
commit
a8b395e20d
248 changed files with 29342 additions and 4805 deletions
|
|
@ -2,17 +2,13 @@
|
|||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Country;
|
||||
use App\Models\ShippingCountry;
|
||||
use App\Models\UserHistory;
|
||||
use App\Models\UserShop;
|
||||
use Illuminate\Support\Str;
|
||||
use Request;
|
||||
use Yard;
|
||||
|
||||
class Util
|
||||
{
|
||||
|
||||
private static $postRoute = 'base.';
|
||||
|
||||
public static function getToken()
|
||||
|
|
@ -23,111 +19,153 @@ class Util
|
|||
public static function uuidToken()
|
||||
{
|
||||
$uuid = (string) Str::uuid();
|
||||
$e_uuid = explode("-", $uuid);
|
||||
$e_uuid = explode('-', $uuid);
|
||||
if (isset($e_uuid[0]) && $e_uuid[1]) {
|
||||
return $e_uuid[0] . "-" . $e_uuid[1];
|
||||
return $e_uuid[0] . '-' . $e_uuid[1];
|
||||
}
|
||||
|
||||
return $uuid;
|
||||
}
|
||||
|
||||
public static function formatDate()
|
||||
{
|
||||
if (\App::getLocale() === "en") {
|
||||
if (\App::getLocale() === 'en') {
|
||||
return 'yyyy-mm-dd';
|
||||
}
|
||||
|
||||
return 'dd.mm.yyyy';
|
||||
}
|
||||
|
||||
public static function formatDateDB()
|
||||
{
|
||||
if (\App::getLocale() === "en") {
|
||||
if (\App::getLocale() === 'en') {
|
||||
return 'Y-m-d';
|
||||
}
|
||||
|
||||
return 'd.m.Y';
|
||||
}
|
||||
|
||||
public static function formatDateTimeDB()
|
||||
{
|
||||
if (\App::getLocale() === "en") {
|
||||
if (\App::getLocale() === 'en') {
|
||||
return 'Y-m-d - H:i';
|
||||
}
|
||||
|
||||
return 'd.m.Y - H:i';
|
||||
}
|
||||
|
||||
public static function _format_number($value)
|
||||
{
|
||||
return preg_replace("/[^0-9,-]/", "", $value);
|
||||
// Erlaubt Zahlen, Komma, Punkt und Minus (für Dezimalzahlen in DE und EN Format)
|
||||
return preg_replace('/[^0-9,.-]/', '', $value);
|
||||
}
|
||||
|
||||
public static function _thousands_separator()
|
||||
{
|
||||
return \App::getLocale() === "en" ? ',' : '.';
|
||||
return \App::getLocale() === 'en' ? ',' : '.';
|
||||
}
|
||||
|
||||
public static function _decimal_separator()
|
||||
{
|
||||
return \App::getLocale() === "en" ? '.' : ',';
|
||||
return \App::getLocale() === 'en' ? '.' : ',';
|
||||
}
|
||||
|
||||
|
||||
public static function maxStrLength($str, $length = 40)
|
||||
{
|
||||
|
||||
if (strlen($str) > $length) {
|
||||
$str = substr($str, 0, $length);
|
||||
//$str = substr($str, 0, strrpos($str, " "));
|
||||
$str = $str . " ...";
|
||||
// $str = substr($str, 0, strrpos($str, " "));
|
||||
$str = $str . ' ...';
|
||||
}
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
|
||||
public static function reFormatNumber($value)
|
||||
{
|
||||
return (float) str_replace(',', '.', self::_format_number($value));
|
||||
// Wenn bereits ein Float/Int, direkt zurückgeben
|
||||
if (is_numeric($value) && ! is_string($value)) {
|
||||
return (float) $value;
|
||||
}
|
||||
|
||||
$value = (string) $value;
|
||||
|
||||
// Entferne alle nicht-numerischen Zeichen außer Punkt, Komma und Minus
|
||||
$value = preg_replace('/[^0-9,.\-]/', '', $value);
|
||||
|
||||
if ($value === '') {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
// Erkenne das Zahlenformat anhand der Position des letzten Trennzeichens
|
||||
$lastComma = strrpos($value, ',');
|
||||
$lastDot = strrpos($value, '.');
|
||||
|
||||
if ($lastComma !== false && ($lastDot === false || $lastComma > $lastDot)) {
|
||||
// Deutsches Format: "1.000,50" -> Punkt entfernen (Tausender), Komma zu Punkt
|
||||
$value = str_replace('.', '', $value);
|
||||
$value = str_replace(',', '.', $value);
|
||||
} else {
|
||||
// Englisches Format: "1,000.50" -> Komma entfernen (Tausender)
|
||||
$value = str_replace(',', '', $value);
|
||||
}
|
||||
|
||||
return (float) $value;
|
||||
}
|
||||
|
||||
public static function formatNumber($value, $dec = 2)
|
||||
{
|
||||
$value = floatval(str_replace(',', '', $value));
|
||||
// Wenn der Wert bereits numerisch ist (int/float), direkt formatieren
|
||||
if (is_numeric($value) && ! is_string($value)) {
|
||||
return number_format((float) $value, $dec, self::_decimal_separator(), self::_thousands_separator());
|
||||
}
|
||||
|
||||
// Bei String-Eingaben: deutsches Format (mit Komma) zu Float konvertieren
|
||||
$value = self::reFormatNumber($value);
|
||||
|
||||
return number_format($value, $dec, self::_decimal_separator(), self::_thousands_separator());
|
||||
}
|
||||
|
||||
public static function cleanIntegerFromString($value)
|
||||
{
|
||||
// Entferne alle nicht-numerischen Zeichen außer Minus
|
||||
$cleanStr = preg_replace("/[^0-9-]/", "", $value);
|
||||
$cleanStr = preg_replace('/[^0-9-]/', '', $value);
|
||||
|
||||
// Konvertiere zu Integer und entferne führende Nullen
|
||||
$number = (int)$cleanStr;
|
||||
$number = (int) $cleanStr;
|
||||
|
||||
return $number;
|
||||
}
|
||||
|
||||
public static function cleanNumberFormat($num = 0, $dec = 2, $fullzero = false)
|
||||
{
|
||||
|
||||
if ($fullzero && $num == 0) {
|
||||
return number_format($num, $dec, self::_decimal_separator(), self::_thousands_separator());
|
||||
}
|
||||
|
||||
return rtrim(rtrim(number_format($num, $dec, self::_decimal_separator(), self::_thousands_separator()), '0'), self::_decimal_separator());
|
||||
}
|
||||
|
||||
public static function utf8ize($mixed)
|
||||
public static function utf8ize($mixed)
|
||||
{
|
||||
if (is_array($mixed)) {
|
||||
foreach ($mixed as $key => $value) {
|
||||
$mixed[$key] = self::utf8ize($value);
|
||||
}
|
||||
} elseif (is_string($mixed)) {
|
||||
return mb_convert_encoding($mixed, "UTF-8", "UTF-8");
|
||||
return mb_convert_encoding($mixed, 'UTF-8', 'UTF-8');
|
||||
}
|
||||
|
||||
return $mixed;
|
||||
}
|
||||
|
||||
|
||||
public static function getPostRoute()
|
||||
{
|
||||
return self::$postRoute;
|
||||
}
|
||||
|
||||
public static function setPostRoute($postRoute)
|
||||
{
|
||||
self::$postRoute = $postRoute;
|
||||
|
|
@ -136,9 +174,10 @@ class Util
|
|||
public static function getUserShop()
|
||||
{
|
||||
$shop = session('user_shop');
|
||||
if (empty($shop) || !is_object($shop)) {
|
||||
if (empty($shop) || ! is_object($shop)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $shop;
|
||||
}
|
||||
|
||||
|
|
@ -148,6 +187,7 @@ class Util
|
|||
if ($user && $user->shop) {
|
||||
return $user->shop;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -158,10 +198,10 @@ class Util
|
|||
return $auth_user;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public static function getUserShopIdentifier()
|
||||
{
|
||||
if (\Session::has('user_shop_identifier')) {
|
||||
|
|
@ -169,6 +209,7 @@ class Util
|
|||
return $user_shop_identifier;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -178,6 +219,7 @@ class Util
|
|||
if ($identifier && \Session::has('user_shop_payment') && \Session::get('user_shop_payment') === 6) {
|
||||
return OrderPaymentService::getInstanceStatus($identifier);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -201,6 +243,7 @@ class Util
|
|||
if (\Session::has('shopping_instance')) {
|
||||
return \Session::get('shopping_instance');
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -211,6 +254,7 @@ class Util
|
|||
if ($user_shop_identifier && $auth_user) {
|
||||
return UserHistory::whereUserId($auth_user->id)->whereIdentifier($user_shop_identifier)->get()->last();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -229,6 +273,7 @@ class Util
|
|||
if ($user_history = self::getUserHistory()) {
|
||||
return $user_history->{$key};
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
@ -239,8 +284,10 @@ class Util
|
|||
return 'test';
|
||||
}
|
||||
}
|
||||
return config('app.mode');
|
||||
|
||||
return config('app.mode');
|
||||
}
|
||||
|
||||
public static function addRoute($p = [])
|
||||
{
|
||||
$b = [];
|
||||
|
|
@ -249,6 +296,7 @@ class Util
|
|||
$b = ['subdomain' => $user_shop->slug];
|
||||
}
|
||||
}
|
||||
|
||||
return array_merge($p, $b);
|
||||
}
|
||||
|
||||
|
|
@ -256,12 +304,14 @@ class Util
|
|||
{
|
||||
|
||||
if (isset($user->account->country_id)) {
|
||||
//ch schweiz is out
|
||||
// ch schweiz is out
|
||||
if ($user->account->country_id === 6) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -272,34 +322,38 @@ class Util
|
|||
return \Auth::guard('customers')->user()->user_shop_domain;
|
||||
}
|
||||
}
|
||||
|
||||
return self::getMyMivitaShopUrl();
|
||||
}
|
||||
|
||||
public static function getMyMivitaShopUrl($add_url = "")
|
||||
public static function getMyMivitaShopUrl($add_url = '')
|
||||
{
|
||||
if (\Session::has('user_shop_domain')) {
|
||||
$url = \Session::get('user_shop_domain') . $add_url;
|
||||
if (!str_starts_with($url, 'http')) {
|
||||
if (! str_starts_with($url, 'http')) {
|
||||
$url = 'https://' . ltrim($url, '/');
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
//alois sein shop
|
||||
// alois sein shop
|
||||
$user = \App\User::find(6);
|
||||
if ($user && $user->shop) {
|
||||
return config('app.protocol') . $user->shop->slug . "." . config('app.domain') . config('app.tld_care') . $add_url;
|
||||
return config('app.protocol') . $user->shop->slug . '.' . config('app.domain') . config('app.tld_care') . $add_url;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static function getMyMivitaPortalUrl($protocol = true)
|
||||
{
|
||||
$pro = $protocol ? config('app.protocol') : "";
|
||||
$pro = $protocol ? config('app.protocol') : '';
|
||||
|
||||
return $pro . config('app.pre_url_portal') . config('app.domain') . config('app.tld_care');
|
||||
}
|
||||
|
||||
public static function getMyMivitaUrl($protocol = true)
|
||||
{
|
||||
$pro = $protocol ? config('app.protocol') : "";
|
||||
$pro = $protocol ? config('app.protocol') : '';
|
||||
|
||||
return $pro . config('app.pre_url_crm') . config('app.domain') . config('app.tld_care');
|
||||
}
|
||||
|
||||
|
|
@ -311,10 +365,11 @@ class Util
|
|||
if (\Session::has('user_shop_payment')) {
|
||||
return \Session::get('user_shop_payment');
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function getUserShopBackUrl($reference = "")
|
||||
public static function getUserShopBackUrl($reference = '')
|
||||
{
|
||||
|
||||
if (\Session::has('user_shop')) {
|
||||
|
|
@ -322,9 +377,10 @@ class Util
|
|||
return \Session::get('user_shop_domain');
|
||||
}
|
||||
if ($user_shop = \Session::get('user_shop')) {
|
||||
return config('app.protocol') . $user_shop->slug . "." . config('app.domain') . config('app.tld_care') . "/back/to/shop/" . $reference;
|
||||
return config('app.protocol') . $user_shop->slug . '.' . config('app.domain') . config('app.tld_care') . '/back/to/shop/' . $reference;
|
||||
}
|
||||
}
|
||||
|
||||
return config('app.protocol') . config('app.domain') . config('app.tld_care');
|
||||
}
|
||||
|
||||
|
|
@ -337,17 +393,19 @@ class Util
|
|||
return \Session::get('back_link');
|
||||
}
|
||||
if (self::getUserPaymentFor($instance) === 3) {
|
||||
return \Session::get('user_shop_domain') . "/user/membership";
|
||||
return \Session::get('user_shop_domain') . '/user/membership';
|
||||
}
|
||||
if (self::getUserPaymentFor($instance) === 2) {
|
||||
return \Session::get('user_shop_domain') . "/user/orders";
|
||||
return \Session::get('user_shop_domain') . '/user/orders';
|
||||
}
|
||||
|
||||
return \Session::get('user_shop_domain');
|
||||
}
|
||||
if ($user_shop = \Session::get('user_shop')) {
|
||||
return config('app.protocol') . $user_shop->slug . "." . config('app.domain') . config('app.tld_care') . $uri;
|
||||
return config('app.protocol') . $user_shop->slug . '.' . config('app.domain') . config('app.tld_care') . $uri;
|
||||
}
|
||||
}
|
||||
|
||||
return config('app.protocol') . config('app.domain') . config('app.tld_care');
|
||||
}
|
||||
|
||||
|
|
@ -363,6 +421,7 @@ class Util
|
|||
if (Request::getHost() === 'naturcosmetic.' . config('app.domain') . config('app.tld_care')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return \Config::get('app.url') === config('app.domain') . config('app.tld_shop');
|
||||
}
|
||||
|
||||
|
|
@ -372,8 +431,10 @@ class Util
|
|||
if ($dev && config('app.debug') !== true) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -382,7 +443,7 @@ class Util
|
|||
if ($size > 0) {
|
||||
$size = (int) $size;
|
||||
$base = log($size) / log(1024);
|
||||
$suffixes = array(' bytes', ' KB', ' MB', ' GB', ' TB');
|
||||
$suffixes = [' bytes', ' KB', ' MB', ' GB', ' TB'];
|
||||
|
||||
return round(pow(1024, $base - floor($base)), $precision) . $suffixes[floor($base)];
|
||||
} else {
|
||||
|
|
@ -390,56 +451,70 @@ class Util
|
|||
}
|
||||
}
|
||||
|
||||
public static function formatTextWithLineBreaks($text, $translate = false)
|
||||
{
|
||||
if ($translate) {
|
||||
$translated = ['payment.commission_shop', 'payment.commission_payline', 'payment.commission_growth_bonus'];
|
||||
foreach ($translated as $value) {
|
||||
// $text = str_replace($key, trans($value), $text);
|
||||
$text = str_replace($value, __($value), $text);
|
||||
}
|
||||
}
|
||||
|
||||
return nl2br($text);
|
||||
}
|
||||
|
||||
public static function sanitize($string, $force_lowercase = true, $anal = false, $substr = false)
|
||||
{
|
||||
$strip = array(
|
||||
"~",
|
||||
"`",
|
||||
"!",
|
||||
"@",
|
||||
"#",
|
||||
"$",
|
||||
"%",
|
||||
"^",
|
||||
"&",
|
||||
"*",
|
||||
"(",
|
||||
")",
|
||||
"_",
|
||||
"=",
|
||||
"+",
|
||||
"[",
|
||||
"{",
|
||||
"]",
|
||||
"}",
|
||||
"\\",
|
||||
"|",
|
||||
";",
|
||||
":",
|
||||
"\"",
|
||||
$strip = [
|
||||
'~',
|
||||
'`',
|
||||
'!',
|
||||
'@',
|
||||
'#',
|
||||
'$',
|
||||
'%',
|
||||
'^',
|
||||
'&',
|
||||
'*',
|
||||
'(',
|
||||
')',
|
||||
'_',
|
||||
'=',
|
||||
'+',
|
||||
'[',
|
||||
'{',
|
||||
']',
|
||||
'}',
|
||||
'\\',
|
||||
'|',
|
||||
';',
|
||||
':',
|
||||
'"',
|
||||
"'",
|
||||
"‘",
|
||||
"’",
|
||||
"“",
|
||||
"”",
|
||||
"–",
|
||||
"—",
|
||||
"—",
|
||||
"–",
|
||||
",",
|
||||
"<",
|
||||
".",
|
||||
">",
|
||||
"/",
|
||||
"?"
|
||||
);
|
||||
$clean = trim(str_replace($strip, "", strip_tags($string)));
|
||||
$clean = preg_replace('/\s+/', "_", $clean);
|
||||
$clean = ($anal) ? preg_replace("/[^a-zA-Z0-9]/", "", $clean) : $clean;
|
||||
'‘',
|
||||
'’',
|
||||
'“',
|
||||
'”',
|
||||
'–',
|
||||
'—',
|
||||
'—',
|
||||
'–',
|
||||
',',
|
||||
'<',
|
||||
'.',
|
||||
'>',
|
||||
'/',
|
||||
'?',
|
||||
];
|
||||
$clean = trim(str_replace($strip, '', strip_tags($string)));
|
||||
$clean = preg_replace('/\s+/', '_', $clean);
|
||||
$clean = ($anal) ? preg_replace('/[^a-zA-Z0-9]/', '', $clean) : $clean;
|
||||
|
||||
if ($substr) {
|
||||
$clean = (strlen($clean) > 20) ? substr($clean, -20) : $clean;
|
||||
}
|
||||
|
||||
return ($force_lowercase) ?
|
||||
(function_exists('mb_strtolower')) ?
|
||||
mb_strtolower($clean, 'UTF-8') :
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue