fix up down price

This commit is contained in:
2026-06-02 11:18:05 +03:30
parent cf466c616c
commit 3e6c4b588d
3 changed files with 28 additions and 18 deletions
@@ -6,6 +6,7 @@ use App\Http\Controllers\Controller;
use App\Http\Controllers\SuperController;
use App\Models\Cnt;
use App\Models\Product;
use App\Models\Setting;
use App\DB\Te\TableEngine;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;
@@ -140,6 +141,8 @@ class ProductController extends SuperController
// }catch (\Exception $e){}
$config = app(ConfigService::class);
$mainProductId = Cnt::where('key', 'main_product')->value('value');
$hasExtremeKeys = Setting::whereIn('key', ['up_price', 'down_price'])->count() === 2;
$products = Product::with([])->whereNotNull('reading_method')->get();
foreach ($products as $product) {
$collection = collect($RPrices);
@@ -160,9 +163,14 @@ class ProductController extends SuperController
'price' => $RPrice['price'],
'price_profit' => $RPrice['profit'],
]);
$config->trackDailyPriceExtreme(
(float) $RPrice['price'] + (float) ($RPrice['profit'] ?? 0)
);
$productPrice = (float) $RPrice['price'] + (float) ($RPrice['profit'] ?? 0);
if (
$hasExtremeKeys
&& $mainProductId
&& (int) $product->id === (int) $mainProductId
) {
$config->trackDailyPriceExtreme($productPrice);
}
if ($product->bubble == 1) {
$ReportController = new ReportController();
@@ -181,7 +189,13 @@ class ProductController extends SuperController
'price_profit' => 0,
'updated_at' => \Carbon\Carbon::now()->format('Y-m-d H:i:s'),
]);
$config->trackDailyPriceExtreme((float) $cp);
if (
$hasExtremeKeys
&& $mainProductId
&& Product::where('id', $mainProductId)->where('metal_id', 3)->exists()
) {
$config->trackDailyPriceExtreme((float) $cp);
}
}
return response()->json(true);