fix(订单地址): 明细保存改地址也触发地理编码并提示解析失败
- 详情底部保存会带 orderPatch.delivery_address;地址变化后执行坐标解析与路线重算 - 解析失败返回 delivery_address_geocode_failed,前端提示重新核验地址 - 补充契约测试
This commit is contained in:
@@ -899,7 +899,7 @@ export async function syncOrderManageItems(params: {
|
||||
: {};
|
||||
|
||||
const orderResult = await pool.query(
|
||||
`SELECT order_code, order_status, customer_code, branch_code, created_at, delivery_date
|
||||
`SELECT order_code, order_status, customer_code, branch_code, created_at, delivery_date, delivery_address
|
||||
FROM orders WHERE order_code = $1 LIMIT 1`,
|
||||
[orderCode]
|
||||
);
|
||||
@@ -907,6 +907,7 @@ export async function syncOrderManageItems(params: {
|
||||
if (!order) {
|
||||
throw Object.assign(new Error('订单不存在'), { status: 404, code: 'not_found' });
|
||||
}
|
||||
const previousDeliveryAddress = String(order.delivery_address || '').trim();
|
||||
const orderStatus = Number(order.order_status) || 0;
|
||||
const orderCompleted = orderStatus >= ORDER_COMPLETED_STATUS;
|
||||
const canPostExtraDishCost = orderStatus >= EXTRA_DISH_COST_FROM_STATUS;
|
||||
@@ -926,6 +927,7 @@ export async function syncOrderManageItems(params: {
|
||||
|
||||
let totalAmount = 0;
|
||||
let totalWeight = 0;
|
||||
let deliveryAddressGeocodeFailed = false;
|
||||
const weightItems: Array<{ quantity: number; unit: string }> = [];
|
||||
let allocation: Awaited<ReturnType<typeof reprocessOrderAllocation>> | undefined;
|
||||
let allocationSoftWarnings: string[] = [];
|
||||
@@ -1883,6 +1885,37 @@ export async function syncOrderManageItems(params: {
|
||||
client.release();
|
||||
}
|
||||
|
||||
/**
|
||||
* 明细保存也会带 `orderPatch.delivery_address`(详情页绿色保存按钮)。
|
||||
* 地址真变了同样要地理编码;失败时在明细保存响应里回传,前端提示重新核验。
|
||||
*/
|
||||
const patchedAddressRaw = params.orderPatch?.delivery_address;
|
||||
if (
|
||||
params.orderPatch &&
|
||||
patchedAddressRaw !== undefined &&
|
||||
String(patchedAddressRaw || '').trim() !== previousDeliveryAddress
|
||||
) {
|
||||
const patchedAddress = String(patchedAddressRaw || '').trim();
|
||||
if (patchedAddress) {
|
||||
try {
|
||||
const { applyDeliveryAddressSideEffects } = await import('./orderDeliveryAddressService');
|
||||
const effects = await applyDeliveryAddressSideEffects({
|
||||
orderCode,
|
||||
branchCode: order.branch_code || null,
|
||||
address: patchedAddress,
|
||||
customerCode: order.customer_code || null,
|
||||
});
|
||||
deliveryAddressGeocodeFailed = !effects.geocoded;
|
||||
} catch (error: unknown) {
|
||||
deliveryAddressGeocodeFailed = true;
|
||||
console.error(
|
||||
'[delivery-address] 明细保存后的地址副作用失败:',
|
||||
(error as Error)?.message || error
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* **先改后通知**(2026-10-12 口径):明细写入已 COMMIT ⇒ 现在**异步通知**主系统我方改了价/量。
|
||||
* 非阻塞、失败不改我方值;主系统的同意/驳回都不回改我方(只留痕)。
|
||||
@@ -2267,6 +2300,7 @@ export async function syncOrderManageItems(params: {
|
||||
...(costReconciled ? { cost_reconciled: true } : {}),
|
||||
...(extraDishCostPosted ? { extra_dish_cost_posted: true } : {}),
|
||||
...(quoteCostSync ? { quote_cost_sync: quoteCostSync } : {}),
|
||||
...(deliveryAddressGeocodeFailed ? { delivery_address_geocode_failed: true } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -64,6 +64,7 @@ describe('单独改收货地址:路由与门槛', () => {
|
||||
'utf8'
|
||||
);
|
||||
expect(page).toContain("t('orders.addressGeocodeFailed')");
|
||||
expect(manageService).toContain('delivery_address_geocode_failed');
|
||||
});
|
||||
|
||||
it('终态与垃圾桶分别拒:>=90 与 order_trashed', () => {
|
||||
|
||||
@@ -2208,6 +2208,9 @@ export const OrderManagement: React.FC = () => {
|
||||
if (saved?.data?.total_amount != null) {
|
||||
savedTotalAmount = Number(saved.data.total_amount) || totalAmount;
|
||||
}
|
||||
if (saved?.data?.delivery_address_geocode_failed) {
|
||||
notify.warning(t('orders.addressGeocodeFailed'));
|
||||
}
|
||||
if (saved?.data?.total_weight != null) {
|
||||
savedTotalWeight = Number(saved.data.total_weight) || totalWeight;
|
||||
}
|
||||
|
||||
@@ -729,6 +729,7 @@ export async function saveOrderItemsWithFulfillmentApi(
|
||||
statement_sync?: 'created' | 'updated' | 'skipped' | 'empty';
|
||||
cost_reconciled?: boolean;
|
||||
extra_dish_cost_posted?: boolean;
|
||||
delivery_address_geocode_failed?: boolean;
|
||||
allocation_soft_warnings?: string[];
|
||||
quote_cost_sync?: {
|
||||
quote_sheet_code: string | null;
|
||||
|
||||
Reference in New Issue
Block a user