NASER fix issues in getting price and close orders
This commit is contained in:
@@ -21,6 +21,7 @@ use Illuminate\Support\Facades\Mail;
|
||||
use Morilog\Jalali\Jalalian;
|
||||
use App\Http\Controllers\Admin\ProductController;
|
||||
|
||||
|
||||
class ReportController extends Controller
|
||||
{
|
||||
public function candleChart()
|
||||
@@ -74,7 +75,6 @@ class ReportController extends Controller
|
||||
|
||||
public function upDownPrice()
|
||||
{
|
||||
// $difference = config('fee.single');
|
||||
$difference = Setting::where('key', 'fee_single')->first()->value;
|
||||
$today = Carbon::now()->format("Y-m-d");
|
||||
$prises = Price::where('date_at', $today)->get("price");
|
||||
@@ -94,22 +94,10 @@ class ReportController extends Controller
|
||||
}
|
||||
}
|
||||
if (count($prises) === 0) {
|
||||
// Fetching the current gold price from the API
|
||||
$response = Http::get('https://www.tala.ir/ajax/price');
|
||||
$data = $response->json();
|
||||
$price = Price::orderBy('id', 'desc')->first();
|
||||
$priceValue = $price->price;
|
||||
|
||||
// Clean the price value retrieved from API
|
||||
$data['gold']['gold_18k']['v'] = str_replace(',', '', $data['gold']['gold_18k']['v']);
|
||||
$priceValue = $data['gold']['gold_18k']['v'] * 10; // Assuming the multiplication by 10 is needed
|
||||
|
||||
// Create and save the new Price instance
|
||||
$price = new Price();
|
||||
$price->price = $priceValue; // Assign the cleaned and calculated price value
|
||||
$price->time_at = Carbon::now()->toTimeString(); // Set current time
|
||||
$price->date_at = Carbon::now()->toDateString(); // Set current date
|
||||
$price->save(); // Save to the database
|
||||
|
||||
return ['sell' => $price->price - $difference, 'buy' => $price->price + $difference];
|
||||
return ['sell' => $priceValue - $difference, 'buy' => $priceValue + $difference];
|
||||
} else {
|
||||
|
||||
// Assuming $minP and $maxP are defined elsewhere in your code
|
||||
@@ -124,21 +112,36 @@ class ReportController extends Controller
|
||||
public function lastPrice()
|
||||
{
|
||||
$closed = false;
|
||||
if($this->Config('close_price') == 'true'){
|
||||
$current = Carbon::now()->format("H:i:s");
|
||||
$start = "20:00:00";
|
||||
$end = "11:00:00";
|
||||
|
||||
if($current >= $start || $current <= $end){
|
||||
$closed = true;
|
||||
// if(auth('customer')->id() == 525){dd($close_setting->is_active == '1');}
|
||||
|
||||
if($this->Config('close_price') == 'true'){
|
||||
$current = Carbon::now();
|
||||
$start = Carbon::today()->setTime(11, 0);
|
||||
$end = Carbon::today()->setTime(20, 0);
|
||||
// if(auth('customer')->id() == 525){dd("2026-05-08 23:00:00" >= $start && "2026-05-08 23:00:00" <= $end);}
|
||||
|
||||
if(!$current->between($start, $end)){
|
||||
|
||||
// $closed = true;
|
||||
Cnt::where('key', 'app_closed')->update(['value' => "true"]);
|
||||
Cnt::where('key', 'goldir_closed')->update(['value' => "true"]);
|
||||
$liman_price = 0;
|
||||
return [
|
||||
'sell' => 0,
|
||||
'buy' => 0,
|
||||
'price_last' => 0,
|
||||
'price' => 0,
|
||||
'main_product' => 0,
|
||||
'taban_gohar' => 0,
|
||||
'goldir' => 0,
|
||||
'closed'=> true,
|
||||
'time'=>now()->format('H:i:s'),
|
||||
];
|
||||
}else{
|
||||
Cnt::where('key', 'app_closed')->update(['value' => "false"]);
|
||||
Cnt::where('key', 'goldir_closed')->update(['value' => "false"]);
|
||||
}
|
||||
|
||||
}
|
||||
// $difference = config('fee.single');
|
||||
$settings = Setting::whereIn('key', ['fee_single', 'goldir_price', 'tabanGohar_price', 'main_product_price'])->get();
|
||||
@@ -248,7 +251,7 @@ class ReportController extends Controller
|
||||
$priceValue = 0;
|
||||
}
|
||||
$lastPrice = Price::latest()->first();
|
||||
if (($lastPrice || $lastPrice->price !== $priceValue) && $priceValue > 30000000) {
|
||||
if (!$closed && (($lastPrice || $lastPrice->price !== $priceValue) && $priceValue > 30000000)) {
|
||||
$price = new Price();
|
||||
$price->price = $priceValue; // Assign the cleaned price value
|
||||
$price->time_at = Carbon::now()->toTimeString();
|
||||
@@ -288,6 +291,7 @@ class ReportController extends Controller
|
||||
'taban_gohar' => $tgn ?? 0,
|
||||
'goldir' => $goldir_price ?? 0,
|
||||
'closed'=>$closed ?? null,
|
||||
'time'=>now(),
|
||||
];
|
||||
} else {
|
||||
return [];
|
||||
|
||||
Reference in New Issue
Block a user