fix kashkool

This commit is contained in:
2026-06-30 21:44:39 +03:30
parent 4a697af4c7
commit cd81ea8af0
9 changed files with 130 additions and 86 deletions
@@ -360,11 +360,12 @@ class ProductController extends SuperController
public function activationSnapshotStatus()
{
$row = Cnt::where('key', self::ACTIVATION_SNAPSHOT_KEY)->first();
$items = $row?->value_json['items'] ?? [];
$payload = $row?->jsonPayload() ?? [];
$items = $payload['items'] ?? [];
return response()->json([
'has_snapshot' => ! empty($items),
'saved_at' => $row?->value_json['saved_at'] ?? null,
'saved_at' => $payload['saved_at'] ?? null,
'count' => count($items),
]);
}
@@ -387,15 +388,13 @@ class ProductController extends SuperController
'open_sell' => (bool) $product->open_sell,
])->values()->all();
Cnt::updateOrCreate(
['key' => self::ACTIVATION_SNAPSHOT_KEY],
Cnt::saveJsonPayload(
self::ACTIVATION_SNAPSHOT_KEY,
[
'title_fa' => 'ذخیره وضعیت محصولات',
'value_json' => [
'saved_at' => now()->timezone('Asia/Tehran')->format('Y-m-d H:i:s'),
'items' => $items,
],
]
'saved_at' => now()->timezone('Asia/Tehran')->format('Y-m-d H:i:s'),
'items' => $items,
],
'ذخیره وضعیت محصولات'
);
$affected = Product::query()->update([
@@ -418,7 +417,7 @@ class ProductController extends SuperController
public function restoreActivationSnapshot()
{
$row = Cnt::where('key', self::ACTIVATION_SNAPSHOT_KEY)->first();
$items = $row?->value_json['items'] ?? [];
$items = $row?->jsonPayload()['items'] ?? [];
if (empty($items)) {
return response()->json(['error' => 'اسنAPSHOTی برای بازگردانی وجود ندارد.'], 422);
+1 -1
View File
@@ -164,7 +164,7 @@ class AuthController extends Controller
return response()->json(['message' => 'کد نامعتبر می باشد'], 422);
}
} else {
if ($this->Config('referral_id') == 'required') {
if ($cfg->isReferralRequired()) {
return response()->json(['message' => 'کد معرف اجباریست'], 422);
}
}
+1 -53
View File
@@ -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) {