added setting for user
This commit is contained in:
@@ -1451,10 +1451,42 @@ class SingleOrderController extends Controller
|
||||
];
|
||||
}
|
||||
|
||||
$customerId = (int) (auth('customer')->id() ?? 0);
|
||||
if ($customerId <= 0) {
|
||||
$customerId = (int) (request()->input('customer_id') ?? 0);
|
||||
}
|
||||
$specialSvc = app(\App\Services\CustomerSpecialPricingService::class);
|
||||
$specialRule = $specialSvc->ruleForCustomerProduct($customerId, (int) ($product->id ?? 0));
|
||||
if ($specialRule && ! ($specialRule['show_product'] ?? true)) {
|
||||
throw new UnprocessableEntityHttpException('این محصول برای شما در دسترس نیست.');
|
||||
}
|
||||
$specialAmt = $specialSvc->profitForDirection($specialRule, $direction);
|
||||
if ($specialAmt > 0) {
|
||||
$amount += $specialAmt;
|
||||
$keys[] = 'customer_special_pricing';
|
||||
$lines[] = [
|
||||
'kind' => 'special_pricing',
|
||||
'key' => 'customer_special_pricing',
|
||||
'label' => 'قیمت ویژه مشتری · ' . ($specialRule['title'] ?? '') . ' · ' . $side,
|
||||
'is_percent' => false,
|
||||
'raw' => $specialAmt,
|
||||
'per_unit' => $specialAmt,
|
||||
'detail' => number_format($specialAmt) . ' ریال / گرم',
|
||||
'package_id' => $specialRule['package_id'] ?? null,
|
||||
];
|
||||
}
|
||||
|
||||
$hasApp = collect($lines)->contains(fn ($l) => ($l['kind'] ?? '') === 'app_spread');
|
||||
$hasProduct = collect($lines)->contains(fn ($l) => ($l['kind'] ?? '') === 'product_spread');
|
||||
$hasSpecial = collect($lines)->contains(fn ($l) => ($l['kind'] ?? '') === 'special_pricing');
|
||||
|
||||
if ($hasApp && $hasProduct) {
|
||||
if ($hasSpecial && ($hasApp || $hasProduct)) {
|
||||
$source = 'app+product+special';
|
||||
$label = 'اختلاف پایه/محصول + قیمت ویژه مشتری = ' . number_format($amount) . ' ریال / گرم';
|
||||
} elseif ($hasSpecial) {
|
||||
$source = 'special';
|
||||
$label = ($lines[array_key_last($lines)]['label'] ?? 'قیمت ویژه مشتری') . ' = ' . number_format($amount) . ' ریال';
|
||||
} elseif ($hasApp && $hasProduct) {
|
||||
$source = 'app+product';
|
||||
$label = 'قیمت صفحه اصلی اپلیکیشن + تب اختلاف محصول = ' . number_format($amount) . ' ریال / گرم';
|
||||
} elseif ($hasApp) {
|
||||
|
||||
Reference in New Issue
Block a user