table('store_receipt_product_cost_rows')->insert([ $this->row('cuiqiao-1', '崔桥工厂仓', 10, 2, 20, '天猫'), $this->row('cuiqiao-2', '崔桥工厂仓', 10, 3, 30, '天猫'), $this->row('accessory', '配件单仓', 5, 1, 5, '京东'), $this->row('missing-price', '崔桥工厂仓', null, 99, null, '天猫'), $this->row('missing-warehouse', null, 10, 4, 40, '天猫'), $this->row('other-month', '崔桥工厂仓', 10, 8, 80, '天猫', '2026-08-01'), ]); $response = $this->loginAs()->getJson(route( 'business.financial-operations.product-costs.summary-details', [ 'month' => '2026-09', 'platform' => '天猫', ], )); $response ->assertOk() ->assertJsonPath('summary.warehouse_count', 2) ->assertJsonPath('summary.quantity_total', 9) ->assertJsonPath('summary.cost_total', 90) ->assertJsonPath('rows.0.warehouse', '崔桥工厂仓') ->assertJsonPath('rows.0.quantity', 5) ->assertJsonPath('rows.0.cost', 50) ->assertJsonPath('rows.1.warehouse', '未填写发货仓库') ->assertJsonPath('rows.1.quantity', 4) ->assertJsonPath('rows.1.cost', 40); $cacheControl = (string) $response->headers->get('Cache-Control'); $this->assertStringContainsString('private', $cacheControl); $this->assertStringContainsString('no-store', $cacheControl); } public function test_summary_details_rejects_invalid_month(): void { $this->loginAs() ->getJson(route('business.financial-operations.product-costs.summary-details', [ 'month' => 'invalid', ])) ->assertUnprocessable() ->assertJsonPath('message', '请选择有效月份。'); } private function row( string $rowKey, ?string $warehouse, int|float|null $unitPrice, int|float $quantity, int|float|null $cost, string $platform, string $reportMonth = '2026-09-01' ): array { return [ 'report_month' => $reportMonth, 'row_key' => $rowKey, 'platform' => $platform, 'occurred_date' => $reportMonth, 'store_name' => 'HX旗舰店', 'online_order_no' => 'ORDER-' . $rowKey, 'warehouse' => $warehouse, 'warehouse_short_name' => $warehouse, 'product_code' => 'SKU-' . $rowKey, 'product_quantity' => $quantity, 'unit_price' => $unitPrice, 'product_cost' => $cost, 'remark' => null, 'imported_at' => now(), ]; } }