Files
links/patches/application/common/service/SplitTicketSyncService.php
T
2026-06-04 14:15:12 +08:00

61 lines
2.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
declare(strict_types=1);
namespace app\common\service;
use app\admin\model\split\Ticket;
use think\Exception;
/**
* 分流工单数据同步服务(骨架,后续按 ticket_type 对接各云控 API
*
* 期望第三方接口 payload 字段映射:
* - complete_count int 完成数量
* - inbound_count int 进线人数
* - speed_per_hour float 每小时进线人数
* - number_count int 号码总数(含离线+封号)
* - number_offline_count int 可选 离线数
* - number_banned_count int 可选 封号数
* - online_count int 在线人数
*/
class SplitTicketSyncService
{
/**
* 同步单条工单(后续实现:按 ticket_type 选择适配器并请求 API
*/
public function syncOne(int $ticketId): bool
{
$ticket = Ticket::get($ticketId);
if (!$ticket) {
return false;
}
// TODO: 调用具体云控适配器获取 $payload
return false;
}
/**
* 将同步结果写入工单表
*
* @param array<string, mixed> $payload
*/
public function applySyncResult(Ticket $ticket, array $payload, bool $success, string $message = ''): void
{
$data = [
'complete_count' => max(0, (int) ($payload['complete_count'] ?? 0)),
'inbound_count' => max(0, (int) ($payload['inbound_count'] ?? 0)),
'speed_per_hour' => max(0, (float) ($payload['speed_per_hour'] ?? 0)),
'number_count' => max(0, (int) ($payload['number_count'] ?? 0)),
'number_offline_count' => max(0, (int) ($payload['number_offline_count'] ?? 0)),
'number_banned_count' => max(0, (int) ($payload['number_banned_count'] ?? 0)),
'online_count' => max(0, (int) ($payload['online_count'] ?? 0)),
'sync_status' => $success ? 'success' : 'error',
'sync_time' => time(),
'sync_message' => $success ? '' : mb_substr($message, 0, 255, 'UTF-8'),
];
if (!$ticket->allowField(array_keys($data))->save($data)) {
throw new Exception('工单同步结果保存失败');
}
}
}