const OIL_VOLUMES = new Set(['2.5', '5', '10', '15', '115']) export function parseOilProductPaste(raw) { const result = { type: 'product', cn: '', en: '', memberPrice: null, retailPrice: null, volume: null, customDrops: null, productAmount: null, productUnit: null, } if (!raw || !raw.trim()) return result const text = raw.replace(/[::]/g, ':').replace(/[¥¥]/g, '') const memberMatch = text.match(/(?:优惠顾客价|会员价|批发价)\s*:?\s*(\d+(?:\.\d+)?)/) const retailMatch = text.match(/零售价\s*:?\s*(\d+(?:\.\d+)?)/) const specMatch = text.match(/规格\s*:?\s*(\d+(?:\.\d+)?)\s*(毫升|ml|ML|克|g|G|颗|粒|片)/) if (memberMatch) result.memberPrice = Number(memberMatch[1]) if (retailMatch) result.retailPrice = Number(retailMatch[1]) for (const line of raw.split(/\r?\n/)) { const s = line.trim() if (!s) continue if (/优惠顾客价|会员价|零售价|点数|规格|PT\s*:|批发价/i.test(s)) continue const m = s.match(/^([^A-Za-z]+?)\s+([A-Za-z].*)$/) if (m) { result.cn = m[1].trim(); result.en = m[2].trim() } else { result.cn = s } break } if (specMatch) { const amount = specMatch[1] const unitRaw = specMatch[2].toLowerCase() const isMl = unitRaw === '毫升' || unitRaw === 'ml' if (isMl && OIL_VOLUMES.has(String(Number(amount)))) { result.type = 'oil' result.volume = String(Number(amount)) } else { result.type = 'product' result.productAmount = Number(amount) result.productUnit = (unitRaw === '克' || unitRaw === 'g') ? 'g' : (unitRaw === '颗' || unitRaw === '粒' || unitRaw === '片') ? 'capsule' : 'ml' } } return result }