make(\App\Repositories\Setting\SettingCachedRepository::class); // Nếu có dấu chấm => lấy theo group if (Str::contains($key, '.')) { [$group, $subKey] = explode('.', $key, 2); $groupData = $repo->getByKey($group); if (is_string($groupData)) { $groupData = json_decode($groupData, true); } return $groupData[$subKey] ?? null; } // Ngược lại là setting đơn return $repo->getByKey($key); } } if (!function_exists('format_price')) { function format_price($price, $suffix = '₫') { if ($price === null) return ''; return number_format($price, 0, ',', '.') . ' ' . $suffix; } } if (!function_exists('format_point')) { function format_point($point, $suffix = '𝑝') { if ($point === null) return ''; return number_format($point, 0, ',', '.') . ' ' . $suffix; } } if (!function_exists('format_day')) { function format_day($date, $format = 'd/m/Y') { if (empty($date)) return ''; try { return \Carbon\Carbon::parse($date)->format($format); } catch (\Exception $e) { return ''; } } } if (!function_exists('customer')) { function customer() { return Auth::guard('users')->user(); } } if (!function_exists('generate_order_number')) { /** * Generate a unique order number with given prefix * * @param string $prefix Default prefix 'TGS' * @param int $length Length of random number (default 6) * @return string Unique order number */ function generate_order_number(string $prefix = 'TGS', int $length = 6): string { do { $randomNumber = random_int(10 ** ($length - 1), (10 ** $length) - 1); $orderNum = $prefix . $randomNumber; } while (\App\Models\Order::where('order_num', $orderNum)->exists()); return $orderNum; } }