Commit f5abc05f by 张立顺

feat bug修复

1 parent 7c5c9602
...@@ -4,9 +4,9 @@ ...@@ -4,9 +4,9 @@
## 规模 ## 规模
- 节点:4246 - 节点:4249
- 关系:8119 - 关系:8121
- 未解析:89 - 未解析:90
## 节点类型 ## 节点类型
...@@ -18,10 +18,10 @@ ...@@ -18,10 +18,10 @@
| domain | 6 | | domain | 6 |
| endpoint | 234 | | endpoint | 234 |
| globalState | 32 | | globalState | 32 |
| method | 2929 | | method | 2931 |
| module | 365 | | module | 365 |
| page | 72 | | page | 72 |
| test | 80 | | test | 81 |
## 关系类型 ## 关系类型
...@@ -31,14 +31,14 @@ ...@@ -31,14 +31,14 @@
| calls | 885 | | calls | 885 |
| callsApi | 221 | | callsApi | 221 |
| callsEndpoint | 332 | | callsEndpoint | 332 |
| contains | 711 | | contains | 712 |
| coveredBy | 63 | | coveredBy | 63 |
| declares | 2930 | | declares | 2932 |
| definesApi | 332 | | definesApi | 332 |
| documentedBy | 60 | | documentedBy | 60 |
| imports | 437 | | imports | 437 |
| navigatesTo | 71 | | navigatesTo | 71 |
| readsState | 773 | | readsState | 772 |
| usesComponent | 314 | | usesComponent | 314 |
| writesState | 51 | | writesState | 51 |
......
...@@ -68,8 +68,8 @@ ...@@ -68,8 +68,8 @@
| `tabWorkOrder/pages/confirmOrder/confirmOrder.js` | `tabWorkOrder/pages/orderDetail/orderDetail` | `tabWorkOrder/pages/confirmOrder/confirmOrder.js:173` | | `tabWorkOrder/pages/confirmOrder/confirmOrder.js` | `tabWorkOrder/pages/orderDetail/orderDetail` | `tabWorkOrder/pages/confirmOrder/confirmOrder.js:173` |
| `tabWorkOrder/pages/confirmOrder/confirmOrder.js` | `tabWorkOrder/pages/orderDetail/orderDetail` | `tabWorkOrder/pages/confirmOrder/confirmOrder.js:259` | | `tabWorkOrder/pages/confirmOrder/confirmOrder.js` | `tabWorkOrder/pages/orderDetail/orderDetail` | `tabWorkOrder/pages/confirmOrder/confirmOrder.js:259` |
| `tabWorkOrder/pages/confirmOrder/confirmOrder.js` | `tabWorkOrder/pages/orderDetail/orderDetail` | `tabWorkOrder/pages/confirmOrder/confirmOrder.js:195` | | `tabWorkOrder/pages/confirmOrder/confirmOrder.js` | `tabWorkOrder/pages/orderDetail/orderDetail` | `tabWorkOrder/pages/confirmOrder/confirmOrder.js:195` |
| `tabWorkOrder/pages/createOrder/createOrder.js` | `pages/tab/workspace/workspace` | `tabWorkOrder/pages/createOrder/createOrder.js:2150` | | `tabWorkOrder/pages/createOrder/createOrder.js` | `pages/tab/workspace/workspace` | `tabWorkOrder/pages/createOrder/createOrder.js:2174` |
| `tabWorkOrder/pages/createOrder/createOrder.js` | `tabWorkOrder/pages/ocr/ocr` | `tabWorkOrder/pages/createOrder/createOrder.js:681` | | `tabWorkOrder/pages/createOrder/createOrder.js` | `tabWorkOrder/pages/ocr/ocr` | `tabWorkOrder/pages/createOrder/createOrder.js:682` |
| `tabWorkOrder/pages/createOrder/submitStrategy.js` | `tabWorkOrder/pages/confirmOrder/confirmOrder` | `tabWorkOrder/pages/createOrder/submitStrategy.js:352` | | `tabWorkOrder/pages/createOrder/submitStrategy.js` | `tabWorkOrder/pages/confirmOrder/confirmOrder` | `tabWorkOrder/pages/createOrder/submitStrategy.js:352` |
| `tabWorkOrder/pages/createOrder/submitStrategy.js` | `tabWorkOrder/pages/index/index` | `tabWorkOrder/pages/createOrder/submitStrategy.js:338` | | `tabWorkOrder/pages/createOrder/submitStrategy.js` | `tabWorkOrder/pages/index/index` | `tabWorkOrder/pages/createOrder/submitStrategy.js:338` |
| `tabWorkOrder/pages/index/index.js` | `tabWorkOrder/pages/createOrder/createOrder` | `tabWorkOrder/pages/index/index.js:731` | | `tabWorkOrder/pages/index/index.js` | `tabWorkOrder/pages/createOrder/createOrder` | `tabWorkOrder/pages/index/index.js:731` |
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
| component | 24 | | component | 24 |
| apiOperation | 79 | | apiOperation | 79 |
| globalState | 2 | | globalState | 2 |
| test | 35 | | test | 36 |
| document | 4 | | document | 4 |
## 可定位实体 ## 可定位实体
...@@ -155,6 +155,7 @@ ...@@ -155,6 +155,7 @@
| test | `tabWorkOrder/pages/createOrder/tests/goodsChooseEcho.helpers.test.mjs` | | test | `tabWorkOrder/pages/createOrder/tests/goodsChooseEcho.helpers.test.mjs` |
| test | `tabWorkOrder/pages/createOrder/tests/goodsPriceBoundary.helpers.test.mjs` | | test | `tabWorkOrder/pages/createOrder/tests/goodsPriceBoundary.helpers.test.mjs` |
| test | `tabWorkOrder/pages/createOrder/tests/goodsPriceBoundary.integration.test.mjs` | | test | `tabWorkOrder/pages/createOrder/tests/goodsPriceBoundary.integration.test.mjs` |
| test | `tabWorkOrder/pages/createOrder/tests/goodsPriceEcho.integration.test.mjs` |
| test | `tabWorkOrder/pages/createOrder/tests/goodsPriceEdit.helpers.test.mjs` | | test | `tabWorkOrder/pages/createOrder/tests/goodsPriceEdit.helpers.test.mjs` |
| test | `tabWorkOrder/pages/createOrder/tests/lowPriceCatalogFilter.integration.test.mjs` | | test | `tabWorkOrder/pages/createOrder/tests/lowPriceCatalogFilter.integration.test.mjs` |
| test | `tabWorkOrder/pages/createOrder/tests/lowPriceGoodsValidation.helpers.test.mjs` | | test | `tabWorkOrder/pages/createOrder/tests/lowPriceGoodsValidation.helpers.test.mjs` |
......
...@@ -212,7 +212,7 @@ flowchart TD ...@@ -212,7 +212,7 @@ flowchart TD
### 6.2 低价审批 ### 6.2 低价审批
`lowPriceFlag=1` 链路使用 [`lowPriceGoodsValidation.helpers.js`](../../tabWorkOrder/pages/createOrder/services/lowPriceGoodsValidation.helpers.js) 做整单资格校验,并用 `minPriceApproval.js` 按同一 `minSellPrice` 口径构建审批商品列表。校验通过后先展示审批确认弹层,用户确认后才请求下单接口;成功后返回低价单“待审批”页签。低价单页面订单类型固定显示为“低价订单”,底层继续提交 `djOrderType=1 + lowPriceFlag=1`;页面先准备 `100101/精品升级/1` 本地兜底,再允许最近场景或门店可用场景覆盖,提交与审批确认不再改写场景。商品价格小于 `0` 或大于 `100000` 元时阻止提交。 `lowPriceFlag=1` 链路使用 [`lowPriceGoodsValidation.helpers.js`](../../tabWorkOrder/pages/createOrder/services/lowPriceGoodsValidation.helpers.js) 做整单资格校验,并用 `minPriceApproval.js` 按同一 `minSellPrice` 口径构建审批商品列表。校验通过后先展示审批确认弹层,用户确认后才请求下单接口;成功后返回低价单“待审批”页签。低价单页面订单类型固定显示为“低价订单”,底层继续提交 `djOrderType=1 + lowPriceFlag=1`;页面先准备 `100101/精品升级/1` 本地兜底,再允许最近场景或门店可用场景覆盖,提交与审批确认不再改写场景。商品价格小于 `0`、保留两位小数后等于 `0`,或大于 `100000` 元时阻止提交;录入期间允许 `0`、`0.`、`0.0` 等草稿态,失焦和提交时执行最终非零校验;赠品折后价可以为 `0`,但其可编辑原价仍须大于 `0`。
## 7. 支付确认 ## 7. 支付确认
......
...@@ -108,7 +108,7 @@ flowchart TD ...@@ -108,7 +108,7 @@ flowchart TD
- 等于/高于最低价、未开启、缺少最低价或价格为空都统一提示“价格未触发最低价,其他正常单请到生意助手侧录单”; - 等于/高于最低价、未开启、缺少最低价或价格为空都统一提示“价格未触发最低价,其他正常单请到生意助手侧录单”;
- 商品行回显“最低价:¥金额”,未开启时显示“最低价:未开启”; - 商品行回显“最低价:¥金额”,未开启时显示“最低价:未开启”;
- 输入和失焦不执行最低价资格校验;提交时复核并展示审批确认弹层,确认成功后返回低价单“待审批”列表; - 输入和失焦不执行最低价资格校验;提交时复核并展示审批确认弹层,确认成功后返回低价单“待审批”列表;
- 商品价格小于 `0` 或大于 `100000` 元时明确拒绝,普通工单原最低价逻辑不变。 - 商品价格小于 `0`、保留两位小数后等于 `0`,或大于 `100000` 元时明确拒绝;输入过程中允许 `0`、`0.`、`0.0` 等草稿态以便继续录入 `0.01`,失焦和提交时再严格拒绝最终为 `0` 的价格;赠品仅折后价为 `0` 且可编辑原价大于 `0` 时不受影响,普通工单原最低价逻辑不变。
--- ---
......
...@@ -83,6 +83,7 @@ import { preprocessSelectOrderCatalogItem } from './services/selectOrderCatalogP ...@@ -83,6 +83,7 @@ import { preprocessSelectOrderCatalogItem } from './services/selectOrderCatalogP
import { import {
mergeSubOrderListForEcho, mergeSubOrderListForEcho,
findCatalogSingleGoodsItem, findCatalogSingleGoodsItem,
normalizeOrderMoney,
resolveSubOrderUnitPrice, resolveSubOrderUnitPrice,
applySubOrderDiscountEcho, applySubOrderDiscountEcho,
isMultiSpecSubOrderLine isMultiSpecSubOrderLine
...@@ -1122,7 +1123,9 @@ Page({ ...@@ -1122,7 +1123,9 @@ Page({
const subItem = strategy?.getSubItemData?.(gindex) const subItem = strategy?.getSubItemData?.(gindex)
let number let number
if (this.isLowPriceOrder()) { if (this.isLowPriceOrder()) {
const priceValidation = validateGoodsPriceInput(value) const priceValidation = validateGoodsPriceInput(value, {
allowZeroDraft: true
})
if (!priceValidation.valid) { if (!priceValidation.valid) {
if (subItem) subItem.priceBoundaryError = priceValidation.message if (subItem) subItem.priceBoundaryError = priceValidation.message
this.setData({ goodsList }) this.setData({ goodsList })
...@@ -1201,7 +1204,9 @@ Page({ ...@@ -1201,7 +1204,9 @@ Page({
const data = strategy.getData() const data = strategy.getData()
let number let number
if (this.isLowPriceOrder()) { if (this.isLowPriceOrder()) {
const priceValidation = validateGoodsPriceInput(value) const priceValidation = validateGoodsPriceInput(value, {
allowZeroDraft: true
})
if (!priceValidation.valid) { if (!priceValidation.valid) {
data.priceBoundaryError = priceValidation.message data.priceBoundaryError = priceValidation.message
this.setData({ goodsList }) this.setData({ goodsList })
...@@ -1300,7 +1305,26 @@ Page({ ...@@ -1300,7 +1305,26 @@ Page({
if (!strategy) return if (!strategy) return
if (this.isLowPriceOrder()) { if (this.isLowPriceOrder()) {
const isPackageSubItem =
Number.isInteger(gindex) &&
gindex >= 0 &&
typeof strategy.getSubItemData === 'function'
const target = isPackageSubItem
? strategy.getSubItemData(gindex)
: strategy.getData()
const rawPrice = isPackageSubItem
? target?.basePrice ?? target?.sellPrice ?? target?.price
: strategy.getBasePrice()
const priceValidation = validateGoodsPriceInput(rawPrice)
if (target) {
target.priceBoundaryError = priceValidation.valid
? ''
: priceValidation.message
}
this.setGoodsTotal(goodsList) this.setGoodsTotal(goodsList)
if (!priceValidation.valid) {
wx.$util.showToast(priceValidation.message)
}
return return
} }
...@@ -2423,13 +2447,14 @@ Page({ ...@@ -2423,13 +2447,14 @@ Page({
e.price = unitPrice e.price = unitPrice
e.sellPrice = unitPrice e.sellPrice = unitPrice
} }
} else if (!e.price) { } else {
const unitPrice = resolveSubOrderUnitPrice( const unitPrice = resolveSubOrderUnitPrice(
e, e,
false, false
(n, d) => wx.$util.decimal(n, d)
) )
e.price = unitPrice if (unitPrice != null && unitPrice !== '') {
e.price = unitPrice
}
} }
e.sellPrice = e.price e.sellPrice = e.price
e.goodsId = e.merchantGoodsId e.goodsId = e.merchantGoodsId
...@@ -2547,28 +2572,26 @@ Page({ ...@@ -2547,28 +2572,26 @@ Page({
if (orderObj.resetOrder) g.resetOrder = true if (orderObj.resetOrder) g.resetOrder = true
if (orderObj.resetOrder) { if (orderObj.resetOrder) {
// 再次编辑优先使用订单回显单价,避免被 originalPrice(目录原价)覆盖 // 再次编辑优先使用订单回显单价,避免被 originalPrice(目录原价)覆盖
const count = Number(g.number) || 1 const unitPrice = resolveSubOrderUnitPrice(g, true)
const unitPrice =
g.sellPrice || g.sellPrice === 0
? g.sellPrice
: g.totalPrice || g.totalPrice === 0
? Number(g.totalPrice) / count
: undefined
if (unitPrice != null && unitPrice !== '') { if (unitPrice != null && unitPrice !== '') {
g.price = unitPrice g.price = unitPrice
g.sellPrice = unitPrice g.sellPrice = unitPrice
} }
} else { } else {
const priceFromTotal = const priceFromTotal = resolveSubOrderUnitPrice(
g.totalPrice || g.totalPrice === 0 {
? Number(g.totalPrice) / Number(g.number) totalPrice: g.totalPrice,
: undefined number: g.number
},
false
)
const echoedSellPrice = normalizeOrderMoney(g.sellPrice)
g.sellPrice = g.sellPrice =
g.sellPrice || g.sellPrice === 0 echoedSellPrice !== undefined
? g.sellPrice ? echoedSellPrice
: priceFromTotal !== undefined : priceFromTotal !== undefined
? priceFromTotal ? priceFromTotal
: g.upgradePrice : normalizeOrderMoney(g.upgradePrice)
g.price = g.price =
priceFromTotal !== undefined ? priceFromTotal : g.sellPrice priceFromTotal !== undefined ? priceFromTotal : g.sellPrice
} }
...@@ -2606,16 +2629,23 @@ Page({ ...@@ -2606,16 +2629,23 @@ Page({
}) })
e.goodsList = e.packageGoodsOrderList e.goodsList = e.packageGoodsOrderList
e.upgradePrice = e.goodsList.reduce((prev, cur) => { e.upgradePrice = e.goodsList.reduce((prev, cur) => {
return prev + cur.sellPrice return NP.plus(prev, Number(cur.sellPrice || 0))
}, 0) }, 0)
e.count = e.goodsList.length ? e.goodsList[0].number : 1 e.count = e.goodsList.length ? e.goodsList[0].number : 1
e.price = e.goodsList.reduce((prev, cur) => { e.price = e.goodsList.reduce((prev, cur) => {
return ( const unitPrice = orderObj.resetOrder
prev + ? normalizeOrderMoney(cur.price)
(orderObj.resetOrder : resolveSubOrderUnitPrice(
? Number(cur.price) {
: Number(cur.totalPrice) / Number(cur.number)) totalPrice: cur.totalPrice,
number: cur.number
},
false
)
return NP.plus(
prev,
unitPrice !== undefined ? unitPrice : 0
) )
}, 0) }, 0)
...@@ -2650,17 +2680,21 @@ Page({ ...@@ -2650,17 +2680,21 @@ Page({
// 修复取值字段名字错误问题 // 修复取值字段名字错误问题
if (orderObj.resetOrder) { if (orderObj.resetOrder) {
// 再次编辑优先使用订单回显单价,避免被 originalPrice(目录原价)覆盖 // 再次编辑优先使用订单回显单价,避免被 originalPrice(目录原价)覆盖
const count = Number(e.number) || 1 const unitPrice = resolveSubOrderUnitPrice(e, true)
const unitPrice = if (unitPrice != null && unitPrice !== '') {
e.sellPrice ?? (e.totalPrice ? Number(e.totalPrice) / count : undefined) e.price = unitPrice
e.sellPrice = unitPrice
}
} else {
const unitPrice = resolveSubOrderUnitPrice(
e,
false
)
if (unitPrice != null && unitPrice !== '') { if (unitPrice != null && unitPrice !== '') {
e.price = unitPrice e.price = unitPrice
//最低价
e.sellPrice = unitPrice e.sellPrice = unitPrice
} }
} else if (!e.price) {
e.price = wx.$util.decimal(Number(e.totalPrice / e.number), 2)
//最低价
e.sellPrice = e.price
} }
e.goodsId = e.merchantGoodsId e.goodsId = e.merchantGoodsId
if (!e.minSellPrice) e.minSellPrice = e.upgradeShopMinPrice if (!e.minSellPrice) e.minSellPrice = e.upgradeShopMinPrice
......
...@@ -6,6 +6,31 @@ ...@@ -6,6 +6,31 @@
import NP from 'number-precision' import NP from 'number-precision'
/** /**
* 将订单金额归一到分,避免接口总价/数量换算后的二进制浮点长尾进入输入框。
* @param {number|string} value
* @returns {number|undefined}
*/
export function normalizeOrderMoney(value) {
if (
value === null ||
value === undefined ||
(typeof value === 'string' && value.trim() === '')
) {
return undefined
}
const amount = Number(value)
if (!Number.isFinite(amount)) return undefined
return Math.round(Number(`${amount}e2`)) / 100
}
function resolveUnitPriceFromTotal(line) {
if (line.totalPrice == null || line.totalPrice === '') return undefined
const count = Number(line.number) || 1
const raw = Number(line.totalPrice) / count
return normalizeOrderMoney(raw)
}
/**
* 合并子单与套餐行(套餐在 packageGoodsList 时过滤 subOrder 内 packageName 行) * 合并子单与套餐行(套餐在 packageGoodsList 时过滤 subOrder 内 packageName 行)
* @param {Array<object>|undefined} subOrderList * @param {Array<object>|undefined} subOrderList
* @param {Array<object>|undefined} packageGoodsList * @param {Array<object>|undefined} packageGoodsList
...@@ -64,26 +89,20 @@ export function applySubOrderDiscountEcho(goods) { ...@@ -64,26 +89,20 @@ export function applySubOrderDiscountEcho(goods) {
* 解析回显单价(再次编辑优先 sellPrice,否则 total/number) * 解析回显单价(再次编辑优先 sellPrice,否则 total/number)
* @param {object} line subOrder 行 * @param {object} line subOrder 行
* @param {boolean} resetOrder 是否再次编辑 * @param {boolean} resetOrder 是否再次编辑
* @param {(n:number,d:number)=>number} [decimalFn] 可选 decimal 函数(页面 wx.$util.decimal)
* @returns {number|undefined} * @returns {number|undefined}
*/ */
export function resolveSubOrderUnitPrice(line, resetOrder, decimalFn) { export function resolveSubOrderUnitPrice(line, resetOrder) {
const count = Number(line.number) || 1
if (resetOrder) { if (resetOrder) {
if (line.sellPrice != null && line.sellPrice !== '') { if (line.sellPrice != null && line.sellPrice !== '') {
return Number(line.sellPrice) return normalizeOrderMoney(line.sellPrice)
}
if (line.totalPrice != null && line.totalPrice !== '') {
return Number(line.totalPrice) / count
} }
return undefined return resolveUnitPriceFromTotal(line)
} }
if (line.price != null && line.price !== '') { if (line.price != null && line.price !== '') {
return Number(line.price) return normalizeOrderMoney(line.price)
} }
if (line.totalPrice != null && line.number) { if (line.totalPrice != null && line.number) {
const raw = Number(line.totalPrice) / Number(line.number) return resolveUnitPriceFromTotal(line)
return decimalFn ? decimalFn(raw, 2) : raw
} }
return undefined return undefined
} }
......
...@@ -6,14 +6,19 @@ import { resolveLowPriceGoodsEntries } from './lowPriceGoodsValidation.helpers.j ...@@ -6,14 +6,19 @@ import { resolveLowPriceGoodsEntries } from './lowPriceGoodsValidation.helpers.j
export const GOODS_PRICE_MAX = 100000 export const GOODS_PRICE_MAX = 100000
export const GOODS_PRICE_NEGATIVE_MESSAGE = '商品价格不能小于0元' export const GOODS_PRICE_NEGATIVE_MESSAGE = '商品价格不能小于0元'
export const GOODS_PRICE_ZERO_MESSAGE = '商品价格不能等于0元'
export const GOODS_PRICE_OVER_LIMIT_MESSAGE = '商品价格不能大于100000元' export const GOODS_PRICE_OVER_LIMIT_MESSAGE = '商品价格不能大于100000元'
/** /**
* 校验并按现有金额精度规则规范输入值,不静默修正越界金额。 * 校验并按现有金额精度规则规范输入值,不静默修正越界金额。
* @param {*} rawValue * @param {*} rawValue
* @param {{allowZeroDraft?:boolean}} [options]
* @returns {{valid:boolean,value:string|null,message:string}} * @returns {{valid:boolean,value:string|null,message:string}}
*/ */
export function validateGoodsPriceInput(rawValue) { export function validateGoodsPriceInput(
rawValue,
{ allowZeroDraft = false } = {}
) {
const raw = String(rawValue ?? '').trim() const raw = String(rawValue ?? '').trim()
if (raw.includes('-')) { if (raw.includes('-')) {
return { return {
...@@ -45,7 +50,16 @@ export function validateGoodsPriceInput(rawValue) { ...@@ -45,7 +50,16 @@ export function validateGoodsPriceInput(rawValue) {
} }
const normalizedNumber = Number.parseFloat(normalized) const normalizedNumber = Number.parseFloat(normalized)
if (!Number.isFinite(normalizedNumber)) normalized = '0' if (
!allowZeroDraft &&
(!Number.isFinite(normalizedNumber) || normalizedNumber === 0)
) {
return {
valid: false,
value: null,
message: GOODS_PRICE_ZERO_MESSAGE
}
}
return { valid: true, value: normalized, message: '' } return { valid: true, value: normalized, message: '' }
} }
...@@ -69,6 +83,9 @@ export function findGoodsPriceBoundaryError(goodsList = []) { ...@@ -69,6 +83,9 @@ export function findGoodsPriceBoundaryError(goodsList = []) {
if (Number.isFinite(numericPrice) && numericPrice < 0) { if (Number.isFinite(numericPrice) && numericPrice < 0) {
return GOODS_PRICE_NEGATIVE_MESSAGE return GOODS_PRICE_NEGATIVE_MESSAGE
} }
if (Number.isFinite(numericPrice) && numericPrice === 0) {
return GOODS_PRICE_ZERO_MESSAGE
}
if (Number.isFinite(numericPrice) && numericPrice > GOODS_PRICE_MAX) { if (Number.isFinite(numericPrice) && numericPrice > GOODS_PRICE_MAX) {
return GOODS_PRICE_OVER_LIMIT_MESSAGE return GOODS_PRICE_OVER_LIMIT_MESSAGE
} }
......
...@@ -7,7 +7,8 @@ import { ...@@ -7,7 +7,8 @@ import {
applySubOrderDiscountEcho, applySubOrderDiscountEcho,
buildSingleGoodsChooseEntry, buildSingleGoodsChooseEntry,
resolveSubOrderMarketingEcho, resolveSubOrderMarketingEcho,
isMultiSpecSubOrderLine isMultiSpecSubOrderLine,
normalizeOrderMoney
} from '../services/goodsChooseEcho.helpers.js' } from '../services/goodsChooseEcho.helpers.js'
describe('goodsChooseEcho.helpers', () => { describe('goodsChooseEcho.helpers', () => {
...@@ -43,6 +44,38 @@ describe('goodsChooseEcho.helpers', () => { ...@@ -43,6 +44,38 @@ describe('goodsChooseEcho.helpers', () => {
) )
}) })
it('IT-WO-ECHO-010: total price division is normalized to cents', () => {
for (const resetOrder of [false, true]) {
assert.equal(
resolveSubOrderUnitPrice(
{ totalPrice: 9999.95, number: 5 },
resetOrder
),
1999.99,
`resetOrder=${resetOrder}`
)
}
})
it('IT-WO-ECHO-011: echoed sell price drops binary floating-point tails', () => {
assert.equal(
resolveSubOrderUnitPrice(
{ sellPrice: 1999.9900000000002, number: 5 },
true
),
1999.99
)
})
it('IT-WO-ECHO-012: missing echoed money is distinct from explicit zero', () => {
assert.equal(normalizeOrderMoney(null), undefined)
assert.equal(normalizeOrderMoney(undefined), undefined)
assert.equal(normalizeOrderMoney(''), undefined)
assert.equal(normalizeOrderMoney(' '), undefined)
assert.equal(normalizeOrderMoney(0), 0)
assert.equal(normalizeOrderMoney('0'), 0)
})
it('IT-WO-ECHO-005: applySubOrderDiscountEcho ratio', () => { it('IT-WO-ECHO-005: applySubOrderDiscountEcho ratio', () => {
const g = { sellPrice: 100, discountType: 1, discountValue: 8 } const g = { sellPrice: 100, discountType: 1, discountValue: 8 }
applySubOrderDiscountEcho(g) applySubOrderDiscountEcho(g)
......
...@@ -22,12 +22,37 @@ describe('goods price boundary validation', () => { ...@@ -22,12 +22,37 @@ describe('goods price boundary validation', () => {
}) })
}) })
it('accepts both boundaries and normalizes to two decimals', () => { it('rejects prices that are zero after normalizing to two decimals', () => {
assert.deepEqual(validateGoodsPriceInput('0'), { for (const rawPrice of ['', '0', '0.0', '0.00', '0.001']) {
valid: true, assert.deepEqual(validateGoodsPriceInput(rawPrice), {
value: '0', valid: false,
message: '' value: null,
}) message: '商品价格不能等于0元'
})
}
})
it('allows zero-valued drafts while a cent price is being entered', () => {
const drafts = [
['0', '0'],
['0.', '0.'],
['0.0', '0.0'],
['0.01', '0.01']
]
for (const [rawPrice, expectedValue] of drafts) {
assert.deepEqual(
validateGoodsPriceInput(rawPrice, { allowZeroDraft: true }),
{
valid: true,
value: expectedValue,
message: ''
}
)
}
})
it('accepts the upper boundary and normalizes to two decimals', () => {
assert.deepEqual(validateGoodsPriceInput('100000'), { assert.deepEqual(validateGoodsPriceInput('100000'), {
valid: true, valid: true,
value: '100000', value: '100000',
...@@ -75,4 +100,46 @@ describe('goods price boundary validation', () => { ...@@ -75,4 +100,46 @@ describe('goods price boundary validation', () => {
'商品价格不能大于100000元' '商品价格不能大于100000元'
) )
}) })
it('rejects zero prices already present in normal, SKU or package echo data', () => {
const goodsLists = [
[{ goodsFlag: 1, goods: { basePrice: 0, sellPrice: 0 } }],
[
{
goodsFlag: 2,
multipleSpecificationsGoods: { goods: { sellPrice: '0.0' } }
}
],
[
{
goodsFlag: 3,
packageGoods: { goodsList: [{ sellPrice: '0.00' }] }
}
]
]
for (const goodsList of goodsLists) {
assert.equal(
findGoodsPriceBoundaryError(goodsList),
'商品价格不能等于0元'
)
}
})
it('allows a zero gift final price when its editable base price is positive', () => {
assert.equal(
findGoodsPriceBoundaryError([
{
goodsFlag: 1,
goods: {
basePrice: 10,
sellPrice: 10,
finalPrice: 0,
discountType: 4
}
}
]),
''
)
})
}) })
...@@ -54,6 +54,31 @@ function createPage() { ...@@ -54,6 +54,31 @@ function createPage() {
return { page, goods } return { page, goods }
} }
function createPackagePage() {
const { page } = createPage()
const subItem = {
validMinSellPrice: 'Y',
minSellPrice: 100,
price: 80,
sellPrice: 80,
basePrice: 80,
finalPrice: 80,
discountType: 3
}
page.data.goodsList = [
{
goodsFlag: 3,
count: 1,
totalPrice: 80,
packageGoods: {
price: 80,
goodsList: [subItem]
}
}
]
return { page, subItem }
}
describe('createOrder goods price boundaries', () => { describe('createOrder goods price boundaries', () => {
let messages let messages
...@@ -84,6 +109,63 @@ describe('createOrder goods price boundaries', () => { ...@@ -84,6 +109,63 @@ describe('createOrder goods price boundaries', () => {
) )
}) })
it('allows 0.01 to be completed through zero-valued input drafts', () => {
const { page, goods } = createPage()
for (const value of ['0', '0.', '0.0', '0.01']) {
pageConfig.changePrice.call(page, {
detail: { index: 0, value }
})
assert.equal(goods.basePrice, value)
}
assert.deepEqual(messages, [])
assert.equal(goods.priceBoundaryError, '')
})
it('rejects a zero draft on blur and blocks submit', () => {
const { page, goods } = createPage()
pageConfig.changePrice.call(page, {
detail: { index: 0, value: '0.0' }
})
assert.deepEqual(messages, [])
assert.equal(goods.basePrice, '0.0')
pageConfig.priceBlur.call(page, {
detail: { index: 0 }
})
assert.deepEqual(messages, ['商品价格不能等于0元'])
assert.equal(goods.priceBoundaryError, '商品价格不能等于0元')
assert.equal(
pageConfig.checkGoods.call(
page,
false,
[],
true,
page.data.goodsList,
page.data.orderObj
),
'商品价格不能等于0元'
)
})
it('allows a package child to complete 0.01 through zero-valued drafts', () => {
const { page, subItem } = createPackagePage()
for (const value of ['0', '0.', '0.0', '0.01']) {
pageConfig.changeMealPrice.call(page, {
detail: { index: 0, gindex: 0, value }
})
assert.equal(subItem.basePrice, value)
}
assert.deepEqual(messages, [])
assert.equal(subItem.priceBoundaryError, '')
})
it('rejects an over-limit price without clamping and clears the error after correction', () => { it('rejects an over-limit price without clamping and clears the error after correction', () => {
const { page, goods } = createPage() const { page, goods } = createPage()
......
import assert from 'node:assert/strict'
import { register } from 'node:module'
import test from 'node:test'
register(
'../../../../tests/work-order-migration/shims/create-order-context-loader.mjs',
import.meta.url
)
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, fixed) {
const pow = Math.pow(10, fixed)
return Math.round(Number(value) * pow) / pow
},
getUserInfo: () => ({})
}
}
await import(`../createOrder.js?goods-price-echo=${Date.now()}`)
function createPage(resetOrder) {
const catalog = [
{
goodsFlag: 1,
goods: { merchantGoodsId: 'NORMAL-1', sellPrice: 2000 }
},
{
goodsFlag: 2,
multipleSpecificationsGoods: {
id: 'SPEC-1',
specificationGoodsMap: {
'A;~;B': [{ merchantGoodsId: 'SKU-1', sellPrice: 2000 }]
}
}
}
]
const orderObj = {
lowPriceFlag: 1,
resetOrder,
subOrderList: [
{
merchantGoodsId: 'NORMAL-1',
number: 5,
totalPrice: 9999.95,
price: resetOrder ? undefined : 1999.9900000000002
},
{
merchantGoodsId: 'SKU-1',
number: 5,
totalPrice: 9999.95,
price: resetOrder ? undefined : 1999.9900000000002,
specificationData: 'A;~;B'
}
],
packageGoodsList: [
{
packageCode: 'PACKAGE-1',
packageName: '精度测试套餐',
packageGoodsOrderList: [
{
merchantGoodsId: 'PACKAGE-GOODS-1',
number: 5,
totalPrice: 9999.95,
sellPrice: resetOrder ? undefined : 1999.9900000000002
}
]
}
]
}
return {
...pageConfig,
data: {
...structuredClone(pageConfig.data),
orderObj,
goodsData: catalog,
copyGoodsData: catalog,
packageList: [],
positionTypeList: [],
marketingFlagMap: {},
activityIdMap: {}
},
setData(patch, callback) {
Object.assign(this.data, patch)
callback?.()
},
setGoodsTotal(goodsList) {
this.data.goodsList = goodsList
}
}
}
test('待跟进回显时普通商品、多规格和套餐子项单价都归一到分', () => {
for (const resetOrder of [false, true]) {
const page = createPage(resetOrder)
pageConfig.getChooseList.call(page)
const ordinary = page.data.goodsList.find(item => item.goodsFlag === 1)
const multiSpec = page.data.goodsList.find(item => item.goodsFlag === 2)
const packageItem = page.data.goodsList.find(item => item.goodsFlag === 3)
assert.equal(ordinary.goods.sellPrice, 1999.99, `ordinary reset=${resetOrder}`)
assert.equal(
multiSpec.multipleSpecificationsGoods.goods.sellPrice,
1999.99,
`multi-spec reset=${resetOrder}`
)
assert.equal(
packageItem.packageGoods.goodsList[0].sellPrice,
1999.99,
`package reset=${resetOrder}`
)
}
})
test('套餐子项缺少 sellPrice 时按总价和数量回退回显,且不误判为 0', () => {
for (const missingSellPrice of [null, '']) {
const page = createPage(false)
const packageChild =
page.data.orderObj.packageGoodsList[0].packageGoodsOrderList[0]
packageChild.sellPrice = missingSellPrice
pageConfig.getChooseList.call(page)
const packageItem = page.data.goodsList.find(item => item.goodsFlag === 3)
assert.equal(
packageItem.packageGoods.goodsList[0].sellPrice,
1999.99,
`sellPrice=${JSON.stringify(missingSellPrice)}`
)
assert.equal(
packageItem.packageGoods.upgradePrice,
1999.99,
`upgradePrice sellPrice=${JSON.stringify(missingSellPrice)}`
)
}
})
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!