fix pargar 2
This commit is contained in:
@@ -110,10 +110,7 @@ class PargarInboundController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
$customer->pargar_account_id = $accountId;
|
$customer->pargar_account_id = $accountId;
|
||||||
if ($fullName !== '') {
|
$this->applyPargarCustomerName($customer, $fullName);
|
||||||
$customer->fname = $fullName;
|
|
||||||
$customer->name = $fullName;
|
|
||||||
}
|
|
||||||
$customer->save();
|
$customer->save();
|
||||||
$messages[] = "کد حسابداری مشتری {$fullName} ویرایش شد";
|
$messages[] = "کد حسابداری مشتری {$fullName} ویرایش شد";
|
||||||
continue;
|
continue;
|
||||||
@@ -126,8 +123,7 @@ class PargarInboundController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($fullName !== '') {
|
if ($fullName !== '') {
|
||||||
$byAccount->fname = $fullName;
|
$this->applyPargarCustomerName($byAccount, $fullName);
|
||||||
$byAccount->name = $fullName;
|
|
||||||
}
|
}
|
||||||
$byAccount->mobile = $mobile;
|
$byAccount->mobile = $mobile;
|
||||||
if (empty($byAccount->password)) {
|
if (empty($byAccount->password)) {
|
||||||
@@ -140,8 +136,7 @@ class PargarInboundController extends Controller
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$customer = new Customer();
|
$customer = new Customer();
|
||||||
$customer->fname = $fullName !== '' ? $fullName : 'مشتری';
|
$this->applyPargarCustomerName($customer, $fullName !== '' ? $fullName : 'مشتری');
|
||||||
$customer->name = $customer->fname;
|
|
||||||
$customer->mobile = $mobile;
|
$customer->mobile = $mobile;
|
||||||
$customer->pargar_account_id = $accountId;
|
$customer->pargar_account_id = $accountId;
|
||||||
$customer->active = true;
|
$customer->active = true;
|
||||||
@@ -315,7 +310,7 @@ class PargarInboundController extends Controller
|
|||||||
->whereNull('deleted_at')
|
->whereNull('deleted_at')
|
||||||
->whereNull('pargar_account_id')
|
->whereNull('pargar_account_id')
|
||||||
->limit(100)
|
->limit(100)
|
||||||
->get(['id', 'fname', 'lname', 'mobile']);
|
->get(['id', 'fname', 'lname', 'name', 'mobile']);
|
||||||
|
|
||||||
if ($customers->isEmpty()) {
|
if ($customers->isEmpty()) {
|
||||||
return response()->json([
|
return response()->json([
|
||||||
@@ -326,12 +321,19 @@ class PargarInboundController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
$rows = $customers->map(function (Customer $customer) {
|
$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 [
|
return [
|
||||||
'id' => (string) $customer->id,
|
'id' => (string) $customer->id,
|
||||||
'name' => $nameParts[0] ?? '',
|
'name' => $fname,
|
||||||
'family' => $nameParts[1] ?? '',
|
'family' => $lname,
|
||||||
'mobile' => (string) $customer->mobile,
|
'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));
|
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
|
private function uniqueReferralId(): string
|
||||||
{
|
{
|
||||||
do {
|
do {
|
||||||
|
|||||||
Reference in New Issue
Block a user