handled some bugs and adde some feature for banner

This commit is contained in:
2026-07-19 15:53:05 +03:30
parent fc9de5198c
commit 160d6bd923
10 changed files with 158 additions and 36 deletions
@@ -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;