fix register 3

This commit is contained in:
2026-06-01 18:46:57 +03:30
parent 205d4c2502
commit 0a50125ee9
4 changed files with 68 additions and 15 deletions
@@ -12,7 +12,8 @@ use Illuminate\Http\Request;
use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException; use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Http;
use \App\Http\Controllers\Customer\FundController; use \App\Http\Controllers\Customer\FundController;
use App\Http\Controllers\Site\ReportController ; use App\Http\Controllers\Site\ReportController;
use App\Services\ConfigService;
class ProductController extends SuperController class ProductController extends SuperController
@@ -138,6 +139,7 @@ class ProductController extends SuperController
// } // }
// }catch (\Exception $e){} // }catch (\Exception $e){}
$config = app(ConfigService::class);
$products = Product::with([])->whereNotNull('reading_method')->get(); $products = Product::with([])->whereNotNull('reading_method')->get();
foreach ($products as $product) { foreach ($products as $product) {
$collection = collect($RPrices); $collection = collect($RPrices);
@@ -158,6 +160,9 @@ class ProductController extends SuperController
'price' => $RPrice['price'], 'price' => $RPrice['price'],
'price_profit' => $RPrice['profit'], 'price_profit' => $RPrice['profit'],
]); ]);
$config->trackDailyPriceExtreme(
(float) $RPrice['price'] + (float) ($RPrice['profit'] ?? 0)
);
if ($product->bubble == 1) { if ($product->bubble == 1) {
$ReportController = new ReportController(); $ReportController = new ReportController();
@@ -176,6 +181,7 @@ class ProductController extends SuperController
'price_profit' => 0, 'price_profit' => 0,
'updated_at' => \Carbon\Carbon::now()->format('Y-m-d H:i:s'), 'updated_at' => \Carbon\Carbon::now()->format('Y-m-d H:i:s'),
]); ]);
$config->trackDailyPriceExtreme((float) $cp);
} }
return response()->json(true); return response()->json(true);
+26 -12
View File
@@ -75,20 +75,36 @@ class ReportController extends Controller
public function upDownPrice() public function upDownPrice()
{ {
$upSetting = Setting::where('key', 'up_price')->first();
$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;
if ($updatedToday) {
$down = (float) $downSetting->value;
$up = (float) $upSetting->value;
if ($down > 0 && $up > 0) {
return ['sell' => $down, 'buy' => $up];
}
}
}
$difference = Setting::where('key', 'fee_single')->first()->value; $difference = Setting::where('key', 'fee_single')->first()->value;
$today = Carbon::now()->format("Y-m-d"); $today = Carbon::now()->format("Y-m-d");
$prises = Price::where('date_at', $today)->get("price"); $prises = Price::where('date_at', $today)->get("price");
$minP = 0; // Initialize to the highest possible value $minP = 0;
$maxP = 0; // Initialize to the lowest possible value $maxP = 0;
foreach ($prises as $p) { foreach ($prises as $p) {
// Initialize $minP to the first price if it's null
if ($minP == 0 || $p->price < $minP) { if ($minP == 0 || $p->price < $minP) {
$minP = $p->price; $minP = $p->price;
} }
// Initialize $maxP to the first price if it's null
if ($maxP == 0 || $p->price > $maxP) { if ($maxP == 0 || $p->price > $maxP) {
$maxP = $p->price; $maxP = $p->price;
} }
@@ -98,15 +114,9 @@ class ReportController extends Controller
$priceValue = $price->price; $priceValue = $price->price;
return ['sell' => $priceValue - $difference, 'buy' => $priceValue + $difference]; return ['sell' => $priceValue - $difference, 'buy' => $priceValue + $difference];
} else {
// Assuming $minP and $maxP are defined elsewhere in your code
return ['sell' => $minP - $difference, 'buy' => $maxP + $difference];
} }
// return $prises;
// $add_sell_price = config('add_sell_price.major'); return ['sell' => $minP - $difference, 'buy' => $maxP + $difference];
// $price = PriceCandle::whereDate('date_at',)->first();
// $price_price = Price::orderBy('id','desc')->first();
} }
public function lastPrice() public function lastPrice()
@@ -452,6 +462,10 @@ class ReportController extends Controller
$priceLast = ceil($priceValue + $difference); $priceLast = ceil($priceValue + $difference);
} }
if (!$closed && $priceValue > 0) {
$config->trackDailyPriceExtreme((float) $priceValue);
}
return [ return [
'sell' => $sell, 'sell' => $sell,
'buy' => $buy, 'buy' => $buy,
+1 -1
View File
@@ -12,7 +12,7 @@ class Price extends Model
"price", "price",
"date_at", "date_at",
"time_at", "time_at",
"user_id" "user_id",
]; ];
public function user() public function user()
{ {
+34 -1
View File
@@ -13,9 +13,42 @@ class ConfigService
public function UpdateConfig($name, $value) public function UpdateConfig($name, $value)
{ {
return \App\Models\Setting::updateOrCreate( return Setting::updateOrCreate(
['key' => $name], ['key' => $name],
['value' => $value] ['value' => $value]
); );
} }
public function trackDailyPriceExtreme(float $price): void
{
if ($price <= 0) {
return;
}
$upSetting = Setting::where('key', 'up_price')->first();
$downSetting = Setting::where('key', 'down_price')->first();
if (!$upSetting || !$downSetting) {
return;
}
$priceInt = (int) round($price);
$today = now()->toDateString();
if (!$upSetting->updated_at || $upSetting->updated_at->toDateString() !== $today) {
$this->UpdateConfig('up_price', $priceInt);
$this->UpdateConfig('down_price', $priceInt);
return;
}
$currentUp = (float) ($upSetting->value ?: 0);
$currentDown = (float) ($downSetting->value ?: 0);
if ($currentUp <= 0 || $priceInt > $currentUp) {
$this->UpdateConfig('up_price', $priceInt);
}
if ($currentDown <= 0 || $priceInt < $currentDown) {
$this->UpdateConfig('down_price', $priceInt);
}
}
} }