@pisell/pisellos 2.3.230 → 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/index.js +0 -9
- package/dist/model/strategy/adapter/promotion/type.d.ts +10 -2
- package/dist/modules/Customer/types.d.ts +0 -4
- package/dist/modules/Order/index.js +1411 -1318
- package/dist/modules/Order/types.d.ts +13 -36
- package/dist/modules/Order/types.js +2 -0
- package/dist/modules/Order/utils.js +0 -2
- package/dist/modules/Product/index.d.ts +1 -1
- package/dist/solution/BaseSales/index.js +0 -3
- package/dist/solution/BaseSales/utils/cartPromotion.d.ts +5 -18
- package/dist/solution/BaseSales/utils/cartPromotion.js +252 -168
- package/dist/solution/BookingByStep/index.d.ts +3 -3
- package/dist/solution/BookingTicket/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.js +45 -21
- package/dist/solution/BookingTicket/utils/redeemArrival.d.ts +9 -9
- package/dist/solution/Checkout/index.js +69 -104
- package/dist/solution/Checkout/types.d.ts +0 -1
- package/dist/solution/ScanOrder/index.d.ts +1 -0
- package/dist/solution/ScanOrder/index.js +54 -48
- 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/dist/solution/VenueBooking/index.js +490 -522
- 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/Customer/types.d.ts +0 -4
- package/lib/modules/Order/index.js +109 -76
- package/lib/modules/Order/types.d.ts +13 -36
- package/lib/modules/Order/types.js +1 -0
- package/lib/modules/Order/utils.js +1 -5
- package/lib/modules/Product/index.d.ts +1 -1
- package/lib/solution/BaseSales/index.js +0 -3
- package/lib/solution/BaseSales/utils/cartPromotion.d.ts +5 -18
- package/lib/solution/BaseSales/utils/cartPromotion.js +87 -40
- package/lib/solution/BookingByStep/index.d.ts +3 -3
- package/lib/solution/BookingTicket/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.js +28 -11
- package/lib/solution/BookingTicket/utils/redeemArrival.d.ts +9 -9
- package/lib/solution/Checkout/index.js +0 -21
- package/lib/solution/Checkout/types.d.ts +0 -1
- package/lib/solution/ScanOrder/index.d.ts +1 -0
- package/lib/solution/ScanOrder/index.js +26 -19
- 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/lib/solution/VenueBooking/index.js +1 -6
- package/package.json +1 -1
- package/dist/modules/Order/utils/bookingUuid.d.ts +0 -4
- package/dist/modules/Order/utils/bookingUuid.js +0 -24
- package/lib/modules/Order/utils/bookingUuid.d.ts +0 -4
- package/lib/modules/Order/utils/bookingUuid.js +0 -25
|
@@ -174,13 +174,22 @@ class PromotionAdapter {
|
|
|
174
174
|
parseBuyXGetYFreeAction(action) {
|
|
175
175
|
const value = action.value || {};
|
|
176
176
|
const config = action.config || {};
|
|
177
|
+
const fixedGiftProducts = config.fixedGiftProducts;
|
|
178
|
+
if (fixedGiftProducts !== undefined) {
|
|
179
|
+
if (!Number.isSafeInteger(value.buyQuantity) || value.buyQuantity <= 0 || !Array.isArray(fixedGiftProducts) || fixedGiftProducts.length === 0 || fixedGiftProducts.some(gift => !gift || !Number.isSafeInteger(gift.product_id) || gift.product_id <= 0 || !Number.isSafeInteger(gift.product_variant_id) || gift.product_variant_id < 0 || !Number.isSafeInteger(gift.quantity) || gift.quantity <= 0) || new Set(fixedGiftProducts.map(gift => gift.product_id)).size !== fixedGiftProducts.length) {
|
|
180
|
+
return undefined;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
177
183
|
return {
|
|
178
184
|
type: _type.PROMOTION_ACTION_TYPES.BUY_X_GET_Y_FREE,
|
|
179
185
|
buyQuantity: value.buyQuantity || 1,
|
|
180
186
|
freeQuantity: value.freeQuantity || 1,
|
|
181
187
|
giftSelectionMode: config.giftSelectionMode || 'user_select',
|
|
182
188
|
cumulative: config.cumulative ?? true,
|
|
183
|
-
giftProducts: config.giftProducts || []
|
|
189
|
+
giftProducts: config.giftProducts || [],
|
|
190
|
+
...(fixedGiftProducts && {
|
|
191
|
+
fixedGiftProducts
|
|
192
|
+
})
|
|
184
193
|
};
|
|
185
194
|
}
|
|
186
195
|
|
|
@@ -830,7 +830,8 @@ class PromotionEvaluator {
|
|
|
830
830
|
buyQuantity,
|
|
831
831
|
freeQuantity,
|
|
832
832
|
cumulative,
|
|
833
|
-
giftProducts
|
|
833
|
+
giftProducts,
|
|
834
|
+
fixedGiftProducts
|
|
834
835
|
} = detail;
|
|
835
836
|
const result = [];
|
|
836
837
|
let originalAmount = new _decimal.default(0);
|
|
@@ -896,17 +897,28 @@ class PromotionEvaluator {
|
|
|
896
897
|
}
|
|
897
898
|
|
|
898
899
|
// 4. 计算赠品数量(使用促销数量)
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
900
|
+
const groupCount = isFulfilled ? cumulative ? Math.floor(totalPromoQty / buyQuantity) : 1 : 0;
|
|
901
|
+
const giftQuotas = fixedGiftProducts?.map(gift => ({
|
|
902
|
+
...gift,
|
|
903
|
+
quantity: gift.quantity * groupCount
|
|
904
|
+
}));
|
|
905
|
+
const giftCount = giftQuotas ? giftQuotas.reduce((total, gift) => total + gift.quantity, 0) : groupCount * freeQuantity;
|
|
903
906
|
|
|
904
907
|
// 5. 构建赠品信息
|
|
905
908
|
const giftInfo = giftCount > 0 ? {
|
|
906
909
|
strategyId,
|
|
907
910
|
strategyName,
|
|
908
911
|
giftCount,
|
|
909
|
-
giftOptions:
|
|
912
|
+
giftOptions: fixedGiftProducts ? fixedGiftProducts.map(({
|
|
913
|
+
product_id,
|
|
914
|
+
product_variant_id
|
|
915
|
+
}) => ({
|
|
916
|
+
product_id,
|
|
917
|
+
product_variant_id
|
|
918
|
+
})) : giftProducts || [],
|
|
919
|
+
...(giftQuotas && {
|
|
920
|
+
giftQuotas
|
|
921
|
+
})
|
|
910
922
|
} : null;
|
|
911
923
|
return {
|
|
912
924
|
products: result,
|
|
@@ -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
|
* 带定价的购物车评估结果
|
|
@@ -44,10 +44,6 @@ export interface ShopGetCustomerListParams {
|
|
|
44
44
|
num?: number;
|
|
45
45
|
/** 搜索关键词 */
|
|
46
46
|
search?: string;
|
|
47
|
-
/** Full national phone number, without the international calling code. */
|
|
48
|
-
phone?: string;
|
|
49
|
-
/** Exact email lookup, independent from the generic search keyword. */
|
|
50
|
-
email?: string;
|
|
51
47
|
/** 关联查询参数 */
|
|
52
48
|
with?: CustomerWith[];
|
|
53
49
|
/** wallet搜索标识 */
|
|
@@ -11,7 +11,6 @@ Object.defineProperty(exports, "isFulfillmentTimingBooking", {
|
|
|
11
11
|
}
|
|
12
12
|
});
|
|
13
13
|
var _loadSalesOrderSnapshot = require("../../shared/sales/loadSalesOrderSnapshot");
|
|
14
|
-
var _bookingUuid = require("./utils/bookingUuid");
|
|
15
14
|
var _localEftposState = require("./localEftposState");
|
|
16
15
|
var _BaseModule = require("../BaseModule");
|
|
17
16
|
var _types = require("./types");
|
|
@@ -1043,40 +1042,62 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
1043
1042
|
if (!tempOrder) {
|
|
1044
1043
|
return null;
|
|
1045
1044
|
}
|
|
1045
|
+
const isCurrentOrder = () => this.store.tempOrder === tempOrder && (options?.isCurrentOrder?.() ?? true);
|
|
1046
1046
|
if (this.isActiveVirtualSettlementOrder(tempOrder)) {
|
|
1047
1047
|
tempOrder.products = (0, _virtualSettlement.normalizeVirtualSettlementProducts)(tempOrder.products);
|
|
1048
1048
|
return null;
|
|
1049
1049
|
}
|
|
1050
|
+
const previousFixedGiftQuotas = tempOrder._extend?.fixedGiftQuotas || [];
|
|
1050
1051
|
const strategyConfigs = this.promotionEvaluator.getStrategyConfigs?.();
|
|
1051
|
-
if (Array.isArray(strategyConfigs) && strategyConfigs.length === 0) {
|
|
1052
|
+
if (Array.isArray(strategyConfigs) && strategyConfigs.length === 0 && !previousFixedGiftQuotas.length) {
|
|
1052
1053
|
return null;
|
|
1053
1054
|
}
|
|
1054
1055
|
this.isApplyingPromotion = true;
|
|
1055
1056
|
try {
|
|
1056
|
-
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
|
+
};
|
|
1057
1071
|
|
|
1058
|
-
//
|
|
1072
|
+
// 同步移除赠品行和占用的预约。
|
|
1059
1073
|
if (result.giftActions.toRemove.length > 0) {
|
|
1060
|
-
const removeSet = new Set(result.giftActions.toRemove.
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
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);
|
|
1065
1081
|
}
|
|
1082
|
+
const removedBookings = nextOrder.bookings?.length !== tempOrder.bookings?.length;
|
|
1066
1083
|
|
|
1067
1084
|
// step 2: toReduce —— 调整数量
|
|
1068
1085
|
for (const reduce of result.giftActions.toReduce) {
|
|
1069
1086
|
for (const item of reduce.items) {
|
|
1070
|
-
const
|
|
1071
|
-
if (
|
|
1072
|
-
|
|
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
|
+
};
|
|
1073
1093
|
}
|
|
1074
1094
|
}
|
|
1075
1095
|
}
|
|
1076
1096
|
|
|
1077
1097
|
// step 3: toAdd —— 补赠品
|
|
1098
|
+
const giftSelectResolver = this.giftSelectResolver;
|
|
1078
1099
|
if (result.giftActions.toAdd.length > 0) {
|
|
1079
|
-
if (!
|
|
1100
|
+
if (!giftSelectResolver) {
|
|
1080
1101
|
if (result.giftActions.toAdd.some(g => g.giftOptions.length > 1)) {
|
|
1081
1102
|
// 多选项必须走 resolver;单选项也建议走(避免 OS 自造 stub),但允许跳过
|
|
1082
1103
|
console.warn('[OrderModule] giftSelectResolver not set, skip applying gifts', result.giftActions.toAdd);
|
|
@@ -1084,53 +1105,82 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
1084
1105
|
console.warn('[OrderModule] giftSelectResolver not set, skip applying single-option gifts', result.giftActions.toAdd);
|
|
1085
1106
|
}
|
|
1086
1107
|
} else {
|
|
1108
|
+
if (result.giftActions.toRemove.length || result.giftActions.toReduce.length) {
|
|
1109
|
+
publishGiftChanges();
|
|
1110
|
+
}
|
|
1087
1111
|
for (const addAction of result.giftActions.toAdd) {
|
|
1088
1112
|
// 唯一候选也可能有规格/套餐。每次补赠都交给 SDK 判断,不能复用旧赠品的选择。
|
|
1089
1113
|
|
|
1090
|
-
const
|
|
1114
|
+
const fixedGiftQuotas = addAction.giftQuotas;
|
|
1115
|
+
const giftMutationBaseline = options?.isCurrentOrder || fixedGiftQuotas ? (0, _lodashEs.cloneDeep)({
|
|
1091
1116
|
products: tempOrder.products,
|
|
1092
1117
|
bookings: tempOrder.bookings
|
|
1093
1118
|
}) : null;
|
|
1094
1119
|
try {
|
|
1095
|
-
const
|
|
1096
|
-
|
|
1120
|
+
const inventoryProducts = fixedGiftQuotas ? nextOrder.products : tempOrder.products;
|
|
1121
|
+
const giftResult = await giftSelectResolver({
|
|
1122
|
+
...addAction,
|
|
1123
|
+
inventoryReserved: inventoryProducts.map(line => ({
|
|
1097
1124
|
product_id: Number(line.product_id),
|
|
1098
1125
|
product_variant_id: Number(line.product_variant_id || 0),
|
|
1099
1126
|
quantity: Number(line.num) || 0
|
|
1100
|
-
}))
|
|
1101
|
-
strategyId: addAction.strategyId,
|
|
1102
|
-
strategyName: addAction.strategyName,
|
|
1103
|
-
giftCount: addAction.giftCount,
|
|
1104
|
-
giftOptions: addAction.giftOptions,
|
|
1105
|
-
sourceProductIds: addAction.sourceProductIds
|
|
1127
|
+
}))
|
|
1106
1128
|
});
|
|
1107
|
-
if (
|
|
1108
|
-
if (
|
|
1129
|
+
if (!isCurrentOrder()) return null;
|
|
1130
|
+
if (giftMutationBaseline && !(0, _lodashEs.isEqual)({
|
|
1109
1131
|
products: tempOrder.products,
|
|
1110
1132
|
bookings: tempOrder.bookings
|
|
1111
1133
|
}, giftMutationBaseline)) return null;
|
|
1112
1134
|
const giftProducts = Array.isArray(giftResult) ? giftResult : giftResult?.products;
|
|
1113
1135
|
const giftBookings = Array.isArray(giftResult) ? [] : giftResult?.bookings || [];
|
|
1114
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 = [];
|
|
1115
1153
|
for (const [index, gp] of giftProducts.entries()) {
|
|
1116
1154
|
if (!gp) continue;
|
|
1117
|
-
const
|
|
1155
|
+
const productUid = (0, _cartPromotion.getOrderProductUid)(gp);
|
|
1156
|
+
const booking = fixedBookingsByProduct ? fixedBookingsByProduct.get(productUid) : giftBookings[index];
|
|
1118
1157
|
if (booking) {
|
|
1158
|
+
fixedBookingsByProduct?.delete(productUid);
|
|
1119
1159
|
const linked = this.createLinkedProductAndBooking({
|
|
1120
1160
|
product: gp,
|
|
1121
1161
|
booking
|
|
1122
1162
|
});
|
|
1123
|
-
|
|
1124
|
-
|
|
1163
|
+
products.push(linked.product);
|
|
1164
|
+
bookings.push(linked.booking);
|
|
1125
1165
|
continue;
|
|
1126
1166
|
}
|
|
1167
|
+
if (fixedBookingsByProduct && gp.metadata?.booking_uid) {
|
|
1168
|
+
throw new Error('Gift booking does not match its selected product');
|
|
1169
|
+
}
|
|
1127
1170
|
// normalize 略过:调用方应保证返回完整 OrderProduct。
|
|
1128
|
-
|
|
1171
|
+
products.push(gp);
|
|
1129
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();
|
|
1130
1180
|
}
|
|
1131
1181
|
} catch (error) {
|
|
1132
|
-
if (
|
|
1133
|
-
if (
|
|
1182
|
+
if (!isCurrentOrder()) return null;
|
|
1183
|
+
if (giftMutationBaseline && !(0, _lodashEs.isEqual)({
|
|
1134
1184
|
products: tempOrder.products,
|
|
1135
1185
|
bookings: tempOrder.bookings
|
|
1136
1186
|
}, giftMutationBaseline)) return null;
|
|
@@ -1140,8 +1190,24 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
1140
1190
|
}
|
|
1141
1191
|
}
|
|
1142
1192
|
}
|
|
1143
|
-
if (
|
|
1144
|
-
|
|
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
|
+
}
|
|
1145
1211
|
if (tempOrder.products.length === 0) {
|
|
1146
1212
|
// 删除主商品后,促销重算可能继续移除最后的赠品。
|
|
1147
1213
|
tempOrder.shop_discount = '0.00';
|
|
@@ -1155,7 +1221,10 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
1155
1221
|
strategyId: g.strategyId,
|
|
1156
1222
|
strategyName: g.strategyName,
|
|
1157
1223
|
giftCount: g.giftCount,
|
|
1158
|
-
giftOptions: g.giftOptions
|
|
1224
|
+
giftOptions: g.giftOptions,
|
|
1225
|
+
...(g.giftQuotas && {
|
|
1226
|
+
giftQuotas: g.giftQuotas
|
|
1227
|
+
})
|
|
1159
1228
|
})),
|
|
1160
1229
|
products: tempOrder.products
|
|
1161
1230
|
};
|
|
@@ -2586,7 +2655,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
2586
2655
|
booking_uid: bookingUid
|
|
2587
2656
|
},
|
|
2588
2657
|
booking: {
|
|
2589
|
-
...
|
|
2658
|
+
...params.booking,
|
|
2590
2659
|
is_all: (0, _utils.normalizeBookingIsAll)(params.booking),
|
|
2591
2660
|
product_uid: productUid,
|
|
2592
2661
|
sub_type: (0, _utils.normalizeBookingSubType)(params.booking),
|
|
@@ -3201,7 +3270,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
3201
3270
|
const tempOrder = this.ensureTempOrder();
|
|
3202
3271
|
const bookings = tempOrder.bookings || [];
|
|
3203
3272
|
const firstIndex = bookings.findIndex(_pickupTiming.isFulfillmentTimingBooking);
|
|
3204
|
-
const nextBooking = (0,
|
|
3273
|
+
const nextBooking = (0, _pickupTiming.buildPickupTimingBooking)(input, bookings[firstIndex]);
|
|
3205
3274
|
// Keep the first row's identity and position; repair duplicate marked rows only.
|
|
3206
3275
|
tempOrder.bookings = firstIndex === -1 ? [...bookings, nextBooking] : bookings.flatMap((booking, index) => index === firstIndex ? [nextBooking] : (0, _pickupTiming.isFulfillmentTimingBooking)(booking) ? [] : [booking]);
|
|
3207
3276
|
this.notifyTempOrderChanged();
|
|
@@ -3853,16 +3922,6 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
3853
3922
|
* if (pending) await pending;
|
|
3854
3923
|
*/
|
|
3855
3924
|
appendProductLineToTempOrder(tempOrder, product, booking, options) {
|
|
3856
|
-
const incomingBookingUuid = booking?.uuid;
|
|
3857
|
-
if (booking && incomingBookingUuid && tempOrder.bookings?.some(item => item.uuid === incomingBookingUuid)) {
|
|
3858
|
-
// Appending a copy creates a different booking; editing uses the update path below.
|
|
3859
|
-
booking = {
|
|
3860
|
-
...booking,
|
|
3861
|
-
uuid: (0, _utils.createUuidV4)(),
|
|
3862
|
-
id: undefined,
|
|
3863
|
-
schedule_event_id: undefined
|
|
3864
|
-
};
|
|
3865
|
-
}
|
|
3866
3925
|
const linked = booking ? this.createLinkedProductAndBooking({
|
|
3867
3926
|
product,
|
|
3868
3927
|
booking
|
|
@@ -4027,12 +4086,6 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
4027
4086
|
singleLine.num = 1;
|
|
4028
4087
|
delete singleLine.product_quantity;
|
|
4029
4088
|
const singleBooking = (0, _lodashEs.cloneDeep)(booking);
|
|
4030
|
-
if (index > 0) {
|
|
4031
|
-
// Both single-add and batch-add quantity splits create separate appointments.
|
|
4032
|
-
delete singleBooking.uuid;
|
|
4033
|
-
delete singleBooking.schedule_event_id;
|
|
4034
|
-
delete singleBooking.id;
|
|
4035
|
-
}
|
|
4036
4089
|
const bookingHolder = booking?.holder && typeof booking.holder === 'object' ? booking.holder : null;
|
|
4037
4090
|
const metadataHolder = booking?.metadata?.holder && typeof booking.metadata.holder === 'object' ? booking.metadata.holder : null;
|
|
4038
4091
|
const rawHolderIds = bookingHolder?.form_record ?? booking?.metadata?.holder_id ?? metadataHolder?.form_record ?? product?.metadata?.holder_id;
|
|
@@ -4283,8 +4336,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
4283
4336
|
const target = live.products[targetIndex];
|
|
4284
4337
|
const scopeKey = String(target?.metadata?.venue_booking_scope_key || '');
|
|
4285
4338
|
const targetBookingUid = String(target?.booking_uid || target?.metadata?.booking_uid || '');
|
|
4286
|
-
|
|
4287
|
-
if (!uid || !target || !scopeKey || live.order_id || target.order_detail_id != null || Number(target.num) !== 1 || Number(params.product.num ?? 1) !== 1 || target.metadata?.venue_booking_role !== 'party_main' || params.product.metadata?.venue_booking_role !== 'party_main' || params.product.metadata?.venue_booking_scope_key !== scopeKey || !Array.isArray(params.relatedRetailProducts) || (live.payments || []).length > 0 || !targetBookingUid || String(params.booking.metadata?.unique_identification_number || '') !== targetBookingUid || targetBookings.length !== 1 || live.products.filter(line => line.metadata?.venue_booking_role === 'party_main' && line.metadata?.venue_booking_scope_key === scopeKey).length !== 1) {
|
|
4339
|
+
if (!uid || !target || !scopeKey || live.order_id || target.order_detail_id != null || Number(target.num) !== 1 || Number(params.product.num ?? 1) !== 1 || target.metadata?.venue_booking_role !== 'party_main' || params.product.metadata?.venue_booking_role !== 'party_main' || params.product.metadata?.venue_booking_scope_key !== scopeKey || !Array.isArray(params.relatedRetailProducts) || (live.payments || []).length > 0 || !targetBookingUid || String(params.booking.metadata?.unique_identification_number || '') !== targetBookingUid || (live.bookings || []).filter(booking => this.getBookingUniqueIdentificationNumber(booking) === targetBookingUid).length !== 1 || live.products.filter(line => line.metadata?.venue_booking_role === 'party_main' && line.metadata?.venue_booking_scope_key === scopeKey).length !== 1) {
|
|
4288
4340
|
throw new Error('[Order] Party replacement requires one unsubmitted, unpaid main booking in the same scope');
|
|
4289
4341
|
}
|
|
4290
4342
|
const children = live.products.filter(line => line.metadata?.venue_booking_role === 'party_extra' && String(line.metadata?.venue_booking_parent_uid || '') === uid);
|
|
@@ -4344,9 +4396,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
4344
4396
|
venue_booking_service_datetime: serviceDatetime
|
|
4345
4397
|
};
|
|
4346
4398
|
replacement.unique_identification_number = uid;
|
|
4347
|
-
|
|
4348
|
-
replacementBooking.uuid = targetBookings[0].uuid || replacementBooking.uuid;
|
|
4349
|
-
await this.appendProductLineToTempOrder(draft, replacement, replacementBooking, {
|
|
4399
|
+
await this.appendProductLineToTempOrder(draft, replacement, (0, _lodashEs.cloneDeep)(params.booking), {
|
|
4350
4400
|
insertAtIndex: targetIndex,
|
|
4351
4401
|
disableMerge: true,
|
|
4352
4402
|
beforeCommit
|
|
@@ -4754,22 +4804,12 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
4754
4804
|
...(normalizedProduct.metadata || {}),
|
|
4755
4805
|
unique_identification_number: productUid
|
|
4756
4806
|
};
|
|
4757
|
-
const originalBookingUid = targetProduct.booking_uid || targetProduct.metadata?.booking_uid || preservedBookingUid;
|
|
4758
|
-
const bookings = tempOrder.bookings || [];
|
|
4759
|
-
const eventId = booking.schedule_event_id;
|
|
4760
|
-
const originalBooking = bookings.find(row => Number(eventId) > 0 && String(row.schedule_event_id) === String(eventId)) ?? bookings.find(row => originalBookingUid && row.metadata?.unique_identification_number === originalBookingUid);
|
|
4761
|
-
const {
|
|
4762
|
-
uuid: incomingUuid = originalBooking?.uuid
|
|
4763
|
-
} = booking;
|
|
4764
4807
|
const linked = this.createLinkedProductAndBooking({
|
|
4765
4808
|
product: {
|
|
4766
4809
|
...normalizedProduct,
|
|
4767
4810
|
unique_identification_number: productUid
|
|
4768
4811
|
},
|
|
4769
|
-
booking
|
|
4770
|
-
...booking,
|
|
4771
|
-
uuid: originalBooking?.uuid || incomingUuid
|
|
4772
|
-
}
|
|
4812
|
+
booking
|
|
4773
4813
|
});
|
|
4774
4814
|
this.removeLinkedBookingsForProduct(tempOrder, targetProduct);
|
|
4775
4815
|
normalizedProduct = {
|
|
@@ -5031,13 +5071,9 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
5031
5071
|
throw new Error('[Order] 目标 booking 不存在,无法更新');
|
|
5032
5072
|
}
|
|
5033
5073
|
const targetBooking = tempOrder.bookings[bookingIndex] || {};
|
|
5034
|
-
const {
|
|
5035
|
-
uuid: incomingUuid = targetBooking.uuid
|
|
5036
|
-
} = updates;
|
|
5037
5074
|
const nextBooking = {
|
|
5038
5075
|
...targetBooking,
|
|
5039
5076
|
...updates,
|
|
5040
|
-
uuid: targetBooking.uuid || incomingUuid,
|
|
5041
5077
|
metadata: {
|
|
5042
5078
|
...(targetBooking.metadata || {}),
|
|
5043
5079
|
...(updates.metadata || {}),
|
|
@@ -5047,7 +5083,6 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
5047
5083
|
unique_identification_number: bookingUid
|
|
5048
5084
|
}
|
|
5049
5085
|
};
|
|
5050
|
-
(0, _bookingUuid.assignBookingUuid)(nextBooking);
|
|
5051
5086
|
this.syncBookingMetadataHolder(nextBooking, nextBooking.metadata);
|
|
5052
5087
|
nextBooking.is_all = (0, _utils.normalizeBookingIsAll)(nextBooking);
|
|
5053
5088
|
nextBooking.sub_type = (0, _utils.normalizeBookingSubType)(nextBooking);
|
|
@@ -5221,6 +5256,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
5221
5256
|
...tempOrder._extend,
|
|
5222
5257
|
productsByUid: {}
|
|
5223
5258
|
};
|
|
5259
|
+
delete tempOrder._extend.fixedGiftQuotas;
|
|
5224
5260
|
}
|
|
5225
5261
|
if (mutation.commit) tempOrder = await mutation.commit();
|
|
5226
5262
|
const promotionPayload = await this.evaluatePromotion();
|
|
@@ -5748,7 +5784,6 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
5748
5784
|
* @returns 后端返回的订单数据(包含订单ID等)
|
|
5749
5785
|
*/
|
|
5750
5786
|
async createOrderByCheckout(params) {
|
|
5751
|
-
params.bookings?.forEach(_bookingUuid.assignBookingUuid);
|
|
5752
5787
|
// 过滤掉由在线店铺下单的 payment 支付数据
|
|
5753
5788
|
const onlineStorePaymentCodeList = ['WXPAY', 'WECHAT', 'ALIPAY', 'APPLE_PAY', 'CREDIT_CARD_3DS', 'CREDIT_CARD_TOKEN', 'GOOGLE_PAY', 'GOOGLE_PAY_3DS', 'CREDIT_CARD'];
|
|
5754
5789
|
params.payments = params.payments?.filter(p => !onlineStorePaymentCodeList.includes(p.code));
|
|
@@ -5836,7 +5871,6 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
5836
5871
|
url,
|
|
5837
5872
|
query
|
|
5838
5873
|
} = params;
|
|
5839
|
-
query.bookings?.forEach(_bookingUuid.assignBookingUuid);
|
|
5840
5874
|
const fetchUrl = url || '/order/sales/checkout';
|
|
5841
5875
|
const handledByOsServer = this.isSalesCheckoutHandledByOsServer(fetchUrl);
|
|
5842
5876
|
const requestQuery = handledByOsServer ? query : (0, _localEftposState.stripLocalEftposState)((0, _osPrivatePayload.stripOsPrivatePayloadFields)(query));
|
|
@@ -6191,9 +6225,8 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
6191
6225
|
})) : [];
|
|
6192
6226
|
nextTempOrder.bookings = Array.isArray(raw.bookings) ? raw.bookings.map(b => {
|
|
6193
6227
|
const booking = this.normalizeHydratedBookingHolder(b || {});
|
|
6194
|
-
const submitted = (0, _pickupTiming.isFulfillmentTimingBooking)(booking) || Number(booking.parent_id) !== 0;
|
|
6195
6228
|
return {
|
|
6196
|
-
...
|
|
6229
|
+
...booking,
|
|
6197
6230
|
is_all: (0, _utils.normalizeBookingIsAll)(booking),
|
|
6198
6231
|
sub_type: (0, _utils.normalizeBookingSubType)(booking)
|
|
6199
6232
|
};
|
|
@@ -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
|
}
|
|
@@ -617,8 +596,6 @@ export interface CommitOrderParams {
|
|
|
617
596
|
};
|
|
618
597
|
}
|
|
619
598
|
export interface OrderSubmitBooking {
|
|
620
|
-
/** Stable booking identity, created once and shared with external allocations. */
|
|
621
|
-
uuid?: string | null;
|
|
622
599
|
relation_id?: string;
|
|
623
600
|
form_id?: string;
|
|
624
601
|
collect_pax?: number;
|
|
@@ -140,7 +140,6 @@ var _manualProductDiscount = require("./utils/manualProductDiscount");
|
|
|
140
140
|
var _utils = require("../Holder/utils");
|
|
141
141
|
var _utils2 = require("../../solution/ScanOrder/utils");
|
|
142
142
|
var _orderCollectionIdentity = require("./utils/orderCollectionIdentity");
|
|
143
|
-
var _bookingUuid = require("./utils/bookingUuid");
|
|
144
143
|
var _salesNotes = require("./salesNotes");
|
|
145
144
|
var _pickupTiming = require("./pickupTiming");
|
|
146
145
|
var _holderRelations = require("./holderRelations");
|
|
@@ -1665,10 +1664,7 @@ function buildSubmitPayload(params) {
|
|
|
1665
1664
|
delivery_type: tempOrder.delivery_type || 'shop_service',
|
|
1666
1665
|
schedule_date: scheduleDate,
|
|
1667
1666
|
// created_at: tempOrder.created_at || formatDateTime(now), 和后端协定这个字段先不提交到接口
|
|
1668
|
-
bookings: (tempOrder.bookings || []).filter(booking => (0, _pickupTiming.isFulfillmentTimingBooking)(booking) || Number(booking.parent_id) !== 0).map(booking =>
|
|
1669
|
-
(0, _bookingUuid.assignBookingUuid)(booking);
|
|
1670
|
-
return normalizeSubmitBooking(booking);
|
|
1671
|
-
}),
|
|
1667
|
+
bookings: (tempOrder.bookings || []).filter(booking => (0, _pickupTiming.isFulfillmentTimingBooking)(booking) || Number(booking.parent_id) !== 0).map(booking => normalizeSubmitBooking(booking)),
|
|
1672
1668
|
payments: tempOrder.payments || [],
|
|
1673
1669
|
relation_forms: tempOrder.relation_forms || [],
|
|
1674
1670
|
// contacts: tempOrder.contacts || [],
|
|
@@ -49,5 +49,5 @@ export declare class Product extends BaseModule implements Module {
|
|
|
49
49
|
getCategories(): ProductCategory[];
|
|
50
50
|
setOtherParams(key: string, value: any): void;
|
|
51
51
|
getOtherParams(): any;
|
|
52
|
-
getProductType(): "normal" | "
|
|
52
|
+
getProductType(): "normal" | "duration" | "session";
|
|
53
53
|
}
|
|
@@ -223,9 +223,6 @@ function mergeBaseSalesCollectionItem(kind, currentItem, incomingItem, uidRemaps
|
|
|
223
223
|
}
|
|
224
224
|
}
|
|
225
225
|
const mergedItem = mergedUid ? (0, _orderCollectionIdentity.setOrderCollectionUid)(kind, incomingItem, mergedUid) : (0, _lodashEs.cloneDeep)(incomingItem);
|
|
226
|
-
if (kind === 'booking' && !mergedItem.uuid && currentItem.uuid !== undefined) {
|
|
227
|
-
mergedItem.uuid = currentItem.uuid;
|
|
228
|
-
}
|
|
229
226
|
const persistentIdField = BASE_SALES_PERSISTENT_ID_FIELD_BY_KIND[kind];
|
|
230
227
|
if (isBaseSalesBlankValue(mergedItem[persistentIdField]) && !isBaseSalesBlankValue(identityMergedItem[persistentIdField])) {
|
|
231
228
|
mergedItem[persistentIdField] = identityMergedItem[persistentIdField];
|