Update source into github

This commit is contained in:
pbao9
2025-07-24 16:18:27 +07:00
parent 41419358dd
commit 69851ac7bc
2642 changed files with 284095 additions and 0 deletions
+86
View File
@@ -0,0 +1,86 @@
<?php
use App\Repositories\Setting\SettingCachedRepository;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Str;
if (!function_exists('setting')) {
function setting(string $key = '')
{
// Cách gọi setting('setting') để lấy toàn bộ group json
$repo = app()->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;
}
}