Commit 03038b9a by 张立顺

feat: relax low-price minimum validation

1 parent e603820c
# 低价单客户档案导入与商品目录过滤设计
> 2026-08-13 更新:本文的“商品目录过滤”与逐商品最低价规则已被[低价单最低价格校验策略调整设计](./2026-08-13-low-price-minimum-validation-policy-design.md)替代;“客户档案导入”设计仍然有效。
## 目标
在低价单创建页补充两项交互约束:从客户档案选择客户时只导入客户信息,不覆盖当前订单中的商品、套餐、支付和门店上下文;展示可选商品时,只展示已开启最低价格校验的商品,其中套餐必须保证每个子商品都已开启,多规格商品按 SKU 分别过滤。
......
......@@ -74,7 +74,6 @@ import {
POSITION_BUCKET_DATA_KEYS
} from './services/selectOrderCatalogClassification'
import { preprocessSelectOrderCatalogItem } from './services/selectOrderCatalogPreprocess'
import { filterLowPriceSelectOrderCatalog } from './services/lowPriceCatalogFilter.helpers.js'
import {
mergeSubOrderListForEcho,
findCatalogSingleGoodsItem,
......@@ -83,8 +82,9 @@ import {
} from './services/goodsChooseEcho.helpers.js'
import { isMarketingGoodsPriceLocked } from './services/goodsPriceEdit.helpers.js'
import {
applyLowPriceGoodsPresentation,
LOW_PRICE_NOT_TRIGGERED_MESSAGE,
applyLowPriceGoodsValidation
validateLowPriceGoodsList
} from './services/lowPriceGoodsValidation.helpers.js'
import {
ensureCatalogUpgradePrice,
......@@ -1027,21 +1027,13 @@ Page({
const selectedGoodsList = Array.isArray(e?.detail)
? e.detail
: this.data.goodsList
this.applyLowPriceGoodsRules(selectedGoodsList)
if (this.isLowPriceOrder()) {
applyLowPriceGoodsPresentation(selectedGoodsList)
}
},
isLowPriceOrder() {
return Number(this.data.orderObj?.lowPriceFlag) === 1
},
applyLowPriceGoodsRules(goodsList = this.data.goodsList, options = {}) {
if (!this.isLowPriceOrder()) {
return { valid: true, invalidGoods: [], entries: [] }
}
const result = applyLowPriceGoodsValidation(goodsList)
if (options.notify && result.entries.length && !result.valid) {
wx.$util.showToast(LOW_PRICE_NOT_TRIGGERED_MESSAGE)
}
return result
},
//修改套餐价格
changeMealPrice(e) {
console.log(e)
......@@ -1102,7 +1094,6 @@ Page({
strategy.updateSubItemPrice(gindex, number)
this.setGoodsTotal(goodsList)
this.applyLowPriceGoodsRules(goodsList, { notify: true })
}
return number
},
......@@ -1155,7 +1146,6 @@ Page({
strategy.setBasePrice(number)
}
this.setGoodsTotal(goodsList)
this.applyLowPriceGoodsRules(goodsList, { notify: true })
}
return number
},
......@@ -1215,7 +1205,6 @@ Page({
if (!strategy) return
if (this.isLowPriceOrder()) {
this.applyLowPriceGoodsRules(goodsList)
this.setGoodsTotal(goodsList)
return
}
......@@ -1265,7 +1254,7 @@ Page({
},
setGoodsTotal(goodsList) {
if (this.isLowPriceOrder()) {
applyLowPriceGoodsValidation(goodsList)
applyLowPriceGoodsPresentation(goodsList)
}
let total = 0
goodsList.forEach(item => {
......@@ -1348,9 +1337,8 @@ Page({
checkGoods(save, subOrderList, priceDisabled, goodsList, orderObj) {
if (save) return false
if (Number(orderObj?.lowPriceFlag) === 1) {
const lowPriceValidation = applyLowPriceGoodsValidation(goodsList)
const lowPriceValidation = validateLowPriceGoodsList(goodsList)
if (!lowPriceValidation.valid) {
this.setData({ goodsList })
return LOW_PRICE_NOT_TRIGGERED_MESSAGE
}
}
......@@ -1580,7 +1568,7 @@ Page({
}
}
if (errTargetNum) {
if (Number(orderObj?.lowPriceFlag) !== 1 && errTargetNum) {
return '商品不能低于最低价格'
}
},
......@@ -2054,10 +2042,7 @@ Page({
normalizeMarketingMetaOnItem(val)
preprocessSelectOrderCatalogItem(val)
})
const catalogData = filterLowPriceSelectOrderCatalog(
rawCatalogData,
orderObj?.lowPriceFlag
)
const catalogData = rawCatalogData
const classified = classifySelectOrderCatalog(catalogData, {
subOrderList
})
......
/**
* @file 低价单可选商品目录过滤。
*/
import { SELECT_ORDER_GOODS_FLAG } from './selectOrderCatalogClassification.js'
function hasMinPriceValidation(goods) {
return goods?.validMinSellPrice === 'Y'
}
function filterSpecificationGoodsMap(specificationGoodsMap) {
return Object.entries(specificationGoodsMap).reduce(
(filteredMap, [specificationKey, goodsList]) => {
const enabledGoodsList = Array.isArray(goodsList)
? goodsList.filter(hasMinPriceValidation)
: []
if (enabledGoodsList.length) {
filteredMap[specificationKey] = enabledGoodsList
}
return filteredMap
},
{},
)
}
function filterSpecificationList(specificationList, specificationKeys) {
if (!Array.isArray(specificationList)) return specificationList
const allowedValuesByIndex = specificationKeys.reduce(
(allowedValues, specificationKey) => {
specificationKey.split(';~;').forEach((value, index) => {
if (!allowedValues[index]) allowedValues[index] = new Set()
allowedValues[index].add(value)
})
return allowedValues
},
[],
)
return specificationList.map((specification, index) => {
const allowedValues = allowedValuesByIndex[index] || new Set()
const filteredSpecification = { ...specification }
if (Array.isArray(specification.specificationSelectValueList)) {
filteredSpecification.specificationSelectValueList =
specification.specificationSelectValueList.filter((value) =>
allowedValues.has(value),
)
}
if (Array.isArray(specification.specificationValueList)) {
filteredSpecification.specificationValueList =
specification.specificationValueList.filter((value) =>
allowedValues.has(value?.specificationValue),
)
}
return filteredSpecification
})
}
/**
* 低价单只展示已开启最低价格校验的商品。
* @param {Array<object>} items
* @param {number|string} lowPriceFlag
* @returns {Array<object>}
*/
export function filterLowPriceSelectOrderCatalog(items, lowPriceFlag) {
const list = Array.isArray(items) ? items : []
if (Number(lowPriceFlag) !== 1) return list
return list.reduce((result, item) => {
if (item?.goodsFlag == SELECT_ORDER_GOODS_FLAG.SINGLE) {
if (hasMinPriceValidation(item.goods)) result.push(item)
return result
}
if (item?.goodsFlag == SELECT_ORDER_GOODS_FLAG.MULTI_SPEC) {
const root = item.multipleSpecificationsGoods
const skuGoodsList = Array.isArray(root?.skuGoodsList)
? root.skuGoodsList.filter(hasMinPriceValidation)
: []
const hasSpecificationGoodsMap =
root?.specificationGoodsMap &&
typeof root.specificationGoodsMap === 'object' &&
!Array.isArray(root.specificationGoodsMap)
const specificationGoodsMap = hasSpecificationGoodsMap
? filterSpecificationGoodsMap(root.specificationGoodsMap)
: undefined
const specificationKeys = specificationGoodsMap
? Object.keys(specificationGoodsMap)
: []
const hasSelectableSku = hasSpecificationGoodsMap
? specificationKeys.length > 0
: skuGoodsList.length > 0
if (hasSelectableSku) {
result.push({
...item,
multipleSpecificationsGoods: {
...root,
skuGoodsList,
...(hasSpecificationGoodsMap
? {
specificationGoodsMap,
specificationList: filterSpecificationList(
root.specificationList,
specificationKeys,
),
}
: {}),
},
})
}
return result
}
if (item?.goodsFlag == SELECT_ORDER_GOODS_FLAG.PACKAGE) {
const goodsList = item.packageGoods?.goodsList
if (
Array.isArray(goodsList) &&
goodsList.length > 0 &&
goodsList.every(hasMinPriceValidation)
) {
result.push(item)
}
}
return result
}, [])
}
......@@ -74,35 +74,41 @@ export function validateLowPriceGoods(goods = {}) {
/**
* @param {Array<object>} goodsList
* @returns {{valid:boolean, invalidGoods:Array<object>, entries:Array<object>}}
* @returns {{valid:boolean, matchedGoods:Array<object>, invalidGoods:Array<object>, entries:Array<object>}}
*/
export function validateLowPriceGoodsList(goodsList = []) {
const entries = resolveLowPriceGoodsEntries(goodsList)
const invalidGoods = entries.filter(goods => !validateLowPriceGoods(goods).valid)
const matchedGoods = []
const invalidGoods = []
entries.forEach(goods => {
if (validateLowPriceGoods(goods).valid) {
matchedGoods.push(goods)
} else {
invalidGoods.push(goods)
}
})
return {
valid: invalidGoods.length === 0,
valid: matchedGoods.length > 0,
matchedGoods,
invalidGoods,
entries
}
}
/**
* 同步商品行最低价文案和低价单错误态。
* 仅应由 lowPriceFlag=1 的页面分支调用。
* 同步商品行最低价提示文案,不执行资格校验,也不改变输入错误态。
* @param {Array<object>} goodsList
* @returns {{valid:boolean, invalidGoods:Array<object>, entries:Array<object>}}
* @returns {Array<object>}
*/
export function applyLowPriceGoodsValidation(goodsList = []) {
const result = validateLowPriceGoodsList(goodsList)
result.entries.forEach(goods => {
const validation = validateLowPriceGoods(goods)
export function applyLowPriceGoodsPresentation(goodsList = []) {
const entries = resolveLowPriceGoodsEntries(goodsList)
entries.forEach(goods => {
const enabled = goods?.validMinSellPrice === 'Y'
const minPrice = toFiniteNumber(goods?.minSellPrice)
goods.lowPriceMinPriceText =
validation.enabled && validation.minPrice !== null
? `最低价:¥${validation.minPrice}`
enabled && minPrice !== null
? `最低价:¥${minPrice}`
: '最低价:未开启'
goods.errorTarget = !validation.valid
goods.checkError = !validation.valid
goods.basePriceError = !validation.valid
})
return result
return entries
}
import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import { describe, it } from 'node:test'
import { filterLowPriceSelectOrderCatalog } from '../services/lowPriceCatalogFilter.helpers.js'
const helperSource = readFileSync(
new URL('../services/lowPriceCatalogFilter.helpers.js', import.meta.url),
'utf8',
)
function single(testId, validMinSellPrice) {
return {
testId,
goodsFlag: 1,
goods: { validMinSellPrice },
}
}
function multi(testId, skuGoodsList, extra = {}) {
return {
testId,
goodsFlag: 2,
multipleSpecificationsGoods: { skuGoodsList, ...extra },
}
}
function packageItem(testId, goodsList) {
return {
testId,
goodsFlag: 3,
packageGoods: { goodsList },
}
}
describe('filterLowPriceSelectOrderCatalog', () => {
it('avoids logical assignment syntax unsupported by the mini-program loader', () => {
assert.doesNotMatch(helperSource, /\?\?=/)
})
it('keeps only single goods with minimum-price validation enabled', () => {
const enabled = single('enabled', 'Y')
const disabled = single('disabled', 'N')
const missing = single('missing')
assert.deepEqual(
filterLowPriceSelectOrderCatalog([enabled, disabled, missing], 1),
[enabled],
)
})
it('keeps only enabled SKUs without mutating the original multi-spec item', () => {
const enabledSku = { id: 'sku-enabled', validMinSellPrice: 'Y' }
const disabledSku = { id: 'sku-disabled', validMinSellPrice: 'N' }
const item = multi('mixed-multi', [enabledSku, disabledSku], {
specificationGoodsMap: {
red: [enabledSku],
blue: [disabledSku],
mixed: [enabledSku, disabledSku],
},
specificationList: [
{
specificationSelectValueList: ['red', 'blue'],
specificationValueList: [
{ show: true, specificationValue: 'red' },
{ show: true, specificationValue: 'blue' },
],
},
],
})
const [filtered] = filterLowPriceSelectOrderCatalog([item], '1')
assert.notEqual(filtered, item)
assert.notEqual(
filtered.multipleSpecificationsGoods,
item.multipleSpecificationsGoods,
)
assert.deepEqual(
filtered.multipleSpecificationsGoods.skuGoodsList.map((sku) => sku.id),
['sku-enabled'],
)
assert.deepEqual(
Object.keys(filtered.multipleSpecificationsGoods.specificationGoodsMap),
['red', 'mixed'],
)
assert.deepEqual(
filtered.multipleSpecificationsGoods.specificationGoodsMap.mixed.map(
(sku) => sku.id,
),
['sku-enabled'],
)
assert.deepEqual(
filtered.multipleSpecificationsGoods.specificationList[0]
.specificationSelectValueList,
['red'],
)
assert.equal(item.multipleSpecificationsGoods.skuGoodsList.length, 2)
assert.equal(
item.multipleSpecificationsGoods.specificationGoodsMap.blue.length,
1,
)
assert.deepEqual(
item.multipleSpecificationsGoods.specificationList[0]
.specificationSelectValueList,
['red', 'blue'],
)
})
it('uses the specification map as the selectable SKU source', () => {
const enabledSku = { id: 'map-enabled', validMinSellPrice: 'Y' }
const enabled = multi('map-enabled-multi', [], {
specificationGoodsMap: { red: [enabledSku] },
})
const disabled = multi('map-disabled-multi', [enabledSku], {
specificationGoodsMap: {
blue: [{ id: 'map-disabled', validMinSellPrice: 'N' }],
},
})
const filtered = filterLowPriceSelectOrderCatalog([enabled, disabled], 1)
assert.deepEqual(
filtered.map((item) => item.testId),
['map-enabled-multi'],
)
assert.equal(
filtered[0].multipleSpecificationsGoods.specificationGoodsMap.red[0].id,
'map-enabled',
)
})
it('hides a multi-spec item when no enabled SKU remains', () => {
const item = multi('disabled-multi', [
{ id: 'sku-disabled', validMinSellPrice: 'N' },
{ id: 'sku-missing' },
])
assert.deepEqual(filterLowPriceSelectOrderCatalog([item], 1), [])
})
it('keeps a package only when its non-empty child list is fully enabled', () => {
const allEnabled = packageItem('enabled-package', [
{ validMinSellPrice: 'Y' },
{ validMinSellPrice: 'Y' },
])
const mixed = packageItem('mixed-package', [
{ validMinSellPrice: 'Y' },
{ validMinSellPrice: 'N' },
])
const missing = packageItem('missing-package', [
{ validMinSellPrice: 'Y' },
{},
])
const empty = packageItem('empty-package', [])
assert.deepEqual(
filterLowPriceSelectOrderCatalog([allEnabled, mixed, missing, empty], 1),
[allEnabled],
)
})
it('keeps the complete original catalog for normal orders', () => {
const fullCatalog = [
single('disabled-single', 'N'),
multi('disabled-multi', [{ validMinSellPrice: 'N' }]),
packageItem('mixed-package', [
{ validMinSellPrice: 'Y' },
{ validMinSellPrice: 'N' },
]),
{ testId: 'unknown', goodsFlag: 99 },
]
assert.equal(filterLowPriceSelectOrderCatalog(fullCatalog, 0), fullCatalog)
})
it('treats invalid low-price input and unknown goods types as hidden', () => {
assert.deepEqual(filterLowPriceSelectOrderCatalog(null, 1), [])
assert.deepEqual(
filterLowPriceSelectOrderCatalog([{ goodsFlag: 99 }], 1),
[],
)
})
})
......@@ -144,42 +144,43 @@ async function loadCatalog(
return page
}
describe('createOrder low-price catalog filtering', () => {
it('filters low-price catalog before page classification', async () => {
describe('createOrder low-price catalog display', () => {
it('keeps the full catalog for low-price orders', async () => {
const pageConfig = await loadPageConfig()
const page = await loadCatalog(pageConfig, 1)
assert.deepEqual(
page.data.goodsData.map((item) => item.testId),
['enabled-single', 'mixed-multi'],
['enabled-single', 'disabled-single', 'mixed-multi', 'mixed-package'],
)
assert.deepEqual(
page.data.goodsData[1].multipleSpecificationsGoods.skuGoodsList.map(
page.data.goodsData[2].multipleSpecificationsGoods.skuGoodsList.map(
(item) => item.id,
),
['sku-enabled'],
['sku-enabled', 'sku-disabled'],
)
assert.deepEqual(
Object.keys(
page.data.goodsData[1].multipleSpecificationsGoods
page.data.goodsData[2].multipleSpecificationsGoods
.specificationGoodsMap,
),
['red'],
['red', 'blue'],
)
assert.deepEqual(
page.data.goodsData[1].multipleSpecificationsGoods.specificationGoodsMap.red.map(
page.data.goodsData[2].multipleSpecificationsGoods.specificationGoodsMap.blue.map(
(item) => item.id,
),
['sku-enabled'],
['sku-disabled'],
)
assert.deepEqual(
page.data.goodsData[1].multipleSpecificationsGoods.specificationList[0]
page.data.goodsData[2].multipleSpecificationsGoods.specificationList[0]
.specificationSelectValueList,
['red'],
['red', 'blue'],
)
assert.equal(page.data.frontGearArr.length, 1)
assert.equal(page.data.sideBeforeRearGearArr.length, 1)
assert.equal(page.data.otherProduct.length, 1)
assert.equal(page.data.packageList.length, 0)
assert.equal(page.data.packageList.length, 1)
})
it('keeps the full catalog for normal orders', async () => {
......
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import {
applyLowPriceGoodsPresentation,
LOW_PRICE_NOT_TRIGGERED_MESSAGE,
resolveLowPriceGoodsEntries,
validateLowPriceGoods,
validateLowPriceGoodsList,
applyLowPriceGoodsValidation
validateLowPriceGoodsList
} from '../services/lowPriceGoodsValidation.helpers.js'
describe('lowPriceGoodsValidation.helpers', () => {
......@@ -90,7 +90,7 @@ describe('lowPriceGoodsValidation.helpers', () => {
)
})
it('IT-WO-LPG-005: whole-order validation fails when any leaf does not trigger minimum price', () => {
it('IT-WO-LPG-005: whole-order validation passes when any leaf triggers minimum price', () => {
const result = validateLowPriceGoodsList([
{
goodsFlag: 1,
......@@ -114,44 +114,78 @@ describe('lowPriceGoodsValidation.helpers', () => {
}
])
assert.equal(result.valid, false)
assert.equal(result.valid, true)
assert.equal(result.matchedGoods.length, 1)
assert.equal(result.invalidGoods.length, 1)
})
it('IT-WO-LPG-006: applies minimum-price echo and clears stale normal-order errors for valid low-price goods', () => {
const valid = {
validMinSellPrice: 'Y',
minSellPrice: 100,
sellPrice: 80,
errorTarget: true,
checkError: true,
basePriceError: true
}
const disabled = {
validMinSellPrice: 'N',
minSellPrice: 60,
sellPrice: 30
}
const goodsList = [
{ goodsFlag: 1, goods: valid },
{ goodsFlag: 1, goods: disabled }
]
it('IT-WO-LPG-006: whole-order validation fails when no leaf triggers minimum price', () => {
const result = validateLowPriceGoodsList([
{
goodsFlag: 1,
goods: {
validMinSellPrice: 'Y',
minSellPrice: 100,
sellPrice: 100
}
},
{
goodsFlag: 1,
goods: {
validMinSellPrice: 'N',
minSellPrice: 60,
sellPrice: 30
}
}
])
assert.equal(result.valid, false)
assert.deepEqual(result.matchedGoods, [])
assert.equal(result.invalidGoods.length, 2)
})
const result = applyLowPriceGoodsValidation(goodsList)
it('IT-WO-LPG-007: empty goods cannot satisfy whole-order minimum price', () => {
const result = validateLowPriceGoodsList([])
assert.equal(result.valid, false)
assert.equal(valid.lowPriceMinPriceText, '最低价:¥100')
assert.equal(valid.errorTarget, false)
assert.equal(valid.checkError, false)
assert.equal(valid.basePriceError, false)
assert.equal(disabled.lowPriceMinPriceText, '最低价:未开启')
assert.equal(disabled.errorTarget, true)
assert.deepEqual(result.matchedGoods, [])
assert.deepEqual(result.invalidGoods, [])
})
it('IT-WO-LPG-007: exposes the required reminder copy', () => {
it('IT-WO-LPG-008: exposes the required reminder copy', () => {
assert.equal(
LOW_PRICE_NOT_TRIGGERED_MESSAGE,
'价格未触发最低价,其他正常单请到生意助手侧录单'
)
})
it('IT-WO-LPG-009: presentation text never creates or changes input errors', () => {
const enabled = {
validMinSellPrice: 'Y',
minSellPrice: 100,
sellPrice: 120
}
const disabled = {
validMinSellPrice: 'N',
minSellPrice: 80,
sellPrice: 20,
errorTarget: false,
checkError: false,
basePriceError: false
}
applyLowPriceGoodsPresentation([
{ goodsFlag: 1, goods: enabled },
{ goodsFlag: 1, goods: disabled }
])
assert.equal(enabled.lowPriceMinPriceText, '最低价:¥100')
assert.equal(disabled.lowPriceMinPriceText, '最低价:未开启')
assert.equal(Object.hasOwn(enabled, 'errorTarget'), false)
assert.equal(Object.hasOwn(enabled, 'checkError'), false)
assert.equal(Object.hasOwn(enabled, 'basePriceError'), false)
assert.equal(disabled.errorTarget, false)
assert.equal(disabled.checkError, false)
assert.equal(disabled.basePriceError, false)
})
})
......@@ -12,149 +12,243 @@ const pageSource = readFileSync(
new URL('../createOrder.js', import.meta.url),
'utf8'
)
const pageTemplate = readFileSync(
new URL('../createOrder.wxml', import.meta.url),
'utf8'
)
const rowComponentSource = readFileSync(
new URL('../components/OrderGoodsRow/order-goods-row.js', import.meta.url),
'utf8'
)
const rowComponentTemplate = readFileSync(
new URL('../components/OrderGoodsRow/order-goods-row.wxml', import.meta.url),
'utf8'
)
const chooseGoodsStart = pageSource.indexOf(' chooseGoods(e) {')
const chooseGoodsEnd = pageSource.indexOf('\n isLowPriceOrder()', chooseGoodsStart)
const chooseGoodsSource = pageSource.slice(chooseGoodsStart, chooseGoodsEnd)
function methodSource(name, nextName) {
const start = pageSource.indexOf(` ${name}(`)
const end = pageSource.indexOf(`\n ${nextName}(`, start)
return pageSource.slice(start, end)
}
const chooseGoodsSource = methodSource('chooseGoods', 'isLowPriceOrder')
const changeMealPriceSource = methodSource('changeMealPrice', 'changePrice')
const changePriceSource = methodSource('changePrice', 'showMinPriceApprovalPopup')
const priceBlurSource = methodSource('priceBlur', 'setGoodsTotal')
const setGoodsTotalSource = methodSource('setGoodsTotal', 'delGoodsList')
async function loadPageConfig(toastMessages) {
let pageConfig
globalThis.getApp = () => ({ globalData: {} })
globalThis.Page = config => {
pageConfig = config
}
globalThis.wx = {
getAccountInfoSync: () => ({
miniProgram: { appId: 'test-app-id', envVersion: 'develop' }
}),
getSystemInfoSync: () => ({ platform: 'devtools' }),
getStorageSync: () => '',
$util: {
decimal: value => Number(value),
getUserInfo: () => ({}),
removeLeadingZerosAndEnsureNonNegative: value => Number(value),
showToast: message => toastMessages.push(message)
}
}
await import(`../createOrder.js?low-price-goods=${Date.now()}-${Math.random()}`)
return pageConfig
}
function createPage(pageConfig, goodsList) {
return {
...pageConfig,
data: {
...pageConfig.data,
orderObj: {
...pageConfig.data.orderObj,
lowPriceFlag: 1,
djOrderType: 1,
selectPayType: 1,
subOrderList: []
},
goodsList
},
setData(patch) {
Object.assign(this.data, patch)
}
}
}
describe('createOrder low-price goods integration', () => {
it('IT-WO-LPG-008: selection only syncs state while live price input enables the reminder', () => {
assert.match(
pageSource,
/LOW_PRICE_NOT_TRIGGERED_MESSAGE[\s\S]*applyLowPriceGoodsValidation/
)
assert.match(
pageSource,
/Number\(this\.data\.orderObj\?\.lowPriceFlag\) === 1/
)
assert.match(chooseGoodsSource, /applyLowPriceGoodsRules\(selectedGoodsList\)/)
assert.doesNotMatch(chooseGoodsSource, /notify:\s*true/)
assert.match(
pageSource,
/changeMealPrice\(e\)[\s\S]*applyLowPriceGoodsRules\(goodsList,\s*\{\s*notify:\s*true\s*\}\)/
)
assert.match(
pageSource,
/changePrice\(e\)[\s\S]*applyLowPriceGoodsRules\(goodsList,\s*\{\s*notify:\s*true\s*\}\)/
)
assert.match(
pageSource,
/wx\.\$util\.showToast\(LOW_PRICE_NOT_TRIGGERED_MESSAGE\)/
)
it('IT-WO-LPG-009: selection and price interactions do not validate minimum price', () => {
for (const source of [
chooseGoodsSource,
changeMealPriceSource,
changePriceSource,
priceBlurSource,
setGoodsTotalSource
]) {
assert.doesNotMatch(
source,
/validateLowPriceGoodsList|applyLowPriceGoodsValidation|LOW_PRICE_NOT_TRIGGERED_MESSAGE/
)
}
})
it('IT-WO-LPG-009: revalidates the full goods list before building the submit payload', () => {
it('IT-WO-LPG-010: submission is the only low-price eligibility gate', () => {
assert.match(
pageSource,
/checkGoods\(save, subOrderList, priceDisabled, goodsList, orderObj\)[\s\S]*Number\(orderObj\?\.lowPriceFlag\) === 1[\s\S]*applyLowPriceGoodsValidation\(goodsList\)[\s\S]*LOW_PRICE_NOT_TRIGGERED_MESSAGE/
/checkGoods\(save, subOrderList, priceDisabled, goodsList, orderObj\)[\s\S]*Number\(orderObj\?\.lowPriceFlag\) === 1[\s\S]*validateLowPriceGoodsList\(goodsList\)[\s\S]*LOW_PRICE_NOT_TRIGGERED_MESSAGE/
)
})
it('IT-WO-LPG-010: passes lowPriceFlag to every selected-goods row and renders the minimum-price echo only for low-price orders', () => {
const rowTags = [
...pageTemplate.matchAll(/<order-goods-row[\s\S]*?\/>/g)
].map(match => match[0])
assert.ok(rowTags.length > 0)
rowTags.forEach(tag => {
assert.match(tag, /lowPriceFlag="\{\{ orderObj\.lowPriceFlag \}\}"/)
})
assert.match(rowComponentSource, /lowPriceFlag:\s*\{[\s\S]*type:\s*Number/)
assert.match(
rowComponentTemplate,
/class="low-price-minimum"\s+wx:if="\{\{ lowPriceFlag == 1 \}\}">\{\{product\.lowPriceMinPriceText\}\}/
)
})
it('IT-WO-LPG-011: selection stays silent, live input warns, and submit blocks invalid low-price goods', async () => {
let pageConfig
it('IT-WO-LPG-011: price input stays silent and mixed qualifying goods submit', async () => {
const toastMessages = []
globalThis.getApp = () => ({ globalData: {} })
globalThis.Page = config => {
pageConfig = config
}
globalThis.wx = {
getAccountInfoSync: () => ({
miniProgram: { appId: 'test-app-id', envVersion: 'develop' }
}),
getSystemInfoSync: () => ({ platform: 'devtools' }),
getStorageSync: () => '',
$util: {
getUserInfo: () => ({}),
showToast: message => toastMessages.push(message)
}
const pageConfig = await loadPageConfig(toastMessages)
const qualifying = {
validMinSellPrice: 'Y',
minSellPrice: 100,
sellPrice: 80
}
await import(`../createOrder.js?low-price-goods=${Date.now()}`)
const lowPriceGoods = {
const disabled = {
validMinSellPrice: 'N',
minSellPrice: 100,
sellPrice: 80
}
const lowPriceGoodsList = [{ goodsFlag: 1, goods: lowPriceGoods }]
const lowPricePage = {
...pageConfig,
data: {
orderObj: { lowPriceFlag: 1 },
goodsList: lowPriceGoodsList
},
setData(patch) {
Object.assign(this.data, patch)
}
}
const goodsList = [
{ goodsFlag: 1, count: 1, goods: qualifying },
{ goodsFlag: 1, count: 1, goods: disabled }
]
const page = createPage(pageConfig, goodsList)
lowPricePage.chooseGoods({ detail: lowPriceGoodsList })
assert.equal(lowPriceGoods.lowPriceMinPriceText, '最低价:未开启')
assert.deepEqual(toastMessages, [])
pageConfig.chooseGoods.call(page, { detail: goodsList })
pageConfig.changePrice.call(page, {
detail: { index: 1, value: '70' }
})
pageConfig.priceBlur.call(page, {
detail: { index: 1 }
})
const liveResult = lowPricePage.applyLowPriceGoodsRules(
lowPriceGoodsList,
{ notify: true }
)
const submitMessage = lowPricePage.checkGoods(
const submitMessage = pageConfig.checkGoods.call(
page,
false,
[],
true,
lowPriceGoodsList,
lowPricePage.data.orderObj
goodsList,
page.data.orderObj
)
assert.equal(liveResult.valid, false)
assert.equal(lowPriceGoods.errorTarget, true)
assert.deepEqual(toastMessages, [
'价格未触发最低价,其他正常单请到生意助手侧录单'
])
assert.deepEqual(toastMessages, [])
assert.notEqual(disabled.errorTarget, true)
assert.notEqual(disabled.checkError, true)
assert.notEqual(disabled.basePriceError, true)
assert.equal(submitMessage, undefined)
})
it('IT-WO-LPG-012: submission blocks only when no goods triggers minimum price', async () => {
const toastMessages = []
const pageConfig = await loadPageConfig(toastMessages)
const goodsList = [
{
goodsFlag: 1,
count: 1,
goods: {
validMinSellPrice: 'Y',
minSellPrice: 100,
sellPrice: 100
}
},
{
goodsFlag: 1,
count: 1,
goods: {
validMinSellPrice: 'N',
minSellPrice: 100,
sellPrice: 50
}
}
]
const page = createPage(pageConfig, goodsList)
assert.equal(
submitMessage,
pageConfig.checkGoods.call(
page,
false,
[],
true,
goodsList,
page.data.orderObj
),
'价格未触发最低价,其他正常单请到生意助手侧录单'
)
})
const normalGoods = {
it('IT-WO-LPG-013: selected SKU or one package child can satisfy submission', async () => {
const toastMessages = []
const pageConfig = await loadPageConfig(toastMessages)
const qualifying = {
validMinSellPrice: 'Y',
minSellPrice: 100,
sellPrice: 80
}
const normalPage = {
...pageConfig,
data: {
orderObj: { lowPriceFlag: 0 },
goodsList: [{ goodsFlag: 1, goods: normalGoods }]
}
const invalid = {
validMinSellPrice: 'N',
minSellPrice: 100,
sellPrice: 50
}
assert.equal(normalPage.applyLowPriceGoodsRules().valid, true)
assert.equal(normalGoods.lowPriceMinPriceText, undefined)
const candidates = [
[
{
goodsFlag: 2,
count: 1,
multipleSpecificationsGoods: { goods: { ...qualifying } }
}
],
[
{
goodsFlag: 3,
count: 1,
packageGoods: {
packageCode: 'PACKAGE-1',
packageName: '测试套餐',
goodsList: [{ ...invalid }, { ...qualifying }]
}
}
]
]
candidates.forEach(goodsList => {
const page = createPage(pageConfig, goodsList)
assert.equal(
pageConfig.checkGoods.call(
page,
false,
[],
true,
goodsList,
page.data.orderObj
),
undefined
)
})
})
it('IT-WO-LPG-014: normal orders keep the existing minimum-price error gate', async () => {
const toastMessages = []
const pageConfig = await loadPageConfig(toastMessages)
const goodsList = [
{
goodsFlag: 1,
count: 1,
goods: {
sellPrice: 80,
errorTarget: true
}
}
]
const page = createPage(pageConfig, goodsList)
page.data.orderObj.lowPriceFlag = 0
assert.equal(
pageConfig.checkGoods.call(
page,
false,
[],
true,
goodsList,
page.data.orderObj
),
'商品不能低于最低价格'
)
})
})
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!