NASER send orders to gold.ir

This commit is contained in:
2026-03-10 15:39:30 +03:30
parent 068e673fec
commit 5fa7582d93
3 changed files with 145 additions and 43 deletions
@@ -22,6 +22,7 @@ use App\Models\TransactionsAdmin;
use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
use Illuminate\Support\Facades\Http;
use App\Models\Setting;
use App\Models\Cnt;
class SingleOrderController extends Controller
@@ -44,7 +45,7 @@ class SingleOrderController extends Controller
$fee_free = Setting::where('key', 'fee_free')->where('is_active', true)->value('value');
if($fee_free && $this->feeFree($data['customer_id'], $fee_free)){
if ($fee_free && $this->feeFree($data['customer_id'], $fee_free)) {
$data['service_charge_percentage'] = 0;
// $data['difference'] = 0;
$data['fee_free'] = true;
@@ -78,7 +79,7 @@ class SingleOrderController extends Controller
// Check if the method is cash
if ($data['method'] == "cash") {
$response['buy'] = $this->processBuyTransactionProduct($data, $wallet, $wallet_interface);
$response['buy'] = $this->processBuyTransactionProduct($data, $wallet, $wallet_interface);
} // Check if the method is gold
else if ($data['method'] == "gold") {
@@ -119,11 +120,11 @@ class SingleOrderController extends Controller
$response['sell'] = $this->processSellTransaction($data, $wallet, $wallet_interface);
}
}
if(Setting::where('key', 'send_to_tahesab')->first()->value == "true"){
if (Setting::where('key', 'send_to_tahesab')->first()->value == "true") {
try {
$tahesab = new TahesabController();
$data['tahesab'] = $tahesab->storeTrade($data);
}catch (\Exception $e){
} catch (\Exception $e) {
return response($e->getMessage(), 500);
}
}
@@ -157,32 +158,19 @@ class SingleOrderController extends Controller
], 1, true, false);
$response['1'] = 2;
//send to liman
if ($this->Config('do_send_liman') == "true") {
$payload = [
'amount' => "$order->amount",
'description' => $this->Config('name_fa') . " - " . auth('customer')->user()->name,
'ref_id' => $order->id,
'direction' => 1,
'product_id' => 2
];
return $response = Http::withToken($this->Config('liman_token'))
->post("https://limangold.ir/kernel/customer/order", $payload)->json();
$order->total_price_liman = $response["payment_amount"];
$order->save();
}
$this->sendGoldir($data);
return $response;
}
private function processBuyTransactionProduct(&$data, $wallet, $wallet_interface)
{
$data['price'] = $data['product']['price'] + $data['product']['price_profit'];
$data['price'] = $data['product']['price'] + $data['product']['price_profit'];
$data['price'] += $data['difference'];
$data['amount'] = $data['number'] * $data['product']['amount'];
$data['total_amount'] = $data['amount']+($data['product']['percent_fee_buy']*$data['amount']);
$data['total_amount'] = $data['amount'] + ($data['product']['percent_fee_buy'] * $data['amount']);
$data['total_price'] = $data['total_amount'] * $data['price'];
$data['payment_amount'] = $data['total_price'];
$data['service_charge'] = isset($data['fee_free']) && $data['fee_free'] === true ? 0 : ($data['product']['percent_fee_buy']*$data['amount']);
$data['service_charge'] = isset($data['fee_free']) && $data['fee_free'] === true ? 0 : ($data['product']['percent_fee_buy'] * $data['amount']);
$data['service_charge_price'] = $data['service_charge'] * $data['price_original'];
$data['wallet'] = $wallet;
if ($wallet->cash < $data['payment_amount']) {
@@ -200,7 +188,7 @@ class SingleOrderController extends Controller
'active' => true,
'order_id' => $order->id,
'title' => "برداشت وجه نقد"
], 12, false,false);
], 12, false, false);
$wallet_interface_product = new WalletInterface(auth('customer')->id(), auth('customer')->user()->type, null, $data["product_id"]);
$wallet_interface_product->wallet->gold = intval($wallet_interface_product->wallet->gold);
$wallet_interface_product->wallet->save();
@@ -222,10 +210,10 @@ class SingleOrderController extends Controller
$data['price'] += $data['difference'];
$data['amount'] = $data['number'] * $data['product']['amount'];
$data['total_amount'] = $data['amount']+($data['product']['percent_fee_buy']*$data['amount']);
$data['total_amount'] = $data['amount'] + ($data['product']['percent_fee_buy'] * $data['amount']);
$data['total_price'] = $data['total_amount'] * $data['price'];
$data['payment_amount'] = $data['total_price'];
$data['service_charge'] = isset($data['fee_free']) && $data['fee_free'] === true ? 0 : ($data['product']['percent_fee_buy']*$data['amount']);
$data['service_charge'] = isset($data['fee_free']) && $data['fee_free'] === true ? 0 : ($data['product']['percent_fee_buy'] * $data['amount']);
$data['total_fee'] = 0;
$data['service_charge_price'] = $data['service_charge'] * $data['price_original'];
$data['wallet'] = $wallet;
@@ -244,7 +232,7 @@ class SingleOrderController extends Controller
'active' => true,
'order_id' => $order->id,
'title' => "برداشت طلای ابشده"
], 12, false,true);
], 12, false, true);
$wallet_interface_product = new WalletInterface(auth('customer')->id(), auth('customer')->user()->type, null, $data["product_id"]);
$wallet_interface_product->wallet->gold = intval($wallet_interface_product->wallet->gold);
$wallet_interface_product->wallet->save();
@@ -265,7 +253,7 @@ class SingleOrderController extends Controller
$data['price'] -= $data['difference'];
$data['service_charge'] = isset($data['fee_free']) && $data['fee_free'] === true ? 0 : $data['service_charge_percentage'] * $data['amount'];
$data['service_charge_price'] = $data['service_charge'] * $data['price_original'];
$data['total_price'] = $data['amount'] * $data['price'] -$data['service_charge_price'];
$data['total_price'] = $data['amount'] * $data['price'] - $data['service_charge_price'];
$data['payment_amount'] = $data['total_price'];
$data['payment_amount'] -= $data['service_charge_price'];
if ($wallet->gold < $data['amount']) {
@@ -279,17 +267,21 @@ class SingleOrderController extends Controller
'active' => true,
'order_id' => $order->id
], 2, false, true);
//send to liman
$this->sendGoldir($data);
}
private function processSellTransactionProduct(&$data, $wallet, $wallet_interface)
{
$data['price'] = $data['product']['price'] + $data['product']['price_profit'];
$data['price'] = $data['product']['price'] + $data['product']['price_profit'];
$data['price'] -= $data['difference'];
$data['amount'] = $data['number'] * $data['product']['amount'];
$data['total_amount'] = $data['amount']-($data['product']['percent_fee_sell']*$data['amount']) ;
$data['total_amount'] = $data['amount'] - ($data['product']['percent_fee_sell'] * $data['amount']);
$data['total_price'] = $data['total_amount'] * $data['price'];
$data['payment_amount'] = $data['total_price'];
$data['service_charge'] = isset($data['fee_free']) && $data['fee_free'] === true ? 0 : ($data['product']['percent_fee_sell']*$data['amount']);
$data['service_charge'] = isset($data['fee_free']) && $data['fee_free'] === true ? 0 : ($data['product']['percent_fee_sell'] * $data['amount']);
$data['service_charge_price'] = $data['service_charge'] * $data['price_original'];
$wallet_interface_product = new WalletInterface(auth('customer')->id(), auth('customer')->user()->type, null, $data["product_id"]);
@@ -318,17 +310,18 @@ class SingleOrderController extends Controller
'active' => true,
'order_id' => $order->id,
'title' => "واریز وجه نقد"
], 12, false,true);
], 12, false, true);
}
private function processSellTransactionProductByGold(&$data, $wallet, $wallet_interface)
{
$data['price'] -= $data['difference'];
$data['amount'] = $data['number'] * $data['product']['amount'];
$data['total_amount'] = $data['amount']-($data['product']['percent_fee_sell']*$data['amount']) ;
$data['total_amount'] = $data['amount'] - ($data['product']['percent_fee_sell'] * $data['amount']);
$data['total_price'] = $data['total_amount'] * $data['price'];
$data['payment_amount'] = $data['total_price'];
$data['service_charge'] = isset($data['fee_free']) && $data['fee_free'] === true ? 0 : ($data['product']['percent_fee_sell']*$data['amount']);
$data['service_charge'] = isset($data['fee_free']) && $data['fee_free'] === true ? 0 : ($data['product']['percent_fee_sell'] * $data['amount']);
$data['total_fee'] = 0;
$data['service_charge_price'] = $data['service_charge'] * $data['price_original'];
$wallet_interface_product = new WalletInterface(auth('customer')->id(), auth('customer')->user()->type, null, $data["product_id"]);
@@ -347,7 +340,7 @@ class SingleOrderController extends Controller
'active' => true,
'order_id' => $order->id,
'title' => "واریز طلای ابشده"
], 12, true,false);
], 12, true, false);
$wallet_interface_product->wallet->gold = intval($wallet_interface_product->wallet->gold);
$wallet_interface_product->wallet->save();
new TransactionInterface($wallet_interface_product, [
@@ -359,6 +352,7 @@ class SingleOrderController extends Controller
'start_at' => now(),
], 1, false, false);
}
private function give_order_reward(&$data, $wallet, $wallet_interface)
{
$data['aCustomers'] = [];
@@ -443,6 +437,52 @@ class SingleOrderController extends Controller
$this->send($customer->mobile, $customerMessage);
}
private function sendGoldir($data)
{
if ($this->Config('send_to_goldir') == "true") {
$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("https://gold.ir/server/customer/order", [
"mazaneh" => ((int)$mazaneh),
'amount' => $data['amount'],
'description' => $this->Config('name_fa') . " - " . auth('customer')->user()->name,
'direction' => $data['direction'],
'product_id' => 47,
'cash' => $cash
])/*->json()*/
;
if (isset($response['message']) && $response['message'] == 'no authorised') {
$cnt = new Cnt();
$response = Http::withToken($cnt->goldir_login())//$this->Config('liman_token'))
->post("https://gold.ir/server/customer/order", [
"mazaneh" => ((int)$mazaneh),
'amount' => $data['amount'],
'description' => $this->Config('name_fa') . " - " . auth('customer')->user()->name,
'direction' => $data['direction'],
'product_id' => 47,
'cash' => $cash
])/*->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['total_price_goldir'] = ($data['direction'] == 1) ? ($liman_price+$liman_diff) : ($liman_price-$liman_diff) ;
$data['provider_id'] = $response[1]['id'];
return $response;
}
public function storeBackUp(Request $request)
{
$data = $request->all();
@@ -560,9 +600,9 @@ class SingleOrderController extends Controller
private function feeFree($customer_id, $count)
{
return Order::where('customer_id', $customer_id)
->where('type', 2)
->where('sts', 2)
->where('payment_sts', 4)
->count() < (int)$count;
->where('type', 2)
->where('sts', 2)
->where('payment_sts', 4)
->count() < (int)$count;
}
}