Commit 3543ff79 by 张立顺

fix: limit low-price customer profile import

1 parent a4427e5a
...@@ -27,7 +27,8 @@ import { ...@@ -27,7 +27,8 @@ import {
resolveCustomerId, resolveCustomerId,
shouldFetchCustomerProfile, shouldFetchCustomerProfile,
parseCustomerProfileResponse, parseCustomerProfileResponse,
buildCustomerProfileEchoPatch buildCustomerProfileEchoPatch,
buildCustomerOnlyOrder
} from './services/customerProfileEffects' } from './services/customerProfileEffects'
import { import {
PAY_TYPE, PAY_TYPE,
...@@ -565,6 +566,13 @@ Page({ ...@@ -565,6 +566,13 @@ Page({
*/ */
async chooseCustomerInfo(e) { async chooseCustomerInfo(e) {
let { detail } = e let { detail } = e
if (Number(this.data.orderObj?.lowPriceFlag) === 1) {
const orderObj = buildCustomerOnlyOrder(this.data.orderObj, detail)
this.setData({ orderObj })
await this.echoCustomerProfileIfNeeded({ customer: orderObj.customer })
this.setData(closePagePopupPatch('customerInfoBox'))
return
}
let { let {
outTradeNo, outTradeNo,
showPayList, showPayList,
......
...@@ -6,6 +6,20 @@ ...@@ -6,6 +6,20 @@
*/ */
/** /**
* 客户档案选择仅替换客户域,不带入历史订单的商品、支付等字段。
* @param {Object} [currentOrder]
* @param {Object} [selectedRecord]
* @returns {Object}
*/
export function buildCustomerOnlyOrder(currentOrder, selectedRecord) {
return {
...(currentOrder || {}),
remark: selectedRecord?.remark ?? '',
customer: { ...(selectedRecord?.customer || {}) }
}
}
/**
* 备注是否为空(含仅空格) * 备注是否为空(含仅空格)
* @param {string} [remark] * @param {string} [remark]
* @returns {boolean} * @returns {boolean}
......
...@@ -7,10 +7,51 @@ import { ...@@ -7,10 +7,51 @@ import {
resolveCustomerId, resolveCustomerId,
shouldFetchCustomerProfile, shouldFetchCustomerProfile,
parseCustomerProfileResponse, parseCustomerProfileResponse,
buildCustomerProfileEchoPatch buildCustomerProfileEchoPatch,
buildCustomerOnlyOrder
} from '../services/customerProfileEffects.js' } from '../services/customerProfileEffects.js'
describe('customerProfileEffects', () => { describe('customerProfileEffects', () => {
it('buildCustomerOnlyOrder replaces customer without importing historical order fields', () => {
const current = {
lowPriceFlag: 1,
merchantId: 100,
selectPayType: 3,
payeeType: 1,
remark: '旧客户备注',
subOrderList: [{ goodsCode: 'CURRENT' }],
customer: { customerId: 1, customerName: '旧客户' }
}
const selected = {
selectPayType: 5,
payeeType: 0,
remark: '新客户备注',
subOrderList: [{ goodsCode: 'HISTORY' }],
packageGoodsList: [{ packageCode: 'HISTORY-PKG' }],
customer: {
customerId: 2,
customerName: '新客户',
customerPhone: '13800000000',
standNo: 'VIN-NEW'
}
}
const result = buildCustomerOnlyOrder(current, selected)
assert.notEqual(result, current)
assert.notEqual(result.customer, selected.customer)
assert.deepEqual(result.customer, selected.customer)
assert.equal(result.selectPayType, 3)
assert.equal(result.payeeType, 1)
assert.equal(result.remark, '新客户备注')
assert.deepEqual(result.subOrderList, [{ goodsCode: 'CURRENT' }])
assert.equal(result.packageGoodsList, undefined)
assert.deepEqual(current.customer, {
customerId: 1,
customerName: '旧客户'
})
})
it('isRemarkEmpty treats blank and whitespace as empty', () => { it('isRemarkEmpty treats blank and whitespace as empty', () => {
assert.equal(isRemarkEmpty(''), true) assert.equal(isRemarkEmpty(''), true)
assert.equal(isRemarkEmpty(' '), true) assert.equal(isRemarkEmpty(' '), true)
......
import assert from 'node:assert/strict'
import { register } from 'node:module'
import { describe, it } from 'node:test'
register(
'../../../../tests/work-order-migration/shims/create-order-context-loader.mjs',
import.meta.url
)
async function loadPageConfig() {
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: {
getUserInfo: () => ({}),
showLoading: () => {},
hideLoading: () => {}
}
}
await import(`../createOrder.js?customer-only=${Date.now()}-${Math.random()}`)
return pageConfig
}
function createPage(pageConfig, lowPriceFlag) {
const currentGoods = [{ goodsCode: 'CURRENT' }]
let profileEchoCustomerId
let routeCount = 0
const page = {
data: {
...pageConfig.data,
customerInfoBox: true,
goodsList: currentGoods,
orderObj: {
...pageConfig.data.orderObj,
lowPriceFlag,
merchantId: 100,
selectPayType: 3,
payeeType: 1,
remark: '旧客户备注',
subOrderList: currentGoods,
customer: { customerId: 1, customerName: '旧客户' }
}
},
setData(patch, callback) {
Object.assign(this.data, patch)
callback?.()
},
async echoCustomerProfileIfNeeded(detail) {
profileEchoCustomerId = detail?.customer?.customerId
},
async onRoute(detail) {
routeCount += 1
this.data.orderObj = { ...detail }
await this.echoCustomerProfileIfNeeded(detail)
},
settingPayType() {}
}
return {
currentGoods,
page,
getProfileEchoCustomerId: () => profileEchoCustomerId,
getRouteCount: () => routeCount
}
}
const selectedRecord = {
selectPayType: 5,
payeeType: 0,
remark: '新客户备注',
subOrderList: [{ goodsCode: 'HISTORY' }],
packageGoodsList: [{ packageCode: 'HISTORY-PKG' }],
customer: {
customerId: 2,
customerName: '新客户',
customerPhone: '13800000000'
}
}
describe('createOrder customer profile import', () => {
it('low-price profile selection keeps current goods and payment fields', async () => {
const pageConfig = await loadPageConfig()
const context = createPage(pageConfig, 1)
await pageConfig.chooseCustomerInfo.call(context.page, {
detail: structuredClone(selectedRecord)
})
assert.equal(context.page.data.orderObj.customer.customerId, 2)
assert.equal(context.page.data.orderObj.customer.customerName, '新客户')
assert.equal(context.page.data.orderObj.remark, '新客户备注')
assert.equal(context.page.data.orderObj.selectPayType, 3)
assert.equal(context.page.data.orderObj.payeeType, 1)
assert.deepEqual(context.page.data.orderObj.subOrderList, [
{ goodsCode: 'CURRENT' }
])
assert.equal(context.page.data.orderObj.packageGoodsList, undefined)
assert.equal(context.page.data.goodsList, context.currentGoods)
assert.equal(context.page.data.customerInfoBox, false)
assert.equal(context.getProfileEchoCustomerId(), 2)
assert.equal(context.getRouteCount(), 0)
})
it('normal-order profile selection keeps the existing order routing path', async () => {
const pageConfig = await loadPageConfig()
const context = createPage(pageConfig, 0)
await pageConfig.chooseCustomerInfo.call(context.page, {
detail: structuredClone(selectedRecord)
})
assert.equal(context.getRouteCount(), 1)
assert.equal(context.page.data.orderObj.customer.customerId, 2)
})
})
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!