fix scadule for getting price
This commit is contained in:
@@ -638,7 +638,7 @@ class MontzarService
|
||||
}
|
||||
|
||||
/**
|
||||
* GET وضعیت سفارش روی نود همکار — مسیر از setting + شناسه سفارش همکار.
|
||||
* وضعیت سفارش روی نود همکار — اول GET مسیر+شناسه، اگر sts نبود POST جدول همان مسیر.
|
||||
*
|
||||
* @return array<string, mixed>|null
|
||||
*/
|
||||
@@ -652,12 +652,97 @@ class MontzarService
|
||||
if ($path === '') {
|
||||
$path = '/server/customer/order';
|
||||
}
|
||||
$path = rtrim($path, '/');
|
||||
|
||||
$url = $this->endpoint(rtrim($path, '/') . '/' . $providerOrderId);
|
||||
$got = $this->montzarJson('GET', $this->endpoint($path . '/' . $providerOrderId));
|
||||
$row = $this->colleagueOrderRowFromBody($got, $providerOrderId);
|
||||
if ($row) {
|
||||
return $row;
|
||||
}
|
||||
|
||||
foreach ($this->colleagueOrderTableUrls($path) as $url) {
|
||||
$body = $this->montzarJson('POST', $url, [
|
||||
'filters' => [[
|
||||
'field' => 'id',
|
||||
'cr' => 'and',
|
||||
'type' => 'text',
|
||||
'op' => 'eq',
|
||||
'value' => (string) $providerOrderId,
|
||||
]],
|
||||
'limit' => 12,
|
||||
'page' => 1,
|
||||
'search' => '',
|
||||
]);
|
||||
$row = $this->colleagueOrderRowFromBody($body, $providerOrderId);
|
||||
if ($row) {
|
||||
return $row;
|
||||
}
|
||||
}
|
||||
|
||||
return is_array($got) ? $got : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<string>
|
||||
*/
|
||||
private function colleagueOrderTableUrls(string $path): array
|
||||
{
|
||||
$urls = [$this->endpoint($path . '/table')];
|
||||
if (str_ends_with($path, '/order') && !str_contains($path, '/single/')) {
|
||||
$urls[] = $this->endpoint(str_replace('/customer/order', '/customer/single/order', $path) . '/table');
|
||||
}
|
||||
|
||||
return array_values(array_unique($urls));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed>|null $body
|
||||
* @return array<string, mixed>|null
|
||||
*/
|
||||
private function colleagueOrderRowFromBody(?array $body, int $providerOrderId): ?array
|
||||
{
|
||||
if (!is_array($body)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$candidates = [$body, $body['data'] ?? null, $body['order'] ?? null];
|
||||
if (isset($body['rows']) && is_array($body['rows'])) {
|
||||
foreach ($body['rows'] as $row) {
|
||||
if (is_array($row)) {
|
||||
$candidates[] = $row;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$matched = null;
|
||||
foreach ($candidates as $row) {
|
||||
if (!is_array($row) || !array_key_exists('sts', $row)) {
|
||||
continue;
|
||||
}
|
||||
$id = (int) ($row['id'] ?? $row['order_id'] ?? 0);
|
||||
if ($id === $providerOrderId) {
|
||||
return $row;
|
||||
}
|
||||
if ($id === 0 && $matched === null) {
|
||||
$matched = $row;
|
||||
}
|
||||
}
|
||||
|
||||
return $matched;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $payload
|
||||
* @return array<string, mixed>|null
|
||||
*/
|
||||
private function montzarJson(string $method, string $url, array $payload = []): ?array
|
||||
{
|
||||
$token = $this->getToken();
|
||||
|
||||
try {
|
||||
$httpResponse = $this->http(15)->withToken($token)->get($url);
|
||||
$http = $this->http(15)->withToken($token);
|
||||
$httpResponse = strtoupper($method) === 'POST'
|
||||
? $http->post($url, $payload)
|
||||
: $http->get($url);
|
||||
} catch (\Throwable $e) {
|
||||
Log::warning('Montzar order status request failed', [
|
||||
'url' => $url,
|
||||
@@ -670,7 +755,10 @@ class MontzarService
|
||||
$body = $this->decodeMontzarHttpBody($httpResponse);
|
||||
if (is_array($body) && ($body['message'] ?? null) === 'no authorised') {
|
||||
$token = $this->montzarLogin();
|
||||
$httpResponse = $this->http(15)->withToken($token)->get($url);
|
||||
$http = $this->http(15)->withToken($token);
|
||||
$httpResponse = strtoupper($method) === 'POST'
|
||||
? $http->post($url, $payload)
|
||||
: $http->get($url);
|
||||
$body = $this->decodeMontzarHttpBody($httpResponse);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user