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,21 +127,33 @@ class ProductController extends SuperController
{ {
// $RPrices = Http::get('https://pricing.liman.gold/pricingApi', [])->json(); // $RPrices = Http::get('https://pricing.liman.gold/pricingApi', [])->json();
// $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();
try{ // if(isset($cooper['s_301006']) && isset($cooper['s_200103'])){
$cooper =Http::timeout(40)->get('https://www.livedata.ir/main/static/p.json', [])->json(); // $CP = (($cooper['s_301006']/1000000)*$cooper['s_200103'])*10;
if(isset($cooper['s_301006']) && isset($cooper['s_200103'])){ //// Cnt::where('key', 'cu_price')
$CP = (($cooper['s_301006']/1000000)*$cooper['s_200103'])*10; // }
// Cnt::where('key', 'cu_price') // }catch (\Exception $e){}
}
}catch (\Exception $e){}
$products = Product::with([])->whereNotNull('reading_method')->get(); $products = Product::with([])->whereNotNull('reading_method')->get();
foreach ($products as $product) { foreach ($products as $product) {
foreach ($RPrices as $RPrice) { $collection = collect($RPrices);
if ($product->reading_method == $RPrice['name']) { $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([ $p = Product::where('id', $product->id)->update([
'price' => $RPrice['price'], 'price' => $RPrice['price'],
'price_profit' => $RPrice['profit'], 'price_profit' => $RPrice['profit'],
@@ -156,16 +168,17 @@ class ProductController extends SuperController
} }
} }
if($product->reading_method == 'مس' && $CP){ }
$p = Product::where('id', $product->id)->update([ if (isset($copper) && isset($dollar)) {
'price' => $CP, $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); return response()->json(true);
} }
public function auto_close_open() public function auto_close_open()
@@ -60,6 +60,9 @@ class SingleOrderController extends Controller
} else if (auth('user')->id()) {//admin } else if (auth('user')->id()) {//admin
$data['service_charge_percentage'] = 0; $data['service_charge_percentage'] = 0;
} }
if($data['price'] === 0){
throw new UnprocessableEntityHttpException(' سفارشات بسته میباشد.');
}
$data['sts'] = 2; $data['sts'] = 2;
$data['type'] = 2; $data['type'] = 2;
$data['payment_sts'] = 4; $data['payment_sts'] = 4;
+44 -32
View File
@@ -124,30 +124,37 @@ class ReportController extends Controller
public function lastPrice() public function lastPrice()
{ {
// $difference = config('fee.single'); // $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; $goldir_price = 0;
try{ try{
$goldir = Http::withOptions([ $goldir = Http::timeout(7)->withOptions([
'curl' => [ 'curl' => [
// اجبار به استفاده از IPv4 و جلوگیری از تاخیر IPv6
CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4, CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4,
// افزایش سرعت برقراری ارتباط TCP
CURLOPT_TCP_FASTOPEN => 1, CURLOPT_TCP_FASTOPEN => 1,
] ]
]) ])
->withoutVerifying() // غیرفعال کردن بررسی SSL (برای تست سرعت) ->withoutVerifying() // غیرفعال کردن بررسی SSL (برای تست سرعت)
->withToken(Cnt::where('key', 'goldir')->first()['value']) ->withToken(Cnt::where('key', 'goldir')->first()['value'])
->get('https://gold.ir/server/customer/product/list')->json(); ->get('https://gold.ir/server/customer/product/list')->json();
if((isset($goldir['message']) && $goldir['message'] == 'no authorised') || $goldir == null){ if((isset($goldir['message']) && $goldir['message'] == 'no authorised') || $goldir == null){
$cnt = new Cnt(); $cnt = new Cnt();
$goldir = Http::timeout(2)->withToken($cnt->goldir_login()) $goldir = Http::timeout(2)->withToken($cnt->goldir_login())
->get('https://gold.ir/server/customer/product/list')->json(); ->get('https://gold.ir/server/customer/product/list')->json();
} }
$customPrice= []; $customPrice= [];
foreach ($goldir as $lp) { $collection = collect($goldir);
if ($lp['id'] == 40) { $lp = $collection->firstWhere('id', 40);
// foreach ($goldir as $lp) {
// if ($lp['id'] == 40) {
$buy = $lp['sub_agent']['rate_buy_gram_price']; $buy = $lp['sub_agent']['rate_buy_gram_price'];
$sell = $lp['sub_agent']['rate_sell_gram_price']; $sell = $lp['sub_agent']['rate_sell_gram_price'];
@@ -165,12 +172,8 @@ class ReportController extends Controller
if ($lp['open_sell'] == 'true' && $lp['open_buy'] == 'true') { if ($lp['open_sell'] == 'true' && $lp['open_buy'] == 'true') {
$goldir_price = (int)$customPrice['price']; $goldir_price = (int)$customPrice['price'];
} }
} // }
// }
$customPrice['lp'] = $lp;
}
if($goldir_price == 0){ if($goldir_price == 0){
Cnt::where('key', 'goldir_closed')->update(['value' => "true"]); Cnt::where('key', 'goldir_closed')->update(['value' => "true"]);
}else{ }else{
@@ -179,19 +182,13 @@ class ReportController extends Controller
} catch (\Exception $e) {$goldir_price = 0;} } catch (\Exception $e) {$goldir_price = 0;}
} }
// try { if($main_product_price == 'true'){
// $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']; $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); $pr_product = Product::find($main_product_id);
$pr_price = $pr_product['price'] + $pr_product['price_profit'];
}
if($taban_gohar_price == 'true') {
try { try {
$taban_gohar = Http::withOptions([ $taban_gohar = Http::withOptions([
'curl' => [ 'curl' => [
@@ -202,14 +199,29 @@ class ReportController extends Controller
] ]
])->withoutVerifying()->timeout(2)->get('https://tabangohar.com/GheymatKhan/prices_in_table.html')->json(); ])->withoutVerifying()->timeout(2)->get('https://tabangohar.com/GheymatKhan/prices_in_table.html')->json();
$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' && $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;
// } catch (\Exception $e) {$tala_ir = 0;}
// $refpricer = new ProductController();
// if ($refpricer->getPrice()) {
// $ref = true;
// } else {
// $ref = false;
// }
if($gold_ir_price == 'true' && $goldir_price !== 0) {
$priceValue = (int)$goldir_price; $priceValue = (int)$goldir_price;
}elseif($this->Config('tabanGohar_price') == 'true' && $tgn !== 0){ }elseif($taban_gohar_price == 'true' && $tgn !== 0){
$priceValue = $tgn !== 0 ? $tgn : $pr_product['price'] + $pr_product['price_profit'];//$tala_ir;//4000 $priceValue = $tgn;
}elseif($main_product_price == 'true' && $pr_price !== 0){
$priceValue = $pr_price;
}else{ }else{
$priceValue = $pr_product['price'] + $pr_product['price_profit'];//$tala_ir;//4000 $priceValue = 0;
} }
$lastPrice = Price::latest()->first(); $lastPrice = Price::latest()->first();
if (!$lastPrice || $lastPrice->price != $priceValue and $priceValue > 30000000) { if (!$lastPrice || $lastPrice->price != $priceValue and $priceValue > 30000000) {
@@ -244,11 +256,11 @@ class ReportController extends Controller
$difference = $goldir_profit; $difference = $goldir_profit;
} }
return [ return [
'sell' => ceil($price->price - $difference), 'sell' => $priceValue !== 0 ? ceil($price->price - $difference) : 0,
'buy' => ceil($price->price + $difference), 'buy' => $priceValue !== 0 ? ceil($price->price + $difference) : 0,
'price_last' => ceil($price->price + $difference), 'price_last' => $priceValue !== 0 ? ceil($price->price + $difference) : 0,
'price' => $priceValue, 'price' => $priceValue,
'main_product' => $pr_product['price'] + $pr_product['price_profit'], 'main_product' => $pr_price ?? 0,
'taban_gohar' => $tgn ?? 0, 'taban_gohar' => $tgn ?? 0,
'goldir' => $goldir_price ?? 0 'goldir' => $goldir_price ?? 0
]; ];
+6 -4
View File
@@ -16,11 +16,14 @@ use Illuminate\Http\Request;
Route::get('/refPricer', function () { Route::get('/refPricer', function () {
// $RPrices = Http::get('https://pricing.liman.gold/pricingApi', [])->json(); // $RPrices = Http::get('https://pricing.liman.gold/pricingApi', [])->json();
$RPrices = Http::get('http://212.23.201.173:8381/price_list', [])->json(); $RPrices = Http::get('http://37.32.11.142:4949/api/free', [])->json();
$products = Product::with([])->whereNotNull('reading_method')->get(); $products = Product::with([])->whereNotNull('reading_method')->get();
foreach ($products as $product) { foreach ($products as $product) {
foreach ($RPrices as $RPrice) { $collection = collect($RPrices);
$RPrice = $collection->firstWhere('key', $product->reading_method);
if (!empty($RPrice)) {
// foreach ($RPrices as $RPrice) {
if ($RPrice['name'] == 'TGJU فلز مس') { if ($RPrice['name'] == 'TGJU فلز مس') {
$copper = $RPrice['price'] + $RPrice['profit']; $copper = $RPrice['price'] + $RPrice['profit'];
} }
@@ -30,12 +33,11 @@ Route::get('/refPricer', function () {
if ($RPrice['name'] == 'گلد دات ای از آبشده - رسمی - نقد فردا') { if ($RPrice['name'] == 'گلد دات ای از آبشده - رسمی - نقد فردا') {
$RPrice['price'] = $RPrice['price'] / 4.3318; $RPrice['price'] = $RPrice['price'] / 4.3318;
} }
if ($product->reading_method == $RPrice['name']) {
$p = Product::where('id', $product->id)->update([ $p = Product::where('id', $product->id)->update([
'price' => $RPrice['price'], 'price' => $RPrice['price'],
'price_profit' => $RPrice['profit'], 'price_profit' => $RPrice['profit'],
]); ]);
} // }
} }
} }
if (isset($copper) && isset($dollar)) { if (isset($copper) && isset($dollar)) {