feat(settings): enable_automation gate; reject stale montzar quote jumps

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-24 16:15:52 +03:30
co-authored by Cursor
parent b28a98938e
commit 352bb9976d
9 changed files with 212 additions and 18 deletions
@@ -8,6 +8,7 @@ use App\Models\Automation;
use App\Services\Automation\AutomationCatalog;
use App\Services\Automation\AutomationEngine;
use App\Services\Automation\AutomationFingerprint;
use App\Services\ConfigService;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
@@ -16,6 +17,7 @@ class AutomationController extends Controller
{
public function table(Request $request)
{
$this->assertFeatureEnabled();
$query = Automation::query();
TableEngine::create($query, $request->all())
->initSearch(['name', 'code', 'title', 'body'])
@@ -27,11 +29,14 @@ class AutomationController extends Controller
public function catalog()
{
$this->assertFeatureEnabled();
return response()->json(app(AutomationCatalog::class)->toArray());
}
public function preview(Request $request)
{
$this->assertFeatureEnabled();
$conditions = array_values((array) $request->input('conditions', []));
$count = app(AutomationEngine::class)->previewCount($conditions);
@@ -40,6 +45,7 @@ class AutomationController extends Controller
public function store(Request $request)
{
$this->assertFeatureEnabled();
$data = $this->validated($request);
$data['created_by'] = auth()->id();
$row = Automation::create($data);
@@ -49,6 +55,7 @@ class AutomationController extends Controller
public function update(Request $request, $id)
{
$this->assertFeatureEnabled();
$row = Automation::query()->findOrFail($id);
$data = $this->validated($request, (int) $row->id);
$row->fill($data)->save();
@@ -58,6 +65,7 @@ class AutomationController extends Controller
public function toggle($id)
{
$this->assertFeatureEnabled();
$row = Automation::query()->findOrFail($id);
if (! $row->is_active) {
$dup = $this->duplicateOf($row->logic_fingerprint, (int) $row->id, true);
@@ -75,11 +83,19 @@ class AutomationController extends Controller
public function destroy($id)
{
$this->assertFeatureEnabled();
Automation::query()->findOrFail($id)->delete();
return response()->json(true);
}
private function assertFeatureEnabled(): void
{
if (! app(ConfigService::class)->isAutomationEnabled()) {
throw new UnprocessableEntityHttpException('قابلیت اتوماسیون خاموش است.');
}
}
private function validated(Request $request, ?int $ignoreId = null): array
{
$name = trim((string) $request->input('name', ''));
+11 -4
View File
@@ -341,7 +341,8 @@ class ReportController extends Controller
$config->applyMontzarSyncFailure();
if (!$config->getBool('montzar_closed', true)) {
$montzarLivePrice = $config->getInt('montzar_live_price', 0);
$stale = $config->getInt('montzar_live_price', 0);
$montzarLivePrice = $config->isPlausibleQuotePrice((float) $stale) ? $stale : 0;
}
}
}
@@ -392,7 +393,12 @@ class ReportController extends Controller
if ($priceProvider === 'zaarbox' && $zaarbox_price > 0 && !$closed) {
$priceValue = $zaarbox_price;
$priceSource = 'zaarbox';
} elseif ($priceProvider === 'montzar' && ($montzarLivePrice ?? 0) !== 0 && !$closed) {
} elseif (
$priceProvider === 'montzar'
&& ($montzarLivePrice ?? 0) !== 0
&& !$closed
&& $config->isPlausibleQuotePrice((float) $montzarLivePrice)
) {
$priceValue = (int) $montzarLivePrice;
$priceSource = 'montzar';
} elseif ($priceProvider === 'main_product' && ($pr_price ?? 0) !== 0 && !$closed) {
@@ -581,13 +587,14 @@ class ReportController extends Controller
$montzar = 0;
$config->applyMontzarSyncFailure();
if (!$config->getBool('montzar_closed', true)) {
$montzar = $config->getInt('montzar_live_price', 0);
$stale = $config->getInt('montzar_live_price', 0);
$montzar = $config->isPlausibleQuotePrice((float) $stale) ? $stale : 0;
}
\Log::error('STORE MONZAR PRICE ERROR', ['message' => $e->getMessage()]);
}
}
if ($montzarEnabled && $montzar !== 0) {
if ($montzarEnabled && $montzar !== 0 && $config->isPlausibleQuotePrice((float) $montzar)) {
$priceValue = $montzar;
$priceSource = 'montzar';
} else {