@pisell/pisellos 2.2.103 → 2.2.105
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 +0 -9
- package/dist/modules/Order/index.d.ts +1 -1
- package/dist/modules/Product/index.d.ts +1 -1
- package/dist/modules/Rules/index.js +33 -24
- package/dist/server/modules/order/index.js +189 -155
- package/dist/solution/BookingTicket/index.d.ts +1 -1
- package/lib/modules/Order/index.d.ts +1 -1
- package/lib/modules/Product/index.d.ts +1 -1
- package/lib/modules/Rules/index.js +17 -12
- package/lib/server/modules/order/index.js +10 -6
- package/lib/solution/BookingTicket/index.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
// 导出评估器
|
|
2
|
-
export { PromotionEvaluator } from "./evaluator";
|
|
3
|
-
|
|
4
|
-
// 导出适配器
|
|
5
|
-
export { PromotionAdapter } from "./adapter";
|
|
6
|
-
export { default } from "./adapter";
|
|
7
|
-
|
|
8
|
-
// 导出策略配置示例常量
|
|
9
|
-
export { X_ITEMS_FOR_Y_PRICE_STRATEGY, BUY_X_GET_Y_FREE_STRATEGY } from "./examples";
|
|
@@ -23,7 +23,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
|
|
|
23
23
|
*/
|
|
24
24
|
private logError;
|
|
25
25
|
createOrder(params: CommitOrderParams['query']): {
|
|
26
|
-
type: "
|
|
26
|
+
type: "appointment_booking" | "virtual";
|
|
27
27
|
platform: string;
|
|
28
28
|
sales_channel: string;
|
|
29
29
|
order_sales_channel: string;
|
|
@@ -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(): "
|
|
52
|
+
getProductType(): "duration" | "session" | "normal";
|
|
53
53
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
var _excluded = ["_original_add_price"]
|
|
1
|
+
var _excluded = ["_original_add_price"],
|
|
2
|
+
_excluded2 = ["_original_price", "_original_add_price"];
|
|
2
3
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
3
4
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
4
5
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
@@ -148,7 +149,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
148
149
|
if (productList.every(function (item) {
|
|
149
150
|
var _product$discount_lis;
|
|
150
151
|
var product = _this2.hooks.getProduct(item);
|
|
151
|
-
return product.booking_id && (((_product$discount_lis = product.discount_list) === null || _product$discount_lis === void 0 ? void 0 : _product$discount_lis.length) ||
|
|
152
|
+
return product.booking_id && (((_product$discount_lis = product.discount_list) === null || _product$discount_lis === void 0 ? void 0 : _product$discount_lis.length) || product.total == 0);
|
|
152
153
|
})) {
|
|
153
154
|
return {
|
|
154
155
|
isAvailable: false,
|
|
@@ -839,15 +840,21 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
839
840
|
};
|
|
840
841
|
var optionDiscountAmount = 0;
|
|
841
842
|
var discountedOptions = options.map(function (option) {
|
|
842
|
-
var _ref5, _option$num, _option$
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
var
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
843
|
+
var _ref5, _ref6, _option$_original_pri, _ref7, _option$num, _rest$price, _option$_original_pri2;
|
|
844
|
+
// 折前单价:优先 price,缺失再 add_price;已写回折后价时用 _original_price(或旧字段 _original_add_price)
|
|
845
|
+
var rawUnit = (_ref5 = (_ref6 = (_option$_original_pri = option._original_price) !== null && _option$_original_pri !== void 0 ? _option$_original_pri : option._original_add_price) !== null && _ref6 !== void 0 ? _ref6 : option.price) !== null && _ref5 !== void 0 ? _ref5 : option.add_price;
|
|
846
|
+
var baseUnitNum = Number(rawUnit !== null && rawUnit !== void 0 ? rawUnit : 0);
|
|
847
|
+
if (baseUnitNum <= 0) return option;
|
|
848
|
+
var discountedPrice = getDiscountAmount(discount, baseUnitNum, baseUnitNum);
|
|
849
|
+
var optQty = Number((_ref7 = (_option$num = option.num) !== null && _option$num !== void 0 ? _option$num : option.quantity) !== null && _ref7 !== void 0 ? _ref7 : 1);
|
|
850
|
+
optionDiscountAmount = new Decimal(optionDiscountAmount).plus(new Decimal(baseUnitNum).minus(discountedPrice).mul(optQty)).toNumber();
|
|
851
|
+
var _original_add_price = option._original_add_price,
|
|
852
|
+
rest = _objectWithoutProperties(option, _excluded);
|
|
853
|
+
var tmpl = (_rest$price = rest.price) !== null && _rest$price !== void 0 ? _rest$price : rest.add_price;
|
|
854
|
+
var nextPrice = typeof tmpl === 'string' ? String(discountedPrice) : discountedPrice;
|
|
855
|
+
return _objectSpread(_objectSpread({}, rest), {}, {
|
|
856
|
+
_original_price: (_option$_original_pri2 = option._original_price) !== null && _option$_original_pri2 !== void 0 ? _option$_original_pri2 : _original_add_price !== undefined ? _original_add_price : rawUnit,
|
|
857
|
+
price: nextPrice
|
|
851
858
|
});
|
|
852
859
|
});
|
|
853
860
|
return {
|
|
@@ -858,11 +865,13 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
858
865
|
var restoreOptionPrices = function restoreOptionPrices(options) {
|
|
859
866
|
if (!(options !== null && options !== void 0 && options.length)) return options;
|
|
860
867
|
return options.map(function (option) {
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
868
|
+
var orig = option._original_price !== undefined ? option._original_price : option._original_add_price;
|
|
869
|
+
if (orig !== undefined) {
|
|
870
|
+
var _original_price = option._original_price,
|
|
871
|
+
_original_add_price = option._original_add_price,
|
|
872
|
+
rest = _objectWithoutProperties(option, _excluded2);
|
|
864
873
|
return _objectSpread(_objectSpread({}, rest), {}, {
|
|
865
|
-
|
|
874
|
+
price: orig
|
|
866
875
|
});
|
|
867
876
|
}
|
|
868
877
|
return option;
|
|
@@ -871,9 +880,9 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
871
880
|
var getOptionTotal = function getOptionTotal(options) {
|
|
872
881
|
if (!(options !== null && options !== void 0 && options.length)) return 0;
|
|
873
882
|
return options.reduce(function (sum, opt) {
|
|
874
|
-
var
|
|
875
|
-
var unit = Number((
|
|
876
|
-
var n = Number((
|
|
883
|
+
var _ref8, _opt$price, _ref9, _opt$num;
|
|
884
|
+
var unit = Number((_ref8 = (_opt$price = opt.price) !== null && _opt$price !== void 0 ? _opt$price : opt.add_price) !== null && _ref8 !== void 0 ? _ref8 : 0);
|
|
885
|
+
var n = Number((_ref9 = (_opt$num = opt.num) !== null && _opt$num !== void 0 ? _opt$num : opt.quantity) !== null && _ref9 !== void 0 ? _ref9 : 1);
|
|
877
886
|
return new Decimal(sum).plus(new Decimal(unit).mul(n)).toNumber();
|
|
878
887
|
}, 0);
|
|
879
888
|
};
|
|
@@ -1007,8 +1016,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1007
1016
|
var _product$discount_lis5, _product11, _product11$every;
|
|
1008
1017
|
// 主商品:判断自身是否手动折扣
|
|
1009
1018
|
isManualDiscount = typeof product.isManualDiscount === 'boolean' ? product.isManualDiscount : product.total != product.origin_total && (product.bundle || []).every(function (item) {
|
|
1010
|
-
var
|
|
1011
|
-
return !((
|
|
1019
|
+
var _ref10;
|
|
1020
|
+
return !((_ref10 = item.discount_list || []) !== null && _ref10 !== void 0 && _ref10.length);
|
|
1012
1021
|
}) && (!((_product$discount_lis5 = product.discount_list) !== null && _product$discount_lis5 !== void 0 && _product$discount_lis5.length) || ((_product11 = product) === null || _product11 === void 0 || (_product11 = _product11.discount_list) === null || _product11 === void 0 || (_product11$every = _product11.every) === null || _product11$every === void 0 ? void 0 : _product11$every.call(_product11, function (item) {
|
|
1013
1022
|
return item.type === 'product';
|
|
1014
1023
|
})));
|
|
@@ -1021,8 +1030,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1021
1030
|
if (parentProduct) {
|
|
1022
1031
|
var _parentProduct$discou, _parentProduct$discou2, _parentProduct$discou3;
|
|
1023
1032
|
isManualDiscount = typeof parentProduct.isManualDiscount === 'boolean' ? parentProduct.isManualDiscount : parentProduct.total != parentProduct.origin_total && (parentProduct.bundle || []).every(function (item) {
|
|
1024
|
-
var
|
|
1025
|
-
return !((
|
|
1033
|
+
var _ref11;
|
|
1034
|
+
return !((_ref11 = item.discount_list || []) !== null && _ref11 !== void 0 && _ref11.length);
|
|
1026
1035
|
}) && (!((_parentProduct$discou = parentProduct.discount_list) !== null && _parentProduct$discou !== void 0 && _parentProduct$discou.length) || (parentProduct === null || parentProduct === void 0 || (_parentProduct$discou2 = parentProduct.discount_list) === null || _parentProduct$discou2 === void 0 || (_parentProduct$discou3 = _parentProduct$discou2.every) === null || _parentProduct$discou3 === void 0 ? void 0 : _parentProduct$discou3.call(_parentProduct$discou2, function (item) {
|
|
1027
1036
|
return item.type === 'product';
|
|
1028
1037
|
})));
|
|
@@ -1115,8 +1124,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1115
1124
|
discount_list: _this3.filterDiscountListByType(product.discount_list, 'promotion')
|
|
1116
1125
|
}))]);
|
|
1117
1126
|
} else {
|
|
1118
|
-
var
|
|
1119
|
-
var total = product.inPromotion ? (
|
|
1127
|
+
var _ref12, _product$_promotion$f, _product12, _product$origin_total;
|
|
1128
|
+
var total = product.inPromotion ? (_ref12 = (_product$_promotion$f = (_product12 = product) === null || _product12 === void 0 || (_product12 = _product12._promotion) === null || _product12 === void 0 ? void 0 : _product12.finalPrice) !== null && _product$_promotion$f !== void 0 ? _product$_promotion$f : product.origin_total) !== null && _ref12 !== void 0 ? _ref12 : product.total : (_product$origin_total = product.origin_total) !== null && _product$origin_total !== void 0 ? _product$origin_total : product.total;
|
|
1120
1129
|
var main_product_selling_price = product.price;
|
|
1121
1130
|
if ((product.discount_list || []).some(function (item) {
|
|
1122
1131
|
return item.type === 'promotion';
|
|
@@ -182,29 +182,63 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
182
182
|
}, {
|
|
183
183
|
key: "preload",
|
|
184
184
|
value: function () {
|
|
185
|
-
var _preload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
186
|
-
var
|
|
187
|
-
|
|
188
|
-
|
|
185
|
+
var _preload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
186
|
+
var _this2 = this;
|
|
187
|
+
var getData;
|
|
188
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
189
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
189
190
|
case 0:
|
|
190
|
-
|
|
191
|
-
|
|
191
|
+
// const cachedOrders = await this.loadOrdersFromSQLite()
|
|
192
|
+
// const hasPulledInCurrentWindow = this.hasPulledOrdersToday()
|
|
193
|
+
// // 仅当缓存属于当前统计窗口时才直接复用,避免跨天/跨营业日窗口继续使用旧数据
|
|
194
|
+
// if (cachedOrders.length > 0 && hasPulledInCurrentWindow) {
|
|
195
|
+
// this.store.list = cloneDeep(cachedOrders)
|
|
196
|
+
// this.syncOrdersMap()
|
|
197
|
+
// this.core.effects.emit(OrderHooks.onOrdersChanged, this.store.list)
|
|
198
|
+
// return
|
|
199
|
+
// }
|
|
200
|
+
// if (hasPulledInCurrentWindow) {
|
|
201
|
+
// this.logInfo('当天已完成全量订单拉取,跳过本次全量拉取', {
|
|
202
|
+
// lastFullFetchAt: this.getStorageItem(ORDER_LAST_FULL_FETCH_AT_STORAGE_KEY),
|
|
203
|
+
// })
|
|
204
|
+
// return
|
|
205
|
+
// }
|
|
206
|
+
getData = /*#__PURE__*/function () {
|
|
207
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
208
|
+
var orders;
|
|
209
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
210
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
211
|
+
case 0:
|
|
212
|
+
_context2.next = 2;
|
|
213
|
+
return _this2.loadOrdersByServer();
|
|
214
|
+
case 2:
|
|
215
|
+
orders = _context2.sent;
|
|
216
|
+
if (!(orders.length === 0)) {
|
|
217
|
+
_context2.next = 5;
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
220
|
+
return _context2.abrupt("return");
|
|
221
|
+
case 5:
|
|
222
|
+
_this2.store.list = cloneDeep(orders);
|
|
223
|
+
_this2.syncOrdersMap();
|
|
224
|
+
_this2.core.effects.emit(OrderHooks.onOrdersChanged, _this2.store.list);
|
|
225
|
+
_this2.core.effects.emit(OrderHooks.onOrdersSyncCompleted, null);
|
|
226
|
+
case 9:
|
|
227
|
+
case "end":
|
|
228
|
+
return _context2.stop();
|
|
229
|
+
}
|
|
230
|
+
}, _callee2);
|
|
231
|
+
}));
|
|
232
|
+
return function getData() {
|
|
233
|
+
return _ref.apply(this, arguments);
|
|
234
|
+
};
|
|
235
|
+
}();
|
|
236
|
+
getData();
|
|
192
237
|
case 2:
|
|
193
|
-
orders = _context2.sent;
|
|
194
|
-
if (!(orders.length === 0)) {
|
|
195
|
-
_context2.next = 5;
|
|
196
|
-
break;
|
|
197
|
-
}
|
|
198
|
-
return _context2.abrupt("return");
|
|
199
|
-
case 5:
|
|
200
|
-
this.store.list = cloneDeep(orders);
|
|
201
|
-
this.syncOrdersMap();
|
|
202
|
-
this.core.effects.emit(OrderHooks.onOrdersChanged, this.store.list);
|
|
203
|
-
case 8:
|
|
204
238
|
case "end":
|
|
205
|
-
return
|
|
239
|
+
return _context3.stop();
|
|
206
240
|
}
|
|
207
|
-
},
|
|
241
|
+
}, _callee3);
|
|
208
242
|
}));
|
|
209
243
|
function preload() {
|
|
210
244
|
return _preload.apply(this, arguments);
|
|
@@ -231,11 +265,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
231
265
|
}, {
|
|
232
266
|
key: "loadOrdersByServer",
|
|
233
267
|
value: function () {
|
|
234
|
-
var _loadOrdersByServer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
268
|
+
var _loadOrdersByServer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
|
|
235
269
|
var _this$store;
|
|
236
270
|
var orderList, data;
|
|
237
|
-
return _regeneratorRuntime().wrap(function
|
|
238
|
-
while (1) switch (
|
|
271
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
272
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
239
273
|
case 0:
|
|
240
274
|
orderList = [];
|
|
241
275
|
this.logInfo('loadOrdersByServer-开始', {
|
|
@@ -243,46 +277,46 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
243
277
|
query: ((_this$store = this.store) === null || _this$store === void 0 ? void 0 : _this$store.createdAtQuery) || null
|
|
244
278
|
});
|
|
245
279
|
if (!this.orderDataSource) {
|
|
246
|
-
|
|
280
|
+
_context4.next = 16;
|
|
247
281
|
break;
|
|
248
282
|
}
|
|
249
|
-
|
|
250
|
-
|
|
283
|
+
_context4.prev = 3;
|
|
284
|
+
_context4.next = 6;
|
|
251
285
|
return this.orderDataSource.run({
|
|
252
286
|
http: {
|
|
253
287
|
query: this.store.createdAtQuery
|
|
254
288
|
}
|
|
255
289
|
});
|
|
256
290
|
case 6:
|
|
257
|
-
data =
|
|
291
|
+
data = _context4.sent;
|
|
258
292
|
orderList = data || [];
|
|
259
293
|
this.logInfo('loadOrdersByServer-拉取成功', {
|
|
260
294
|
count: orderList.length
|
|
261
295
|
});
|
|
262
296
|
this.markOrderPulledAtNow();
|
|
263
|
-
|
|
297
|
+
_context4.next = 16;
|
|
264
298
|
break;
|
|
265
299
|
case 12:
|
|
266
|
-
|
|
267
|
-
|
|
300
|
+
_context4.prev = 12;
|
|
301
|
+
_context4.t0 = _context4["catch"](3);
|
|
268
302
|
orderList = [];
|
|
269
303
|
this.logInfo('loadOrdersByServer-拉取失败,回退为空数组');
|
|
270
304
|
case 16:
|
|
271
|
-
|
|
305
|
+
_context4.next = 18;
|
|
272
306
|
return this.saveOrdersToSQLite(orderList);
|
|
273
307
|
case 18:
|
|
274
308
|
this.logInfo('loadOrdersByServer-结束', {
|
|
275
309
|
count: orderList.length
|
|
276
310
|
});
|
|
277
|
-
|
|
311
|
+
_context4.next = 21;
|
|
278
312
|
return this.core.effects.emit(OrderHooks.onOrdersLoaded, orderList);
|
|
279
313
|
case 21:
|
|
280
|
-
return
|
|
314
|
+
return _context4.abrupt("return", orderList);
|
|
281
315
|
case 22:
|
|
282
316
|
case "end":
|
|
283
|
-
return
|
|
317
|
+
return _context4.stop();
|
|
284
318
|
}
|
|
285
|
-
},
|
|
319
|
+
}, _callee4, this, [[3, 12]]);
|
|
286
320
|
}));
|
|
287
321
|
function loadOrdersByServer() {
|
|
288
322
|
return _loadOrdersByServer.apply(this, arguments);
|
|
@@ -292,10 +326,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
292
326
|
}, {
|
|
293
327
|
key: "getOrdersByResourceId",
|
|
294
328
|
value: function getOrdersByResourceId(resourceId) {
|
|
295
|
-
var
|
|
329
|
+
var _this3 = this;
|
|
296
330
|
var ids = this.resourceIdIndex.get(String(resourceId)) || [];
|
|
297
331
|
return ids.map(function (id) {
|
|
298
|
-
return
|
|
332
|
+
return _this3.store.map.get(id);
|
|
299
333
|
}).filter(function (order) {
|
|
300
334
|
return !!order;
|
|
301
335
|
});
|
|
@@ -320,7 +354,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
320
354
|
}, {
|
|
321
355
|
key: "syncOrdersMap",
|
|
322
356
|
value: function syncOrdersMap() {
|
|
323
|
-
var
|
|
357
|
+
var _this4 = this;
|
|
324
358
|
this.store.map.clear();
|
|
325
359
|
this.resourceIdIndex.clear();
|
|
326
360
|
var _iterator = _createForOfIteratorHelper(this.store.list),
|
|
@@ -330,20 +364,20 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
330
364
|
var order = _step.value;
|
|
331
365
|
var id = order.order_id;
|
|
332
366
|
if (id === undefined || id === null) return 1; // continue
|
|
333
|
-
|
|
334
|
-
var resourceIds =
|
|
367
|
+
_this4.store.map.set(_this4.getIdKey(id), order);
|
|
368
|
+
var resourceIds = _this4.extractResourceIds(order);
|
|
335
369
|
var _iterator2 = _createForOfIteratorHelper(resourceIds),
|
|
336
370
|
_step2;
|
|
337
371
|
try {
|
|
338
372
|
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
339
373
|
var resourceId = _step2.value;
|
|
340
374
|
var key = String(resourceId);
|
|
341
|
-
var existing =
|
|
375
|
+
var existing = _this4.resourceIdIndex.get(key) || [];
|
|
342
376
|
if (existing.some(function (eid) {
|
|
343
|
-
return
|
|
377
|
+
return _this4.getIdKey(eid) === _this4.getIdKey(id);
|
|
344
378
|
})) continue;
|
|
345
379
|
existing.push(id);
|
|
346
|
-
|
|
380
|
+
_this4.resourceIdIndex.set(key, existing);
|
|
347
381
|
}
|
|
348
382
|
} catch (err) {
|
|
349
383
|
_iterator2.e(err);
|
|
@@ -412,27 +446,27 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
412
446
|
}, {
|
|
413
447
|
key: "setupOrderSync",
|
|
414
448
|
value: function setupOrderSync() {
|
|
415
|
-
var
|
|
449
|
+
var _this5 = this;
|
|
416
450
|
if (!this.orderDataSource) return;
|
|
417
451
|
var shouldSkipHttpPull = this.hasPulledOrdersToday();
|
|
418
452
|
var syncPayload = {
|
|
419
453
|
pubsub: {
|
|
420
454
|
callback: function callback(res) {
|
|
421
455
|
var _message$id, _message$order_id, _message$type;
|
|
422
|
-
var message =
|
|
456
|
+
var message = _this5.normalizeOrderSyncMessage(res);
|
|
423
457
|
if (!message) return;
|
|
424
|
-
|
|
425
|
-
|
|
458
|
+
_this5.pendingSyncMessages.push(message);
|
|
459
|
+
_this5.logInfo('orderSync-收到消息并入队', {
|
|
426
460
|
id: (_message$id = message.id) !== null && _message$id !== void 0 ? _message$id : null,
|
|
427
461
|
order_id: (_message$order_id = message.order_id) !== null && _message$order_id !== void 0 ? _message$order_id : null,
|
|
428
462
|
type: (_message$type = message.type) !== null && _message$type !== void 0 ? _message$type : null,
|
|
429
|
-
pendingCount:
|
|
430
|
-
debounceMs:
|
|
463
|
+
pendingCount: _this5.pendingSyncMessages.length,
|
|
464
|
+
debounceMs: _this5.ORDER_SYNC_DEBOUNCE_MS
|
|
431
465
|
});
|
|
432
|
-
if (
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
},
|
|
466
|
+
if (_this5.syncTimer) clearTimeout(_this5.syncTimer);
|
|
467
|
+
_this5.syncTimer = setTimeout(function () {
|
|
468
|
+
_this5.processOrderSyncMessages();
|
|
469
|
+
}, _this5.ORDER_SYNC_DEBOUNCE_MS);
|
|
436
470
|
}
|
|
437
471
|
}
|
|
438
472
|
};
|
|
@@ -441,7 +475,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
441
475
|
skipHttp: shouldSkipHttpPull
|
|
442
476
|
};
|
|
443
477
|
this.orderDataSource.run(syncPayload).then(function () {
|
|
444
|
-
if (!shouldSkipHttpPull)
|
|
478
|
+
if (!shouldSkipHttpPull) _this5.markOrderPulledAtNow();
|
|
445
479
|
}).catch(function () {
|
|
446
480
|
// 忽略同步初始化异常,避免影响主流程
|
|
447
481
|
});
|
|
@@ -457,18 +491,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
457
491
|
}, {
|
|
458
492
|
key: "processOrderSyncMessages",
|
|
459
493
|
value: (function () {
|
|
460
|
-
var _processOrderSyncMessages = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
494
|
+
var _processOrderSyncMessages = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
|
|
461
495
|
var messages, upsertOrders, refreshIds, _iterator3, _step3, _msg$id, _msg$relation_order_i, msg, hasBatchIds, singleId, hasSingleId, rawBody, normalizedBody, uniqueRefreshIds, upsertList, freshOrders;
|
|
462
|
-
return _regeneratorRuntime().wrap(function
|
|
463
|
-
while (1) switch (
|
|
496
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
497
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
464
498
|
case 0:
|
|
465
499
|
messages = _toConsumableArray(this.pendingSyncMessages);
|
|
466
500
|
this.pendingSyncMessages = [];
|
|
467
501
|
if (!(messages.length === 0)) {
|
|
468
|
-
|
|
502
|
+
_context5.next = 4;
|
|
469
503
|
break;
|
|
470
504
|
}
|
|
471
|
-
return
|
|
505
|
+
return _context5.abrupt("return");
|
|
472
506
|
case 4:
|
|
473
507
|
this.logInfo('processOrderSyncMessages-开始', {
|
|
474
508
|
messageCount: messages.length
|
|
@@ -476,11 +510,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
476
510
|
upsertOrders = new Map();
|
|
477
511
|
refreshIds = [];
|
|
478
512
|
_iterator3 = _createForOfIteratorHelper(messages);
|
|
479
|
-
|
|
513
|
+
_context5.prev = 8;
|
|
480
514
|
_iterator3.s();
|
|
481
515
|
case 10:
|
|
482
516
|
if ((_step3 = _iterator3.n()).done) {
|
|
483
|
-
|
|
517
|
+
_context5.next = 23;
|
|
484
518
|
break;
|
|
485
519
|
}
|
|
486
520
|
msg = _step3.value;
|
|
@@ -490,27 +524,27 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
490
524
|
rawBody = msg.body || msg.data;
|
|
491
525
|
normalizedBody = this.normalizeOrderSyncPayload(rawBody);
|
|
492
526
|
if (!(hasSingleId && normalizedBody)) {
|
|
493
|
-
|
|
527
|
+
_context5.next = 20;
|
|
494
528
|
break;
|
|
495
529
|
}
|
|
496
530
|
upsertOrders.set(this.getIdKey(normalizedBody.order_id), normalizedBody);
|
|
497
|
-
return
|
|
531
|
+
return _context5.abrupt("continue", 21);
|
|
498
532
|
case 20:
|
|
499
533
|
if (hasBatchIds) refreshIds.push.apply(refreshIds, _toConsumableArray(msg.ids));else if (hasSingleId) refreshIds.push(singleId);else if ((_msg$relation_order_i = msg.relation_order_ids) !== null && _msg$relation_order_i !== void 0 && _msg$relation_order_i.length) refreshIds.push.apply(refreshIds, _toConsumableArray(msg.relation_order_ids));
|
|
500
534
|
case 21:
|
|
501
|
-
|
|
535
|
+
_context5.next = 10;
|
|
502
536
|
break;
|
|
503
537
|
case 23:
|
|
504
|
-
|
|
538
|
+
_context5.next = 28;
|
|
505
539
|
break;
|
|
506
540
|
case 25:
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
_iterator3.e(
|
|
541
|
+
_context5.prev = 25;
|
|
542
|
+
_context5.t0 = _context5["catch"](8);
|
|
543
|
+
_iterator3.e(_context5.t0);
|
|
510
544
|
case 28:
|
|
511
|
-
|
|
545
|
+
_context5.prev = 28;
|
|
512
546
|
_iterator3.f();
|
|
513
|
-
return
|
|
547
|
+
return _context5.finish(28);
|
|
514
548
|
case 31:
|
|
515
549
|
uniqueRefreshIds = this.uniqueOrderIds(refreshIds);
|
|
516
550
|
upsertList = _toConsumableArray(upsertOrders.values());
|
|
@@ -519,44 +553,44 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
519
553
|
refreshIdCount: uniqueRefreshIds.length
|
|
520
554
|
});
|
|
521
555
|
if (!(upsertList.length > 0)) {
|
|
522
|
-
|
|
556
|
+
_context5.next = 37;
|
|
523
557
|
break;
|
|
524
558
|
}
|
|
525
|
-
|
|
559
|
+
_context5.next = 37;
|
|
526
560
|
return this.mergeOrdersToStore(upsertList);
|
|
527
561
|
case 37:
|
|
528
562
|
if (!(uniqueRefreshIds.length > 0)) {
|
|
529
|
-
|
|
563
|
+
_context5.next = 44;
|
|
530
564
|
break;
|
|
531
565
|
}
|
|
532
|
-
|
|
566
|
+
_context5.next = 40;
|
|
533
567
|
return this.fetchOrdersByHttp(uniqueRefreshIds);
|
|
534
568
|
case 40:
|
|
535
|
-
freshOrders =
|
|
569
|
+
freshOrders = _context5.sent;
|
|
536
570
|
if (!(freshOrders.length > 0)) {
|
|
537
|
-
|
|
571
|
+
_context5.next = 44;
|
|
538
572
|
break;
|
|
539
573
|
}
|
|
540
|
-
|
|
574
|
+
_context5.next = 44;
|
|
541
575
|
return this.mergeOrdersToStore(freshOrders);
|
|
542
576
|
case 44:
|
|
543
577
|
if (!(upsertList.length === 0 && uniqueRefreshIds.length === 0)) {
|
|
544
|
-
|
|
578
|
+
_context5.next = 46;
|
|
545
579
|
break;
|
|
546
580
|
}
|
|
547
|
-
return
|
|
581
|
+
return _context5.abrupt("return");
|
|
548
582
|
case 46:
|
|
549
583
|
this.logInfo('processOrderSyncMessages-结束', {
|
|
550
584
|
upsertCount: upsertList.length,
|
|
551
585
|
refreshIdCount: uniqueRefreshIds.length
|
|
552
586
|
});
|
|
553
|
-
|
|
587
|
+
_context5.next = 49;
|
|
554
588
|
return this.core.effects.emit(OrderHooks.onOrdersSyncCompleted, null);
|
|
555
589
|
case 49:
|
|
556
590
|
case "end":
|
|
557
|
-
return
|
|
591
|
+
return _context5.stop();
|
|
558
592
|
}
|
|
559
|
-
},
|
|
593
|
+
}, _callee5, this, [[8, 25, 28, 31]]);
|
|
560
594
|
}));
|
|
561
595
|
function processOrderSyncMessages() {
|
|
562
596
|
return _processOrderSyncMessages.apply(this, arguments);
|
|
@@ -570,29 +604,29 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
570
604
|
}, {
|
|
571
605
|
key: "fetchOrdersByHttp",
|
|
572
606
|
value: (function () {
|
|
573
|
-
var _fetchOrdersByHttp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
607
|
+
var _fetchOrdersByHttp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(ids) {
|
|
574
608
|
var _orderList, orderList;
|
|
575
|
-
return _regeneratorRuntime().wrap(function
|
|
576
|
-
while (1) switch (
|
|
609
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
610
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
577
611
|
case 0:
|
|
578
612
|
if (!(!this.orderDataSource || ids.length === 0)) {
|
|
579
|
-
|
|
613
|
+
_context6.next = 2;
|
|
580
614
|
break;
|
|
581
615
|
}
|
|
582
|
-
return
|
|
616
|
+
return _context6.abrupt("return", []);
|
|
583
617
|
case 2:
|
|
584
|
-
|
|
618
|
+
_context6.prev = 2;
|
|
585
619
|
if (!(typeof this.orderDataSource.fetchOrdersByIds === 'function')) {
|
|
586
|
-
|
|
620
|
+
_context6.next = 8;
|
|
587
621
|
break;
|
|
588
622
|
}
|
|
589
|
-
|
|
623
|
+
_context6.next = 6;
|
|
590
624
|
return this.orderDataSource.fetchOrdersByIds(ids);
|
|
591
625
|
case 6:
|
|
592
|
-
_orderList =
|
|
593
|
-
return
|
|
626
|
+
_orderList = _context6.sent;
|
|
627
|
+
return _context6.abrupt("return", _orderList || []);
|
|
594
628
|
case 8:
|
|
595
|
-
|
|
629
|
+
_context6.next = 10;
|
|
596
630
|
return this.orderDataSource.run({
|
|
597
631
|
http: {
|
|
598
632
|
query: {
|
|
@@ -601,17 +635,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
601
635
|
}
|
|
602
636
|
});
|
|
603
637
|
case 10:
|
|
604
|
-
orderList =
|
|
605
|
-
return
|
|
638
|
+
orderList = _context6.sent;
|
|
639
|
+
return _context6.abrupt("return", orderList || []);
|
|
606
640
|
case 14:
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
return
|
|
641
|
+
_context6.prev = 14;
|
|
642
|
+
_context6.t0 = _context6["catch"](2);
|
|
643
|
+
return _context6.abrupt("return", []);
|
|
610
644
|
case 17:
|
|
611
645
|
case "end":
|
|
612
|
-
return
|
|
646
|
+
return _context6.stop();
|
|
613
647
|
}
|
|
614
|
-
},
|
|
648
|
+
}, _callee6, this, [[2, 14]]);
|
|
615
649
|
}));
|
|
616
650
|
function fetchOrdersByHttp(_x3) {
|
|
617
651
|
return _fetchOrdersByHttp.apply(this, arguments);
|
|
@@ -625,11 +659,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
625
659
|
}, {
|
|
626
660
|
key: "mergeOrdersToStore",
|
|
627
661
|
value: (function () {
|
|
628
|
-
var _mergeOrdersToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
629
|
-
var
|
|
662
|
+
var _mergeOrdersToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(freshOrders) {
|
|
663
|
+
var _this6 = this;
|
|
630
664
|
var freshMap, _iterator4, _step4, order, id, uniqueFreshCount, updatedList, _iterator5, _step5, _order;
|
|
631
|
-
return _regeneratorRuntime().wrap(function
|
|
632
|
-
while (1) switch (
|
|
665
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
666
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
633
667
|
case 0:
|
|
634
668
|
this.logInfo('mergeOrdersToStore-开始', {
|
|
635
669
|
freshOrderCount: freshOrders.length,
|
|
@@ -637,42 +671,42 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
637
671
|
});
|
|
638
672
|
freshMap = new Map();
|
|
639
673
|
_iterator4 = _createForOfIteratorHelper(freshOrders);
|
|
640
|
-
|
|
674
|
+
_context7.prev = 3;
|
|
641
675
|
_iterator4.s();
|
|
642
676
|
case 5:
|
|
643
677
|
if ((_step4 = _iterator4.n()).done) {
|
|
644
|
-
|
|
678
|
+
_context7.next = 13;
|
|
645
679
|
break;
|
|
646
680
|
}
|
|
647
681
|
order = _step4.value;
|
|
648
682
|
id = order === null || order === void 0 ? void 0 : order.order_id;
|
|
649
683
|
if (!(id === undefined || id === null)) {
|
|
650
|
-
|
|
684
|
+
_context7.next = 10;
|
|
651
685
|
break;
|
|
652
686
|
}
|
|
653
|
-
return
|
|
687
|
+
return _context7.abrupt("continue", 11);
|
|
654
688
|
case 10:
|
|
655
689
|
freshMap.set(this.getIdKey(id), order);
|
|
656
690
|
case 11:
|
|
657
|
-
|
|
691
|
+
_context7.next = 5;
|
|
658
692
|
break;
|
|
659
693
|
case 13:
|
|
660
|
-
|
|
694
|
+
_context7.next = 18;
|
|
661
695
|
break;
|
|
662
696
|
case 15:
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
_iterator4.e(
|
|
697
|
+
_context7.prev = 15;
|
|
698
|
+
_context7.t0 = _context7["catch"](3);
|
|
699
|
+
_iterator4.e(_context7.t0);
|
|
666
700
|
case 18:
|
|
667
|
-
|
|
701
|
+
_context7.prev = 18;
|
|
668
702
|
_iterator4.f();
|
|
669
|
-
return
|
|
703
|
+
return _context7.finish(18);
|
|
670
704
|
case 21:
|
|
671
705
|
uniqueFreshCount = freshMap.size;
|
|
672
706
|
updatedList = this.store.list.map(function (order) {
|
|
673
707
|
var id = order.order_id;
|
|
674
708
|
if (id === undefined || id === null) return order;
|
|
675
|
-
var key =
|
|
709
|
+
var key = _this6.getIdKey(id);
|
|
676
710
|
if (!freshMap.has(key)) return order;
|
|
677
711
|
var fresh = freshMap.get(key);
|
|
678
712
|
freshMap.delete(key);
|
|
@@ -691,7 +725,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
691
725
|
}
|
|
692
726
|
this.store.list = updatedList;
|
|
693
727
|
this.syncOrdersMap();
|
|
694
|
-
|
|
728
|
+
_context7.next = 29;
|
|
695
729
|
return this.saveOrdersToSQLite(this.store.list);
|
|
696
730
|
case 29:
|
|
697
731
|
this.logInfo('mergeOrdersToStore-结束', {
|
|
@@ -701,9 +735,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
701
735
|
this.core.effects.emit(OrderHooks.onOrdersChanged, this.store.list);
|
|
702
736
|
case 31:
|
|
703
737
|
case "end":
|
|
704
|
-
return
|
|
738
|
+
return _context7.stop();
|
|
705
739
|
}
|
|
706
|
-
},
|
|
740
|
+
}, _callee7, this, [[3, 15, 18, 21]]);
|
|
707
741
|
}));
|
|
708
742
|
function mergeOrdersToStore(_x4) {
|
|
709
743
|
return _mergeOrdersToStore.apply(this, arguments);
|
|
@@ -842,32 +876,32 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
842
876
|
}, {
|
|
843
877
|
key: "loadOrdersFromSQLite",
|
|
844
878
|
value: function () {
|
|
845
|
-
var _loadOrdersFromSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
879
|
+
var _loadOrdersFromSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
|
|
846
880
|
var orders;
|
|
847
|
-
return _regeneratorRuntime().wrap(function
|
|
848
|
-
while (1) switch (
|
|
881
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
882
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
849
883
|
case 0:
|
|
850
884
|
if (this.dbManager) {
|
|
851
|
-
|
|
885
|
+
_context8.next = 2;
|
|
852
886
|
break;
|
|
853
887
|
}
|
|
854
|
-
return
|
|
888
|
+
return _context8.abrupt("return", []);
|
|
855
889
|
case 2:
|
|
856
|
-
|
|
857
|
-
|
|
890
|
+
_context8.prev = 2;
|
|
891
|
+
_context8.next = 5;
|
|
858
892
|
return this.dbManager.getAll(INDEXDB_STORE_NAME);
|
|
859
893
|
case 5:
|
|
860
|
-
orders =
|
|
861
|
-
return
|
|
894
|
+
orders = _context8.sent;
|
|
895
|
+
return _context8.abrupt("return", orders || []);
|
|
862
896
|
case 9:
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
return
|
|
897
|
+
_context8.prev = 9;
|
|
898
|
+
_context8.t0 = _context8["catch"](2);
|
|
899
|
+
return _context8.abrupt("return", []);
|
|
866
900
|
case 12:
|
|
867
901
|
case "end":
|
|
868
|
-
return
|
|
902
|
+
return _context8.stop();
|
|
869
903
|
}
|
|
870
|
-
},
|
|
904
|
+
}, _callee8, this, [[2, 9]]);
|
|
871
905
|
}));
|
|
872
906
|
function loadOrdersFromSQLite() {
|
|
873
907
|
return _loadOrdersFromSQLite.apply(this, arguments);
|
|
@@ -877,53 +911,53 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
877
911
|
}, {
|
|
878
912
|
key: "saveOrdersToSQLite",
|
|
879
913
|
value: function () {
|
|
880
|
-
var _saveOrdersToSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
881
|
-
return _regeneratorRuntime().wrap(function
|
|
882
|
-
while (1) switch (
|
|
914
|
+
var _saveOrdersToSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(orderList) {
|
|
915
|
+
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
916
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
883
917
|
case 0:
|
|
884
918
|
if (this.dbManager) {
|
|
885
|
-
|
|
919
|
+
_context9.next = 2;
|
|
886
920
|
break;
|
|
887
921
|
}
|
|
888
|
-
return
|
|
922
|
+
return _context9.abrupt("return");
|
|
889
923
|
case 2:
|
|
890
|
-
|
|
924
|
+
_context9.prev = 2;
|
|
891
925
|
this.logInfo('saveOrdersToSQLite-开始', {
|
|
892
926
|
count: orderList.length
|
|
893
927
|
});
|
|
894
|
-
|
|
928
|
+
_context9.next = 6;
|
|
895
929
|
return this.dbManager.clear(INDEXDB_STORE_NAME);
|
|
896
930
|
case 6:
|
|
897
931
|
this.logInfo('saveOrdersToSQLite-clear完成', {
|
|
898
932
|
count: orderList.length
|
|
899
933
|
});
|
|
900
934
|
if (!(orderList.length === 0)) {
|
|
901
|
-
|
|
935
|
+
_context9.next = 9;
|
|
902
936
|
break;
|
|
903
937
|
}
|
|
904
|
-
return
|
|
938
|
+
return _context9.abrupt("return");
|
|
905
939
|
case 9:
|
|
906
|
-
|
|
940
|
+
_context9.next = 11;
|
|
907
941
|
return this.dbManager.bulkAdd(INDEXDB_STORE_NAME, orderList);
|
|
908
942
|
case 11:
|
|
909
943
|
this.logInfo('saveOrdersToSQLite-bulkAdd完成', {
|
|
910
944
|
count: orderList.length
|
|
911
945
|
});
|
|
912
|
-
|
|
946
|
+
_context9.next = 17;
|
|
913
947
|
break;
|
|
914
948
|
case 14:
|
|
915
|
-
|
|
916
|
-
|
|
949
|
+
_context9.prev = 14;
|
|
950
|
+
_context9.t0 = _context9["catch"](2);
|
|
917
951
|
// SQLite 异常,避免影响主流程
|
|
918
952
|
this.logError('保存订单到 SQLite 失败', {
|
|
919
|
-
error:
|
|
953
|
+
error: _context9.t0 instanceof Error ? _context9.t0.message : String(_context9.t0),
|
|
920
954
|
orderList: orderList.length
|
|
921
955
|
});
|
|
922
956
|
case 17:
|
|
923
957
|
case "end":
|
|
924
|
-
return
|
|
958
|
+
return _context9.stop();
|
|
925
959
|
}
|
|
926
|
-
},
|
|
960
|
+
}, _callee9, this, [[2, 14]]);
|
|
927
961
|
}));
|
|
928
962
|
function saveOrdersToSQLite(_x5) {
|
|
929
963
|
return _saveOrdersToSQLite.apply(this, arguments);
|
|
@@ -933,27 +967,27 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
933
967
|
}, {
|
|
934
968
|
key: "clear",
|
|
935
969
|
value: function () {
|
|
936
|
-
var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
937
|
-
return _regeneratorRuntime().wrap(function
|
|
938
|
-
while (1) switch (
|
|
970
|
+
var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
|
|
971
|
+
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
972
|
+
while (1) switch (_context10.prev = _context10.next) {
|
|
939
973
|
case 0:
|
|
940
974
|
this.store.list = [];
|
|
941
975
|
this.store.map = new Map();
|
|
942
976
|
this.resourceIdIndex.clear();
|
|
943
977
|
if (!this.dbManager) {
|
|
944
|
-
|
|
978
|
+
_context10.next = 6;
|
|
945
979
|
break;
|
|
946
980
|
}
|
|
947
|
-
|
|
981
|
+
_context10.next = 6;
|
|
948
982
|
return this.dbManager.clear(INDEXDB_STORE_NAME);
|
|
949
983
|
case 6:
|
|
950
984
|
this.setStorageItem(ORDER_LAST_FULL_FETCH_AT_STORAGE_KEY, '');
|
|
951
985
|
this.core.effects.emit(OrderHooks.onOrdersChanged, this.store.list);
|
|
952
986
|
case 8:
|
|
953
987
|
case "end":
|
|
954
|
-
return
|
|
988
|
+
return _context10.stop();
|
|
955
989
|
}
|
|
956
|
-
},
|
|
990
|
+
}, _callee10, this);
|
|
957
991
|
}));
|
|
958
992
|
function clear() {
|
|
959
993
|
return _clear.apply(this, arguments);
|
|
@@ -131,7 +131,7 @@ export declare class BookingTicketImpl extends BaseModule implements Module {
|
|
|
131
131
|
* 获取当前的客户搜索条件
|
|
132
132
|
* @returns 当前搜索条件
|
|
133
133
|
*/
|
|
134
|
-
getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "
|
|
134
|
+
getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "skip" | "num">;
|
|
135
135
|
/**
|
|
136
136
|
* 获取客户列表状态(包含滚动加载相关状态)
|
|
137
137
|
* @returns 客户状态
|
|
@@ -23,7 +23,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
|
|
|
23
23
|
*/
|
|
24
24
|
private logError;
|
|
25
25
|
createOrder(params: CommitOrderParams['query']): {
|
|
26
|
-
type: "
|
|
26
|
+
type: "appointment_booking" | "virtual";
|
|
27
27
|
platform: string;
|
|
28
28
|
sales_channel: string;
|
|
29
29
|
order_sales_channel: string;
|
|
@@ -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(): "
|
|
52
|
+
getProductType(): "duration" | "session" | "normal";
|
|
53
53
|
}
|
|
@@ -96,7 +96,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
96
96
|
if (productList.every((item) => {
|
|
97
97
|
var _a;
|
|
98
98
|
const product = this.hooks.getProduct(item);
|
|
99
|
-
return product.booking_id && (((_a = product.discount_list) == null ? void 0 : _a.length) ||
|
|
99
|
+
return product.booking_id && (((_a = product.discount_list) == null ? void 0 : _a.length) || product.total == 0);
|
|
100
100
|
})) {
|
|
101
101
|
return {
|
|
102
102
|
isAvailable: false,
|
|
@@ -593,16 +593,20 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
593
593
|
return { discountedOptions: options2, optionDiscountAmount: 0 };
|
|
594
594
|
let optionDiscountAmount = 0;
|
|
595
595
|
const discountedOptions = options2.map((option) => {
|
|
596
|
-
const
|
|
597
|
-
|
|
596
|
+
const rawUnit = option._original_price ?? option._original_add_price ?? option.price ?? option.add_price;
|
|
597
|
+
const baseUnitNum = Number(rawUnit ?? 0);
|
|
598
|
+
if (baseUnitNum <= 0)
|
|
598
599
|
return option;
|
|
599
|
-
const discountedPrice = (0, import_utils.getDiscountAmount)(discount,
|
|
600
|
+
const discountedPrice = (0, import_utils.getDiscountAmount)(discount, baseUnitNum, baseUnitNum);
|
|
600
601
|
const optQty = Number(option.num ?? option.quantity ?? 1);
|
|
601
|
-
optionDiscountAmount = new import_decimal.default(optionDiscountAmount).plus(new import_decimal.default(
|
|
602
|
+
optionDiscountAmount = new import_decimal.default(optionDiscountAmount).plus(new import_decimal.default(baseUnitNum).minus(discountedPrice).mul(optQty)).toNumber();
|
|
603
|
+
const { _original_add_price, ...rest } = option;
|
|
604
|
+
const tmpl = rest.price ?? rest.add_price;
|
|
605
|
+
const nextPrice = typeof tmpl === "string" ? String(discountedPrice) : discountedPrice;
|
|
602
606
|
return {
|
|
603
|
-
...
|
|
604
|
-
|
|
605
|
-
|
|
607
|
+
...rest,
|
|
608
|
+
_original_price: option._original_price ?? (_original_add_price !== void 0 ? _original_add_price : rawUnit),
|
|
609
|
+
price: nextPrice
|
|
606
610
|
};
|
|
607
611
|
});
|
|
608
612
|
return { discountedOptions, optionDiscountAmount };
|
|
@@ -611,9 +615,10 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
611
615
|
if (!(options2 == null ? void 0 : options2.length))
|
|
612
616
|
return options2;
|
|
613
617
|
return options2.map((option) => {
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
618
|
+
const orig = option._original_price !== void 0 ? option._original_price : option._original_add_price;
|
|
619
|
+
if (orig !== void 0) {
|
|
620
|
+
const { _original_price, _original_add_price, ...rest } = option;
|
|
621
|
+
return { ...rest, price: orig };
|
|
617
622
|
}
|
|
618
623
|
return option;
|
|
619
624
|
});
|
|
@@ -622,7 +627,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
622
627
|
if (!(options2 == null ? void 0 : options2.length))
|
|
623
628
|
return 0;
|
|
624
629
|
return options2.reduce((sum, opt) => {
|
|
625
|
-
const unit = Number(opt.
|
|
630
|
+
const unit = Number(opt.price ?? opt.add_price ?? 0);
|
|
626
631
|
const n = Number(opt.num ?? opt.quantity ?? 1);
|
|
627
632
|
return new import_decimal.default(sum).plus(new import_decimal.default(unit).mul(n)).toNumber();
|
|
628
633
|
}, 0);
|
|
@@ -150,12 +150,16 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
150
150
|
}
|
|
151
151
|
}
|
|
152
152
|
async preload() {
|
|
153
|
-
const
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
153
|
+
const getData = async () => {
|
|
154
|
+
const orders = await this.loadOrdersByServer();
|
|
155
|
+
if (orders.length === 0)
|
|
156
|
+
return;
|
|
157
|
+
this.store.list = (0, import_lodash_es.cloneDeep)(orders);
|
|
158
|
+
this.syncOrdersMap();
|
|
159
|
+
this.core.effects.emit(import_types.OrderHooks.onOrdersChanged, this.store.list);
|
|
160
|
+
this.core.effects.emit(import_types.OrderHooks.onOrdersSyncCompleted, null);
|
|
161
|
+
};
|
|
162
|
+
getData();
|
|
159
163
|
}
|
|
160
164
|
getOrders() {
|
|
161
165
|
return this.store.list;
|
|
@@ -131,7 +131,7 @@ export declare class BookingTicketImpl extends BaseModule implements Module {
|
|
|
131
131
|
* 获取当前的客户搜索条件
|
|
132
132
|
* @returns 当前搜索条件
|
|
133
133
|
*/
|
|
134
|
-
getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "
|
|
134
|
+
getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "skip" | "num">;
|
|
135
135
|
/**
|
|
136
136
|
* 获取客户列表状态(包含滚动加载相关状态)
|
|
137
137
|
* @returns 客户状态
|