@pisell/pisellos 2.3.127 → 2.3.128
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/index.js +9 -0
- package/dist/model/strategy/adapter/walletPass/evaluator.d.ts +0 -2
- package/dist/model/strategy/adapter/walletPass/evaluator.js +2 -4
- package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +19 -58
- package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +12 -24
- package/dist/modules/Customer/index.js +3 -6
- package/dist/modules/Customer/types.d.ts +0 -2
- package/dist/modules/Discount/index.d.ts +2 -2
- package/dist/modules/Discount/index.js +151 -37
- package/dist/modules/Discount/types.d.ts +5 -36
- package/dist/modules/Order/index.d.ts +2 -7
- package/dist/modules/Order/index.js +331 -480
- package/dist/modules/Order/utils/orderCollectionIdentity.js +12 -16
- package/dist/modules/Order/utils/weighedProduct.d.ts +12 -0
- package/dist/modules/Order/utils/weighedProduct.js +94 -0
- package/dist/modules/Order/utils.d.ts +1 -1
- package/dist/modules/Order/utils.js +65 -104
- package/dist/modules/Payment/types.d.ts +1 -21
- package/dist/modules/Payment/types.js +0 -2
- package/dist/modules/Payment/walletpass.d.ts +1 -1
- package/dist/modules/Payment/walletpass.js +47 -80
- package/dist/modules/Rules/index.d.ts +2 -2
- package/dist/modules/Rules/index.js +190 -482
- package/dist/modules/Rules/types.d.ts +2 -4
- package/dist/server/modules/order/types.d.ts +0 -2
- package/dist/server/utils/small-ticket.js +1 -1
- package/dist/solution/BaseSales/index.d.ts +2 -3
- package/dist/solution/BaseSales/index.js +77 -44
- package/dist/solution/BaseSales/types.d.ts +7 -3
- package/dist/solution/BaseSales/utils/cartPromotion.js +126 -141
- package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +40 -25
- package/dist/solution/BaseSales/utils.js +3 -2
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.d.ts +3 -2
- package/dist/solution/BookingTicket/index.js +63 -60
- package/dist/solution/BookingTicket/types.d.ts +1 -5
- package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +0 -2
- package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +147 -338
- package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +4 -8
- package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +0 -6
- package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.js +6 -19
- package/dist/solution/ScanOrder/utils.js +3 -2
- package/dist/solution/ShopDiscount/index.d.ts +0 -2
- package/dist/solution/ShopDiscount/index.js +42 -99
- package/dist/solution/ShopDiscount/utils.d.ts +2 -4
- package/dist/solution/ShopDiscount/utils.js +23 -43
- package/dist/solution/UnifiedBookingSales/index.js +2 -2
- package/lib/model/strategy/adapter/promotion/index.js +1 -46
- package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +0 -2
- package/lib/model/strategy/adapter/walletPass/evaluator.js +0 -2
- package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +6 -35
- package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +6 -13
- package/lib/modules/Customer/index.js +1 -5
- package/lib/modules/Customer/types.d.ts +0 -2
- package/lib/modules/Discount/index.d.ts +2 -2
- package/lib/modules/Discount/index.js +129 -23
- package/lib/modules/Discount/types.d.ts +5 -36
- package/lib/modules/Order/index.d.ts +2 -7
- package/lib/modules/Order/index.js +109 -222
- package/lib/modules/Order/utils/orderCollectionIdentity.js +11 -14
- package/lib/modules/Order/utils/weighedProduct.d.ts +12 -0
- package/lib/modules/Order/utils/weighedProduct.js +89 -0
- package/lib/modules/Order/utils.d.ts +1 -1
- package/lib/modules/Order/utils.js +6 -41
- package/lib/modules/Payment/types.d.ts +1 -21
- package/lib/modules/Payment/types.js +0 -1
- package/lib/modules/Payment/walletpass.d.ts +1 -1
- package/lib/modules/Payment/walletpass.js +9 -29
- package/lib/modules/Rules/index.d.ts +2 -2
- package/lib/modules/Rules/index.js +114 -359
- package/lib/modules/Rules/types.d.ts +2 -4
- package/lib/server/modules/order/types.d.ts +0 -2
- package/lib/server/utils/small-ticket.js +1 -1
- package/lib/solution/BaseSales/index.d.ts +2 -3
- package/lib/solution/BaseSales/index.js +17 -11
- package/lib/solution/BaseSales/types.d.ts +7 -3
- package/lib/solution/BaseSales/utils/cartPromotion.js +4 -12
- package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +24 -9
- package/lib/solution/BaseSales/utils.js +2 -1
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.d.ts +3 -2
- package/lib/solution/BookingTicket/index.js +33 -36
- package/lib/solution/BookingTicket/types.d.ts +1 -5
- package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +0 -2
- package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +42 -174
- package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +4 -8
- package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +0 -6
- package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.js +3 -11
- package/lib/solution/ScanOrder/utils.js +2 -1
- package/lib/solution/ShopDiscount/index.d.ts +0 -2
- package/lib/solution/ShopDiscount/index.js +9 -55
- package/lib/solution/ShopDiscount/utils.d.ts +2 -4
- package/lib/solution/ShopDiscount/utils.js +25 -42
- package/lib/solution/UnifiedBookingSales/index.js +2 -2
- package/package.json +1 -1
- package/dist/modules/Discount/availability.d.ts +0 -7
- package/dist/modules/Discount/availability.js +0 -49
- package/dist/modules/Discount/entitlementPass.d.ts +0 -34
- package/dist/modules/Discount/entitlementPass.js +0 -147
- package/lib/modules/Discount/availability.d.ts +0 -7
- package/lib/modules/Discount/availability.js +0 -43
- package/lib/modules/Discount/entitlementPass.d.ts +0 -34
- package/lib/modules/Discount/entitlementPass.js +0 -141
|
@@ -5,21 +5,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.applyGlobalScan = applyGlobalScan;
|
|
7
7
|
var _addProductDecision = require("../addProductDecision");
|
|
8
|
+
var _cartView = require("../cartView");
|
|
8
9
|
var _scanProductValues = require("./scanProductValues");
|
|
9
10
|
/** applyGlobalScan 所需的 BookingTicket 运行时能力 */
|
|
10
11
|
|
|
11
|
-
function getRealCustomerId(customer) {
|
|
12
|
-
const customerId = Number(customer?.id ?? customer?.customer_id);
|
|
13
|
-
return Number.isInteger(customerId) && customerId > 1 ? customerId : undefined;
|
|
14
|
-
}
|
|
15
|
-
function getWalletAssetCustomerId(asset) {
|
|
16
|
-
const customerId = Number(asset?.customer_id ?? asset?.holder?.customer_id);
|
|
17
|
-
return Number.isInteger(customerId) && customerId > 1 ? customerId : undefined;
|
|
18
|
-
}
|
|
19
|
-
function getErrorMessage(error) {
|
|
20
|
-
return error instanceof Error ? error.message : String(error || '');
|
|
21
|
-
}
|
|
22
|
-
|
|
23
12
|
/**
|
|
24
13
|
* 处理单条扫码商品的加车决策(含弹窗链)。
|
|
25
14
|
*/
|
|
@@ -104,81 +93,17 @@ async function applyGlobalScan(host, formatted, bridge) {
|
|
|
104
93
|
const {
|
|
105
94
|
searchType,
|
|
106
95
|
data,
|
|
107
|
-
scanCode
|
|
108
|
-
customerId: formattedCustomerId,
|
|
109
|
-
isCrossShopWallet,
|
|
110
|
-
isWalletPassUnavailableAtStore
|
|
96
|
+
scanCode
|
|
111
97
|
} = formatted;
|
|
112
98
|
if (searchType === 'wallet') {
|
|
113
|
-
|
|
114
|
-
const currentCustomerId = getRealCustomerId(currentCustomer);
|
|
115
|
-
let customer = data;
|
|
116
|
-
if (isCrossShopWallet) {
|
|
117
|
-
const sourceCustomerId = getRealCustomerId({
|
|
118
|
-
id: formattedCustomerId
|
|
119
|
-
});
|
|
120
|
-
if (sourceCustomerId === undefined || !host.resolveCustomerById) {
|
|
121
|
-
bridge?.onNotify?.('fail', 'pisell2.text.scan-global-failed');
|
|
122
|
-
return {
|
|
123
|
-
status: 'failed',
|
|
124
|
-
reason: 'invalid_data'
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
try {
|
|
128
|
-
customer = await host.resolveCustomerById(sourceCustomerId);
|
|
129
|
-
} catch (error) {
|
|
130
|
-
bridge?.onNotify?.('fail', getErrorMessage(error) || 'pisell2.text.scan-global-failed');
|
|
131
|
-
return {
|
|
132
|
-
status: 'failed',
|
|
133
|
-
reason: 'invalid_data'
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
const customerId = getRealCustomerId(customer) ?? (!isCrossShopWallet ? getRealCustomerId({
|
|
138
|
-
id: formattedCustomerId
|
|
139
|
-
}) : undefined);
|
|
140
|
-
if (!customer || customerId === undefined) {
|
|
99
|
+
if (!data) {
|
|
141
100
|
bridge?.onNotify?.('fail', 'pisell2.text.scan-global-failed');
|
|
142
101
|
return {
|
|
143
102
|
status: 'failed',
|
|
144
103
|
reason: 'invalid_data'
|
|
145
104
|
};
|
|
146
105
|
}
|
|
147
|
-
|
|
148
|
-
...customer,
|
|
149
|
-
id: customerId
|
|
150
|
-
} : customer;
|
|
151
|
-
if (currentCustomerId === customerId) {
|
|
152
|
-
return {
|
|
153
|
-
status: 'success',
|
|
154
|
-
kind: 'customer'
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
if (currentCustomerId !== undefined) {
|
|
158
|
-
// 未接入新桥接的宿主保持原行为:已有客户时不直接覆盖。
|
|
159
|
-
if (!bridge?.requestCustomerSwitch) {
|
|
160
|
-
return {
|
|
161
|
-
status: 'success',
|
|
162
|
-
kind: 'customer'
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
try {
|
|
166
|
-
const switched = await bridge.requestCustomerSwitch(orderCustomer);
|
|
167
|
-
return switched ? {
|
|
168
|
-
status: 'success',
|
|
169
|
-
kind: 'customer'
|
|
170
|
-
} : {
|
|
171
|
-
status: 'cancelled'
|
|
172
|
-
};
|
|
173
|
-
} catch (error) {
|
|
174
|
-
bridge.onNotify?.('fail', getErrorMessage(error) || 'pisell2.text.scan-global-failed');
|
|
175
|
-
return {
|
|
176
|
-
status: 'failed',
|
|
177
|
-
reason: 'invalid_data'
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
host.setOrderCustomer(orderCustomer);
|
|
106
|
+
host.setOrderCustomer(data);
|
|
182
107
|
bridge?.onNotify?.('success', 'pisell2.text.add-client-success');
|
|
183
108
|
return {
|
|
184
109
|
status: 'success',
|
|
@@ -186,70 +111,8 @@ async function applyGlobalScan(host, formatted, bridge) {
|
|
|
186
111
|
};
|
|
187
112
|
}
|
|
188
113
|
if (searchType === 'walletPass') {
|
|
189
|
-
if (isWalletPassUnavailableAtStore) {
|
|
190
|
-
bridge?.onNotify?.('fail', 'pisell2.text.wallet-pass-not-available-at-store');
|
|
191
|
-
return {
|
|
192
|
-
status: 'failed',
|
|
193
|
-
reason: 'invalid_data'
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
114
|
const snapshot = host.getOrderCustomerSnapshot();
|
|
197
|
-
|
|
198
|
-
const bindWalletPassCustomer = async asset => {
|
|
199
|
-
if (getRealCustomerId(activeCustomer) !== undefined) {
|
|
200
|
-
return {
|
|
201
|
-
resolveFailed: false,
|
|
202
|
-
customerBound: false
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
const assetCustomerId = getWalletAssetCustomerId(asset) ?? getRealCustomerId({
|
|
206
|
-
id: formattedCustomerId
|
|
207
|
-
});
|
|
208
|
-
let customer = null;
|
|
209
|
-
if (assetCustomerId !== undefined) {
|
|
210
|
-
if (!host.resolveCustomerById) {
|
|
211
|
-
bridge?.onNotify?.('fail', 'pisell2.text.scan-global-failed');
|
|
212
|
-
return {
|
|
213
|
-
resolveFailed: true,
|
|
214
|
-
customerBound: false
|
|
215
|
-
};
|
|
216
|
-
}
|
|
217
|
-
try {
|
|
218
|
-
customer = await host.resolveCustomerById(assetCustomerId);
|
|
219
|
-
} catch (error) {
|
|
220
|
-
console.warn('[GlobalScan] Wallet asset customer lookup failed', error);
|
|
221
|
-
bridge?.onNotify?.('fail', getErrorMessage(error) || 'pisell2.text.scan-global-failed');
|
|
222
|
-
return {
|
|
223
|
-
resolveFailed: true,
|
|
224
|
-
customerBound: false
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
const customerId = getRealCustomerId(customer);
|
|
229
|
-
if (!customer || customerId === undefined) {
|
|
230
|
-
if (assetCustomerId !== undefined) {
|
|
231
|
-
bridge?.onNotify?.('fail', 'pisell2.text.scan-global-failed');
|
|
232
|
-
}
|
|
233
|
-
return {
|
|
234
|
-
resolveFailed: assetCustomerId !== undefined,
|
|
235
|
-
customerBound: false
|
|
236
|
-
};
|
|
237
|
-
}
|
|
238
|
-
const orderCustomer = customer.id === undefined || customer.id === null ? {
|
|
239
|
-
...customer,
|
|
240
|
-
id: customerId
|
|
241
|
-
} : customer;
|
|
242
|
-
host.setOrderCustomer(orderCustomer);
|
|
243
|
-
activeCustomer = orderCustomer;
|
|
244
|
-
await host.refreshWalletAssets?.({
|
|
245
|
-
preserveSelection: false,
|
|
246
|
-
retainSearchResultCodes: [scanCode]
|
|
247
|
-
});
|
|
248
|
-
return {
|
|
249
|
-
resolveFailed: false,
|
|
250
|
-
customerBound: true
|
|
251
|
-
};
|
|
252
|
-
};
|
|
115
|
+
const scannedCustomerIsWalkIn = (0, _cartView.isWalkInCustomer)(data);
|
|
253
116
|
const trySelectWalletAsset = async () => {
|
|
254
117
|
if (!host.scanWalletAsset) return null;
|
|
255
118
|
const walletResult = await host.scanWalletAsset(scanCode).catch(error => {
|
|
@@ -260,56 +123,61 @@ async function applyGlobalScan(host, formatted, bridge) {
|
|
|
260
123
|
if (walletResult.type !== 'normalCode' || !walletResult.asset) {
|
|
261
124
|
return null;
|
|
262
125
|
}
|
|
263
|
-
const bindResult = await bindWalletPassCustomer(walletResult.asset);
|
|
264
126
|
if (walletResult.selected) {
|
|
265
|
-
|
|
266
|
-
bridge?.onNotify?.('success');
|
|
267
|
-
}
|
|
127
|
+
bridge?.onNotify?.('success');
|
|
268
128
|
return {
|
|
269
129
|
status: 'success',
|
|
270
130
|
kind: 'promotion'
|
|
271
131
|
};
|
|
272
132
|
}
|
|
273
133
|
// 已识别为 Wallet 支付资产但当前不可用:保留禁用展示,不回退优惠码。
|
|
274
|
-
|
|
275
|
-
bridge?.onNotify?.('fail', 'pisell2.text.goodpass.code-invalid-cart');
|
|
276
|
-
}
|
|
134
|
+
bridge?.onNotify?.('fail', 'pisell2.text.goodpass.code-invalid-cart');
|
|
277
135
|
return {
|
|
278
136
|
status: 'failed',
|
|
279
137
|
reason: 'invalid_data'
|
|
280
138
|
};
|
|
281
139
|
};
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
140
|
+
if ((0, _cartView.isWalkInCustomer)(snapshot) || scannedCustomerIsWalkIn) {
|
|
141
|
+
// 当前购物车或 walletPass 绑定客户为 walk-in 时不绑客户,避免覆盖已有下单客户。
|
|
142
|
+
const walletSelection = await trySelectWalletAsset();
|
|
143
|
+
if (walletSelection) return walletSelection;
|
|
144
|
+
if (!bridge?.applyPromotionCode) {
|
|
145
|
+
return {
|
|
146
|
+
status: 'failed',
|
|
147
|
+
reason: 'no_bridge'
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
const result = await bridge.applyPromotionCode(scanCode);
|
|
151
|
+
if (result?.isAccepted ?? result?.isAvailable) {
|
|
152
|
+
return {
|
|
153
|
+
status: 'success',
|
|
154
|
+
kind: 'promotion'
|
|
155
|
+
};
|
|
156
|
+
}
|
|
289
157
|
return {
|
|
290
158
|
status: 'failed',
|
|
291
|
-
reason: '
|
|
292
|
-
};
|
|
293
|
-
}
|
|
294
|
-
const promotionCustomerId = getRealCustomerId(activeCustomer);
|
|
295
|
-
const promotionResult = bindResult.customerBound ? await bridge.applyPromotionCode(scanCode, promotionCustomerId, {
|
|
296
|
-
suppressFailureNotification: true
|
|
297
|
-
}) : await bridge.applyPromotionCode(scanCode, promotionCustomerId);
|
|
298
|
-
if (promotionResult?.isAccepted ?? promotionResult?.isAvailable) {
|
|
299
|
-
return {
|
|
300
|
-
status: 'success',
|
|
301
|
-
kind: 'promotion'
|
|
159
|
+
reason: 'invalid_data'
|
|
302
160
|
};
|
|
303
161
|
}
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
162
|
+
host.setOrderCustomer(data);
|
|
163
|
+
await host.refreshWalletAssets?.({
|
|
164
|
+
preserveSelection: false
|
|
165
|
+
});
|
|
166
|
+
const walletSelection = await trySelectWalletAsset();
|
|
167
|
+
if (walletSelection) return walletSelection;
|
|
168
|
+
if (bridge?.applyPromotionCode) {
|
|
169
|
+
const promotionResult = await bridge.applyPromotionCode(scanCode, Number(data?.id ?? data?.customer_id) || undefined);
|
|
170
|
+
if (promotionResult?.isAccepted ?? promotionResult?.isAvailable) {
|
|
171
|
+
return {
|
|
172
|
+
status: 'success',
|
|
173
|
+
kind: 'promotion'
|
|
174
|
+
};
|
|
175
|
+
}
|
|
309
176
|
}
|
|
177
|
+
bridge?.onNotify?.('success', 'pisell2.text.add-client-success');
|
|
310
178
|
return {
|
|
311
|
-
status: '
|
|
312
|
-
|
|
179
|
+
status: 'success',
|
|
180
|
+
kind: 'customer'
|
|
313
181
|
};
|
|
314
182
|
}
|
|
315
183
|
if (searchType === 'product' || searchType === 'local_product') {
|
|
@@ -14,8 +14,7 @@ const searchWalletPass = async (request, code) => {
|
|
|
14
14
|
// 翻译识别码名称 0:不翻译 1:翻译
|
|
15
15
|
relation_product: 1,
|
|
16
16
|
// 组装关联商品: 0不处理 1处理
|
|
17
|
-
|
|
18
|
-
with: ['customer', 'franchiseeWalletPass:shop_id,source_shop_id,product_id,use'],
|
|
17
|
+
with: ['customer'],
|
|
19
18
|
tags: ['point_card',
|
|
20
19
|
// 积分卡
|
|
21
20
|
'gift_card',
|
|
@@ -26,8 +25,6 @@ const searchWalletPass = async (request, code) => {
|
|
|
26
25
|
// 折扣卡
|
|
27
26
|
'good_pass',
|
|
28
27
|
// 商品券
|
|
29
|
-
'entitlement_pass',
|
|
30
|
-
// 月卡 / 年卡 / 多次使用卡
|
|
31
28
|
'session_ticket',
|
|
32
29
|
// 场次票
|
|
33
30
|
'appointment_ticket' // 预约类门票
|
|
@@ -54,18 +51,17 @@ exports.searchWalletPass = searchWalletPass;
|
|
|
54
51
|
const searchWallet = async (request, code) => {
|
|
55
52
|
const params = {
|
|
56
53
|
code,
|
|
57
|
-
with_customer: 1
|
|
58
|
-
with_franchisor_data: 1
|
|
54
|
+
with_customer: 1
|
|
59
55
|
};
|
|
60
56
|
try {
|
|
61
57
|
const res = await request?.post('/wallet/detail/search', params);
|
|
62
|
-
if (res?.
|
|
58
|
+
if (res?.code == 200 && !!res?.data) {
|
|
63
59
|
return {
|
|
64
60
|
searchType: 'wallet',
|
|
65
61
|
response: res
|
|
66
62
|
};
|
|
67
63
|
}
|
|
68
|
-
throw new Error(
|
|
64
|
+
throw new Error('没有找到对应的识别码');
|
|
69
65
|
} catch (error) {
|
|
70
66
|
throw error;
|
|
71
67
|
}
|
|
@@ -6,12 +6,6 @@ export interface GlobalScanFormattedResult {
|
|
|
6
6
|
searchType: GlobalScanSearchType;
|
|
7
7
|
data: any;
|
|
8
8
|
scanCode: string;
|
|
9
|
-
/** Wallet / Wallet Pass 来源客户 ID;跨店时必须先解析为当前店客户。 */
|
|
10
|
-
customerId?: string | number;
|
|
11
|
-
/** 仅 Wallet 返回;true 时禁止直接使用响应内的来源客户。 */
|
|
12
|
-
isCrossShopWallet?: boolean;
|
|
13
|
-
/** 总店 Wallet Pass 未共享给当前子店。 */
|
|
14
|
-
isWalletPassUnavailableAtStore?: boolean;
|
|
15
9
|
}
|
|
16
10
|
interface RawScanSearchResult {
|
|
17
11
|
searchType?: GlobalScanSearchType;
|
|
@@ -36,22 +36,14 @@ function formatGlobalScanResult(raw, scanCode) {
|
|
|
36
36
|
return {
|
|
37
37
|
searchType,
|
|
38
38
|
data: resultData?.customer,
|
|
39
|
-
scanCode
|
|
40
|
-
customerId: resultData?.customer_id,
|
|
41
|
-
isCrossShopWallet: resultData?.is_cross_shop_wallet === true || Number(resultData?.is_cross_shop_wallet) === 1
|
|
39
|
+
scanCode
|
|
42
40
|
};
|
|
43
41
|
}
|
|
44
42
|
if (searchType === 'walletPass') {
|
|
45
|
-
const firstResult = resultData?.[0];
|
|
46
|
-
const isWalletPassUnavailableAtStore = firstResult?.is_franchisor_pass === 1 && firstResult?.franchisee_wallet_pass?.use !== 'enabled';
|
|
47
43
|
return {
|
|
48
44
|
searchType,
|
|
49
|
-
data:
|
|
50
|
-
scanCode
|
|
51
|
-
customerId: firstResult?.customer_id ?? firstResult?.holder?.customer_id ?? firstResult?.customer?.id ?? firstResult?.customer?.customer_id,
|
|
52
|
-
...(isWalletPassUnavailableAtStore ? {
|
|
53
|
-
isWalletPassUnavailableAtStore: true
|
|
54
|
-
} : {})
|
|
45
|
+
data: resultData?.[0]?.customer,
|
|
46
|
+
scanCode
|
|
55
47
|
};
|
|
56
48
|
}
|
|
57
49
|
if (searchType === 'product' || searchType === 'local_product') {
|
|
@@ -34,6 +34,7 @@ exports.toNonNegativeInt = toNonNegativeInt;
|
|
|
34
34
|
exports.toNonNegativeNumber = toNonNegativeNumber;
|
|
35
35
|
exports.toPositiveString = toPositiveString;
|
|
36
36
|
exports.toPriceString = toPriceString;
|
|
37
|
+
var _weighedProduct = require("../../modules/Order/utils/weighedProduct");
|
|
37
38
|
var _dayjs = _interopRequireDefault(require("dayjs"));
|
|
38
39
|
var _decimal = _interopRequireDefault(require("decimal.js"));
|
|
39
40
|
var _utils = require("../../modules/Order/utils");
|
|
@@ -612,7 +613,7 @@ function normalizeOrderProduct(product) {
|
|
|
612
613
|
});
|
|
613
614
|
const composedOriginalPrice = (0, _utils.composeLinePrice)({
|
|
614
615
|
mainPrice: mainOriginalStr,
|
|
615
|
-
bundle: normalizedBundle,
|
|
616
|
+
bundle: Number(productSku.open_sold_weight) === 1 && (0, _manualProductDiscount.hasManualProductDiscountFlag)(metadata) ? (0, _weighedProduct.withOriginalBundleOptionPrices)(normalizedBundle) : normalizedBundle,
|
|
616
617
|
useOriginalBundle: true
|
|
617
618
|
});
|
|
618
619
|
const finalOriginalPrice = (0, _utils.resolveManualOverrideLineOriginalPrice)({
|
|
@@ -43,7 +43,6 @@ export declare class ShopDiscountImpl extends BaseModule implements Module {
|
|
|
43
43
|
batchSearchByProductIds(productIds: number[]): Promise<Discount[]>;
|
|
44
44
|
scanCode(code: string, customerId?: number): Promise<{
|
|
45
45
|
isAvailable: boolean;
|
|
46
|
-
isAccepted?: boolean;
|
|
47
46
|
productList: Record<string, any>[];
|
|
48
47
|
discountList: Discount[];
|
|
49
48
|
type: "server" | "clientCalc";
|
|
@@ -63,7 +62,6 @@ export declare class ShopDiscountImpl extends BaseModule implements Module {
|
|
|
63
62
|
action?: 'create' | 'edit';
|
|
64
63
|
with_good_pass?: 0 | 1;
|
|
65
64
|
with_discount_card?: 0 | 1;
|
|
66
|
-
with_entitlement_pass?: 0 | 1;
|
|
67
65
|
}): Promise<void>;
|
|
68
66
|
}
|
|
69
67
|
export default ShopDiscountImpl;
|
|
@@ -7,10 +7,8 @@ exports.default = exports.ShopDiscountImpl = void 0;
|
|
|
7
7
|
var _BaseModule = require("../../modules/BaseModule");
|
|
8
8
|
var _Discount = require("../../modules/Discount");
|
|
9
9
|
var _Rules = require("../../modules/Rules");
|
|
10
|
-
var _entitlementPass = require("../../modules/Discount/entitlementPass");
|
|
11
10
|
var _utils = require("./utils");
|
|
12
11
|
var _types = require("../../modules/Rules/types");
|
|
13
|
-
var _availability = require("../../modules/Discount/availability");
|
|
14
12
|
var _decimal = _interopRequireDefault(require("decimal.js"));
|
|
15
13
|
var _lodashEs = require("lodash-es");
|
|
16
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -127,8 +125,7 @@ class ShopDiscountImpl extends _BaseModule.BaseModule {
|
|
|
127
125
|
customerId: customer.id,
|
|
128
126
|
action: 'create',
|
|
129
127
|
with_good_pass: 1,
|
|
130
|
-
with_discount_card: 1
|
|
131
|
-
with_entitlement_pass: 1
|
|
128
|
+
with_discount_card: 1
|
|
132
129
|
});
|
|
133
130
|
});
|
|
134
131
|
}
|
|
@@ -350,7 +347,6 @@ class ShopDiscountImpl extends _BaseModule.BaseModule {
|
|
|
350
347
|
const {
|
|
351
348
|
productList: newProductList,
|
|
352
349
|
discountList: newDiscountList,
|
|
353
|
-
evaluatedDiscountList,
|
|
354
350
|
isAvailable,
|
|
355
351
|
unavailableReason
|
|
356
352
|
} = rulesModule.isDiscountListAvailable({
|
|
@@ -365,7 +361,6 @@ class ShopDiscountImpl extends _BaseModule.BaseModule {
|
|
|
365
361
|
productList: this.store.productList || [],
|
|
366
362
|
discountList: this.getDiscountList()
|
|
367
363
|
};
|
|
368
|
-
let isAccepted = isAvailable;
|
|
369
364
|
if (isAvailable) {
|
|
370
365
|
this.setDiscountList(newDiscountList || []);
|
|
371
366
|
this.store.originalDiscountList = newDiscountList || [];
|
|
@@ -373,34 +368,12 @@ class ShopDiscountImpl extends _BaseModule.BaseModule {
|
|
|
373
368
|
if (this.isWalkIn() && resultDiscountList.length && this.options.otherParams?.platform === 'shop' && !((resultDiscountList[0].customer_id || 1) === 1)) {
|
|
374
369
|
await this.getCustomerWallet(resultDiscountList[0].customer_id);
|
|
375
370
|
}
|
|
376
|
-
} else {
|
|
377
|
-
const scannedIds = new Set(withScanList.map(discount => String(discount.id)));
|
|
378
|
-
const retainedScannedDiscounts = (evaluatedDiscountList || withScanList).filter(discount => scannedIds.has(String(discount.id)) && !(0, _availability.getDiscountLifecycleReason)(discount));
|
|
379
|
-
if (retainedScannedDiscounts.length) {
|
|
380
|
-
const retainedDiscounts = new Map(this.getDiscountList().map(discount => [String(discount.id), discount]));
|
|
381
|
-
retainedScannedDiscounts.forEach(discount => {
|
|
382
|
-
retainedDiscounts.set(String(discount.id), {
|
|
383
|
-
...discount,
|
|
384
|
-
isScan: true,
|
|
385
|
-
isAvailable: false,
|
|
386
|
-
isSelected: false,
|
|
387
|
-
reasonCode: discount.reasonCode || 'product_not_applicable',
|
|
388
|
-
appliedProductDetails: [],
|
|
389
|
-
savedAmount: 0
|
|
390
|
-
});
|
|
391
|
-
});
|
|
392
|
-
this.setDiscountList([...retainedDiscounts.values()]);
|
|
393
|
-
this.store.originalDiscountList = this.getDiscountList();
|
|
394
|
-
await this.store.discount?.setOriginalDiscountList(this.getDiscountList());
|
|
395
|
-
isAccepted = true;
|
|
396
|
-
}
|
|
397
371
|
}
|
|
398
372
|
return {
|
|
399
373
|
type: "clientCalc",
|
|
400
374
|
isAvailable: isAvailable || false,
|
|
401
|
-
isAccepted: Boolean(isAccepted),
|
|
402
375
|
productList: newProductList || this.store.productList || [],
|
|
403
|
-
discountList: this.getDiscountList(),
|
|
376
|
+
discountList: newDiscountList || this.getDiscountList(),
|
|
404
377
|
unavailableReason
|
|
405
378
|
};
|
|
406
379
|
} catch (error) {
|
|
@@ -443,7 +416,7 @@ class ShopDiscountImpl extends _BaseModule.BaseModule {
|
|
|
443
416
|
if (item.booking_id) {
|
|
444
417
|
const product = this.hooks?.getProduct(item);
|
|
445
418
|
(item.discount_list || []).forEach(discount => {
|
|
446
|
-
if (discount.id && ['
|
|
419
|
+
if (discount.id && ['good_pass', 'discount_card'].includes(discount.type)) {
|
|
447
420
|
const index = editModeDiscountList.findIndex(n => n.id === (discount.discount?.resource_id || discount.id));
|
|
448
421
|
if (index !== -1) {
|
|
449
422
|
editModeDiscountList[index] = {
|
|
@@ -549,8 +522,6 @@ class ShopDiscountImpl extends _BaseModule.BaseModule {
|
|
|
549
522
|
with_good_pass: 1,
|
|
550
523
|
with_discount_card: 1,
|
|
551
524
|
with_wallet_pass_holder: 1,
|
|
552
|
-
with_entitlement_pass: 1,
|
|
553
|
-
filter_order_wallet_pass_usage: 0,
|
|
554
525
|
request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
555
526
|
...(orderId ? {
|
|
556
527
|
order_id: orderId
|
|
@@ -559,34 +530,17 @@ class ShopDiscountImpl extends _BaseModule.BaseModule {
|
|
|
559
530
|
const goodPassList = prepareConfigResult?.discountList || [];
|
|
560
531
|
const scanDiscount = this.getDiscountList()?.filter(item => item.isScan);
|
|
561
532
|
|
|
562
|
-
//
|
|
563
|
-
|
|
564
|
-
const
|
|
565
|
-
const
|
|
566
|
-
const newGoodPassList = goodPassList.flatMap(discount => {
|
|
567
|
-
const key = String(discount.id);
|
|
568
|
-
const scannedDiscount = scanDiscountById.get(key);
|
|
569
|
-
if (!scannedDiscount) return [discount];
|
|
570
|
-
if ((0, _entitlementPass.isEntitlementPass)(scannedDiscount) && (0, _entitlementPass.isEntitlementPass)(discount)) {
|
|
571
|
-
refreshedScanEntitlementIds.add(key);
|
|
572
|
-
return [{
|
|
573
|
-
...discount,
|
|
574
|
-
isScan: true,
|
|
575
|
-
isSelected: scannedDiscount.isSelected ?? discount.isSelected,
|
|
576
|
-
isManualSelect: scannedDiscount.isManualSelect ?? discount.isManualSelect
|
|
577
|
-
}];
|
|
578
|
-
}
|
|
579
|
-
return [];
|
|
580
|
-
});
|
|
581
|
-
const retainedScanDiscounts = scanDiscount.filter(discount => !refreshedScanEntitlementIds.has(String(discount.id)));
|
|
582
|
-
const newDiscountList = [...retainedScanDiscounts, ...newGoodPassList];
|
|
533
|
+
// goodPassList 里可能有 scanDiscount 重合的部分,goodPassList 需要剔除
|
|
534
|
+
const scanDiscountIds = scanDiscount.map(n => n.id);
|
|
535
|
+
const newGoodPassList = goodPassList?.filter(n => !scanDiscountIds.includes(n.id));
|
|
536
|
+
const newDiscountList = [...scanDiscount, ...(newGoodPassList || [])];
|
|
583
537
|
|
|
584
538
|
// 存储原始优惠券列表
|
|
585
539
|
this.store.originalDiscountList = newDiscountList;
|
|
586
540
|
await this.store.discount?.setOriginalDiscountList(newDiscountList);
|
|
587
541
|
|
|
588
|
-
//
|
|
589
|
-
const filteredDiscountList = newDiscountList;
|
|
542
|
+
// 根据当前预约时间过滤优惠券列表
|
|
543
|
+
const filteredDiscountList = this.filterDiscountListByBookingTime(newDiscountList, this.store.currentBookingTime);
|
|
590
544
|
this.store.filteredDiscountList = filteredDiscountList;
|
|
591
545
|
this.setDiscountList(filteredDiscountList || []);
|
|
592
546
|
if (this.store.productList?.length) {
|
|
@@ -59,14 +59,12 @@ export interface ScheduleItem {
|
|
|
59
59
|
}
|
|
60
60
|
export declare const getDateIsInSchedule: (dateTime: string, scheduleList: ScheduleItem[]) => boolean;
|
|
61
61
|
/**
|
|
62
|
-
*
|
|
62
|
+
* 根据预约时间过滤优惠券列表
|
|
63
63
|
* @param discountList 优惠券列表
|
|
64
|
-
* @param bookingTime
|
|
64
|
+
* @param bookingTime 预约时间 (格式: YYYY-MM-DD HH:mm:ss)
|
|
65
65
|
* @returns 过滤后的优惠券列表
|
|
66
66
|
*/
|
|
67
67
|
export declare const filterDiscountListByBookingTime: (discountList: Discount[], bookingTime: string | null) => Discount[];
|
|
68
|
-
/** 与抵扣计算共用时间判断,区分未开始、有效期不匹配和日程限制。 */
|
|
69
|
-
export declare const getDiscountTimeUnavailableReason: (discount: Discount, useTime: string) => 'not_started' | 'time_limit' | 'outside_schedule' | undefined;
|
|
70
68
|
/**
|
|
71
69
|
* 判断是否是订单级别的固定金额折扣卡
|
|
72
70
|
* @param discount 折扣
|
|
@@ -3,15 +3,10 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.uniqueById = exports.isOrderLevelFixedAmountDiscount = exports.isNormalProductByDurationSchedule = exports.isAllNormalProduct = exports.
|
|
6
|
+
exports.uniqueById = exports.isOrderLevelFixedAmountDiscount = exports.isNormalProductByDurationSchedule = exports.isAllNormalProduct = exports.getDiscountListAmountTotal = exports.getDiscountListAmount = exports.getDiscountAmount = exports.getDateIsInSchedule = exports.filterDiscountListByBookingTime = exports.calculateOrderLevelDiscountAllocation = void 0;
|
|
7
7
|
var _decimal = _interopRequireDefault(require("decimal.js"));
|
|
8
8
|
var _dayjs = _interopRequireDefault(require("dayjs"));
|
|
9
|
-
var _isSameOrAfter = _interopRequireDefault(require("dayjs/plugin/isSameOrAfter"));
|
|
10
|
-
var _isSameOrBefore = _interopRequireDefault(require("dayjs/plugin/isSameOrBefore"));
|
|
11
|
-
var _entitlementPass = require("../../modules/Discount/entitlementPass");
|
|
12
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
_dayjs.default.extend(_isSameOrAfter.default);
|
|
14
|
-
_dayjs.default.extend(_isSameOrBefore.default);
|
|
15
10
|
const uniqueById = (arr, key = 'id') => {
|
|
16
11
|
const seen = new Set();
|
|
17
12
|
return arr.filter(item => !seen.has(item[key]) && seen.add(item[key]));
|
|
@@ -40,8 +35,8 @@ const isAllNormalProduct = items => {
|
|
|
40
35
|
*/
|
|
41
36
|
exports.isAllNormalProduct = isAllNormalProduct;
|
|
42
37
|
const getDiscountAmount = (discount, total, price) => {
|
|
43
|
-
//
|
|
44
|
-
if (
|
|
38
|
+
// 商品券
|
|
39
|
+
if (discount.tag === 'good_pass') {
|
|
45
40
|
return new _decimal.default(price).minus(new _decimal.default(price || 0)).toNumber();
|
|
46
41
|
}
|
|
47
42
|
|
|
@@ -381,53 +376,41 @@ const isInWeeklyRepeatForDate = (targetDate, startDate, repeatRule) => {
|
|
|
381
376
|
};
|
|
382
377
|
|
|
383
378
|
/**
|
|
384
|
-
*
|
|
379
|
+
* 根据预约时间过滤优惠券列表
|
|
385
380
|
* @param discountList 优惠券列表
|
|
386
|
-
* @param bookingTime
|
|
381
|
+
* @param bookingTime 预约时间 (格式: YYYY-MM-DD HH:mm:ss)
|
|
387
382
|
* @returns 过滤后的优惠券列表
|
|
388
383
|
*/
|
|
389
384
|
const filterDiscountListByBookingTime = (discountList, bookingTime) => {
|
|
390
|
-
if (!bookingTime)
|
|
391
|
-
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
/** 与抵扣计算共用时间判断,区分未开始、有效期不匹配和日程限制。 */
|
|
395
|
-
exports.filterDiscountListByBookingTime = filterDiscountListByBookingTime;
|
|
396
|
-
const getDiscountTimeUnavailableReason = (discount, useTime) => {
|
|
397
|
-
const useTimeDayjs = (0, _dayjs.default)(useTime);
|
|
398
|
-
if (!useTimeDayjs.isValid()) return 'time_limit';
|
|
399
|
-
try {
|
|
385
|
+
if (!bookingTime) {
|
|
386
|
+
return discountList;
|
|
387
|
+
}
|
|
388
|
+
return discountList.filter(discount => {
|
|
400
389
|
if (discount?.metadata?.validity_type === "custom_schedule_validity") {
|
|
401
|
-
return getDateIsInSchedule(
|
|
402
|
-
}
|
|
403
|
-
const isHasStart = !!discount.start_date && !!discount.start_time;
|
|
404
|
-
const startDate = (0, _dayjs.default)(`${discount.start_date} ${discount.start_time}`);
|
|
405
|
-
|
|
406
|
-
// 开始时刻包含在有效期内。
|
|
407
|
-
if (isHasStart) {
|
|
408
|
-
if (!startDate.isValid()) return 'time_limit';
|
|
409
|
-
if (useTimeDayjs.isBefore(startDate)) return 'not_started';
|
|
390
|
+
return getDateIsInSchedule(bookingTime, discount.custom_schedule_snapshot?.data || []);
|
|
410
391
|
}
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
392
|
+
try {
|
|
393
|
+
const isHasStart = !!discount.start_date && !!discount.start_time;
|
|
394
|
+
const startDate = (0, _dayjs.default)(`${discount.start_date} ${discount.start_time}`);
|
|
395
|
+
const bookingTimeDayjs = (0, _dayjs.default)(bookingTime);
|
|
396
|
+
|
|
397
|
+
// 判断预约时间是否在开始时间之后
|
|
398
|
+
const isAfterStart = isHasStart ? bookingTimeDayjs.isSameOrAfter(startDate) : true;
|
|
399
|
+
|
|
400
|
+
// 判断预约时间是否在过期时间之前(expire_time 为空时为长期有效)
|
|
401
|
+
const isBeforeExpire = discount.expire_time ? bookingTimeDayjs.isSameOrBefore((0, _dayjs.default)(discount.expire_time)) : true;
|
|
402
|
+
return isAfterStart && isBeforeExpire;
|
|
403
|
+
} catch (error) {
|
|
404
|
+
return true;
|
|
419
405
|
}
|
|
420
|
-
|
|
421
|
-
} catch (error) {
|
|
422
|
-
return 'time_limit';
|
|
423
|
-
}
|
|
406
|
+
});
|
|
424
407
|
};
|
|
425
408
|
/**
|
|
426
409
|
* 判断是否是订单级别的固定金额折扣卡
|
|
427
410
|
* @param discount 折扣
|
|
428
411
|
* @returns 是否是订单级别的固定金额折扣卡
|
|
429
412
|
*/
|
|
430
|
-
exports.
|
|
413
|
+
exports.filterDiscountListByBookingTime = filterDiscountListByBookingTime;
|
|
431
414
|
const isOrderLevelFixedAmountDiscount = discount => {
|
|
432
415
|
return discount.tag === 'product_discount_card' && discount?.metadata?.discount_card_type === 'fixed_amount' && discount?.metadata?.discount_calculation_mode === 'order_level';
|
|
433
416
|
};
|
|
@@ -159,7 +159,7 @@ function buildPlannerDiscountResult(params) {
|
|
|
159
159
|
const productDiscounts = [...(Array.isArray(product.discount_list) ? product.discount_list : []), ...(Array.isArray(product.product_bundle) ? product.product_bundle.flatMap(bundle => bundle?.discount_list || []) : [])];
|
|
160
160
|
productDiscounts.forEach(discount => {
|
|
161
161
|
const type = discount.tag || discount.type;
|
|
162
|
-
if (!['
|
|
162
|
+
if (!['good_pass', 'discount_card', 'product_discount_card'].includes(type)) return;
|
|
163
163
|
const discountId = resolvePlannerDiscountId(discount);
|
|
164
164
|
applications.push({
|
|
165
165
|
discountId,
|
|
@@ -201,7 +201,7 @@ function isLocalOrderId(orderId) {
|
|
|
201
201
|
}
|
|
202
202
|
function isCustomerBoundDiscount(discount) {
|
|
203
203
|
const type = discount?.type ?? discount?.tag;
|
|
204
|
-
return type === '
|
|
204
|
+
return type === 'good_pass' || type === 'discount_card' || type === 'product_discount_card';
|
|
205
205
|
}
|
|
206
206
|
function filterCustomerBoundDiscounts(discountList) {
|
|
207
207
|
if (!Array.isArray(discountList)) return [];
|