montzar added
This commit is contained in:
@@ -23,7 +23,8 @@ use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use App\Models\Setting;
|
||||
use App\Models\Cnt;
|
||||
use App\Services\LimanService;
|
||||
use App\Services\MontzarService;
|
||||
use App\Services\ConfigService;
|
||||
|
||||
|
||||
class SingleOrderController extends Controller
|
||||
@@ -31,27 +32,24 @@ class SingleOrderController extends Controller
|
||||
public function store(Request $request)
|
||||
{
|
||||
$data = $request->all();
|
||||
$config = app(ConfigService::class);
|
||||
|
||||
$toBool = function ($value) {
|
||||
return filter_var($value, FILTER_VALIDATE_BOOLEAN);
|
||||
};
|
||||
|
||||
if ($this->Config('liman_price') == 'true') {
|
||||
$liman_closed = Cnt::where('key', 'liman_closed')->value('value') == "true";
|
||||
$liman_buy = Cnt::where('key', 'liman_open_buy')->value('value') == "false" && $data['direction'] == 1;
|
||||
$liman_sell = Cnt::where('key', 'liman_open_sell')->value('value') == "false" && $data['direction'] == 2;
|
||||
if ($toBool($config->Config('montzar_price'))) {
|
||||
$montzar_closed = $toBool($config->Config('montzar_closed'));
|
||||
$montzar_buy = !$toBool($config->Config('montzar_open_buy')) && (int) $data['direction'] === 1;
|
||||
$montzar_sell = !$toBool($config->Config('montzar_open_sell')) && (int) $data['direction'] === 2;
|
||||
|
||||
if ($liman_closed || $liman_buy || $liman_sell) {
|
||||
throw new UnprocessableEntityHttpException('عدم ارائه سرویس.');
|
||||
}
|
||||
} elseif ($this->Config('goldir_price') == 'true') {
|
||||
$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) {
|
||||
if ($montzar_closed || $montzar_buy || $montzar_sell) {
|
||||
throw new UnprocessableEntityHttpException('عدم ارائه سرویس.');
|
||||
}
|
||||
}
|
||||
if($this->Config('close_price') == 'true'){
|
||||
if(Cnt::where('key', 'app_closed')->first()['value'] == "true"){
|
||||
|
||||
if ($toBool($config->Config('close_price'))) {
|
||||
if (Cnt::where('key', 'app_closed')->value('value') == "true") {
|
||||
throw new UnprocessableEntityHttpException('عدم ارائه سرویس.');
|
||||
}
|
||||
}
|
||||
@@ -190,7 +188,7 @@ class SingleOrderController extends Controller
|
||||
'start_at' => now(),
|
||||
], 1, true, false);
|
||||
$response['1'] = 2;
|
||||
//send to Goldir
|
||||
//send to provider
|
||||
$this->sendProviderOrder($data, $wallet_interface, (int) $data['direction']);
|
||||
return $response;
|
||||
}
|
||||
@@ -472,9 +470,9 @@ class SingleOrderController extends Controller
|
||||
|
||||
private function sendProviderOrder(array &$data, $wallet_interface, int $direction)
|
||||
{
|
||||
if ($this->Config('liman_price') == "true") {
|
||||
if ($this->Config('montzar_price') == "true") {
|
||||
try {
|
||||
return app(LimanService::class)->sendOrder($data);
|
||||
return app(MontzarService::class)->sendOrder($data);
|
||||
} catch (UnprocessableEntityHttpException $e) {
|
||||
$this->rollbackProviderFailedOrder($data, $wallet_interface, $direction);
|
||||
throw $e;
|
||||
@@ -482,12 +480,12 @@ class SingleOrderController extends Controller
|
||||
$this->rollbackProviderFailedOrder($data, $wallet_interface, $direction);
|
||||
|
||||
throw new UnprocessableEntityHttpException(
|
||||
'خطا در ثبت سفارش نزد لیمان: ' . $e->getMessage()
|
||||
'خطا در ثبت سفارش ارائه دهنده: ' . $e->getMessage()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->sendGoldir($data);
|
||||
return null;
|
||||
}
|
||||
|
||||
private function rollbackProviderFailedOrder(array $data, $wallet_interface, int $direction): void
|
||||
@@ -520,56 +518,6 @@ class SingleOrderController extends Controller
|
||||
$order->delete();
|
||||
}
|
||||
|
||||
private function sendGoldir($data)
|
||||
{
|
||||
if ($this->Config('send_to_goldir') == "true") {
|
||||
|
||||
$goldir_base_url=$this->Config('goldir_base_url')??'https://gold.ir';
|
||||
|
||||
// $liman_diff = Cnt::where('key', 'goldir_diff')->value('value');
|
||||
// $liman_price = Cnt::where('key', 'goldir_price')->value('value');
|
||||
$mazaneh = ($data['direction'] == 1) ? Cnt::where('key', 'goldir_truly_buy_mazaneh')->value('value') : Cnt::where('key', 'goldir_truly_sell_mazaneh')->value('value');
|
||||
$cash = Cnt::where('key', 'goldir_price')->value('value') * $data['amount'];
|
||||
|
||||
$response = Http::withToken(Cnt::where('key', 'goldir')->first()['value'])->post($goldir_base_url."/server/customer/order", [
|
||||
"mazaneh" => ((int)$mazaneh),
|
||||
'amount' => $data['amount'],
|
||||
'description' => $this->Config('name_fa') . " - " . auth('customer')->user()->name,
|
||||
'direction' => $data['direction'],
|
||||
'product_id' => $this->Config('hamkar_product_id'),
|
||||
'cash' => $cash,
|
||||
'input_mode'=> 'gold'
|
||||
|
||||
])/*->json()*/
|
||||
;
|
||||
if (isset($response['message']) && $response['message'] == 'no authorised') {
|
||||
$cnt = new Cnt();
|
||||
$response = Http::withToken($cnt->goldir_login())//$this->ConfigService('liman_token'))
|
||||
->post($goldir_base_url."/server/customer/order", [
|
||||
"mazaneh" => ((int)$mazaneh),
|
||||
'amount' => $data['amount'],
|
||||
'description' => $this->Config('name_fa') . " - " . auth('customer')->user()->name,
|
||||
'direction' => $data['direction'],
|
||||
'product_id' => $this->Config('hamkar_product_id'),
|
||||
'cash' => $cash,
|
||||
'input_mode'=> 'gold'
|
||||
])/*->json()*/
|
||||
;
|
||||
}
|
||||
|
||||
Cnt::where('key', 'goldir_order_response')->update(['value' => $response /*json_encode($response, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)*/]);
|
||||
Cnt::where('key', 'last_order_log')->update(['value' => $response]);
|
||||
if (!isset($response[1]) && !isset($response[1]['id'])) {
|
||||
throw new UnprocessableEntityHttpException('سفارشات توسط ارائه دهنده بسته شده است.');
|
||||
}
|
||||
|
||||
$data['provider_id'] = $response[1]['id'];
|
||||
return $response;
|
||||
}
|
||||
// $data['total_price_goldir'] = ($data['direction'] == 1) ? ($liman_price+$liman_diff) : ($liman_price-$liman_diff) ;
|
||||
|
||||
}
|
||||
|
||||
public function storeBackUp(Request $request)
|
||||
{
|
||||
$data = $request->all();
|
||||
|
||||
Reference in New Issue
Block a user