NASER fix price issues & close trade when tahesab is unavailable

This commit is contained in:
gholak tala
2026-03-16 10:04:14 +00:00
parent 69dec434d7
commit df4972eceb
3 changed files with 26 additions and 6 deletions
@@ -359,4 +359,18 @@ class TahesabController extends Controller
}
public function healthCheck()
{
$tahesab = Http::withoutVerifying()->withHeaders([
'Content-Type' => 'application/json',
'DBName'=> 'tahesabDB1',
'Authorization'=> 'Bearer K7F5P8H2Q1O4I8M8M4J3L4L3W8N2A2P6I2T4I8N4E2T2N2D7O7Y5K3W6P2N4G3X2T1T4C5V4I1X2T6S1'
])->post('https://217.114.40.30:8081/', ["CheckHealth" => [] ])->json();
if($tahesab['Api_Status'] === "OK" && $tahesab['DB_Status'] === "OK"){
return true;
}else{
return false;
}
}
}
@@ -30,7 +30,9 @@ class SingleOrderController extends Controller
public function store(Request $request)
{
$goldir = Cnt::where('key', 'goldir_closed')->first();
if(isset($goldir) && $goldir['value'] == "true"){
$tahesab = new TahesabController();
$healthCheck = $tahesab->healthCheck();
if(isset($goldir) && $goldir['value'] == "true" && $healthCheck){
throw new UnprocessableEntityHttpException('عدم ارائه سرویس.');
}
@@ -152,9 +152,9 @@ class ReportController extends Controller
$buy = $lp['sub_agent']['rate_buy_gram_price'];
$sell = $lp['sub_agent']['rate_sell_gram_price'];
$customPrice['price'] = ($buy + $sell) / 2;
$customPrice['price'] = (ceil($buy) + ceil($sell)) / 2;
Cnt::where('key', 'goldir_price')->update(['value' => (float)$customPrice['price']]);//was float
$customPrice['diff'] = ($buy - $sell) / 2;
$customPrice['diff'] = (ceil($buy) - ceil($sell)) / 2;
Cnt::where('key', 'goldir_diff')->update(['value' => (float)$customPrice['diff']]);//was float
Cnt::where('key', 'goldir_mazaneh')->update(['value' => ((float)$customPrice['price'] * 4.331802)]);
@@ -239,10 +239,14 @@ class ReportController extends Controller
}
$price = Price::orderBy('id', 'desc')->first();
if ($price) {
if($this->Config('goldir_price') == 'true' && $goldir_price !==0){
$goldir_profit = Cnt::where('key', 'goldir_diff')->first()['value'];
$difference = $goldir_profit;
}
return [
'sell' => $price->price - $difference,
'buy' => $price->price + $difference,
'price_last' => $price->price + $difference,
'sell' => ceil($price->price - $difference),
'buy' => ceil($price->price + $difference),
'price_last' => ceil($price->price + $difference),
'price' => $priceValue,
'main_product' => $pr_product['price'] + $pr_product['price_profit'],
'taban_gohar' => $tgn ?? 0,