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;
}
}
+49 -6
View File
@@ -126,6 +126,49 @@ class ReportController extends Controller
// $difference = config('fee.single');
$difference = Setting::where('key', 'fee_single')->first()->value;
if($this->Config('goldir_price') == 'true'){
$goldir_price = 0;
try{
$goldir = Http::withToken(Cnt::where('key', 'goldir')->first()['value'])
->get('https://gold.ir/server/customer/product/list')->json();
if((isset($goldir['message']) && $goldir['message'] == 'no authorised') || $goldir == null){
$cnt = new Cnt();
$goldir = Http::timeout(2)->withToken($cnt->goldir_login())
->get('https://gold.ir/server/customer/product/list')->json();
}
$customPrice= [];
foreach ($goldir as $lp) {
if ($lp['id'] == 47) {
$buy = $lp['sub_agent']['rate_buy_gram_price'];
$sell = $lp['sub_agent']['rate_sell_gram_price'];
$customPrice['price'] = ($buy + $sell) / 2;
Cnt::where('key', 'goldir_price')->update(['value' => (float)$customPrice['price']]);//was float
$customPrice['diff'] = ($buy - $sell) / 2;
Cnt::where('key', 'goldir_diff')->update(['value' => (float)$customPrice['diff']]);//was float
Cnt::where('key', 'goldir_mazaneh')->update(['value' => ((float)$customPrice['price'] * 4.331802)]);
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)]);
if ($lp['open_sell'] == 'true' && $lp['open_buy'] == 'true') {
$goldir_price = (int)$customPrice['price'];
}
}
$customPrice['lp'] = $lp;
}
if($goldir_price == 0){
Cnt::where('key', 'goldir_closed')->update(['value' => "true"]);
}else{
Cnt::where('key', 'goldir_closed')->update(['value' => "false"]);
}
} catch (\Exception $e) {$goldir_price = 0;}
}
// try {
// $tala_ir = (int)str_replace(',', '', Http::timeout(2)->get('https://www.tala.ir/ajax/price')->json()['gold']['gold_18k']['v']) * 10;
@@ -145,7 +188,11 @@ class ReportController extends Controller
$tgn = (int)$taban_gohar['c']*10;
}catch (\Exception $e){$tgn = 0;}
$priceValue = /*$tgn !== 0 ? $tgn : */$pr_product['price'] + $pr_product['price_profit'];//$tala_ir;//4000
if($this->Config('goldir_price') == 'true') {
$priceValue = (int)$goldir_price;
}else{
$priceValue = /*$tgn !== 0 ? $tgn : */$pr_product['price'] + $pr_product['price_profit'];//$tala_ir;//4000
}
$lastPrice = Price::latest()->first();
if (!$lastPrice || $lastPrice->price != $priceValue and $priceValue > 30000000) {
$price = new Price();
@@ -179,13 +226,9 @@ class ReportController extends Controller
'buy' => $price->price + $difference,
'price_last' => $price->price + $difference,
'price' => $priceValue,
// 'tala_ir' => $tala_ir,
// 'henzagold' => $henzagold_18,
// 'Ounce' => $henzagold_ons_gold,
// 'milli' => $milli,
'main_product' => $pr_product['price'] + $pr_product['price_profit'],
'taban_gohar' => $tgn,
// 'refpricer' => $ref
'goldir' => $goldir_price ?? 0
];
} else {
return [];
+19
View File
@@ -4,6 +4,7 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Http;
class Cnt extends Model
{
@@ -18,4 +19,22 @@ class Cnt extends Model
protected $casts = [
'value_json'=>'array'
];
public function goldir_login(){
$mobile = self::where('key', 'goldir_mobile')->value('value');
$password = self::where('key', 'goldir_password')->value('value');
$goldir = Http::post('https://gold.ir/server/auth/login', [
'mobile' => $mobile,
'password' => $password,
'provider' => 'customer',
'type_app' => 'client',
])->json();
Cnt::where('key', 'goldir')->update([
'value' => $goldir['access_token'],
'updated_at' => now()
]);
return $goldir['access_token'];
}
}