来源仓库:jxc/ai-fresh-delivery 来源提交:f0b1a180e2deb7e4673b9d1c8542619f7bc0f73d 快照树: 09f679334ff38f0ff25e907961c94a8223bcaedd(与来源 HEAD 工作树逐字节一致,3801 个文件) 按约定本仓库不带任何历史提交:来源仓库的历史中含真实凭据 (生产 SSH 私钥 deploy/id_rsa_tencent、server/.env、.env.tencent/.env.production/.env.gitea、 deploy/小程序AppSecret.txt,其中 MP_APPSECRET / S3 AccessKey 经哈希比对与线上同值), 整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。 供应商系统后续开发自本提交开始。
136 lines
4.4 KiB
TypeScript
136 lines
4.4 KiB
TypeScript
export const CORE_PROCESSING_METHODS = ['原材料', '净菜', '切配', '熟食'] as const;
|
|
|
|
export const STANDARD_PROCESSING_METHODS = [
|
|
'砍',
|
|
'去皮',
|
|
'切片',
|
|
'切块',
|
|
'切丝',
|
|
'切段',
|
|
'切丁',
|
|
'清洗',
|
|
'洗净',
|
|
'打包',
|
|
'分装',
|
|
'净菜',
|
|
'剁碎',
|
|
'去根',
|
|
'去叶',
|
|
] as const;
|
|
|
|
export type ProcessingAlias = {
|
|
alias_name: string;
|
|
processing_method: string;
|
|
};
|
|
|
|
function normalizeText(value: string): string {
|
|
return (value || '').trim().toLowerCase();
|
|
}
|
|
|
|
export type ProcessingOwner = 'supplier' | 'warehouse';
|
|
|
|
export const PROCESSING_OWNER_SUPPLIER: ProcessingOwner = 'supplier';
|
|
export const PROCESSING_OWNER_WAREHOUSE: ProcessingOwner = 'warehouse';
|
|
|
|
export const PROCESSING_OWNER_OPTIONS: Array<{ value: ProcessingOwner; label: string; hint: string }> = [
|
|
{
|
|
value: 'supplier',
|
|
label: '供应商已加工',
|
|
hint: '到货入库验收后直接分拣,不进加工管理',
|
|
},
|
|
{
|
|
value: 'warehouse',
|
|
label: '仓内加工',
|
|
hint: '入库后需加工管理与加工验收',
|
|
},
|
|
];
|
|
|
|
/** 订单加工方式是否需要进入仓内加工作业 */
|
|
export function requiresWarehouseProcessing(
|
|
method: string | null | undefined,
|
|
owner: string | null | undefined
|
|
): boolean {
|
|
const trimmedMethod = String(method || '').trim();
|
|
if (!trimmedMethod || trimmedMethod === '原材料') return false;
|
|
return String(owner || '').trim().toLowerCase() === PROCESSING_OWNER_WAREHOUSE;
|
|
}
|
|
|
|
/**
|
|
* 订单行 unit_cost 种子:仓内加工完工前强制 0,禁止报价成本;已完工分摊保留 existing。
|
|
* 非仓内行原样使用 computedCost。
|
|
*/
|
|
export function seedOrderItemUnitCost(input: {
|
|
processingMethod: string | null | undefined;
|
|
processingOwner: string | null | undefined;
|
|
computedCost: unknown;
|
|
demandCompleted?: boolean;
|
|
existingUnitCost?: unknown;
|
|
}): number {
|
|
if (!requiresWarehouseProcessing(input.processingMethod, input.processingOwner)) {
|
|
const n = Number(input.computedCost);
|
|
return Number.isFinite(n) && n > 0 ? n : 0;
|
|
}
|
|
if (input.demandCompleted) {
|
|
const existing = Number(input.existingUnitCost);
|
|
return Number.isFinite(existing) && existing > 0 ? existing : 0;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
/** @deprecated 使用 requiresWarehouseProcessing */
|
|
export function requiresProcessing(method: string | null | undefined): boolean {
|
|
return requiresWarehouseProcessing(method, PROCESSING_OWNER_WAREHOUSE);
|
|
}
|
|
|
|
export function normalizeProcessingOwner(
|
|
method: string | null | undefined,
|
|
owner: string | null | undefined
|
|
): ProcessingOwner | null {
|
|
const trimmedMethod = String(method || '').trim();
|
|
if (!trimmedMethod || trimmedMethod === '原材料') return null;
|
|
const normalized = String(owner || '').trim().toLowerCase();
|
|
if (normalized === PROCESSING_OWNER_WAREHOUSE) return PROCESSING_OWNER_WAREHOUSE;
|
|
return PROCESSING_OWNER_SUPPLIER;
|
|
}
|
|
|
|
export function processingOwnerLabel(owner: string | null | undefined): string {
|
|
const normalized = String(owner || '').trim().toLowerCase();
|
|
if (normalized === PROCESSING_OWNER_WAREHOUSE) return '仓内加工';
|
|
if (normalized === PROCESSING_OWNER_SUPPLIER) return '供应商已加工';
|
|
return '-';
|
|
}
|
|
|
|
/** 仅仓内加工且单价 > 0 时落库;否则 null */
|
|
export function resolveProcessUnitPriceForOrderItem(
|
|
owner: string | null | undefined,
|
|
raw: unknown
|
|
): number | null {
|
|
if (String(owner || '').trim().toLowerCase() !== PROCESSING_OWNER_WAREHOUSE) return null;
|
|
const n = Number(raw);
|
|
if (!Number.isFinite(n) || n <= 0) return null;
|
|
return Math.round(n * 100) / 100;
|
|
}
|
|
|
|
export function resolveProcessingMethodFromAlias(raw: string, aliases: ProcessingAlias[]): string {
|
|
const trimmed = (raw || '').trim();
|
|
if (!trimmed) return '原材料';
|
|
|
|
const direct = CORE_PROCESSING_METHODS.find((method) => method === trimmed);
|
|
if (direct) return direct;
|
|
|
|
const standard = STANDARD_PROCESSING_METHODS.find((method) => method === trimmed);
|
|
if (standard) return standard;
|
|
|
|
const aliasMatch = aliases.find((item) => normalizeText(item.alias_name) === normalizeText(trimmed));
|
|
if (aliasMatch) return aliasMatch.processing_method;
|
|
|
|
if (trimmed.includes('切')) return '净菜';
|
|
if (trimmed.includes('丁') || trimmed.includes('块') || trimmed.includes('片') || trimmed.includes('丝')) {
|
|
return '切配';
|
|
}
|
|
if (trimmed.includes('卤') || trimmed.includes('熟')) return '熟食';
|
|
if (trimmed.includes('加') || trimmed.includes('工')) return '切配';
|
|
|
|
return '原材料';
|
|
}
|