add: 增加新客立减和计算公式测试

This commit is contained in:
2025-09-17 09:19:12 +08:00
parent a66de31f1b
commit 171c81eea6
8 changed files with 1603 additions and 86 deletions

1357
src/utils/goods.ts Normal file

File diff suppressed because it is too large Load Diff

210
src/utils/test.ts Normal file
View File

@@ -0,0 +1,210 @@
import { OrderPriceCalculator, GoodsType, BackendCoupon, ActivityConfig, CouponType } from "./goods";
// 修正后的测试数据严格匹配BaseCartItem类型
const testGoodsList = [
{
// 核心修正1product_type使用GoodsType枚举替代原product_type字符串
product_type: GoodsType.NORMAL, // "sku"类型归类为普通商品
// 核心修正2isTemporary/isGift从数字转为布尔值
isTemporary: false,
isGift: false,
// 核心修正3discountSaleAmount从字符串转为数字
discountSaleAmount: 0,
// 原有字段(保持不变)
salePrice: 2,
memberPrice: 2,
coverImg: "https://czg-oss.oss-cn-hangzhou.aliyuncs.com/catering/store/9660.png",
name: "多规格起售3",
specInfo: "常温",
packFee: 1,
type: "sku",
skuData: {
barCode: "88888888888888888888",
costPrice: 2,
coverImg: "",
createTime: "2025-03-27 16:23:49",
id: "2451",
isDel: 0,
isGrounding: 1,
isPauseSale: 0,
isSale: 1,
isSoldStock: 0,
lowPrice: 2,
memberPrice: 2,
name: "常温",
originPrice: 2,
productId: "946",
realSalesNumber: 0,
salePrice: 2,
shopId: "29",
specInfo: "常温",
suitNum: 3,
updateTime: "2025-03-27 16:23:49",
weight: 0,
},
id: 18264,
shop_id: 29,
table_code: "APC36217948",
sku_id: 2451,
product_id: 946,
product_name: "",
sku_name: "",
number: 4,
pack_number: 0,
discount_sale_note: "",
is_print: 1,
is_wait_call: 0,
pro_group_info: "",
remark: "",
create_time: "2025-09-16 16:00:25",
update_time: null,
},
{
// 核心修正1package类型映射为GoodsType.PACKAGE
product_type: GoodsType.PACKAGE,
// 核心修正2布尔值转换
isTemporary: false,
isGift: false,
// 核心修正3字符串转数字
discountSaleAmount: 5,
// 原有字段
salePrice: 11,
memberPrice: 22,
coverImg: "https://czg-oss.oss-cn-hangzhou.aliyuncs.com/catering/store/8351.png",
name: "蜜雪冰城",
specInfo: "",
packFee: 555,
type: "package",
skuData: {
barCode: "291739694712255",
costPrice: 0,
coverImg: "",
createTime: "2025-02-16 16:36:46",
id: "2383",
isDel: 0,
isGrounding: 1,
isPauseSale: 0,
isSale: 1,
isSoldStock: 0,
lowPrice: 11,
memberPrice: 22,
name: "",
originPrice: 11,
productId: "943",
realSalesNumber: 0,
salePrice: 11,
shopId: "29",
specInfo: "",
suitNum: 33,
updateTime: null,
weight: 0,
},
id: 18263,
shop_id: 29,
table_code: "APC36217948",
sku_id: 2383,
product_id: 943,
product_name: "",
sku_name: "",
number: 35,
pack_number: 1,
discount_sale_note: "",
is_print: 1,
is_wait_call: 0,
pro_group_info: "",
remark: "",
create_time: "2025-09-16 15:59:59",
update_time: "2025-09-16 16:00:48",
},
{
// 核心修正1空字符串product_type映射为GoodsType.EMPTY
product_type: GoodsType.EMPTY,
// 核心修正2临时菜标记为true
isTemporary: true,
isGift: false,
// 核心修正3折扣金额为数字
discountSaleAmount: 1,
// 补充必需字段salePrice临时菜原价
salePrice: 1,
// 原有字段
id: 18265,
shop_id: 29,
table_code: "APC36217948",
sku_id: -999,
product_id: -18293045,
product_name: "临时菜",
sku_name: "",
number: 1,
pack_number: 0,
discount_sale_note: "",
is_print: 1,
is_wait_call: 0,
pro_group_info: "",
remark: "",
create_time: "2025-09-16 16:00:57",
update_time: null,
},
];
// 修正testCartOrder的key与商品id匹配确保排序正确
const testCartOrder = {
"18264": 1717200000000, // 对应第一个商品id
"18263": 1717200100000, // 对应第二个商品id
"18265": 1717200200000, // 对应第三个商品id
};
// 其他配置保持不变
const testBackendCoupons: BackendCoupon[] = [
{
id: 1,
title: "满减券",
couponType: 1,
fullAmount: 2,
discountAmount: 1,
foods: '946',
useType: 'dine-in,pickup',
useShopType: 'all',
validType: 'custom',
validStartTime: '2025-09-16 16:00:00',
validEndTime: '2025-09-30 16:00:00',
useDays: '周一,周二,周三,周四,周五',
useTimeType: 'all',
},
];
const testOrderConfig = {
currentStoreId: "101",
isMember: false,
memberDiscountRate: 0.95,
userPoints: 0,
pointDeductionRule: {
pointsPerYuan: 100,
maxDeductionAmount: 50,
},
seatFeeConfig: {
isEnabled: false,
pricePerPerson: 3,
personCount: 2,
},
merchantReduction: 10,
additionalFee: 0,
};
const testActivities: ActivityConfig[] = [];
const testCurrentTime = new Date("2024-06-01 12:00:00");
// 调用函数(此时类型完全匹配)
const result = OrderPriceCalculator.calculateOrderCostSummary(
testGoodsList,
"dine-in",
testBackendCoupons,
testActivities,
testOrderConfig,
testCartOrder,
testCurrentTime
);
console.log("计算结果:", result);
export default {}