fix pargar 2
This commit is contained in:
@@ -110,10 +110,7 @@ class PargarInboundController extends Controller
|
||||
}
|
||||
|
||||
$customer->pargar_account_id = $accountId;
|
||||
if ($fullName !== '') {
|
||||
$customer->fname = $fullName;
|
||||
$customer->name = $fullName;
|
||||
}
|
||||
$this->applyPargarCustomerName($customer, $fullName);
|
||||
$customer->save();
|
||||
$messages[] = "کد حسابداری مشتری {$fullName} ویرایش شد";
|
||||
continue;
|
||||
@@ -126,8 +123,7 @@ class PargarInboundController extends Controller
|
||||
}
|
||||
|
||||
if ($fullName !== '') {
|
||||
$byAccount->fname = $fullName;
|
||||
$byAccount->name = $fullName;
|
||||
$this->applyPargarCustomerName($byAccount, $fullName);
|
||||
}
|
||||
$byAccount->mobile = $mobile;
|
||||
if (empty($byAccount->password)) {
|
||||
@@ -140,8 +136,7 @@ class PargarInboundController extends Controller
|
||||
|
||||
try {
|
||||
$customer = new Customer();
|
||||
$customer->fname = $fullName !== '' ? $fullName : 'مشتری';
|
||||
$customer->name = $customer->fname;
|
||||
$this->applyPargarCustomerName($customer, $fullName !== '' ? $fullName : 'مشتری');
|
||||
$customer->mobile = $mobile;
|
||||
$customer->pargar_account_id = $accountId;
|
||||
$customer->active = true;
|
||||
@@ -315,7 +310,7 @@ class PargarInboundController extends Controller
|
||||
->whereNull('deleted_at')
|
||||
->whereNull('pargar_account_id')
|
||||
->limit(100)
|
||||
->get(['id', 'fname', 'lname', 'mobile']);
|
||||
->get(['id', 'fname', 'lname', 'name', 'mobile']);
|
||||
|
||||
if ($customers->isEmpty()) {
|
||||
return response()->json([
|
||||
@@ -326,12 +321,19 @@ class PargarInboundController extends Controller
|
||||
}
|
||||
|
||||
$rows = $customers->map(function (Customer $customer) {
|
||||
$nameParts = preg_split('/\s+/', trim((string) $customer->name), 2) ?: ['', ''];
|
||||
$fname = trim((string) ($customer->fname ?? ''));
|
||||
$lname = trim((string) ($customer->lname ?? ''));
|
||||
|
||||
if ($fname === '' && $lname === '') {
|
||||
$nameParts = preg_split('/\s+/', trim((string) ($customer->name ?? '')), 2) ?: ['', ''];
|
||||
$fname = trim((string) ($nameParts[0] ?? ''));
|
||||
$lname = trim((string) ($nameParts[1] ?? ''));
|
||||
}
|
||||
|
||||
return [
|
||||
'id' => (string) $customer->id,
|
||||
'name' => $nameParts[0] ?? '',
|
||||
'family' => $nameParts[1] ?? '',
|
||||
'name' => $fname,
|
||||
'family' => $lname,
|
||||
'mobile' => (string) $customer->mobile,
|
||||
];
|
||||
});
|
||||
@@ -428,6 +430,33 @@ class PargarInboundController extends Controller
|
||||
return trim(str_replace(array_merge($persian, $arabic), array_merge($latin, $latin), $value));
|
||||
}
|
||||
|
||||
private function applyPargarCustomerName(Customer $customer, string $fullName): void
|
||||
{
|
||||
$fullName = trim($fullName);
|
||||
if ($fullName === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
[$fname, $lname] = $this->splitPargarFullName($fullName);
|
||||
$customer->fname = $fname;
|
||||
$customer->lname = $lname;
|
||||
// mutator مدل Customer مقدار name را از fname + lname میسازد
|
||||
$customer->name = trim("$fname $lname");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{0: string, 1: string}
|
||||
*/
|
||||
private function splitPargarFullName(string $fullName): array
|
||||
{
|
||||
$parts = preg_split('/\s+/u', trim($fullName), 2) ?: ['', ''];
|
||||
|
||||
return [
|
||||
trim((string) ($parts[0] ?? '')),
|
||||
trim((string) ($parts[1] ?? '')),
|
||||
];
|
||||
}
|
||||
|
||||
private function uniqueReferralId(): string
|
||||
{
|
||||
do {
|
||||
|
||||
Reference in New Issue
Block a user