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);
+7 -13
View File
@@ -85,20 +85,14 @@ class ReportController extends Controller
$downSetting = Setting::where('key', 'down_price')->first();
if ($upSetting && $downSetting) {
$today = Carbon::now()->format('Y-m-d');
$updatedToday = $upSetting->updated_at
&& $upSetting->updated_at->format('Y-m-d') === $today;
$down = (float) ($downSetting->value ?: 0);
$up = (float) ($upSetting->value ?: 0);
if ($updatedToday) {
$down = (float) $downSetting->value;
$up = (float) $upSetting->value;
if ($down > 0 && $up > 0) {
return [
'sell' => $down - $diffSell,
'buy' => $up + $diffBuy,
];
}
if ($down > 0 && $up > 0) {
return [
'sell' => $down - $diffSell,
'buy' => $up + $diffBuy,
];
}
}
+3 -1
View File
@@ -34,10 +34,12 @@ class ConfigService
$priceInt = (int) round($price);
$today = now()->toDateString();
$extremeDate = $this->Config('price_extreme_date');
if (!$upSetting->updated_at || $upSetting->updated_at->toDateString() !== $today) {
if ($extremeDate !== $today) {
$this->UpdateConfig('up_price', $priceInt);
$this->UpdateConfig('down_price', $priceInt);
$this->UpdateConfig('price_extreme_date', $today);
return;
}