NASER optimize last api & dynamic price & fix orders with 0 price & test all changes

This commit is contained in:
2026-03-31 18:28:27 +03:30
parent 3b8b4d3004
commit 30f1658074
4 changed files with 115 additions and 85 deletions
@@ -127,45 +127,58 @@ class ProductController extends SuperController
{
// $RPrices = Http::get('https://pricing.liman.gold/pricingApi', [])->json();
// $RPrices = Http::get('https://pricing.liman.gold/pricingApi', [])->json();
// $RPrices =Http::timeout(40)->get('http://212.23.201.173:8381/price_list', [])->json();
$RPrices = Http::timeout(40)->get('http://37.32.11.142:4949/api/free', [])->json();
$RPrices =Http::timeout(40)->get('http://212.23.201.173:8381/price_list', [])->json();
try{
$cooper =Http::timeout(40)->get('https://www.livedata.ir/main/static/p.json', [])->json();
if(isset($cooper['s_301006']) && isset($cooper['s_200103'])){
$CP = (($cooper['s_301006']/1000000)*$cooper['s_200103'])*10;
// Cnt::where('key', 'cu_price')
}
}catch (\Exception $e){}
// try{
// $cooper =Http::timeout(40)->get('https://www.livedata.ir/main/static/p.json', [])->json();
// if(isset($cooper['s_301006']) && isset($cooper['s_200103'])){
// $CP = (($cooper['s_301006']/1000000)*$cooper['s_200103'])*10;
//// Cnt::where('key', 'cu_price')
// }
// }catch (\Exception $e){}
$products = Product::with([])->whereNotNull('reading_method')->get();
foreach ($products as $product) {
foreach ($RPrices as $RPrice) {
if ($product->reading_method == $RPrice['name']) {
$p = Product::where('id', $product->id)->update([
$collection = collect($RPrices);
$RPrice = $collection->firstWhere('key', $product->reading_method);
if (!empty($RPrice)) {
// foreach ($RPrices as $RPrice) {
// if ($product->reading_method == $RPrice['name']) {
if ($RPrice['name'] == 'TGJU فلز مس') {
$copper = $RPrice['price'] + $RPrice['profit'];
}
if ($RPrice['name'] == 'TGJU دلار') {
$dollar = $RPrice['price'] + $RPrice['profit'];
}
if ($RPrice['name'] == 'گلد دات ای از آبشده - رسمی - نقد فردا') {
$RPrice['price'] = $RPrice['price'] / 4.3318;
}
$p = Product::where('id', $product->id)->update([
'price' => $RPrice['price'],
'price_profit' => $RPrice['profit'],
]);
if($product->bubble== 1){
if ($product->bubble == 1) {
$ReportController = new ReportController();
$liquidGold= $ReportController->lastPrice();
$liquidGold = $ReportController->lastPrice();
$p = Product::find($product->id);
$p->amount = $RPrice['price'] / $liquidGold['price'];
$p->save();
}
}
if($product->reading_method == 'مس' && $CP){
$p = Product::where('id', $product->id)->update([
'price' => $CP,
]);
}
}
}
if (isset($copper) && isset($dollar)) {
$cp = ($copper / 1000000) * $dollar;
$p = Product::where('metal_id', 3)->update([
'price' => $cp,
'price_profit' => 0,
'updated_at' => \Carbon\Carbon::now()->format('Y-m-d H:i:s'),
]);
}
return response()->json(true);
}
public function auto_close_open()
@@ -60,6 +60,9 @@ class SingleOrderController extends Controller
} else if (auth('user')->id()) {//admin
$data['service_charge_percentage'] = 0;
}
if($data['price'] === 0){
throw new UnprocessableEntityHttpException(' سفارشات بسته میباشد.');
}
$data['sts'] = 2;
$data['type'] = 2;
$data['payment_sts'] = 4;
+60 -48
View File
@@ -124,53 +124,56 @@ class ReportController extends Controller
public function lastPrice()
{
// $difference = config('fee.single');
$difference = Setting::where('key', 'fee_single')->first()->value;
$settings = Setting::whereIn('key', ['fee_single', 'goldir_price', 'tabanGohar_price', 'main_product_price'])->get();
$settingsMap = $settings->pluck('value', 'key');
$taban_gohar_price = $settingsMap->get('tabanGohar_price');
$difference = $settingsMap->get('fee_single');
$gold_ir_price = $settingsMap->get('goldir_price');
$main_product_price = $settingsMap->get('main_product_price');
if($this->Config('goldir_price') == 'true'){
if($gold_ir_price == 'true'){
$goldir_price = 0;
try{
$goldir = Http::withOptions([
$goldir = Http::timeout(7)->withOptions([
'curl' => [
// اجبار به استفاده از IPv4 و جلوگیری از تاخیر IPv6
CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4,
// افزایش سرعت برقراری ارتباط TCP
CURLOPT_TCP_FASTOPEN => 1,
]
])
->withoutVerifying() // غیرفعال کردن بررسی SSL (برای تست سرعت)
->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'] == 40) {
$collection = collect($goldir);
$lp = $collection->firstWhere('id', 40);
$buy = $lp['sub_agent']['rate_buy_gram_price'];
$sell = $lp['sub_agent']['rate_sell_gram_price'];
// foreach ($goldir as $lp) {
// if ($lp['id'] == 40) {
$customPrice['price'] = (ceil($buy) + ceil($sell)) / 2;
Cnt::where('key', 'goldir_price')->update(['value' => (float)$customPrice['price']]);//was float
$customPrice['diff'] = (ceil($buy) - ceil($sell)) / 2;
Cnt::where('key', 'goldir_diff')->update(['value' => (float)$customPrice['diff']]);//was float
$buy = $lp['sub_agent']['rate_buy_gram_price'];
$sell = $lp['sub_agent']['rate_sell_gram_price'];
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)]);
$customPrice['price'] = (ceil($buy) + ceil($sell)) / 2;
Cnt::where('key', 'goldir_price')->update(['value' => (float)$customPrice['price']]);//was float
$customPrice['diff'] = (ceil($buy) - ceil($sell)) / 2;
Cnt::where('key', 'goldir_diff')->update(['value' => (float)$customPrice['diff']]);//was float
if ($lp['open_sell'] == 'true' && $lp['open_buy'] == 'true') {
$goldir_price = (int)$customPrice['price'];
}
}
$customPrice['lp'] = $lp;
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'];
}
// }
// }
if($goldir_price == 0){
Cnt::where('key', 'goldir_closed')->update(['value' => "true"]);
}else{
@@ -179,37 +182,46 @@ class ReportController extends Controller
} catch (\Exception $e) {$goldir_price = 0;}
}
// try {
if($main_product_price == 'true'){
$main_product_id = Cnt::where('key', 'main_product')->first()['value'];
$pr_product = Product::find($main_product_id);
$pr_price = $pr_product['price'] + $pr_product['price_profit'];
}
if($taban_gohar_price == 'true') {
try {
$taban_gohar = Http::withOptions([
'curl' => [
// اجبار به استفاده از IPv4 و جلوگیری از تاخیر IPv6
CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4,
// افزایش سرعت برقراری ارتباط TCP
CURLOPT_TCP_FASTOPEN => 1,
]
])->withoutVerifying()->timeout(2)->get('https://tabangohar.com/GheymatKhan/prices_in_table.html')->json();
$tgn = (int)$taban_gohar['c'] * 10;
} catch (\Exception $e) {
$tgn = 0;
}
}
// try {
// $tala_ir = (int)str_replace(',', '', Http::timeout(2)->get('https://www.tala.ir/ajax/price')->json()['gold']['gold_18k']['v']) * 10;
// } catch (\Exception $e) {$tala_ir = 0;}
$main_product_id = Cnt::where('key', 'main_product')->first()['value'];
// $refpricer = new ProductController();
// if ($refpricer->getPrice()) {
// $ref = true;
// } else {
// $ref = false;
// }
$pr_product = Product::find($main_product_id);
try {
$taban_gohar = Http::withOptions([
'curl' => [
// اجبار به استفاده از IPv4 و جلوگیری از تاخیر IPv6
CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4,
// افزایش سرعت برقراری ارتباط TCP
CURLOPT_TCP_FASTOPEN => 1,
]
])->withoutVerifying()->timeout(2)->get('https://tabangohar.com/GheymatKhan/prices_in_table.html')->json();
$tgn = (int)$taban_gohar['c']*10;
}catch (\Exception $e){$tgn = 0;}
if($this->Config('goldir_price') == 'true' && $goldir_price !== 0) {
if($gold_ir_price == 'true' && $goldir_price !== 0) {
$priceValue = (int)$goldir_price;
}elseif($this->Config('tabanGohar_price') == 'true' && $tgn !== 0){
$priceValue = $tgn !== 0 ? $tgn : $pr_product['price'] + $pr_product['price_profit'];//$tala_ir;//4000
}elseif($taban_gohar_price == 'true' && $tgn !== 0){
$priceValue = $tgn;
}elseif($main_product_price == 'true' && $pr_price !== 0){
$priceValue = $pr_price;
}else{
$priceValue = $pr_product['price'] + $pr_product['price_profit'];//$tala_ir;//4000
$priceValue = 0;
}
$lastPrice = Price::latest()->first();
if (!$lastPrice || $lastPrice->price != $priceValue and $priceValue > 30000000) {
@@ -244,11 +256,11 @@ class ReportController extends Controller
$difference = $goldir_profit;
}
return [
'sell' => ceil($price->price - $difference),
'buy' => ceil($price->price + $difference),
'price_last' => ceil($price->price + $difference),
'sell' => $priceValue !== 0 ? ceil($price->price - $difference) : 0,
'buy' => $priceValue !== 0 ? ceil($price->price + $difference) : 0,
'price_last' => $priceValue !== 0 ? ceil($price->price + $difference) : 0,
'price' => $priceValue,
'main_product' => $pr_product['price'] + $pr_product['price_profit'],
'main_product' => $pr_price ?? 0,
'taban_gohar' => $tgn ?? 0,
'goldir' => $goldir_price ?? 0
];