1. 优化医生、诊所的设置
Some checks failed
CI / Test (ubuntu-latest) (push) Has been cancelled
CI / Test (windows-latest) (push) Has been cancelled
CI / Lint (ubuntu-latest) (push) Has been cancelled
CI / Lint (windows-latest) (push) Has been cancelled
CI / Check (ubuntu-latest) (push) Has been cancelled
CI / Check (windows-latest) (push) Has been cancelled
CI / CI OK (push) Has been cancelled
CodeQL / Analyze (javascript-typescript) (push) Has been cancelled
Deploy Website on push / Deploy Push Playground Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Docs Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Antd Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Element Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Naive Ftp (push) Has been cancelled
Release Drafter / update_release_draft (push) Has been cancelled

This commit is contained in:
李琦
2026-07-03 10:41:52 +08:00
parent 949167217f
commit 92e145f366
25 changed files with 1616 additions and 105 deletions

View File

@@ -0,0 +1,68 @@
/**
* 与后端 format_price / PrescriptionService 中药计价口径一致
*/
export function parsePriceValue(value: unknown): number {
if (value === null || value === undefined || value === '') {
return 0;
}
const num = Number(value);
return Number.isFinite(num) ? num : 0;
}
/**
* 与后端 format_price 一致:第三位小数非 0 则分位进 1再保留两位小数
*/
export function formatPriceLikeBackend(value: unknown): number {
const price = parsePriceValue(value);
let milli = Math.round(price * 1000);
if (milli % 10 > 0) {
milli += 10;
}
milli -= milli % 10;
return Math.round((milli / 1000) * 100) / 100;
}
/** 模拟 PHP bcmul 在指定 scale 下向零截断 */
function bcmulScale(a: unknown, b: unknown, scale: number): number {
const product = parsePriceValue(a) * parsePriceValue(b);
const factor = 10 ** scale;
return Math.trunc(product * factor) / factor;
}
/** 模拟 PHP bcadd 在指定 scale 下向零截断 */
function bcaddScale(a: number, b: number, scale: number): number {
const sum = a + b;
const factor = 10 ** scale;
return Math.trunc(sum * factor) / factor;
}
type ChineseDrugLine = {
number?: number | string;
price?: number | string;
};
/**
* 中药商品总价(与 PrescriptionService::createChineseReprice 一致)
* 每行bcmul(dosage, bcmul(price, number, 3), 3),累加后 format_price
*/
export function calculateChineseProductPriceLikeBackend(
drugs: ChineseDrugLine[],
dosage = 7,
): number {
if (!drugs?.length) {
return 0;
}
const dose = parsePriceValue(dosage);
let total = 0;
for (const drug of drugs) {
const linePerDose = bcmulScale(drug.price, drug.number ?? 1, 3);
const lineTotal = bcmulScale(dose, linePerDose, 3);
total = bcaddScale(total, lineTotal, 3);
}
return formatPriceLikeBackend(total);
}
export function formatPriceDisplay(value: unknown): string {
return formatPriceLikeBackend(value).toFixed(2);
}