> */ public function mirrorBatch(?array $cursor, string $since, string $until, int $limit): array { $limit = min(max($limit, 1), 5000); $where = [ 'p.[updateTime] >= ?', 'p.[updateTime] < ?', ]; $bindings = [$since, $until]; if ($cursor !== null) { $where[] = '(p.[updateTime] > ? OR (p.[updateTime] = ? AND i.[Id] > ?))'; $bindings[] = $cursor['updated_at']; $bindings[] = $cursor['updated_at']; $bindings[] = $cursor['item_id']; } $sql = 'SELECT TOP (' . $limit . ') ' . 'i.[Id] AS item_id, p.[po_id] AS purchase_order_id, ' . 'CONVERT(varchar(64), CONVERT(decimal(38, 0), p.[source_o_id])) AS source_order_no, ' . 'p.[seller] AS supplier_name, ' . 'i.[sku_id] AS sku_id, i.[i_id] AS style_id, i.[qty] AS quantity, i.[price] AS unit_price, ' . 'p.[status] AS document_status, p.[labels] AS labels, ' . 'CONVERT(varchar(27), p.[createTime], 126) AS document_created_at, ' . 'CONVERT(varchar(27), p.[finish_time], 126) AS finished_at, ' . 'CONVERT(varchar(27), p.[updateTime], 126) AS purchase_updated_at ' . 'FROM [dbo].[jst_purchase] p ' . 'INNER JOIN [dbo].[jst_purchaseItem] i ON i.[po_id] = p.[po_id] ' . 'WHERE (' . implode(') AND (', $where) . ') ' . 'ORDER BY p.[updateTime], i.[Id]'; return $this->queries->forSource(self::SOURCE)->select($sql, $bindings); } }