@pisell/pisellos 2.3.229 → 2.3.231
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/model/strategy/adapter/promotion/adapter.js +14 -2
- package/dist/model/strategy/adapter/promotion/evaluator.js +23 -8
- package/dist/model/strategy/adapter/promotion/type.d.ts +10 -2
- package/dist/modules/Order/index.d.ts +1 -1
- package/dist/modules/Order/index.js +1371 -1234
- package/dist/modules/Order/types.d.ts +13 -34
- package/dist/modules/Order/types.js +2 -0
- package/dist/modules/Summary/utils.d.ts +1 -1
- package/dist/solution/BaseSales/utils/cartPromotion.d.ts +5 -18
- package/dist/solution/BaseSales/utils/cartPromotion.js +252 -168
- package/dist/solution/BookingTicket/index.d.ts +2 -2
- package/dist/solution/BookingTicket/index.js +45 -21
- package/dist/solution/BookingTicket/utils/redeemArrival.d.ts +10 -10
- package/dist/solution/ScanOrder/index.d.ts +1 -0
- package/dist/solution/ScanOrder/index.js +52 -38
- package/dist/solution/ScanOrder/menuAvailability.js +3 -25
- package/dist/solution/ScanOrder/shopTime.d.ts +6 -0
- package/dist/solution/ScanOrder/shopTime.js +36 -0
- package/lib/model/strategy/adapter/promotion/adapter.js +10 -1
- package/lib/model/strategy/adapter/promotion/evaluator.js +18 -6
- package/lib/model/strategy/adapter/promotion/type.d.ts +10 -2
- package/lib/modules/Order/index.d.ts +1 -1
- package/lib/modules/Order/index.js +103 -32
- package/lib/modules/Order/types.d.ts +13 -34
- package/lib/modules/Order/types.js +1 -0
- package/lib/modules/Summary/utils.d.ts +1 -1
- package/lib/solution/BaseSales/utils/cartPromotion.d.ts +5 -18
- package/lib/solution/BaseSales/utils/cartPromotion.js +87 -40
- package/lib/solution/BookingTicket/index.d.ts +2 -2
- package/lib/solution/BookingTicket/index.js +28 -11
- package/lib/solution/BookingTicket/utils/redeemArrival.d.ts +10 -10
- package/lib/solution/ScanOrder/index.d.ts +1 -0
- package/lib/solution/ScanOrder/index.js +26 -13
- package/lib/solution/ScanOrder/menuAvailability.js +3 -20
- package/lib/solution/ScanOrder/shopTime.d.ts +6 -0
- package/lib/solution/ScanOrder/shopTime.js +37 -0
- package/package.json +1 -1
|
@@ -50,8 +50,8 @@ export interface XItemsForYPriceConfig {
|
|
|
50
50
|
export interface BuyXGetYFreeValue {
|
|
51
51
|
/** 买X件 */
|
|
52
52
|
buyQuantity: number;
|
|
53
|
-
/**
|
|
54
|
-
freeQuantity
|
|
53
|
+
/** 任选赠品的总件数 */
|
|
54
|
+
freeQuantity?: number;
|
|
55
55
|
}
|
|
56
56
|
/**
|
|
57
57
|
* 赠品选择模式
|
|
@@ -67,6 +67,8 @@ export interface BuyXGetYFreeConfig {
|
|
|
67
67
|
cumulative?: boolean;
|
|
68
68
|
/** 可选的赠品列表 */
|
|
69
69
|
giftProducts?: ProductIdentifier[];
|
|
70
|
+
/** 每满足一组购买门槛,各款应赠的份数 */
|
|
71
|
+
fixedGiftProducts?: FixedGiftProduct[];
|
|
70
72
|
}
|
|
71
73
|
/**
|
|
72
74
|
* 商品奖励优惠方式
|
|
@@ -138,6 +140,9 @@ export interface ProductIdentifier {
|
|
|
138
140
|
*/
|
|
139
141
|
product_variant_id: number;
|
|
140
142
|
}
|
|
143
|
+
export interface FixedGiftProduct extends ProductIdentifier {
|
|
144
|
+
quantity: number;
|
|
145
|
+
}
|
|
141
146
|
import { ActionEffect } from '../../type';
|
|
142
147
|
/**
|
|
143
148
|
* X件Y元 Action
|
|
@@ -291,6 +296,7 @@ export interface BuyXGetYFreeActionDetail {
|
|
|
291
296
|
cumulative: boolean;
|
|
292
297
|
/** 可选的赠品列表 */
|
|
293
298
|
giftProducts: ProductIdentifier[];
|
|
299
|
+
fixedGiftProducts?: FixedGiftProduct[];
|
|
294
300
|
}
|
|
295
301
|
/**
|
|
296
302
|
* 商品奖励 Action 详情
|
|
@@ -507,6 +513,8 @@ export interface GiftInfo {
|
|
|
507
513
|
giftCount: number;
|
|
508
514
|
/** 可选赠品列表 */
|
|
509
515
|
giftOptions: ProductIdentifier[];
|
|
516
|
+
/** 购物车当前可领取的逐款额度 */
|
|
517
|
+
giftQuotas?: FixedGiftProduct[];
|
|
510
518
|
}
|
|
511
519
|
/**
|
|
512
520
|
* 带定价的购物车评估结果
|
|
@@ -644,7 +644,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
|
|
|
644
644
|
generateIdempotencyToken(): string;
|
|
645
645
|
syncPaymentsToOrder<T = any>(params: SyncPaymentsToOrderParams): Promise<SyncPaymentsToOrderResult<T>>;
|
|
646
646
|
createOrder(params: CommitOrderParams['query']): {
|
|
647
|
-
type: "
|
|
647
|
+
type: "virtual" | "appointment_booking";
|
|
648
648
|
platform: string;
|
|
649
649
|
sales_channel: string;
|
|
650
650
|
order_sales_channel: string;
|
|
@@ -1042,40 +1042,62 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
1042
1042
|
if (!tempOrder) {
|
|
1043
1043
|
return null;
|
|
1044
1044
|
}
|
|
1045
|
+
const isCurrentOrder = () => this.store.tempOrder === tempOrder && (options?.isCurrentOrder?.() ?? true);
|
|
1045
1046
|
if (this.isActiveVirtualSettlementOrder(tempOrder)) {
|
|
1046
1047
|
tempOrder.products = (0, _virtualSettlement.normalizeVirtualSettlementProducts)(tempOrder.products);
|
|
1047
1048
|
return null;
|
|
1048
1049
|
}
|
|
1050
|
+
const previousFixedGiftQuotas = tempOrder._extend?.fixedGiftQuotas || [];
|
|
1049
1051
|
const strategyConfigs = this.promotionEvaluator.getStrategyConfigs?.();
|
|
1050
|
-
if (Array.isArray(strategyConfigs) && strategyConfigs.length === 0) {
|
|
1052
|
+
if (Array.isArray(strategyConfigs) && strategyConfigs.length === 0 && !previousFixedGiftQuotas.length) {
|
|
1051
1053
|
return null;
|
|
1052
1054
|
}
|
|
1053
1055
|
this.isApplyingPromotion = true;
|
|
1054
1056
|
try {
|
|
1055
|
-
const result = (0, _cartPromotion.processCartPromotion)(tempOrder.products, this.promotionEvaluator
|
|
1057
|
+
const result = (0, _cartPromotion.processCartPromotion)(tempOrder.products, this.promotionEvaluator, {
|
|
1058
|
+
previousFixedGiftQuotas
|
|
1059
|
+
});
|
|
1060
|
+
const nextOrder = {
|
|
1061
|
+
...tempOrder,
|
|
1062
|
+
products: result.products
|
|
1063
|
+
};
|
|
1064
|
+
const publishGiftChanges = () => {
|
|
1065
|
+
tempOrder.products = nextOrder.products;
|
|
1066
|
+
tempOrder.bookings = nextOrder.bookings;
|
|
1067
|
+
if (tempOrder.holder_relations !== nextOrder.holder_relations) {
|
|
1068
|
+
tempOrder.holder_relations = nextOrder.holder_relations;
|
|
1069
|
+
}
|
|
1070
|
+
};
|
|
1056
1071
|
|
|
1057
|
-
//
|
|
1072
|
+
// 同步移除赠品行和占用的预约。
|
|
1058
1073
|
if (result.giftActions.toRemove.length > 0) {
|
|
1059
|
-
const removeSet = new Set(result.giftActions.toRemove.
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1074
|
+
const removeSet = new Set(result.giftActions.toRemove.filter(Boolean));
|
|
1075
|
+
const removed = tempOrder.products.filter(p => removeSet.has((0, _cartPromotion.getOrderProductUid)(p)));
|
|
1076
|
+
nextOrder.products = nextOrder.products.filter(p => !removeSet.has((0, _cartPromotion.getOrderProductUid)(p)));
|
|
1077
|
+
for (const product of removed) {
|
|
1078
|
+
this.removeLinkedBookingsForProduct(nextOrder, product);
|
|
1079
|
+
}
|
|
1080
|
+
(0, _holderRelations.removeProductHolderRelations)(nextOrder, removed);
|
|
1064
1081
|
}
|
|
1082
|
+
const removedBookings = nextOrder.bookings?.length !== tempOrder.bookings?.length;
|
|
1065
1083
|
|
|
1066
1084
|
// step 2: toReduce —— 调整数量
|
|
1067
1085
|
for (const reduce of result.giftActions.toReduce) {
|
|
1068
1086
|
for (const item of reduce.items) {
|
|
1069
|
-
const
|
|
1070
|
-
if (
|
|
1071
|
-
|
|
1087
|
+
const productIndex = nextOrder.products.findIndex(p => (0, _cartPromotion.getOrderProductUid)(p) === item.uid);
|
|
1088
|
+
if (productIndex >= 0) {
|
|
1089
|
+
nextOrder.products[productIndex] = {
|
|
1090
|
+
...nextOrder.products[productIndex],
|
|
1091
|
+
num: item.newQuantity
|
|
1092
|
+
};
|
|
1072
1093
|
}
|
|
1073
1094
|
}
|
|
1074
1095
|
}
|
|
1075
1096
|
|
|
1076
1097
|
// step 3: toAdd —— 补赠品
|
|
1098
|
+
const giftSelectResolver = this.giftSelectResolver;
|
|
1077
1099
|
if (result.giftActions.toAdd.length > 0) {
|
|
1078
|
-
if (!
|
|
1100
|
+
if (!giftSelectResolver) {
|
|
1079
1101
|
if (result.giftActions.toAdd.some(g => g.giftOptions.length > 1)) {
|
|
1080
1102
|
// 多选项必须走 resolver;单选项也建议走(避免 OS 自造 stub),但允许跳过
|
|
1081
1103
|
console.warn('[OrderModule] giftSelectResolver not set, skip applying gifts', result.giftActions.toAdd);
|
|
@@ -1083,53 +1105,82 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
1083
1105
|
console.warn('[OrderModule] giftSelectResolver not set, skip applying single-option gifts', result.giftActions.toAdd);
|
|
1084
1106
|
}
|
|
1085
1107
|
} else {
|
|
1108
|
+
if (result.giftActions.toRemove.length || result.giftActions.toReduce.length) {
|
|
1109
|
+
publishGiftChanges();
|
|
1110
|
+
}
|
|
1086
1111
|
for (const addAction of result.giftActions.toAdd) {
|
|
1087
1112
|
// 唯一候选也可能有规格/套餐。每次补赠都交给 SDK 判断,不能复用旧赠品的选择。
|
|
1088
1113
|
|
|
1089
|
-
const
|
|
1114
|
+
const fixedGiftQuotas = addAction.giftQuotas;
|
|
1115
|
+
const giftMutationBaseline = options?.isCurrentOrder || fixedGiftQuotas ? (0, _lodashEs.cloneDeep)({
|
|
1090
1116
|
products: tempOrder.products,
|
|
1091
1117
|
bookings: tempOrder.bookings
|
|
1092
1118
|
}) : null;
|
|
1093
1119
|
try {
|
|
1094
|
-
const
|
|
1095
|
-
|
|
1120
|
+
const inventoryProducts = fixedGiftQuotas ? nextOrder.products : tempOrder.products;
|
|
1121
|
+
const giftResult = await giftSelectResolver({
|
|
1122
|
+
...addAction,
|
|
1123
|
+
inventoryReserved: inventoryProducts.map(line => ({
|
|
1096
1124
|
product_id: Number(line.product_id),
|
|
1097
1125
|
product_variant_id: Number(line.product_variant_id || 0),
|
|
1098
1126
|
quantity: Number(line.num) || 0
|
|
1099
|
-
}))
|
|
1100
|
-
strategyId: addAction.strategyId,
|
|
1101
|
-
strategyName: addAction.strategyName,
|
|
1102
|
-
giftCount: addAction.giftCount,
|
|
1103
|
-
giftOptions: addAction.giftOptions,
|
|
1104
|
-
sourceProductIds: addAction.sourceProductIds
|
|
1127
|
+
}))
|
|
1105
1128
|
});
|
|
1106
|
-
if (
|
|
1107
|
-
if (
|
|
1129
|
+
if (!isCurrentOrder()) return null;
|
|
1130
|
+
if (giftMutationBaseline && !(0, _lodashEs.isEqual)({
|
|
1108
1131
|
products: tempOrder.products,
|
|
1109
1132
|
bookings: tempOrder.bookings
|
|
1110
1133
|
}, giftMutationBaseline)) return null;
|
|
1111
1134
|
const giftProducts = Array.isArray(giftResult) ? giftResult : giftResult?.products;
|
|
1112
1135
|
const giftBookings = Array.isArray(giftResult) ? [] : giftResult?.bookings || [];
|
|
1113
1136
|
if (Array.isArray(giftProducts) && giftProducts.length > 0) {
|
|
1137
|
+
if (fixedGiftQuotas) {
|
|
1138
|
+
const selectedCounts = new Map();
|
|
1139
|
+
for (const product of giftProducts) {
|
|
1140
|
+
const productId = Number(product?.product_id);
|
|
1141
|
+
const quota = fixedGiftQuotas.find(item => item.product_id === productId);
|
|
1142
|
+
const quantity = Number(product?.num);
|
|
1143
|
+
const count = (selectedCounts.get(productId) ?? 0) + quantity;
|
|
1144
|
+
if (!quota || quota.product_variant_id !== 0 && Number(product?.product_variant_id) !== quota.product_variant_id || !Number.isSafeInteger(quantity) || quantity <= 0 || count > quota.quantity || product?.metadata?._giftInfo?.strategyId !== addAction.strategyId) {
|
|
1145
|
+
throw new Error('Gift selection does not match the fixed gift allowance');
|
|
1146
|
+
}
|
|
1147
|
+
selectedCounts.set(productId, count);
|
|
1148
|
+
}
|
|
1149
|
+
}
|
|
1150
|
+
const fixedBookingsByProduct = fixedGiftQuotas ? new Map(giftBookings.filter(booking => booking?.product_uid).map(booking => [String(booking.product_uid), booking])) : null;
|
|
1151
|
+
const products = [];
|
|
1152
|
+
const bookings = [];
|
|
1114
1153
|
for (const [index, gp] of giftProducts.entries()) {
|
|
1115
1154
|
if (!gp) continue;
|
|
1116
|
-
const
|
|
1155
|
+
const productUid = (0, _cartPromotion.getOrderProductUid)(gp);
|
|
1156
|
+
const booking = fixedBookingsByProduct ? fixedBookingsByProduct.get(productUid) : giftBookings[index];
|
|
1117
1157
|
if (booking) {
|
|
1158
|
+
fixedBookingsByProduct?.delete(productUid);
|
|
1118
1159
|
const linked = this.createLinkedProductAndBooking({
|
|
1119
1160
|
product: gp,
|
|
1120
1161
|
booking
|
|
1121
1162
|
});
|
|
1122
|
-
|
|
1123
|
-
|
|
1163
|
+
products.push(linked.product);
|
|
1164
|
+
bookings.push(linked.booking);
|
|
1124
1165
|
continue;
|
|
1125
1166
|
}
|
|
1167
|
+
if (fixedBookingsByProduct && gp.metadata?.booking_uid) {
|
|
1168
|
+
throw new Error('Gift booking does not match its selected product');
|
|
1169
|
+
}
|
|
1126
1170
|
// normalize 略过:调用方应保证返回完整 OrderProduct。
|
|
1127
|
-
|
|
1171
|
+
products.push(gp);
|
|
1128
1172
|
}
|
|
1173
|
+
if (fixedBookingsByProduct && bookings.length !== giftBookings.length) {
|
|
1174
|
+
throw new Error('Gift bookings do not match the selected products');
|
|
1175
|
+
}
|
|
1176
|
+
nextOrder.products = [...nextOrder.products, ...products];
|
|
1177
|
+
if (bookings.length) nextOrder.bookings = [...(nextOrder.bookings || []), ...bookings];
|
|
1178
|
+
// 下一场活动的赠品校验读取已更新的草稿。
|
|
1179
|
+
publishGiftChanges();
|
|
1129
1180
|
}
|
|
1130
1181
|
} catch (error) {
|
|
1131
|
-
if (
|
|
1132
|
-
if (
|
|
1182
|
+
if (!isCurrentOrder()) return null;
|
|
1183
|
+
if (giftMutationBaseline && !(0, _lodashEs.isEqual)({
|
|
1133
1184
|
products: tempOrder.products,
|
|
1134
1185
|
bookings: tempOrder.bookings
|
|
1135
1186
|
}, giftMutationBaseline)) return null;
|
|
@@ -1139,8 +1190,24 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
1139
1190
|
}
|
|
1140
1191
|
}
|
|
1141
1192
|
}
|
|
1142
|
-
if (
|
|
1143
|
-
|
|
1193
|
+
if (!isCurrentOrder()) return null;
|
|
1194
|
+
publishGiftChanges();
|
|
1195
|
+
const fixedGiftQuotas = result.gifts.flatMap(({
|
|
1196
|
+
strategyId,
|
|
1197
|
+
giftQuotas
|
|
1198
|
+
}) => giftQuotas ? [{
|
|
1199
|
+
strategyId,
|
|
1200
|
+
giftQuotas
|
|
1201
|
+
}] : []);
|
|
1202
|
+
if (removedBookings || fixedGiftQuotas.length) this.syncTempOrderHolderFromBookings(tempOrder);
|
|
1203
|
+
if (fixedGiftQuotas.length && giftSelectResolver) {
|
|
1204
|
+
tempOrder._extend = {
|
|
1205
|
+
...tempOrder._extend,
|
|
1206
|
+
fixedGiftQuotas
|
|
1207
|
+
};
|
|
1208
|
+
} else if (!fixedGiftQuotas.length && tempOrder._extend?.fixedGiftQuotas) {
|
|
1209
|
+
delete tempOrder._extend.fixedGiftQuotas;
|
|
1210
|
+
}
|
|
1144
1211
|
if (tempOrder.products.length === 0) {
|
|
1145
1212
|
// 删除主商品后,促销重算可能继续移除最后的赠品。
|
|
1146
1213
|
tempOrder.shop_discount = '0.00';
|
|
@@ -1154,7 +1221,10 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
1154
1221
|
strategyId: g.strategyId,
|
|
1155
1222
|
strategyName: g.strategyName,
|
|
1156
1223
|
giftCount: g.giftCount,
|
|
1157
|
-
giftOptions: g.giftOptions
|
|
1224
|
+
giftOptions: g.giftOptions,
|
|
1225
|
+
...(g.giftQuotas && {
|
|
1226
|
+
giftQuotas: g.giftQuotas
|
|
1227
|
+
})
|
|
1158
1228
|
})),
|
|
1159
1229
|
products: tempOrder.products
|
|
1160
1230
|
};
|
|
@@ -5186,6 +5256,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
5186
5256
|
...tempOrder._extend,
|
|
5187
5257
|
productsByUid: {}
|
|
5188
5258
|
};
|
|
5259
|
+
delete tempOrder._extend.fixedGiftQuotas;
|
|
5189
5260
|
}
|
|
5190
5261
|
if (mutation.commit) tempOrder = await mutation.commit();
|
|
5191
5262
|
const promotionPayload = await this.evaluatePromotion();
|
|
@@ -8,6 +8,7 @@ import type { PaymentItem } from '../Payment/types';
|
|
|
8
8
|
import type { ICustomer } from '../AccountList/types';
|
|
9
9
|
import type { OrderProductDiscountItem } from '../../server/modules/order/types';
|
|
10
10
|
import type { PickupTimingBooking, PickupTimingBookingInput } from './pickupTiming';
|
|
11
|
+
import type { FixedGiftProduct, GiftInfo } from '../../model/strategy/adapter/promotion/type';
|
|
11
12
|
export type { OrderProductDiscountItem } from '../../server/modules/order/types';
|
|
12
13
|
export type PickupReferenceMode = 'counter_pickup' | 'table_service';
|
|
13
14
|
export type ShopServiceType = 'dine_in' | 'takeaway' | 'pick_up' | 'delivery';
|
|
@@ -45,23 +46,17 @@ export interface OrderPromotionEvaluator {
|
|
|
45
46
|
getStrategyConfigs?: () => unknown[];
|
|
46
47
|
}
|
|
47
48
|
/** 赠品解析回调 context(OS → SDK 的请求体) */
|
|
48
|
-
export interface OrderGiftSelectContext {
|
|
49
|
-
/**
|
|
50
|
-
inventoryReserved?:
|
|
51
|
-
product_id: number;
|
|
52
|
-
product_variant_id: number;
|
|
53
|
-
quantity: number;
|
|
54
|
-
}>;
|
|
55
|
-
strategyId: string;
|
|
56
|
-
strategyName: string | Record<string, string>;
|
|
57
|
-
giftCount: number;
|
|
58
|
-
giftOptions: Array<{
|
|
59
|
-
product_id: number;
|
|
60
|
-
product_variant_id: number;
|
|
61
|
-
}>;
|
|
49
|
+
export interface OrderGiftSelectContext extends GiftInfo {
|
|
50
|
+
/** 购物车内已占用库存的商品,含触发活动的主商品 */
|
|
51
|
+
inventoryReserved?: FixedGiftProduct[];
|
|
62
52
|
/** 触发此赠品的主商品 metadata.unique_identification_number 列表 */
|
|
63
53
|
sourceProductIds: string[];
|
|
64
54
|
}
|
|
55
|
+
/** 草稿已提示的额度,包含顾客放弃的部分。 */
|
|
56
|
+
export interface OrderFixedGiftQuotas {
|
|
57
|
+
strategyId: string;
|
|
58
|
+
giftQuotas: FixedGiftProduct[];
|
|
59
|
+
}
|
|
65
60
|
/**
|
|
66
61
|
* 赠品 resolver 返回值。
|
|
67
62
|
*
|
|
@@ -71,7 +66,7 @@ export interface OrderGiftSelectContext {
|
|
|
71
66
|
export interface OrderGiftSelectResult {
|
|
72
67
|
/** 完整赠品购物车行,必须带 metadata._giftInfo。 */
|
|
73
68
|
products: Partial<OrderProduct>[];
|
|
74
|
-
/**
|
|
69
|
+
/** 固定赠品按 product_uid 关联预约,普通买赠沿用 products 下标。 */
|
|
75
70
|
bookings?: AddProductBookingInput[];
|
|
76
71
|
}
|
|
77
72
|
/**
|
|
@@ -104,16 +99,7 @@ export interface OrderUnfulfilledPromotion {
|
|
|
104
99
|
}
|
|
105
100
|
/** 上一次 applyPromotion 计算出的赠品操作(仅供调试/读取使用) */
|
|
106
101
|
export interface OrderLastGiftActions {
|
|
107
|
-
toAdd:
|
|
108
|
-
strategyId: string;
|
|
109
|
-
strategyName: string | Record<string, string>;
|
|
110
|
-
giftCount: number;
|
|
111
|
-
giftOptions: Array<{
|
|
112
|
-
product_id: number;
|
|
113
|
-
product_variant_id: number;
|
|
114
|
-
}>;
|
|
115
|
-
sourceProductIds: string[];
|
|
116
|
-
}>;
|
|
102
|
+
toAdd: OrderGiftSelectContext[];
|
|
117
103
|
toReduce: Array<{
|
|
118
104
|
strategyId: string;
|
|
119
105
|
items: Array<{
|
|
@@ -129,15 +115,7 @@ export interface OrderPromotionAppliedPayload {
|
|
|
129
115
|
unfulfilledPromotions: OrderUnfulfilledPromotion[];
|
|
130
116
|
giftActions: OrderLastGiftActions;
|
|
131
117
|
/** evaluator 返回的赠品摘要 */
|
|
132
|
-
gifts:
|
|
133
|
-
strategyId: string;
|
|
134
|
-
strategyName: string | Record<string, string>;
|
|
135
|
-
giftCount: number;
|
|
136
|
-
giftOptions: Array<{
|
|
137
|
-
product_id: number;
|
|
138
|
-
product_variant_id: number;
|
|
139
|
-
}>;
|
|
140
|
-
}>;
|
|
118
|
+
gifts: GiftInfo[];
|
|
141
119
|
/** 折扣重算后的最终商品列表 */
|
|
142
120
|
products: OrderProduct[];
|
|
143
121
|
}
|
|
@@ -420,6 +398,7 @@ export interface OrderTempOrder {
|
|
|
420
398
|
_extend?: {
|
|
421
399
|
productsByUid?: Record<string, Record<string, any>>;
|
|
422
400
|
salesNotesState?: SalesNotesRuntimeState;
|
|
401
|
+
fixedGiftQuotas?: OrderFixedGiftQuotas[];
|
|
423
402
|
[key: string]: any;
|
|
424
403
|
};
|
|
425
404
|
}
|
|
@@ -72,7 +72,7 @@ export declare const calculateOriginSubtotal: (items: CartItem[]) => string;
|
|
|
72
72
|
* @return {*}
|
|
73
73
|
* @Author: xiangfeng.xue
|
|
74
74
|
*/
|
|
75
|
-
export declare const calculateTaxFee: (shopInfo: any, items: CartItem[]) => "0.00"
|
|
75
|
+
export declare const calculateTaxFee: (shopInfo: any, items: CartItem[]) => Decimal | "0.00";
|
|
76
76
|
/**
|
|
77
77
|
* @title: 计算定金
|
|
78
78
|
* @param items - 购物车商品数组
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { OrderProduct } from '../../../modules/Order/types';
|
|
1
|
+
import type { OrderFixedGiftQuotas, OrderProduct } from '../../../modules/Order/types';
|
|
2
|
+
import type { GiftInfo } from '../../../model/strategy/adapter/promotion/type';
|
|
2
3
|
/**
|
|
3
4
|
* 运行态商品行标记:该行由“不合并商品”加车策略创建,促销重算时必须保持独立。
|
|
4
5
|
* `normalizeSubmitProduct` 会按白名单裁剪 metadata,不会把此字段提交到后端。
|
|
@@ -49,15 +50,7 @@ export interface CartPromotionEvaluator {
|
|
|
49
50
|
_originalId?: string;
|
|
50
51
|
_originalIndex?: number;
|
|
51
52
|
}>;
|
|
52
|
-
gifts:
|
|
53
|
-
strategyId: string;
|
|
54
|
-
strategyName: string | Record<string, string>;
|
|
55
|
-
giftCount: number;
|
|
56
|
-
giftOptions: Array<{
|
|
57
|
-
product_id: number;
|
|
58
|
-
product_variant_id: number;
|
|
59
|
-
}>;
|
|
60
|
-
}>;
|
|
53
|
+
gifts: GiftInfo[];
|
|
61
54
|
totalDiscount: number;
|
|
62
55
|
};
|
|
63
56
|
getProductsApplicableStrategies(input: {
|
|
@@ -94,14 +87,7 @@ export interface GiftReduceItem {
|
|
|
94
87
|
newQuantity: number;
|
|
95
88
|
}
|
|
96
89
|
/** 赠品新增项 */
|
|
97
|
-
export interface GiftToAddAction {
|
|
98
|
-
strategyId: string;
|
|
99
|
-
strategyName: string | Record<string, string>;
|
|
100
|
-
giftCount: number;
|
|
101
|
-
giftOptions: Array<{
|
|
102
|
-
product_id: number;
|
|
103
|
-
product_variant_id: number;
|
|
104
|
-
}>;
|
|
90
|
+
export interface GiftToAddAction extends GiftInfo {
|
|
105
91
|
/** 触发此赠品的主商品 uid 列表 */
|
|
106
92
|
sourceProductIds: string[];
|
|
107
93
|
}
|
|
@@ -291,4 +277,5 @@ export declare function appendPromotionTags<T extends Record<string, any>>(produ
|
|
|
291
277
|
*/
|
|
292
278
|
export declare function processCartPromotion(list: OrderProduct[] | null | undefined, evaluator: CartPromotionEvaluator | null | undefined, options?: {
|
|
293
279
|
channel?: string;
|
|
280
|
+
previousFixedGiftQuotas?: OrderFixedGiftQuotas[];
|
|
294
281
|
}): ProcessCartPromotionResult;
|
|
@@ -595,15 +595,83 @@ function convertToPromotionProduct(product, index) {
|
|
|
595
595
|
// 主流程:processCartPromotion
|
|
596
596
|
// ============================================
|
|
597
597
|
|
|
598
|
+
function reduceGiftQuantity(actions, strategyId, items, quantity) {
|
|
599
|
+
const reductions = [];
|
|
600
|
+
let remaining = quantity;
|
|
601
|
+
for (const item of [...items].reverse()) {
|
|
602
|
+
if (remaining <= 0) break;
|
|
603
|
+
const uid = getOrderProductUid(item);
|
|
604
|
+
const currentQuantity = Number(item.num ?? 1) || 1;
|
|
605
|
+
if (currentQuantity <= remaining) {
|
|
606
|
+
actions.toRemove.push(uid);
|
|
607
|
+
remaining -= currentQuantity;
|
|
608
|
+
} else {
|
|
609
|
+
reductions.push({
|
|
610
|
+
uid,
|
|
611
|
+
currentQuantity,
|
|
612
|
+
newQuantity: currentQuantity - remaining
|
|
613
|
+
});
|
|
614
|
+
remaining = 0;
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
if (reductions.length) actions.toReduce.push({
|
|
618
|
+
strategyId,
|
|
619
|
+
items: reductions
|
|
620
|
+
});
|
|
621
|
+
}
|
|
622
|
+
function calculateFixedGiftActions(gift, existing, previousQuotas, actions) {
|
|
623
|
+
const unmatched = new Set(existing);
|
|
624
|
+
const addedQuotas = [];
|
|
625
|
+
for (const quota of gift.giftQuotas || []) {
|
|
626
|
+
const {
|
|
627
|
+
product_id,
|
|
628
|
+
product_variant_id,
|
|
629
|
+
quantity
|
|
630
|
+
} = quota;
|
|
631
|
+
const matching = existing.filter(item => Number(item.product_id) === product_id && (product_variant_id === 0 || Number(item.product_variant_id) === product_variant_id));
|
|
632
|
+
matching.forEach(item => unmatched.delete(item));
|
|
633
|
+
const existingCount = matching.reduce((count, item) => count + (Number(item.num ?? 1) || 1), 0);
|
|
634
|
+
const previous = previousQuotas.find(item => item.product_id === product_id && item.product_variant_id === product_variant_id);
|
|
635
|
+
// 已放弃的额度可以手动领取。自动选择只请求本次新增的部分。
|
|
636
|
+
const added = quantity - Math.max(existingCount, previous?.quantity ?? 0);
|
|
637
|
+
if (added > 0) {
|
|
638
|
+
addedQuotas.push({
|
|
639
|
+
product_id,
|
|
640
|
+
product_variant_id,
|
|
641
|
+
quantity: added
|
|
642
|
+
});
|
|
643
|
+
} else if (existingCount > quantity) {
|
|
644
|
+
reduceGiftQuantity(actions, gift.strategyId, matching, existingCount - quantity);
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
if (addedQuotas.length) {
|
|
648
|
+
actions.toAdd.push({
|
|
649
|
+
...gift,
|
|
650
|
+
giftCount: addedQuotas.reduce((count, quota) => count + quota.quantity, 0),
|
|
651
|
+
giftOptions: addedQuotas.map(({
|
|
652
|
+
product_id,
|
|
653
|
+
product_variant_id
|
|
654
|
+
}) => ({
|
|
655
|
+
product_id,
|
|
656
|
+
product_variant_id
|
|
657
|
+
})),
|
|
658
|
+
giftQuotas: addedQuotas
|
|
659
|
+
});
|
|
660
|
+
}
|
|
661
|
+
for (const item of unmatched) actions.toRemove.push(getOrderProductUid(item));
|
|
662
|
+
}
|
|
663
|
+
|
|
598
664
|
/**
|
|
599
665
|
* 计算赠品差异化操作(toAdd / toReduce / toRemove)。
|
|
600
666
|
*
|
|
601
|
-
*
|
|
667
|
+
* 任选赠品按活动总量对账,固定赠品按活动内的各款额度对账。
|
|
602
668
|
*/
|
|
603
|
-
function calculateGiftActions(gifts, existingGifts) {
|
|
604
|
-
const
|
|
605
|
-
|
|
606
|
-
|
|
669
|
+
function calculateGiftActions(gifts, existingGifts, previousFixedGiftQuotas) {
|
|
670
|
+
const actions = {
|
|
671
|
+
toAdd: [],
|
|
672
|
+
toReduce: [],
|
|
673
|
+
toRemove: []
|
|
674
|
+
};
|
|
607
675
|
|
|
608
676
|
// 按 strategyId 分组现有赠品
|
|
609
677
|
const existingByStrategy = new Map();
|
|
@@ -633,6 +701,11 @@ function calculateGiftActions(gifts, existingGifts) {
|
|
|
633
701
|
} = giftInfo;
|
|
634
702
|
processedStrategyIds.add(strategyId);
|
|
635
703
|
const existing = existingByStrategy.get(strategyId);
|
|
704
|
+
if (giftInfo.giftQuotas) {
|
|
705
|
+
const previous = previousFixedGiftQuotas.find(item => item.strategyId === strategyId);
|
|
706
|
+
calculateFixedGiftActions(giftInfo, existing?.items || [], previous?.giftQuotas || [], actions);
|
|
707
|
+
continue;
|
|
708
|
+
}
|
|
636
709
|
const existingCount = existing?.totalQuantity ?? 0;
|
|
637
710
|
const diff = giftCount - existingCount;
|
|
638
711
|
if (diff > 0) {
|
|
@@ -640,7 +713,7 @@ function calculateGiftActions(gifts, existingGifts) {
|
|
|
640
713
|
const lastEvaluated = getGiftInfo(existing?.items?.[0])?.lastEvaluatedGiftCount;
|
|
641
714
|
const strategyChanged = lastEvaluated === undefined || giftCount !== lastEvaluated;
|
|
642
715
|
if (strategyChanged) {
|
|
643
|
-
toAdd.push({
|
|
716
|
+
actions.toAdd.push({
|
|
644
717
|
strategyId,
|
|
645
718
|
strategyName,
|
|
646
719
|
giftCount: diff,
|
|
@@ -649,32 +722,7 @@ function calculateGiftActions(gifts, existingGifts) {
|
|
|
649
722
|
});
|
|
650
723
|
}
|
|
651
724
|
} else if (diff < 0) {
|
|
652
|
-
|
|
653
|
-
let remaining = Math.abs(diff);
|
|
654
|
-
const reduceItems = [];
|
|
655
|
-
const removeIds = [];
|
|
656
|
-
const reversed = [...(existing?.items || [])].reverse();
|
|
657
|
-
for (const giftItem of reversed) {
|
|
658
|
-
if (remaining <= 0) break;
|
|
659
|
-
const uid = getOrderProductUid(giftItem);
|
|
660
|
-
const qty = Number(giftItem?.num ?? 1) || 1;
|
|
661
|
-
if (qty <= remaining) {
|
|
662
|
-
removeIds.push(uid);
|
|
663
|
-
remaining -= qty;
|
|
664
|
-
} else {
|
|
665
|
-
reduceItems.push({
|
|
666
|
-
uid,
|
|
667
|
-
currentQuantity: qty,
|
|
668
|
-
newQuantity: qty - remaining
|
|
669
|
-
});
|
|
670
|
-
remaining = 0;
|
|
671
|
-
}
|
|
672
|
-
}
|
|
673
|
-
if (reduceItems.length > 0) toReduce.push({
|
|
674
|
-
strategyId,
|
|
675
|
-
items: reduceItems
|
|
676
|
-
});
|
|
677
|
-
toRemove.push(...removeIds);
|
|
725
|
+
reduceGiftQuantity(actions, strategyId, existing?.items || [], -diff);
|
|
678
726
|
}
|
|
679
727
|
}
|
|
680
728
|
|
|
@@ -682,14 +730,10 @@ function calculateGiftActions(gifts, existingGifts) {
|
|
|
682
730
|
for (const [strategyId, existing] of existingByStrategy) {
|
|
683
731
|
if (processedStrategyIds.has(strategyId)) continue;
|
|
684
732
|
for (const giftItem of existing.items) {
|
|
685
|
-
toRemove.push(getOrderProductUid(giftItem));
|
|
733
|
+
actions.toRemove.push(getOrderProductUid(giftItem));
|
|
686
734
|
}
|
|
687
735
|
}
|
|
688
|
-
return
|
|
689
|
-
toAdd,
|
|
690
|
-
toReduce,
|
|
691
|
-
toRemove
|
|
692
|
-
};
|
|
736
|
+
return actions;
|
|
693
737
|
}
|
|
694
738
|
|
|
695
739
|
/**
|
|
@@ -1123,7 +1167,10 @@ function processCartPromotion(list, evaluator, options) {
|
|
|
1123
1167
|
const giftInfoData = {
|
|
1124
1168
|
strategyName: gift.strategyName,
|
|
1125
1169
|
giftCount: gift.giftCount,
|
|
1126
|
-
giftOptions: gift.giftOptions
|
|
1170
|
+
giftOptions: gift.giftOptions,
|
|
1171
|
+
...(gift.giftQuotas && {
|
|
1172
|
+
giftQuotas: gift.giftQuotas
|
|
1173
|
+
})
|
|
1127
1174
|
};
|
|
1128
1175
|
const bundleIdx = priced.matchedBundleIndex;
|
|
1129
1176
|
if (bundleIdx !== undefined && Array.isArray(newItem.product_bundle) && newItem.product_bundle[bundleIdx]?._promotion) {
|
|
@@ -1211,7 +1258,7 @@ function processCartPromotion(list, evaluator, options) {
|
|
|
1211
1258
|
}
|
|
1212
1259
|
|
|
1213
1260
|
// 10. 赠品操作(在更新 lastEvaluatedGiftCount 前做对比)
|
|
1214
|
-
const giftActions = calculateGiftActions(extendedGifts, existingGifts);
|
|
1261
|
+
const giftActions = calculateGiftActions(extendedGifts, existingGifts, options?.previousFixedGiftQuotas || []);
|
|
1215
1262
|
|
|
1216
1263
|
// 10.1 更新 lastEvaluatedGiftCount,便于下次评估时判别「策略已变」
|
|
1217
1264
|
for (const gift of existingGifts) {
|
|
@@ -295,7 +295,7 @@ export declare class BookingTicketImpl extends BaseSalesImpl implements Module {
|
|
|
295
295
|
private getCustomerContactOrderKey;
|
|
296
296
|
replaceTempOrder(...args: Parameters<BaseSalesImpl['replaceTempOrder']>): Promise<import("../../modules/Order/types").OrderTempOrder>;
|
|
297
297
|
private applyDefaultOrderCustomerContactInfo;
|
|
298
|
-
private
|
|
298
|
+
private withAccountContactFallback;
|
|
299
299
|
private prefillOrderCustomerContactInfo;
|
|
300
300
|
protected waitForOrderCustomerContactInfo(): Promise<void>;
|
|
301
301
|
validateContactInfo(): Promise<void>;
|
|
@@ -374,7 +374,7 @@ export declare class BookingTicketImpl extends BaseSalesImpl implements Module {
|
|
|
374
374
|
* 获取当前的客户搜索条件
|
|
375
375
|
* @returns 当前搜索条件
|
|
376
376
|
*/
|
|
377
|
-
getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "
|
|
377
|
+
getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "num" | "skip">;
|
|
378
378
|
/**
|
|
379
379
|
* 获取客户列表状态(包含滚动加载相关状态)
|
|
380
380
|
* @returns 客户状态
|