work on moving customers from tahesab 2

This commit is contained in:
2026-06-29 00:41:42 +03:30
parent 73ccd4060c
commit 369d2453a5
@@ -109,9 +109,18 @@ class TahesabController extends Controller
->mapWithKeys(fn ($m) => [ltrim((string) $m, '0') => true])
->toArray();
// کدهای مشتریِ قبلاً ثبت‌شده در پنل (برای جلوگیری از تکرار)
$panelCodes = Customer::whereNull('deleted_at')
->whereNotNull('moshtari_code')
->pluck('moshtari_code')
->mapWithKeys(fn ($c) => [(string) $c => true])
->toArray();
$tahesabOnlyList = [];
foreach ($tahesabCustomers as $item) {
if (! is_array($item)) continue;
$code = $item['Code'] ?? null;
if ($code !== null && isset($panelCodes[(string) $code])) continue;
$tel = ltrim((string) ($item['Tel'] ?? ''), '0');
if ($tel && isset($panelMobiles[$tel])) continue;
$tahesabOnlyList[] = [
@@ -186,7 +195,15 @@ class TahesabController extends Controller
$errors = [];
foreach ($validated['customers'] as $item) {
$mobile = '0' . ltrim((string) ($item['tel'] ?? ''), '0');
// تلفن خالی نباید به موبایل «0» تبدیل شود (وگرنه روی unique برخورد می‌کند)
$tel = trim((string) ($item['tel'] ?? ''));
$mobile = $tel !== '' ? '0' . ltrim($tel, '0') : null;
// اگر مشتری با همین کد قبلاً ثبت شده، عملیات موفق در نظر گرفته می‌شود (idempotent)
if (Customer::whereNull('deleted_at')->where('moshtari_code', $item['code'])->exists()) {
$success++;
continue;
}
// کد معرف یکتا
$characters = '0123456789abcdefghijklmnopqrstuvwxyz';