From 69538226d2239de5af4f34ec4c0a581fa6f01737 Mon Sep 17 00:00:00 2001 From: adonis Date: Thu, 16 Jul 2026 14:33:57 +0330 Subject: [PATCH] fix bugs --- .../Controllers/Admin/ProductController.php | 34 ++----------------- app/Http/Controllers/Auth/AuthController.php | 8 ++--- .../Customer/CustomerController.php | 2 -- .../Middleware/EnsureCustomerIsActive.php | 4 +-- app/Services/ProductDisplayPriceService.php | 9 ++--- app/Services/ProductPriceSyncService.php | 8 ++++- app/Support/PersianDigits.php | 24 ------------- resources/lang/en/error.php | 6 ++++ resources/lang/fa/error.php | 6 ++++ 9 files changed, 28 insertions(+), 73 deletions(-) delete mode 100644 app/Support/PersianDigits.php create mode 100644 resources/lang/en/error.php create mode 100644 resources/lang/fa/error.php diff --git a/app/Http/Controllers/Admin/ProductController.php b/app/Http/Controllers/Admin/ProductController.php index 2a73cbd..051a526 100644 --- a/app/Http/Controllers/Admin/ProductController.php +++ b/app/Http/Controllers/Admin/ProductController.php @@ -512,29 +512,6 @@ class ProductController extends SuperController } - /** فروشگاه — نمایش در اپ کاربر: فعال + ساعات + قیمت ذخیره‌شده یا محصول وزنی */ - private function storeProductShowForCustomer(Product $product): bool - { - if (! $product->active) { - return false; - } - - if (! app(ConfigService::class)->isProductWithinTradingHours($product)) { - return false; - } - - $storedPrice = (int) ($product->price ?? 0) + (int) ($product->price_profit ?? 0); - if ($storedPrice > 0) { - return true; - } - - if ((int) ($product->direct_price ?? 0) === 0 && (float) ($product->amount ?? 0) > 0) { - return true; - } - - return false; - } - private function isCustomerApiRequest(): bool { $path = trim((string) request()->path(), '/'); @@ -569,14 +546,7 @@ class ProductController extends SuperController return; } - if (app(ConfigService::class)->isStore()) { - $products->each(function (Product $product) { - $product->setAttribute('show', $this->storeProductShowForCustomer($product)); - }); - - return; - } - + // فروشگاه و خانگی: همان enrich قیمت لحظه‌ای (آبشده/قیمت اپ/مرجع) — بدون UPDATE دیتابیس $displayPriceService = app(ProductDisplayPriceService::class); $displayPriceService->warmLivePriceCache(); $displayPriceService->enrichForApi($products); @@ -592,7 +562,7 @@ class ProductController extends SuperController */ private function enrichAdminTablePrices($rows): void { - if ($rows === null || app(ConfigService::class)->isStore()) { + if ($rows === null) { return; } diff --git a/app/Http/Controllers/Auth/AuthController.php b/app/Http/Controllers/Auth/AuthController.php index c4a93eb..dada1b8 100644 --- a/app/Http/Controllers/Auth/AuthController.php +++ b/app/Http/Controllers/Auth/AuthController.php @@ -53,7 +53,7 @@ class AuthController extends Controller throw new UnprocessableEntityHttpException('شماره موبایل یا پسوورد وارد شده اشتباه است'); } if (!$user->active) { - throw new UnprocessableEntityHttpException(trans('error.no_active')); + throw new UnprocessableEntityHttpException('شما مجوز دسترسی به اکانت خود را ندارید'); } if ($user->is_archive) { throw new UnprocessableEntityHttpException('شما اجازه ورود به سیستم را ندارید'); @@ -70,7 +70,7 @@ class AuthController extends Controller } $user = auth($provider)->user(); if (!$user->active) { - throw new UnprocessableEntityHttpException(trans('error.no_active')); + throw new UnprocessableEntityHttpException('شما مجوز دسترسی به اکانت خود را ندارید'); } if ($provider == 'customer' && $user->is_archive) { throw new UnprocessableEntityHttpException('شما اجازه ورود به سیستم را ندارید'); @@ -94,7 +94,7 @@ class AuthController extends Controller throw new UnprocessableEntityHttpException(trans('لطفا ابتدا ثبت نام بفرمایید')); } if (!$user->active) { - throw new UnprocessableEntityHttpException(trans('اکانت شما باید توسط ادمین فعال شود')); + throw new UnprocessableEntityHttpException('شما مجوز دسترسی به اکانت خود را ندارید'); } if ($provider == 'customer' && $user->is_archive) { throw new UnprocessableEntityHttpException('شما اجازه ورود به سیستم را ندارید'); @@ -124,7 +124,7 @@ class AuthController extends Controller $user->save(); return $this->respondWithToken($token); } - throw new UnprocessableEntityHttpException(trans('error.wrong_code')); + throw new UnprocessableEntityHttpException('کد وارد شده اشتباه است'); } protected function respondWithToken($token) diff --git a/app/Http/Controllers/Customer/CustomerController.php b/app/Http/Controllers/Customer/CustomerController.php index 1e5d9b8..60c47d6 100644 --- a/app/Http/Controllers/Customer/CustomerController.php +++ b/app/Http/Controllers/Customer/CustomerController.php @@ -20,7 +20,6 @@ use App\Http\Controllers\Admin\TahesabController; use App\Services\ConfigService; use App\Services\ReferralGiftService; use App\Services\WalletBalanceService; -use App\Support\PersianDigits; use Carbon\Carbon; use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Schema; @@ -189,7 +188,6 @@ class CustomerController extends Controller $customer = Customer::findOrFail(auth('customer')->id()); $wasLegal = (int) $customer->is_legal; $updateData = $request->except(['referral_id', 'referral_to_id', 'is_legal']); - $updateData = PersianDigits::toEnglish($updateData); if (!empty($updateData['birth_date'])) { try { $updateData['birth_date'] = Carbon::parse($updateData['birth_date'])->format('Y-m-d'); diff --git a/app/Http/Middleware/EnsureCustomerIsActive.php b/app/Http/Middleware/EnsureCustomerIsActive.php index f9d56a6..fdd1612 100644 --- a/app/Http/Middleware/EnsureCustomerIsActive.php +++ b/app/Http/Middleware/EnsureCustomerIsActive.php @@ -23,9 +23,7 @@ class EnsureCustomerIsActive if (!$customer->active) { return response()->json([ - 'message' => trans('error.no_active') !== 'error.no_active' - ? trans('error.no_active') - : 'اکانت شما توسط کارشناس سیستم غیر فعال شد', + 'message' => 'شما مجوز دسترسی به اکانت خود را ندارید', ], 401); } diff --git a/app/Services/ProductDisplayPriceService.php b/app/Services/ProductDisplayPriceService.php index 3efbb92..7820485 100644 --- a/app/Services/ProductDisplayPriceService.php +++ b/app/Services/ProductDisplayPriceService.php @@ -79,17 +79,12 @@ class ProductDisplayPriceService $this->resolveFallbackPayload(); } - if (! app(ConfigService::class)->isStore()) { - app(ZaarboxPriceService::class)->cachedPriceList(false); - } + // فروشگاه و خانگی هر دو ممکن است reading_method / قیمت اپ داشته باشند + app(ZaarboxPriceService::class)->cachedPriceList(false); } public function enrichForApi(Collection|iterable $products): void { - if (app(ConfigService::class)->isStore()) { - return; - } - $collection = collect($products); $zaarbox = app(ZaarboxPriceService::class); // مثل ادمین — روی cache miss یک بار fetch؛ نه فقط getCachedPriceListOnly diff --git a/app/Services/ProductPriceSyncService.php b/app/Services/ProductPriceSyncService.php index e8dfacf..113ee0b 100644 --- a/app/Services/ProductPriceSyncService.php +++ b/app/Services/ProductPriceSyncService.php @@ -37,7 +37,8 @@ class ProductPriceSyncService : 'http://212.23.201.173:8381/price_list'; if ($feed === null) { - return false; + // حتی بدون فید مرجع، محصولات قیمت‌اپ را با مظنه زنده همگام کن + return $this->syncAppPriceProducts(); } $products = Product::query()->whereNotNull('reading_method')->get(); @@ -77,6 +78,11 @@ class ProductPriceSyncService app(PriceSyncLogService::class)->record($source, $sourceUrl, $liquidGoldPrice, $logItems); + // مثل خانگی: آبشده / قیمت‌اپ را هم با مظنه زنده در DB همگام کن (fallback نمایش) + if ($this->syncAppPriceProducts()) { + $synced = true; + } + if ($synced) { app(PriceBroadcastService::class)->broadcastListIfChanged(); } diff --git a/app/Support/PersianDigits.php b/app/Support/PersianDigits.php deleted file mode 100644 index f725a55..0000000 --- a/app/Support/PersianDigits.php +++ /dev/null @@ -1,24 +0,0 @@ - 'شما مجوز دسترسی به اکانت خود را ندارید', + 'wrong_code' => 'کد وارد شده اشتباه است', +]; diff --git a/resources/lang/fa/error.php b/resources/lang/fa/error.php new file mode 100644 index 0000000..8298a7e --- /dev/null +++ b/resources/lang/fa/error.php @@ -0,0 +1,6 @@ + 'شما مجوز دسترسی به اکانت خود را ندارید', + 'wrong_code' => 'کد وارد شده اشتباه است', +];