db = DB::connection((string) config('jushuitan.connection', 'jushuitan_local')); } /** * @param array $filters express_no / sourceno / ship_from / ship_to * @return array{data:array,total:int} */ public function paginate(array $filters, int $page, int $perPage): array { $page = max($page, 1); $perPage = min(max($perPage, 1), 100); $q = $this->db->table('jst_oms_shipping'); if (($filters['express_no'] ?? '') !== '') { $q->where('express_no', '=', trim((string) $filters['express_no'])); } if (($filters['sourceno'] ?? '') !== '') { $q->where('trade_no', '=', trim((string) $filters['sourceno'])); } if (($filters['ship_from'] ?? '') !== '') { $q->where('ship_time', '>=', $filters['ship_from'] . ' 00:00:00'); } if (($filters['ship_to'] ?? '') !== '') { $q->where('ship_time', '<', date('Y-m-d 00:00:00', strtotime($filters['ship_to'] . ' +1 day'))); } $total = (clone $q)->count(); $rows = (clone $q) ->orderByDesc('ship_time') ->orderByDesc('id') ->forPage($page, $perPage) ->get() ->map(fn ($r) => (array) $r) ->all(); return ['data' => $rows, 'total' => $total]; } /** 同步状态(供页面显示同步中/最近完成)。 */ public function syncStatus(): array { try { $row = $this->db->table('jst_sync_state')->where('dataset_key', 'jst.sctrade')->first(); if (! $row) { return ['code' => 'unavailable', 'last_succeeded_at' => null]; } return [ 'code' => (string) ($row->status ?? 'unavailable'), 'last_succeeded_at' => $row->last_succeeded_at ?? null, ]; } catch (\Throwable) { return ['code' => 'unavailable', 'last_succeeded_at' => null]; } } }