work on moving customers from tahesab 2
This commit is contained in:
@@ -109,9 +109,18 @@ class TahesabController extends Controller
|
|||||||
->mapWithKeys(fn ($m) => [ltrim((string) $m, '0') => true])
|
->mapWithKeys(fn ($m) => [ltrim((string) $m, '0') => true])
|
||||||
->toArray();
|
->toArray();
|
||||||
|
|
||||||
|
// کدهای مشتریِ قبلاً ثبتشده در پنل (برای جلوگیری از تکرار)
|
||||||
|
$panelCodes = Customer::whereNull('deleted_at')
|
||||||
|
->whereNotNull('moshtari_code')
|
||||||
|
->pluck('moshtari_code')
|
||||||
|
->mapWithKeys(fn ($c) => [(string) $c => true])
|
||||||
|
->toArray();
|
||||||
|
|
||||||
$tahesabOnlyList = [];
|
$tahesabOnlyList = [];
|
||||||
foreach ($tahesabCustomers as $item) {
|
foreach ($tahesabCustomers as $item) {
|
||||||
if (! is_array($item)) continue;
|
if (! is_array($item)) continue;
|
||||||
|
$code = $item['Code'] ?? null;
|
||||||
|
if ($code !== null && isset($panelCodes[(string) $code])) continue;
|
||||||
$tel = ltrim((string) ($item['Tel'] ?? ''), '0');
|
$tel = ltrim((string) ($item['Tel'] ?? ''), '0');
|
||||||
if ($tel && isset($panelMobiles[$tel])) continue;
|
if ($tel && isset($panelMobiles[$tel])) continue;
|
||||||
$tahesabOnlyList[] = [
|
$tahesabOnlyList[] = [
|
||||||
@@ -186,7 +195,15 @@ class TahesabController extends Controller
|
|||||||
$errors = [];
|
$errors = [];
|
||||||
|
|
||||||
foreach ($validated['customers'] as $item) {
|
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';
|
$characters = '0123456789abcdefghijklmnopqrstuvwxyz';
|
||||||
|
|||||||
Reference in New Issue
Block a user