| @@ -11,8 +11,9 @@ | ||
| 11 | 11 | use SyncBasalam\Services\Ticket\FetchTicketSubjects; |
| 12 | 12 | use SyncBasalam\Services\Ticket\CreateTicket; |
| 13 | 13 | use SyncBasalam\Services\Ticket\CreateTicketItem; |
| 14 | 14 | use SyncBasalam\Services\Ticket\UploadTicketMedia; |
| 15 | +use SyncBasalam\Services\Ticket\UpsertTicketSiteAccess; | |
| 15 | 16 | |
| 16 | 17 | use SyncBasalam\Jobs\Exceptions\RetryableException; |
| 17 | 18 | use SyncBasalam\Jobs\Exceptions\NonRetryableException; |
| 18 | 19 | |
| @@ -29,8 +30,15 @@ | ||
| 29 | 30 | { |
| 30 | 31 | return is_array($response) && isset($response['status_code']) && intval($response['status_code']) === 401; |
| 31 | 32 | } |
| 32 | 33 | |
| 34 | + public static function isSuccessful($response): bool | |
| 35 | + { | |
| 36 | + if (!is_array($response)) return false; | |
| 37 | + $statusCode = intval($response['status_code'] ?? 0); | |
| 38 | + return $statusCode >= 200 && $statusCode < 300; | |
| 39 | + } | |
| 40 | + | |
| 33 | 41 | public static function ticketStatuses(): array |
| 34 | 42 | { |
| 35 | 43 | return [ |
| 36 | 44 | 'pending_response' => 'در انتظار پاسخ', |
| @@ -55,8 +63,26 @@ | ||
| 55 | 63 | { |
| 56 | 64 | return in_array(self::resolveTicketStatus($ticket), ['closed', 'بسته شده'], true); |
| 57 | 65 | } |
| 58 | 66 | |
| 67 | + public static function resolveTicketSiteAccessStatus(array $ticket): string | |
| 68 | + { | |
| 69 | + $siteAccess = $ticket['data']['site_access'] ?? $ticket['site_access'] ?? null; | |
| 70 | + if (!is_array($siteAccess)) return ''; | |
| 71 | + | |
| 72 | + $status = $siteAccess['status'] ?? ''; | |
| 73 | + if (is_array($status)) { | |
| 74 | + $status = $status['slug'] ?? $status['name'] ?? ''; | |
| 75 | + } | |
| 76 | + | |
| 77 | + return strtolower(trim((string) $status)); | |
| 78 | + } | |
| 79 | + | |
| 80 | + public static function isTicketSiteAccessRejected(array $ticket): bool | |
| 81 | + { | |
| 82 | + return in_array(self::resolveTicketSiteAccessStatus($ticket), ['invalid', 'rejected'], true); | |
| 83 | + } | |
| 84 | + | |
| 59 | 85 | public function __construct() |
| 60 | 86 | { |
| 61 | 87 | $settings = (array) syncBasalamSettings()->getSettings(); |
| 62 | 88 | |
| @@ -207,6 +233,19 @@ | ||
| 207 | 233 | 'file_ids' => is_array($fileIds) ? $fileIds : [], |
| 208 | 234 | ]; |
| 209 | 235 | |
| 210 | 236 | return $this->executeWithRetry([$service, 'execute'], [$data]); |
| 237 | + } | |
| 238 | + | |
| 239 | + public function upsertTicketSiteAccess($ticketId, array $accessData): array | |
| 240 | + { | |
| 241 | + $businessId = intval($this->getHamsalamBusinessId()); | |
| 242 | + $ticketId = intval($ticketId); | |
| 243 | + if ($businessId <= 0 || $ticketId <= 0 || empty($accessData)) { | |
| 244 | + return $this->buildErrorResponse('اطلاعات دسترسی معتبر نیست.', 400); | |
| 245 | + } | |
| 246 | + | |
| 247 | + $accessData['ticket_id'] = $ticketId; | |
| 248 | + $service = new UpsertTicketSiteAccess($businessId); | |
| 249 | + return $this->executeWithRetry([$service, 'execute'], [$accessData]); | |
| 211 | 250 | } |
| 212 | 251 | } |