khanegi admin changes

This commit is contained in:
2026-06-13 15:55:28 +03:30
parent 2d2e5f2e4d
commit 9b28a55634
2 changed files with 20 additions and 13 deletions
@@ -5,7 +5,6 @@ namespace App\Http\Controllers\Admin;
use App\DB\Te\TableEngine;
use App\Http\Controllers\Controller;
use App\Models\PriceSyncLog;
use App\Services\ConfigService;
use App\Services\ProductPriceSyncService;
use Illuminate\Http\Request;
@@ -30,12 +29,8 @@ class PriceSyncLogController extends Controller
return response()->json($log);
}
public function runSync(ProductPriceSyncService $syncService, ConfigService $configService)
public function runSync(ProductPriceSyncService $syncService)
{
if (! $configService->isStore()) {
return response()->json(['message' => 'فقط در حالت فروشگاه'], 422);
}
$syncService->syncStorePrices(true);
$log = PriceSyncLog::with('items')->orderByDesc('id')->first();
+19 -7
View File
@@ -8,6 +8,17 @@ use Illuminate\Support\Collection;
class CategoryService
{
/** دسته‌های پیش‌فرض — باید با سلکت افزودن محصول و تب فیلتر اپ یکسان باشند */
public const DEFAULT_CATEGORY_NAMES = [
'آبشده',
'مکعب',
'گوی',
'سکه',
'سکه پارسیان',
'مس',
'نقره',
];
/** دسته‌هایی که صریحاً غیرفعال شده‌اند — بقیه (بدون ردیف) نمایش داده می‌شوند */
public function hiddenCategoryNames(): Collection
{
@@ -54,22 +65,23 @@ class CategoryService
public function syncFromProducts(): int
{
$names = Product::query()
$fromProducts = Product::query()
->whereNotNull('group_type')
->where('group_type', '!=', '')
->distinct()
->orderBy('group_type')
->pluck('group_type');
$names = collect(self::DEFAULT_CATEGORY_NAMES)
->merge($fromProducts)
->map(static fn ($name) => trim((string) $name))
->filter()
->unique()
->values();
$created = 0;
$order = (int) Category::max('sort_order');
foreach ($names as $name) {
$name = trim((string) $name);
if ($name === '') {
continue;
}
if (Category::where('name', $name)->exists()) {
continue;
}