fix ehraz
This commit is contained in:
@@ -20,13 +20,11 @@ use App\Http\Controllers\Admin\TahesabController;
|
|||||||
use App\Services\ConfigService;
|
use App\Services\ConfigService;
|
||||||
use App\Services\ReferralGiftService;
|
use App\Services\ReferralGiftService;
|
||||||
use App\Services\WalletBalanceService;
|
use App\Services\WalletBalanceService;
|
||||||
|
use App\Support\PersianDigits;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
|
||||||
//use App\Models\Price;
|
|
||||||
//use Carbon\Carbon;
|
|
||||||
//use Illuminate\Support\Facades\Http;
|
|
||||||
|
|
||||||
class CustomerController extends Controller
|
class CustomerController extends Controller
|
||||||
{
|
{
|
||||||
public function me()
|
public function me()
|
||||||
@@ -191,6 +189,14 @@ class CustomerController extends Controller
|
|||||||
$customer = Customer::findOrFail(auth('customer')->id());
|
$customer = Customer::findOrFail(auth('customer')->id());
|
||||||
$wasLegal = (int) $customer->is_legal;
|
$wasLegal = (int) $customer->is_legal;
|
||||||
$updateData = $request->except(['referral_id', 'referral_to_id', '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');
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return response()->json(['message' => 'تاریخ تولد نامعتبر است.'], 422);
|
||||||
|
}
|
||||||
|
}
|
||||||
if (isset($request->fname) && isset($request->lname)) {
|
if (isset($request->fname) && isset($request->lname)) {
|
||||||
$updateData['name'] = "$request->fname $request->lname";
|
$updateData['name'] = "$request->fname $request->lname";
|
||||||
}
|
}
|
||||||
@@ -238,9 +244,12 @@ class CustomerController extends Controller
|
|||||||
}
|
}
|
||||||
return response()->json(true);
|
return response()->json(true);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
// نمایش 400 کاراکتر اول از پیام خطا
|
Log::error('customer updateMe failed', [
|
||||||
$errorMessage = substr($e->getMessage(), 0, 400);
|
'customer_id' => auth('customer')->id(),
|
||||||
return response()->json(['error' => $errorMessage], 500);
|
'message' => $e->getMessage(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
return response()->json(['message' => 'خطا در ذخیره اطلاعات. لطفاً دوباره تلاش کنید.'], 422);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -55,6 +55,10 @@ class SingleOrderController extends Controller
|
|||||||
$data['first_buy'] = auth('customer')->id() && $customer && $customer->first_buy_order !== 1;
|
$data['first_buy'] = auth('customer')->id() && $customer && $customer->first_buy_order !== 1;
|
||||||
|
|
||||||
if (auth('customer')->id()) {
|
if (auth('customer')->id()) {
|
||||||
|
if (!$customer || !$customer->trade_active) {
|
||||||
|
throw new UnprocessableEntityHttpException('امکان سفارش برای شما غیرفعال است.');
|
||||||
|
}
|
||||||
|
|
||||||
$data['customer_id'] = auth('customer')->id();
|
$data['customer_id'] = auth('customer')->id();
|
||||||
|
|
||||||
$orderProductId = (int) ($data['abshode_id'] ?? $data['product_id'] ?? $config->mainProductId() ?? 0);
|
$orderProductId = (int) ($data['abshode_id'] ?? $data['product_id'] ?? $config->mainProductId() ?? 0);
|
||||||
|
|||||||
@@ -68,5 +68,6 @@ class Kernel extends HttpKernel
|
|||||||
'request.validation' => \App\Http\Middleware\ValidateRequests::class,
|
'request.validation' => \App\Http\Middleware\ValidateRequests::class,
|
||||||
'pargar.auth' => \App\Http\Middleware\PargarAuth::class,
|
'pargar.auth' => \App\Http\Middleware\PargarAuth::class,
|
||||||
'sms.panel.super' => \App\Http\Middleware\EnsureSmsPanelSuperAdmin::class,
|
'sms.panel.super' => \App\Http\Middleware\EnsureSmsPanelSuperAdmin::class,
|
||||||
|
'customer.active' => \App\Http\Middleware\EnsureCustomerIsActive::class,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use Closure;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
class EnsureCustomerIsActive
|
||||||
|
{
|
||||||
|
public function handle(Request $request, Closure $next)
|
||||||
|
{
|
||||||
|
$customer = auth('customer')->user();
|
||||||
|
|
||||||
|
if (!$customer) {
|
||||||
|
return $next($request);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($customer->is_archive) {
|
||||||
|
return response()->json([
|
||||||
|
'message' => 'شما اجازه ورود به سیستم را ندارید',
|
||||||
|
], 401);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$customer->active) {
|
||||||
|
return response()->json([
|
||||||
|
'message' => trans('error.no_active') !== 'error.no_active'
|
||||||
|
? trans('error.no_active')
|
||||||
|
: 'اکانت شما توسط کارشناس سیستم غیر فعال شد',
|
||||||
|
], 401);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $next($request);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Support;
|
||||||
|
|
||||||
|
class PersianDigits
|
||||||
|
{
|
||||||
|
public static function toEnglish(mixed $value): mixed
|
||||||
|
{
|
||||||
|
if (is_string($value)) {
|
||||||
|
$persian = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹'];
|
||||||
|
$arabic = ['٠', '١', '٢', '٣', '٤', '٥', '٦', '٧', '٨', '٩'];
|
||||||
|
$latin = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
|
||||||
|
$value = str_replace(array_merge($persian, $arabic), array_merge($latin, $latin), $value);
|
||||||
|
|
||||||
|
return str_replace('٫', '.', $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_array($value)) {
|
||||||
|
return array_map([self::class, 'toEnglish'], $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-1
@@ -35,7 +35,7 @@ $priceStreamRoute = Route::get('/price/stream', [PriceStreamController::class, '
|
|||||||
->withoutMiddleware(['throttle:api']);
|
->withoutMiddleware(['throttle:api']);
|
||||||
|
|
||||||
if (! app(ConfigService::class)->isStore()) {
|
if (! app(ConfigService::class)->isStore()) {
|
||||||
$priceStreamRoute->middleware('auth:customer');
|
$priceStreamRoute->middleware(['auth:customer', 'customer.active']);
|
||||||
}
|
}
|
||||||
|
|
||||||
Route::get('/price/updatePrise',[ReportController::class, 'updatePrise']);
|
Route::get('/price/updatePrise',[ReportController::class, 'updatePrise']);
|
||||||
|
|||||||
+1
-1
@@ -41,7 +41,7 @@ if ($isStore) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Route::middleware('auth:customer')->group(function () use ($isStore) {
|
Route::middleware(['auth:customer', 'customer.active'])->group(function () use ($isStore) {
|
||||||
Route::middleware('validation')->group(function () use ($isStore) {
|
Route::middleware('validation')->group(function () use ($isStore) {
|
||||||
//-----------Address
|
//-----------Address
|
||||||
Route::post('/address/table', [AddressController::class, 'table']);
|
Route::post('/address/table', [AddressController::class, 'table']);
|
||||||
|
|||||||
Reference in New Issue
Block a user