diff --git a/app/Http/Controllers/Single/SingleOrderController.php b/app/Http/Controllers/Single/SingleOrderController.php index 1d7b3ff..5959531 100644 --- a/app/Http/Controllers/Single/SingleOrderController.php +++ b/app/Http/Controllers/Single/SingleOrderController.php @@ -29,13 +29,16 @@ class SingleOrderController extends Controller { public function store(Request $request) { - $goldir = Cnt::where('key', 'goldir_closed')->first(); - if(isset($goldir) && $goldir['value'] == "true"){ + $data = $request->all(); + + $goldir_closed = Cnt::where('key', 'goldir_closed')->first()['value'] == "true"; + $goldir_buy = Cnt::where('key', 'goldir_open_buy')->first()['value'] == "false" && $data['direction'] == 1; + $goldir_sell = Cnt::where('key', 'goldir_open_sell')->first()['value'] == "false" && $data['direction'] == 2; + if($goldir_closed || $goldir_buy || $goldir_sell){ throw new UnprocessableEntityHttpException('عدم ارائه سرویس.'); } // throw new UnprocessableEntityHttpException('به دلیل نوسانات سفارشات بسته میباشد.'); - $data = $request->all(); $transactionType = $data['direction'] == 1 ? "خرید" : "فروش"; if (auth('customer')->id()) { $data['customer_id'] = auth('customer')->id(); diff --git a/app/Http/Controllers/Site/ReportController.php b/app/Http/Controllers/Site/ReportController.php index 5488a32..0b41145 100644 --- a/app/Http/Controllers/Site/ReportController.php +++ b/app/Http/Controllers/Site/ReportController.php @@ -131,6 +131,8 @@ class ReportController extends Controller $gold_ir_price = $settingsMap->get('goldir_price'); $main_product_price = $settingsMap->get('main_product_price'); + $open_buy = true; + $open_sell = true; if($gold_ir_price == 'true'){ $goldir_price = 0; try{ @@ -168,8 +170,13 @@ class ReportController extends Controller Cnt::where('key', 'goldir_truly_buy_mazaneh')->update(['value' => $lp['sub_agent']['rate_buy_price']]); Cnt::where('key', 'goldir_truly_sell_mazaneh')->update(['value' => $lp['sub_agent']['rate_sell_price']]); Cnt::where('key', 'log')->update(['value' => json_encode($goldir, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)]); + Cnt::where('key', 'goldir_open_sell')->update(['value' => $lp['open_sell']? "true":"false"]); + Cnt::where('key', 'goldir_open_buy')->update(['value' => $lp['open_buy']? "true":"false"]); - if ($lp['open_sell'] == 'true' && $lp['open_buy'] == 'true') { + $open_buy = $lp['open_buy']; + $open_sell = $lp['open_sell']; + + if ($lp['open_sell'] == 'true' || $lp['open_buy'] == 'true') { $goldir_price = (int)$customPrice['price']; } // } @@ -224,7 +231,7 @@ class ReportController extends Controller $priceValue = 0; } $lastPrice = Price::latest()->first(); - if (!$lastPrice || $lastPrice->price != $priceValue and $priceValue > 30000000) { + if (($lastPrice || $lastPrice->price !== $priceValue) && $priceValue > 30000000) { $price = new Price(); $price->price = $priceValue; // Assign the cleaned price value $price->time_at = Carbon::now()->toTimeString(); @@ -256,8 +263,8 @@ class ReportController extends Controller $difference = $goldir_profit; } return [ - 'sell' => $priceValue !== 0 ? ceil($price->price - $difference) : 0, - 'buy' => $priceValue !== 0 ? ceil($price->price + $difference) : 0, + 'sell' => $priceValue !== 0 ? $open_sell ? ceil($price->price - $difference) : 0 : 0, + 'buy' => $priceValue !== 0 ? $open_buy ? ceil($price->price + $difference) : 0 : 0, 'price_last' => $priceValue !== 0 ? ceil($price->price + $difference) : 0, 'price' => $priceValue, 'main_product' => $pr_price ?? 0,