This commit is contained in:
2026-06-13 12:42:42 +03:30
parent f8c96a420f
commit e70fcef962
8 changed files with 264 additions and 7 deletions
@@ -0,0 +1,48 @@
<?php
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;
class PriceSyncLogController extends Controller
{
public function table(Request $request)
{
$records = PriceSyncLog::query()->orderByDesc('id');
TableEngine::create($records, $request->all())
->initSearch(['source', 'source_url'])
->select(['*'])
->export($records);
return response()->json($records);
}
public function show($id)
{
$log = PriceSyncLog::with('items')->findOrFail($id);
return response()->json($log);
}
public function runSync(ProductPriceSyncService $syncService, ConfigService $configService)
{
if (! $configService->isStore()) {
return response()->json(['message' => 'فقط در حالت فروشگاه'], 422);
}
$syncService->syncStorePrices(true);
$log = PriceSyncLog::with('items')->orderByDesc('id')->first();
return response()->json([
'message' => $log ? 'قیمت‌ها به‌روزرسانی شد' : 'تغییری در قیمت محصولات نبود',
'data' => $log,
]);
}
}