|null> 同一次请求里按月份缓存 */ private array $cache = []; /** @return array|null 快递名称1 => 扣款金额(元);读不到时为 null */ public function byCourier(string $month): ?array { if (! array_key_exists($month, $this->cache)) { $this->cache[$month] = $this->load($month); } return $this->cache[$month]; } /** @param list $expressNames */ public function total(string $month, array $expressNames): ?float { $map = $this->byCourier($month); if ($map === null) { return null; } $sum = 0.0; foreach (array_unique($expressNames) as $name) { $sum += $map[$name] ?? 0.0; } return round($sum, 2); } /** @return array|null */ protected function load(string $month): ?array { try { $result = []; $page = app(AccessoryReshipPageData::class); foreach ($page->rows(['month' => $month, 'match_status' => 'ready']) as $row) { if (! AccessoryReshipPageData::inCategory($row, 'ready')) { continue; } $courier = trim((string) ($row['selected_courier'] ?? ($row['matches'][0]['courier'] ?? ''))); if ($courier !== '') { $result[$courier] = ($result[$courier] ?? 0) + ((int) $row['deduction_cents']) / 100; } } return $result; } catch (Throwable $error) { report($error); return null; } } }