added rahimi
This commit is contained in:
@@ -118,6 +118,112 @@ class MontzarService
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* مانده طلا/ریال اکانت اپ روی نود همکار (دفتر پنل همکار — نه تهحساب اپ).
|
||||
*
|
||||
* @return list<array{name_eng?: string, name_fa?: string, value?: float|int, unit?: string, isKol?: bool}>
|
||||
*/
|
||||
public function fetchColleagueLedgerMandeh(): array
|
||||
{
|
||||
$body = $this->requestColleagueLedger('GET', '/server/customer/fin_tahesab/mandeh');
|
||||
|
||||
if (!is_array($body)) {
|
||||
throw new UnprocessableEntityHttpException('پاسخ نامعتبر مانده دفتر همکار');
|
||||
}
|
||||
|
||||
// بعضی نودها آرایهٔ مستقیم برمیگردانند؛ بعضی داخل data
|
||||
if (isset($body[0]) || $body === []) {
|
||||
return array_values($body);
|
||||
}
|
||||
|
||||
if (isset($body['data']) && is_array($body['data'])) {
|
||||
return array_values($body['data']);
|
||||
}
|
||||
|
||||
return [$body];
|
||||
}
|
||||
|
||||
/**
|
||||
* ریز اسناد دفتر اکانت روی نود همکار در بازهٔ تاریخ میلادی Y-m-d.
|
||||
*
|
||||
* @return list<array<string, mixed>>
|
||||
*/
|
||||
public function fetchColleagueLedgerTable(string $startDate, string $endDate): array
|
||||
{
|
||||
$body = $this->requestColleagueLedger('POST', '/server/customer/fin_tahesab/table', [
|
||||
'startDate' => $startDate,
|
||||
'endDate' => $endDate,
|
||||
]);
|
||||
|
||||
if (!is_array($body)) {
|
||||
throw new UnprocessableEntityHttpException('پاسخ نامعتبر ریز دفتر همکار');
|
||||
}
|
||||
|
||||
if (isset($body[0]) || $body === []) {
|
||||
return array_values($body);
|
||||
}
|
||||
|
||||
if (isset($body['data']) && is_array($body['data'])) {
|
||||
return array_values($body['data']);
|
||||
}
|
||||
|
||||
if (isset($body['rows']) && is_array($body['rows'])) {
|
||||
return array_values($body['rows']);
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed>|null $payload
|
||||
* @return array<mixed>|null
|
||||
*/
|
||||
private function requestColleagueLedger(string $method, string $path, ?array $payload = null): ?array
|
||||
{
|
||||
$token = $this->getToken();
|
||||
$url = $this->endpoint($path);
|
||||
|
||||
$httpResponse = $this->sendColleagueLedgerHttp($method, $url, $token, $payload);
|
||||
$body = $this->decodeMontzarHttpBody($httpResponse);
|
||||
|
||||
if (is_array($body) && ($body['message'] ?? null) === 'no authorised') {
|
||||
$token = $this->montzarLogin();
|
||||
$httpResponse = $this->sendColleagueLedgerHttp($method, $url, $token, $payload);
|
||||
$body = $this->decodeMontzarHttpBody($httpResponse);
|
||||
}
|
||||
|
||||
if ($httpResponse->failed() && !is_array($body)) {
|
||||
Log::warning('Colleague ledger request failed', [
|
||||
'method' => $method,
|
||||
'url' => $url,
|
||||
'status' => $httpResponse->status(),
|
||||
'raw' => $httpResponse->body(),
|
||||
]);
|
||||
throw new UnprocessableEntityHttpException(
|
||||
$this->formatMontzarErrorMessage(null, $httpResponse)
|
||||
);
|
||||
}
|
||||
|
||||
if (is_array($body) && !empty($body['message']) && is_string($body['message']) && !isset($body[0])) {
|
||||
throw new UnprocessableEntityHttpException($body['message']);
|
||||
}
|
||||
|
||||
return $body;
|
||||
}
|
||||
|
||||
private function sendColleagueLedgerHttp(string $method, string $url, string $token, ?array $payload)
|
||||
{
|
||||
$pending = Http::timeout(30)
|
||||
->acceptJson()
|
||||
->withToken($token);
|
||||
|
||||
if (strtoupper($method) === 'GET') {
|
||||
return $pending->get($url, $payload ?? []);
|
||||
}
|
||||
|
||||
return $pending->post($url, $payload ?? []);
|
||||
}
|
||||
|
||||
/**
|
||||
* ثبت سفارش در منتظر — قبل از ایجاد سفارش/تراکنش محلی صدا زده میشود.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user