khanegi admin changes
This commit is contained in:
@@ -5,7 +5,6 @@ namespace App\Http\Controllers\Admin;
|
|||||||
use App\DB\Te\TableEngine;
|
use App\DB\Te\TableEngine;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Models\PriceSyncLog;
|
use App\Models\PriceSyncLog;
|
||||||
use App\Services\ConfigService;
|
|
||||||
use App\Services\ProductPriceSyncService;
|
use App\Services\ProductPriceSyncService;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
@@ -30,12 +29,8 @@ class PriceSyncLogController extends Controller
|
|||||||
return response()->json($log);
|
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);
|
$syncService->syncStorePrices(true);
|
||||||
|
|
||||||
$log = PriceSyncLog::with('items')->orderByDesc('id')->first();
|
$log = PriceSyncLog::with('items')->orderByDesc('id')->first();
|
||||||
|
|||||||
@@ -8,6 +8,17 @@ use Illuminate\Support\Collection;
|
|||||||
|
|
||||||
class CategoryService
|
class CategoryService
|
||||||
{
|
{
|
||||||
|
/** دستههای پیشفرض — باید با سلکت افزودن محصول و تب فیلتر اپ یکسان باشند */
|
||||||
|
public const DEFAULT_CATEGORY_NAMES = [
|
||||||
|
'آبشده',
|
||||||
|
'مکعب',
|
||||||
|
'گوی',
|
||||||
|
'سکه',
|
||||||
|
'سکه پارسیان',
|
||||||
|
'مس',
|
||||||
|
'نقره',
|
||||||
|
];
|
||||||
|
|
||||||
/** دستههایی که صریحاً غیرفعال شدهاند — بقیه (بدون ردیف) نمایش داده میشوند */
|
/** دستههایی که صریحاً غیرفعال شدهاند — بقیه (بدون ردیف) نمایش داده میشوند */
|
||||||
public function hiddenCategoryNames(): Collection
|
public function hiddenCategoryNames(): Collection
|
||||||
{
|
{
|
||||||
@@ -54,22 +65,23 @@ class CategoryService
|
|||||||
|
|
||||||
public function syncFromProducts(): int
|
public function syncFromProducts(): int
|
||||||
{
|
{
|
||||||
$names = Product::query()
|
$fromProducts = Product::query()
|
||||||
->whereNotNull('group_type')
|
->whereNotNull('group_type')
|
||||||
->where('group_type', '!=', '')
|
->where('group_type', '!=', '')
|
||||||
->distinct()
|
->distinct()
|
||||||
->orderBy('group_type')
|
|
||||||
->pluck('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;
|
$created = 0;
|
||||||
$order = (int) Category::max('sort_order');
|
$order = (int) Category::max('sort_order');
|
||||||
|
|
||||||
foreach ($names as $name) {
|
foreach ($names as $name) {
|
||||||
$name = trim((string) $name);
|
|
||||||
if ($name === '') {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Category::where('name', $name)->exists()) {
|
if (Category::where('name', $name)->exists()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user