$p['name'], 'spec' => $p['spec'] ?? '', 'unit' => $p['unit'] ?? '', 'price' => (float)($p['price'] ?? 0)]; } // 行数据来源:编辑=出库明细;新建且带销售订单=销售订单未交明细;否则空行 $rows = []; if ($isEdit) { foreach ($items as $it) $rows[] = ['so_item_id' => $it['so_item_id'], 'product_id' => $it['product_id'], 'name' => $it['name'], 'spec' => $it['spec'], 'unit' => $it['unit'], 'qty' => $it['qty'], 'price' => $it['price']]; } elseif ($so) { foreach ($soItems as $si) { $remain = max(0, (int)($si['qty'] ?? 0) - (int)($si['delivered_qty'] ?? 0)); if ($remain <= 0) continue; $rows[] = ['so_item_id' => $si['id'], 'product_id' => $si['product_id'], 'name' => $si['name'], 'spec' => $si['spec'], 'unit' => $si['unit'], 'qty' => $remain, 'price' => $si['price']]; } } ?>