>,total:int,ready:bool} */ public function paginate(int $page, int $perPage): array { $connection = $this->mirror->connection(); $dataset = $this->datasets->get(self::DATASET); if (! $this->mirror->ready($dataset) || ! Schema::connection($connection->getName())->hasTable($dataset->targetTable())) { return ['data' => [], 'total' => 0, 'ready' => false]; } $perPage = min(max($perPage, 1), 100); $query = $connection->table($dataset->targetTable()); $total = (clone $query)->count(); $rows = $query->orderByDesc('Id')->forPage(max($page, 1), $perPage)->get(); return ['data' => $rows->map(fn (object $row): array => $this->map((array) $row))->all(), 'total' => $total, 'ready' => true]; } /** @param array $row */ private function map(array $row): array { $value = static function (array $row, string ...$names): mixed { foreach ($names as $name) { foreach ($row as $key => $value) if (strcasecmp((string) $key, $name) === 0) return $value; } return null; }; $mapped = [ 'id' => $value($row, 'Id'), 'installation_no' => $value($row, 'ordernum_id', 'OrderNum'), 'quote_status' => $value($row, 'BidStatus'), 'quote_deadline' => $value($row, 'BidEndTime'), 'installation_company' => $value($row, 'installCompanyName'), 'submitted_at' => $value($row, 'SubmitTime'), 'shipped_at' => $value($row, 'ShipTIme'), 'buyer_nickname' => $value($row, 'BuyersNick'), 'store_name' => $value($row, 'shop_name', 'shopname'), 'order_no' => $value($row, 'OrderNum'), 'item_quantity' => $value($row, 'Num'), 'buyer_name' => $value($row, 'BuyersName'), 'buyer_phone' => $value($row, 'Mobile'), 'notes' => $value($row, 'Nots'), 'province' => $value($row, 'Province'), 'city' => $value($row, 'City'), 'district' => $value($row, 'Area'), 'address' => $value($row, 'Address'), 'requested_amount' => $value($row, 'installcost'), 'settled_amount' => $value($row, 'settleAmount'), 'image_urls' => $value($row, 'Picture'), 'completed_status' => $value($row, 'installComplete'), 'customer_service_reviewed_at' => $value($row, 'kfshTime'), 'finance_reviewed_at' => $value($row, 'cwshTime'), 'actual_install_quantity' => $value($row, 'installNum'), 'actual_install_fee' => $value($row, 'install_Cost'), 'actual_install_product_name' => $value($row, 'installGoodsName'), 'installer_phone' => $value($row, 'installTel'), 'installation_company_notes' => $value($row, 'installNote'), 'installation_fee_payer' => $value($row, 'costtaker'), 'payment_channel' => $value($row, 'costWay'), 'payment_transaction_no' => $value($row, 'actporderNum'), 'payment_voucher' => $value($row, 'costWayVoucher'), 'payment_amount' => $value($row, 'acceptAmount'), ]; // 页面按模板的完整 61 列渲染;视图暂未提供的字段必须显式为 null, // 不能让 Blade 读取未定义属性。 return array_replace(array_fill_keys(array_keys(\App\Models\Business\InstallationDetail::columnLabels()), null), $mapped); } }