fix kashkool
This commit is contained in:
@@ -494,15 +494,13 @@ class ReportController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* فروشگاه — منطق lastPrice قبل مرج (ghatreh): montzar_price / nasiryan / prices
|
||||
* فروشگاه — منطق lastPrice: montzar_price / prices
|
||||
*/
|
||||
protected function storeLastPrice(ConfigService $config): array
|
||||
{
|
||||
$toBool = fn ($value) => filter_var($value, FILTER_VALIDATE_BOOLEAN);
|
||||
|
||||
$difference = (float) config('fee.single');
|
||||
$talaIr = 0;
|
||||
$nasiryan = 0;
|
||||
$montzar = 0;
|
||||
|
||||
$montzarExists = Setting::where('key', 'montzar_price')->exists();
|
||||
@@ -560,58 +558,9 @@ class ReportController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
$nasiryanEnabled = $config->Config('price_from_nasiryan') == 'true';
|
||||
if ($nasiryanEnabled) {
|
||||
try {
|
||||
$nasiryanRes = Http::withoutVerifying()
|
||||
->timeout(2)
|
||||
->withToken(Cnt::where('key', 'nasiryan')->first()['value'] ?? '')
|
||||
->get('https://nasiryan.com/server/customer/product/list')
|
||||
->json();
|
||||
|
||||
if ((isset($nasiryanRes['message']) && $nasiryanRes['message'] == 'no authorised') || $nasiryanRes == null) {
|
||||
$cnt = new Cnt();
|
||||
$cnt->nasiryan_login();
|
||||
$nasiryanRes = Http::withoutVerifying()
|
||||
->timeout(2)
|
||||
->withToken(Cnt::where('key', 'nasiryan')->first()['value'] ?? '')
|
||||
->get('https://nasiryan.com/server/customer/product/list')
|
||||
->json();
|
||||
}
|
||||
|
||||
$lp = collect($nasiryanRes)->firstWhere('id', 1);
|
||||
if (! $lp || ! isset($lp['sub_agent'])) {
|
||||
throw new \Exception('Nasiryan product/sub_agent not found');
|
||||
}
|
||||
|
||||
$buy = (float) $lp['sub_agent']['rate_buy_gram_price'];
|
||||
$sell = (float) $lp['sub_agent']['rate_sell_gram_price'];
|
||||
$customPrice = [
|
||||
'price' => ($buy + $sell) / 2,
|
||||
'diff' => ($buy - $sell) / 2,
|
||||
];
|
||||
|
||||
Cnt::where('key', 'nasiryan_price')->update(['value' => (float) $customPrice['price']]);
|
||||
Cnt::where('key', 'nasiryan_diff')->update(['value' => (float) $customPrice['diff']]);
|
||||
Cnt::where('key', 'nasiryan_mazaneh')->update(['value' => ((float) $customPrice['price'] * 4.331802)]);
|
||||
Cnt::where('key', 'nasiryan_truly_buy_mazaneh')->update(['value' => $lp['sub_agent']['rate_buy_price']]);
|
||||
Cnt::where('key', 'nasiryan_truly_sell_mazaneh')->update(['value' => $lp['sub_agent']['rate_sell_price']]);
|
||||
Cnt::where('key', 'log')->update(['value' => json_encode($nasiryanRes, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)]);
|
||||
|
||||
$nasiryan = (int) $customPrice['price'];
|
||||
Cnt::where('key', 'nasiryan_closed')->update(['value' => $nasiryan == 0 ? 'true' : 'false']);
|
||||
} catch (\Throwable $e) {
|
||||
$nasiryan = 0;
|
||||
Cnt::where('key', 'nasiryan_closed')->update(['value' => 'true']);
|
||||
}
|
||||
}
|
||||
|
||||
if ($montzarEnabled && $montzar !== 0) {
|
||||
$priceValue = $montzar;
|
||||
$priceSource = 'montzar';
|
||||
} elseif ($nasiryanEnabled && $nasiryan !== 0) {
|
||||
$priceValue = $nasiryan;
|
||||
$priceSource = 'nasiryan';
|
||||
} else {
|
||||
$priceValue = $talaIr;
|
||||
$priceSource = 'tala_ir';
|
||||
@@ -637,7 +586,6 @@ class ReportController extends Controller
|
||||
'price_last' => $display['priceLast'],
|
||||
'price' => $priceValue,
|
||||
'tala_ir' => $talaIr,
|
||||
'nasiryan' => $nasiryan,
|
||||
];
|
||||
|
||||
if ($montzarExists) {
|
||||
|
||||
Reference in New Issue
Block a user