completed liman for using in sell and buy

This commit is contained in:
2026-05-24 22:29:43 +03:30
parent 81d4aa8926
commit 7f0f91701e
4 changed files with 591 additions and 99 deletions
@@ -23,6 +23,7 @@ use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
use Illuminate\Support\Facades\Http;
use App\Models\Setting;
use App\Models\Cnt;
use App\Services\LimanService;
class SingleOrderController extends Controller
@@ -31,11 +32,21 @@ class SingleOrderController extends Controller
{
$data = $request->all();
if($this->Config('goldir_price') == 'true'){
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 ($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 ($goldir_closed || $goldir_buy || $goldir_sell) {
throw new UnprocessableEntityHttpException('عدم ارائه سرویس.');
}
}
@@ -180,7 +191,7 @@ class SingleOrderController extends Controller
], 1, true, false);
$response['1'] = 2;
//send to Goldir
$this->sendGoldir($data);
$this->sendProviderOrder($data, $wallet_interface, (int) $data['direction']);
return $response;
}
@@ -291,7 +302,7 @@ class SingleOrderController extends Controller
], 2, false, true);
//send to Goldir
$this->sendGoldir($data);
$this->sendProviderOrder($data, $wallet_interface, (int) $data['direction']);
}
@@ -459,6 +470,56 @@ class SingleOrderController extends Controller
$this->send($customer->mobile, $customerMessage);
}
private function sendProviderOrder(array &$data, $wallet_interface, int $direction)
{
if ($this->Config('liman_price') == "true") {
try {
return app(LimanService::class)->sendOrder($data);
} catch (UnprocessableEntityHttpException $e) {
$this->rollbackProviderFailedOrder($data, $wallet_interface, $direction);
throw $e;
} catch (\Throwable $e) {
$this->rollbackProviderFailedOrder($data, $wallet_interface, $direction);
throw new UnprocessableEntityHttpException(
'خطا در ثبت سفارش نزد لیمان: ' . $e->getMessage()
);
}
}
return $this->sendGoldir($data);
}
private function rollbackProviderFailedOrder(array $data, $wallet_interface, int $direction): void
{
$order = $data['order'] ?? null;
if (!$order instanceof Order) {
return;
}
if ($direction === 1) {
new TransactionInterface($wallet_interface, [
'cash' => $data['payment_amount'],
'gold' => $data['amount'],
'expire_at' => now(),
'active' => true,
'order_id' => $order->id,
'start_at' => now(),
], 2, false, true);
} else {
new TransactionInterface($wallet_interface, [
'gold' => $data['amount'],
'cash' => $data['total_price'],
'expire_at' => now(),
'active' => true,
'order_id' => $order->id,
], 1, true, false);
}
$order->delete();
}
private function sendGoldir($data)
{
if ($this->Config('send_to_goldir') == "true") {