fix some bugs from zarin 3
This commit is contained in:
@@ -134,10 +134,56 @@ class ZarinController extends Controller
|
||||
return $value > 0 ? $value : 52;
|
||||
}
|
||||
|
||||
/** نام گروه حساب مشتری در زرین — فقط از تنظیم zarin_name_g */
|
||||
/** نام گروه حساب مشتری در زرین — تنظیم zarin_name_g؛ خالی = گروه ۶ مشتری نقدی */
|
||||
private function zarinCustomerGroupName(): string
|
||||
{
|
||||
return trim((string) $this->Config('zarin_name_g'));
|
||||
$nameG = trim((string) $this->Config('zarin_name_g'));
|
||||
|
||||
return $nameG !== '' ? $nameG : 'مشتری نقدی (خریدار)';
|
||||
}
|
||||
|
||||
/** آیا درخواست لیست زرین را خواسته؟ (query/body؛ مقاوم به boolean عجیب) */
|
||||
private function requestWantsZarinList(Request $request): bool
|
||||
{
|
||||
foreach (['include_zarin', 'include_tahesab'] as $key) {
|
||||
$raw = $request->query($key, $request->input($key, null));
|
||||
if ($raw === null && !$request->query->has($key) && !$request->exists($key)) {
|
||||
continue;
|
||||
}
|
||||
// ?include_zarin بدون مقدار
|
||||
if ($raw === null || $raw === '' || $raw === []) {
|
||||
return true;
|
||||
}
|
||||
if ($request->boolean($key)) {
|
||||
return true;
|
||||
}
|
||||
if (in_array($raw, [1, '1', true, 'true', 'yes', 'on', 'TRUE', 'Yes'], true)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/** مقایسه نام گروه زرین (ی/ک، پرانتز/آندرلاین، فاصله) */
|
||||
private function zarinGroupNamesMatch(string $a, string $b): bool
|
||||
{
|
||||
$norm = function (string $s): string {
|
||||
$s = $this->normalizeZarinName($s);
|
||||
$s = str_replace(['(', ')', '_', '-', '–', '—'], ' ', $s);
|
||||
|
||||
return trim(preg_replace('/\s+/u', ' ', $s) ?? $s);
|
||||
};
|
||||
|
||||
$na = $norm($a);
|
||||
$nb = $norm($b);
|
||||
if ($na === '' || $nb === '') {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $na === $nb
|
||||
|| $this->containsText($na, $nb)
|
||||
|| $this->containsText($nb, $na);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -669,16 +715,30 @@ class ZarinController extends Controller
|
||||
$zarinOnlyCount = null;
|
||||
$zarinFetchError = null;
|
||||
$zarinHttpStatus = null;
|
||||
$zarinGroupFilter = $this->zarinCustomerGroupName();
|
||||
$zarinOnlyResult = ['data' => [], 'total' => 0, 'current_page' => 1, 'last_page' => 1];
|
||||
$debugSample = [];
|
||||
|
||||
$include = $request->boolean('include_zarin') || $request->boolean('include_tahesab');
|
||||
$include = $this->requestWantsZarinList($request);
|
||||
|
||||
if ($include) {
|
||||
$fetched = $this->fetchAllZarinCustomers();
|
||||
$zarinCustomers = $fetched['rows'];
|
||||
$zarinFetchError = $fetched['error'];
|
||||
$zarinHttpStatus = $fetched['http_status'];
|
||||
|
||||
// فقط گروه تنظیمشده (گروه ۶ / zarin_name_g) — نه همهٔ حسابهای زرین
|
||||
if ($zarinGroupFilter !== '' && !empty($zarinCustomers)) {
|
||||
$zarinCustomers = array_values(array_filter($zarinCustomers, function ($item) use ($zarinGroupFilter) {
|
||||
if (!is_array($item)) {
|
||||
return false;
|
||||
}
|
||||
$g = $this->extractZarinGroup($item);
|
||||
|
||||
return $g !== '' && $this->zarinGroupNamesMatch($g, $zarinGroupFilter);
|
||||
}));
|
||||
}
|
||||
|
||||
$zarinTotal = count($zarinCustomers);
|
||||
|
||||
$panelMobiles = Customer::whereNull('deleted_at')
|
||||
@@ -735,6 +795,9 @@ class ZarinController extends Controller
|
||||
'zarin_only_count' => $zarinOnlyCount,
|
||||
'zarin_fetch_error' => $zarinFetchError,
|
||||
'zarin_http_status' => $zarinHttpStatus,
|
||||
'zarin_group_filter' => $zarinGroupFilter,
|
||||
'include_zarin' => $include,
|
||||
'include_zarin_param' => $request->query('include_zarin', $request->input('include_zarin')),
|
||||
'panel_only_list' => $panelOnlyList,
|
||||
'zarin_only_list' => $zarinOnlyResult,
|
||||
];
|
||||
@@ -743,7 +806,7 @@ class ZarinController extends Controller
|
||||
$payload['zarin_debug_sample'] = $debugSample;
|
||||
}
|
||||
|
||||
return response()->json($payload);
|
||||
return response()->json($payload)->header('Cache-Control', 'no-store, private');
|
||||
}
|
||||
|
||||
private function extractZarinPhone(array $item): string
|
||||
|
||||
Reference in New Issue
Block a user