49 lines
1.3 KiB
PHP
49 lines
1.3 KiB
PHP
<?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,
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
}
|