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 Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Http;
use App\Models\Setting; use App\Models\Setting;
use App\Models\Cnt;
class SingleOrderController extends Controller class SingleOrderController extends Controller
@@ -157,20 +158,7 @@ class SingleOrderController extends Controller
], 1, true, false); ], 1, true, false);
$response['1'] = 2; $response['1'] = 2;
//send to liman //send to liman
if ($this->Config('do_send_liman') == "true") { $this->sendGoldir($data);
$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();
}
return $response; return $response;
} }
@@ -279,6 +267,10 @@ class SingleOrderController extends Controller
'active' => true, 'active' => true,
'order_id' => $order->id 'order_id' => $order->id
], 2, false, true); ], 2, false, true);
//send to liman
$this->sendGoldir($data);
} }
private function processSellTransactionProduct(&$data, $wallet, $wallet_interface) private function processSellTransactionProduct(&$data, $wallet, $wallet_interface)
@@ -321,6 +313,7 @@ class SingleOrderController extends Controller
], 12, false, true); ], 12, false, true);
} }
private function processSellTransactionProductByGold(&$data, $wallet, $wallet_interface) private function processSellTransactionProductByGold(&$data, $wallet, $wallet_interface)
{ {
$data['price'] -= $data['difference']; $data['price'] -= $data['difference'];
@@ -359,6 +352,7 @@ class SingleOrderController extends Controller
'start_at' => now(), 'start_at' => now(),
], 1, false, false); ], 1, false, false);
} }
private function give_order_reward(&$data, $wallet, $wallet_interface) private function give_order_reward(&$data, $wallet, $wallet_interface)
{ {
$data['aCustomers'] = []; $data['aCustomers'] = [];
@@ -443,6 +437,52 @@ class SingleOrderController extends Controller
$this->send($customer->mobile, $customerMessage); $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) public function storeBackUp(Request $request)
{ {
$data = $request->all(); $data = $request->all();
+48 -5
View File
@@ -126,6 +126,49 @@ class ReportController extends Controller
// $difference = config('fee.single'); // $difference = config('fee.single');
$difference = Setting::where('key', 'fee_single')->first()->value; $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 { // try {
// $tala_ir = (int)str_replace(',', '', Http::timeout(2)->get('https://www.tala.ir/ajax/price')->json()['gold']['gold_18k']['v']) * 10; // $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; $tgn = (int)$taban_gohar['c']*10;
}catch (\Exception $e){$tgn = 0;} }catch (\Exception $e){$tgn = 0;}
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 $priceValue = /*$tgn !== 0 ? $tgn : */$pr_product['price'] + $pr_product['price_profit'];//$tala_ir;//4000
}
$lastPrice = Price::latest()->first(); $lastPrice = Price::latest()->first();
if (!$lastPrice || $lastPrice->price != $priceValue and $priceValue > 30000000) { if (!$lastPrice || $lastPrice->price != $priceValue and $priceValue > 30000000) {
$price = new Price(); $price = new Price();
@@ -179,13 +226,9 @@ class ReportController extends Controller
'buy' => $price->price + $difference, 'buy' => $price->price + $difference,
'price_last' => $price->price + $difference, 'price_last' => $price->price + $difference,
'price' => $priceValue, 'price' => $priceValue,
// 'tala_ir' => $tala_ir,
// 'henzagold' => $henzagold_18,
// 'Ounce' => $henzagold_ons_gold,
// 'milli' => $milli,
'main_product' => $pr_product['price'] + $pr_product['price_profit'], 'main_product' => $pr_product['price'] + $pr_product['price_profit'],
'taban_gohar' => $tgn, 'taban_gohar' => $tgn,
// 'refpricer' => $ref 'goldir' => $goldir_price ?? 0
]; ];
} else { } else {
return []; return [];
+19
View File
@@ -4,6 +4,7 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Http;
class Cnt extends Model class Cnt extends Model
{ {
@@ -18,4 +19,22 @@ class Cnt extends Model
protected $casts = [ protected $casts = [
'value_json'=>'array' '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'];
}
} }