handled some bugs and adde some feature for banner
This commit is contained in:
@@ -62,6 +62,22 @@ class CustomerController extends SuperController
|
||||
Customer::assertMobileUnique($data['mobile'], (int) $id);
|
||||
}
|
||||
|
||||
if (array_key_exists('pargar_account_id', $data)) {
|
||||
$data['pargar_account_id'] = $this->normalizeAndAssertUniqueAccountingCode(
|
||||
$data['pargar_account_id'],
|
||||
'pargar_account_id',
|
||||
(int) $id
|
||||
);
|
||||
}
|
||||
|
||||
if (array_key_exists('moshtari_code', $data)) {
|
||||
$data['moshtari_code'] = $this->normalizeAndAssertUniqueAccountingCode(
|
||||
$data['moshtari_code'],
|
||||
'moshtari_code',
|
||||
(int) $id
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($data['gold'])){
|
||||
$user = Customer::find($id);
|
||||
if ($user) {
|
||||
@@ -74,6 +90,32 @@ class CustomerController extends SuperController
|
||||
return response()->json($user);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* خالی / 0 / -1 → null؛ در غیر این صورت یکتا بودن کد بین مشتریان فعال.
|
||||
*/
|
||||
private function normalizeAndAssertUniqueAccountingCode(mixed $value, string $column, int $customerId): ?string
|
||||
{
|
||||
if ($value === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$code = trim((string) $value);
|
||||
if ($code === '' || in_array($code, ['0', '-1'], true)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$exists = Customer::whereNull('deleted_at')
|
||||
->where($column, $code)
|
||||
->where('id', '!=', $customerId)
|
||||
->exists();
|
||||
|
||||
if ($exists) {
|
||||
throw new UnprocessableEntityHttpException('این کد حسابداری قبلاً برای مشتری دیگری ثبت شده است');
|
||||
}
|
||||
|
||||
return $code;
|
||||
}
|
||||
public function referrals(Request $request,$customer_id)
|
||||
{
|
||||
$customer_referral_id = Customer::where("id",$customer_id)->first()->referral_id;
|
||||
|
||||
@@ -13,6 +13,16 @@ class SettingsController extends Controller
|
||||
|
||||
private const NEW_SETTING_NOTIFY_MOBILE = '09134469985';
|
||||
|
||||
/**
|
||||
* کلیدهایی که پنل ادمین باید بتواند ویرایش کند حتی اگر در DB هنوز can_edit=0 باشد
|
||||
* (بنرها / سایتهای ریگیری).
|
||||
*/
|
||||
private const PANEL_MANAGED_KEYS = [
|
||||
'tracking_systems',
|
||||
'tracking_systems_enabled',
|
||||
'banner_enabled',
|
||||
];
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
$query = Setting::query()
|
||||
@@ -56,7 +66,7 @@ class SettingsController extends Controller
|
||||
$setting = new Setting();
|
||||
$setting->key = $request->key;
|
||||
$setting->can_edit = $isSystemDeploy ? 0 : 1;
|
||||
} elseif (!$setting->can_edit && !$isDeployAdmin) {
|
||||
} elseif (!$setting->can_edit && !$isDeployAdmin && !$this->isPanelManagedKey((string) $request->key)) {
|
||||
return response()->json(['message' => 'Forbidden'], 403);
|
||||
}
|
||||
|
||||
@@ -119,4 +129,9 @@ class SettingsController extends Controller
|
||||
|
||||
return $this->normalizeAdminMobile($user->mobile ?? '') === self::DEPLOY_ADMIN_MOBILE_SUFFIX;
|
||||
}
|
||||
|
||||
private function isPanelManagedKey(string $key): bool
|
||||
{
|
||||
return in_array($key, self::PANEL_MANAGED_KEYS, true);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user