拦截伪区县写入与下单;推单失败挂 fulfillmentHold,HQ 可见超区/推单失败。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -30,6 +30,12 @@ export function getDistrictsForPicker(province: string, city: string): string[]
|
||||
return [REGION_ALL, ...getDistricts(province, city)];
|
||||
}
|
||||
|
||||
/** 收货地址:不含「全市」 */
|
||||
export function getDistrictsForShippingPicker(province: string, city: string): string[] {
|
||||
if (province === REGION_ALL || city === REGION_ALL) return [];
|
||||
return [...getDistricts(province, city)];
|
||||
}
|
||||
|
||||
export function formatRegion(province: string, city: string, district: string): string {
|
||||
if (!province) return '';
|
||||
if (province === REGION_ALL) return REGION_ALL;
|
||||
@@ -96,6 +102,35 @@ export const DEFAULT_REGION: RegionSelection = {
|
||||
district: REGION_ALL,
|
||||
};
|
||||
|
||||
/** 收货地址默认:不预填伪区县,迫使用户选真实区县 */
|
||||
export const DEFAULT_SHIPPING_REGION: RegionSelection = {
|
||||
province: '河南省',
|
||||
city: '郑州市',
|
||||
district: '',
|
||||
};
|
||||
|
||||
/** 收货场景:区县必须在省市区树内且非全市 */
|
||||
export function normalizeShippingRegionSelection(selection: RegionSelection): RegionSelection {
|
||||
const province = PROVINCES.includes(selection.province)
|
||||
? selection.province
|
||||
: DEFAULT_SHIPPING_REGION.province;
|
||||
const cities = getCities(province);
|
||||
const city = cities.includes(selection.city) ? selection.city : (cities[0] ?? DEFAULT_SHIPPING_REGION.city);
|
||||
const districts = getDistricts(province, city);
|
||||
const district =
|
||||
selection.district &&
|
||||
selection.district !== REGION_ALL &&
|
||||
districts.includes(selection.district)
|
||||
? selection.district
|
||||
: '';
|
||||
return { province, city, district };
|
||||
}
|
||||
|
||||
export function isShippingRegionComplete(selection: RegionSelection): boolean {
|
||||
const n = normalizeShippingRegionSelection(selection);
|
||||
return Boolean(n.province && n.city && n.district && n.district !== REGION_ALL);
|
||||
}
|
||||
|
||||
export function regionFromGeo(province: string, city: string, district?: string): RegionSelection {
|
||||
const cityName = city.endsWith('市') ? city : `${city}市`;
|
||||
const provinceInTree = PROVINCES.includes(province) ? province : DEFAULT_REGION.province;
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
import {
|
||||
REGION_ALL,
|
||||
isShippingRegionComplete,
|
||||
normalizeShippingRegionSelection,
|
||||
type RegionSelection,
|
||||
} from './region-data';
|
||||
|
||||
export const SHIPPING_DETAIL_MIN_LEN = 8;
|
||||
export const SHIPPING_REGION_REQUIRED_MSG = '请选择具体区县';
|
||||
export const SHIPPING_DETAIL_REQUIRED_MSG = '请填写详细地址';
|
||||
export const SHIPPING_DETAIL_TOO_SHORT_MSG = '请填写更详细的收货地址(含街道门牌)';
|
||||
|
||||
export type ShippingAddressLike = {
|
||||
province?: string | null;
|
||||
city?: string | null;
|
||||
district?: string | null;
|
||||
detail?: string | null;
|
||||
};
|
||||
|
||||
export function isDirtyShippingAddress(addr: ShippingAddressLike): boolean {
|
||||
return !validateClientShippingAddress(addr).ok;
|
||||
}
|
||||
|
||||
export function validateClientShippingAddress(addr: ShippingAddressLike): {
|
||||
ok: boolean;
|
||||
message?: string;
|
||||
} {
|
||||
const province = String(addr.province ?? '').trim();
|
||||
const city = String(addr.city ?? '').trim();
|
||||
const district = String(addr.district ?? '').trim();
|
||||
const detail = String(addr.detail ?? '').trim();
|
||||
|
||||
if (!province || !city) return { ok: false, message: '请选择所在地区' };
|
||||
if (!district || district === REGION_ALL || district === '全部') {
|
||||
return { ok: false, message: SHIPPING_REGION_REQUIRED_MSG };
|
||||
}
|
||||
const regionOk = isShippingRegionComplete({ province, city, district });
|
||||
if (!regionOk) {
|
||||
return { ok: false, message: SHIPPING_REGION_REQUIRED_MSG };
|
||||
}
|
||||
if (!detail) return { ok: false, message: SHIPPING_DETAIL_REQUIRED_MSG };
|
||||
if (detail.length < SHIPPING_DETAIL_MIN_LEN) {
|
||||
return { ok: false, message: SHIPPING_DETAIL_TOO_SHORT_MSG };
|
||||
}
|
||||
return { ok: true };
|
||||
}
|
||||
|
||||
export function shippingDetailCityWideHint(detail: string | null | undefined): string | null {
|
||||
const d = String(detail ?? '').trim();
|
||||
if (!d.includes('全市')) return null;
|
||||
if (/路|街|巷|号|大厦|广场|小区|村|镇|乡/.test(d)) return null;
|
||||
return '详细地址含「全市」,建议改为具体街道门牌,以免配送拒单';
|
||||
}
|
||||
|
||||
export function toShippingRegion(addr: ShippingAddressLike): RegionSelection {
|
||||
return normalizeShippingRegionSelection({
|
||||
province: String(addr.province ?? ''),
|
||||
city: String(addr.city ?? ''),
|
||||
district: String(addr.district ?? ''),
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user