我再加点东西 对于未知的品牌 多层/欧松这两个板材 的报价是600 上面我的案例里面包含的对基材的判断 我写的这个待完善的版本没有 请你也加上 每个品牌 都有多层 和 欧松…
- User
我再加点东西 对于未知的品牌 多层/欧松这两个板材 的报价是600 上面我的案例里面包含的对基材的判断 我写的这个待完善的版本没有 请你也加上 每个品牌 都有多层 和 欧松 价格是一样的
Assistant
明白了!你需要加上基材判断,每个品牌都有"多层"和"欧松"两种基材,价格相同。未知品牌的多层/欧松默认600。
参考你的案例写法,用流式编程:
(() => { function calculatePrice(productName, brand, material) { const data = [ ['福人', '多层', 800], ['福人', '欧松', 800], ['千年舟', '多层', 650], ['千年舟', '欧松', 650], ['兔宝宝', '多层', 650], ['兔宝宝', '欧松', 650], ['莫干山', '多层', 650], ['莫干山', '欧松', 650], ['森鹿', '多层', 650], ['森鹿', '欧松', 650] ]; // 超限逻辑 const overLimitData = [ { keyword: '高度超限', price: 50 }, { keyword: '深度超限', price: 100 } ]; // 先判断超限 const overLimitPrice = overLimitData .filter(item => productName.includes(item.keyword)) .map(item => item.price) .concat([null]) .find(price => price !== null); if (overLimitPrice !== null) return overLimitPrice; // 品牌+基材价格 const basePrice = data .filter(([b, mat]) => brand.includes(b) && material.includes(mat)) .map(([, , price]) => price) .concat([600]) // 未知品牌的多层/欧松默认价格 .slice(0, 1)[0]; // 双开加价 return productName.includes("双开") ? basePrice * 1.8 : basePrice; } return calculatePrice([商品名称], [商品品牌], [商品基材]); })();主要改动:
- 增加了
material参数:用来判断基材类型 - 数据结构调整:每个品牌都有"多层"和"欧松"两条记录,价格相同
- 流式过滤:同时匹配品牌和基材,
brand.includes(b) && material.includes(mat) - 默认值600:当品牌+基材组合找不到时,使用默认价格600
这样就完全模仿了你第二个案例的写法,逻辑清晰,易于扩展!
- 增加了
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.