@pisell/pisellos 2.2.228 → 2.2.229
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/modules/Order/index.js +1 -1
- package/dist/server/index.js +8 -11
- package/dist/server/modules/order/index.d.ts +1 -0
- package/dist/server/modules/order/index.js +92 -80
- package/dist/solution/BaseSales/index.js +0 -1
- package/lib/server/index.js +2 -2
- package/lib/server/modules/order/index.d.ts +1 -0
- package/lib/server/modules/order/index.js +8 -0
- package/lib/solution/BaseSales/index.js +0 -1
- package/package.json +1 -1
|
@@ -3115,7 +3115,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
3115
3115
|
return _regeneratorRuntime().wrap(function _callee16$(_context18) {
|
|
3116
3116
|
while (1) switch (_context18.prev = _context18.next) {
|
|
3117
3117
|
case 0:
|
|
3118
|
-
tempOrder = this.ensureTempOrder();
|
|
3118
|
+
tempOrder = this.ensureTempOrder();
|
|
3119
3119
|
if (!booking) {
|
|
3120
3120
|
_context18.next = 18;
|
|
3121
3121
|
break;
|
package/dist/server/index.js
CHANGED
|
@@ -3811,7 +3811,7 @@ var Server = /*#__PURE__*/function () {
|
|
|
3811
3811
|
}
|
|
3812
3812
|
return _context40.abrupt("return", next);
|
|
3813
3813
|
case 9:
|
|
3814
|
-
if (!(!this.order || typeof this.order.
|
|
3814
|
+
if (!(!this.order || typeof this.order.getLocalOrderFromMemoryByLookup !== 'function')) {
|
|
3815
3815
|
_context40.next = 12;
|
|
3816
3816
|
break;
|
|
3817
3817
|
}
|
|
@@ -3824,12 +3824,9 @@ var Server = /*#__PURE__*/function () {
|
|
|
3824
3824
|
return _context40.abrupt("return", next);
|
|
3825
3825
|
case 12:
|
|
3826
3826
|
_context40.prev = 12;
|
|
3827
|
-
|
|
3828
|
-
return this.order.getLocalOrderByLookup(externalSaleNumber);
|
|
3829
|
-
case 15:
|
|
3830
|
-
localOrder = _context40.sent;
|
|
3827
|
+
localOrder = this.order.getLocalOrderFromMemoryByLookup(externalSaleNumber);
|
|
3831
3828
|
if (localOrder) {
|
|
3832
|
-
_context40.next =
|
|
3829
|
+
_context40.next = 17;
|
|
3833
3830
|
break;
|
|
3834
3831
|
}
|
|
3835
3832
|
if (shouldClearLocalOrderId) {
|
|
@@ -3840,7 +3837,7 @@ var Server = /*#__PURE__*/function () {
|
|
|
3840
3837
|
});
|
|
3841
3838
|
}
|
|
3842
3839
|
return _context40.abrupt("return", next);
|
|
3843
|
-
case
|
|
3840
|
+
case 17:
|
|
3844
3841
|
if (this.isBlankCheckoutValue(next.shop_order_number)) {
|
|
3845
3842
|
next.shop_order_number = localOrder.shop_order_number;
|
|
3846
3843
|
}
|
|
@@ -3856,8 +3853,8 @@ var Server = /*#__PURE__*/function () {
|
|
|
3856
3853
|
shop_full_order_number: next.shop_full_order_number
|
|
3857
3854
|
});
|
|
3858
3855
|
return _context40.abrupt("return", next);
|
|
3859
|
-
case
|
|
3860
|
-
_context40.prev =
|
|
3856
|
+
case 23:
|
|
3857
|
+
_context40.prev = 23;
|
|
3861
3858
|
_context40.t0 = _context40["catch"](12);
|
|
3862
3859
|
this.logWarning("".concat(title, ": checkout \u67E5\u627E\u672C\u5730\u8BA2\u5355\u5931\u8D25"), {
|
|
3863
3860
|
external_sale_number: externalSaleNumber,
|
|
@@ -3865,11 +3862,11 @@ var Server = /*#__PURE__*/function () {
|
|
|
3865
3862
|
error_detail: this.normalizeUnknownError(_context40.t0)
|
|
3866
3863
|
});
|
|
3867
3864
|
return _context40.abrupt("return", next);
|
|
3868
|
-
case
|
|
3865
|
+
case 27:
|
|
3869
3866
|
case "end":
|
|
3870
3867
|
return _context40.stop();
|
|
3871
3868
|
}
|
|
3872
|
-
}, _callee40, this, [[12,
|
|
3869
|
+
}, _callee40, this, [[12, 23]]);
|
|
3873
3870
|
}));
|
|
3874
3871
|
function normalizeCheckoutSubmitData(_x42, _x43) {
|
|
3875
3872
|
return _normalizeCheckoutSubmitData.apply(this, arguments);
|
|
@@ -79,6 +79,7 @@ export declare class OrderModule extends BaseModule implements Module {
|
|
|
79
79
|
getOrderById(id: OrderId): OrderData | undefined;
|
|
80
80
|
/** 按 order_id 查询内存订单。 */
|
|
81
81
|
getOrderByOrderId(orderId: OrderId): OrderData | undefined;
|
|
82
|
+
getLocalOrderFromMemoryByLookup(lookup: OrderId): OrderData | null;
|
|
82
83
|
getLocalOrderByLookup(lookup: OrderId): Promise<OrderData | null>;
|
|
83
84
|
loadOrdersByServer(): Promise<OrderData[]>;
|
|
84
85
|
/**
|
|
@@ -561,11 +561,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
561
561
|
value: function getOrderByOrderId(orderId) {
|
|
562
562
|
return this.store.map.get(this.getIdKey(orderId));
|
|
563
563
|
}
|
|
564
|
+
}, {
|
|
565
|
+
key: "getLocalOrderFromMemoryByLookup",
|
|
566
|
+
value: function getLocalOrderFromMemoryByLookup(lookup) {
|
|
567
|
+
var _this5 = this;
|
|
568
|
+
var key = this.getIdKey(lookup);
|
|
569
|
+
var memoryOrderById = this.store.map.get(key);
|
|
570
|
+
if (memoryOrderById) return memoryOrderById;
|
|
571
|
+
var memoryOrder = this.store.list.find(function (order) {
|
|
572
|
+
return _this5.isOrderLookupMatch(order, key);
|
|
573
|
+
});
|
|
574
|
+
return memoryOrder || null;
|
|
575
|
+
}
|
|
564
576
|
}, {
|
|
565
577
|
key: "getLocalOrderByLookup",
|
|
566
578
|
value: function () {
|
|
567
579
|
var _getLocalOrderByLookup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(lookup) {
|
|
568
|
-
var
|
|
580
|
+
var _this6 = this;
|
|
569
581
|
var key, memoryOrderById, memoryOrder, orders, localOrder;
|
|
570
582
|
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
571
583
|
while (1) switch (_context5.prev = _context5.next) {
|
|
@@ -579,7 +591,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
579
591
|
return _context5.abrupt("return", memoryOrderById);
|
|
580
592
|
case 4:
|
|
581
593
|
memoryOrder = this.store.list.find(function (order) {
|
|
582
|
-
return
|
|
594
|
+
return _this6.isOrderLookupMatch(order, key);
|
|
583
595
|
});
|
|
584
596
|
if (!memoryOrder) {
|
|
585
597
|
_context5.next = 7;
|
|
@@ -592,7 +604,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
592
604
|
case 9:
|
|
593
605
|
orders = _context5.sent;
|
|
594
606
|
localOrder = orders.find(function (order) {
|
|
595
|
-
return
|
|
607
|
+
return _this6.isOrderLookupMatch(order, key);
|
|
596
608
|
});
|
|
597
609
|
if (localOrder) {
|
|
598
610
|
_context5.next = 13;
|
|
@@ -601,7 +613,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
601
613
|
return _context5.abrupt("return", null);
|
|
602
614
|
case 13:
|
|
603
615
|
this.store.list = orders.map(function (order) {
|
|
604
|
-
return
|
|
616
|
+
return _this6.normalizeOrderForMemoryList(order);
|
|
605
617
|
});
|
|
606
618
|
this.syncOrdersMap();
|
|
607
619
|
return _context5.abrupt("return", this.normalizeOrderForMemoryList(localOrder));
|
|
@@ -621,7 +633,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
621
633
|
value: function () {
|
|
622
634
|
var _loadOrdersByServer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
|
|
623
635
|
var _this$store,
|
|
624
|
-
|
|
636
|
+
_this7 = this;
|
|
625
637
|
var orderList, data, mergedOrders, memoryOrders;
|
|
626
638
|
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
627
639
|
while (1) switch (_context6.prev = _context6.next) {
|
|
@@ -663,7 +675,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
663
675
|
case 19:
|
|
664
676
|
mergedOrders = _context6.sent;
|
|
665
677
|
memoryOrders = mergedOrders.map(function (order) {
|
|
666
|
-
return
|
|
678
|
+
return _this7.normalizeOrderForMemoryList(order);
|
|
667
679
|
});
|
|
668
680
|
this.logInfo('loadOrdersByServer-结束', {
|
|
669
681
|
count: memoryOrders.length
|
|
@@ -753,10 +765,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
753
765
|
}, {
|
|
754
766
|
key: "getOrdersByResourceId",
|
|
755
767
|
value: function getOrdersByResourceId(resourceId) {
|
|
756
|
-
var
|
|
768
|
+
var _this8 = this;
|
|
757
769
|
var ids = this.resourceIdIndex.get(String(resourceId)) || [];
|
|
758
770
|
return ids.map(function (id) {
|
|
759
|
-
return
|
|
771
|
+
return _this8.store.map.get(id);
|
|
760
772
|
}).filter(function (order) {
|
|
761
773
|
return !!order;
|
|
762
774
|
});
|
|
@@ -784,7 +796,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
784
796
|
key: "overwriteExistingOrder",
|
|
785
797
|
value: (function () {
|
|
786
798
|
var _overwriteExistingOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(fresh) {
|
|
787
|
-
var
|
|
799
|
+
var _this9 = this;
|
|
788
800
|
var orderId, key;
|
|
789
801
|
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
790
802
|
while (1) switch (_context8.prev = _context8.next) {
|
|
@@ -818,7 +830,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
818
830
|
this.store.list = this.store.list.map(function (order) {
|
|
819
831
|
var id = order === null || order === void 0 ? void 0 : order.order_id;
|
|
820
832
|
if (id === undefined || id === null) return order;
|
|
821
|
-
return
|
|
833
|
+
return _this9.getIdKey(id) === key ? fresh : order;
|
|
822
834
|
});
|
|
823
835
|
this.syncOrdersMap();
|
|
824
836
|
_context8.next = 13;
|
|
@@ -884,7 +896,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
884
896
|
key: "markOrderSyncedByExternalSaleNumber",
|
|
885
897
|
value: function () {
|
|
886
898
|
var _markOrderSyncedByExternalSaleNumber = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(params) {
|
|
887
|
-
var
|
|
899
|
+
var _this10 = this,
|
|
888
900
|
_existing$external_sa,
|
|
889
901
|
_nextOrder$order_id;
|
|
890
902
|
var externalSaleNumber, key, targetIndex, existing, nextOrder, storageKey;
|
|
@@ -905,7 +917,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
905
917
|
targetIndex = this.store.list.findIndex(function (order) {
|
|
906
918
|
var value = order === null || order === void 0 ? void 0 : order.external_sale_number;
|
|
907
919
|
if (value === undefined || value === null || value === '') return false;
|
|
908
|
-
return
|
|
920
|
+
return _this10.getIdKey(value) === key;
|
|
909
921
|
});
|
|
910
922
|
if (!(targetIndex < 0)) {
|
|
911
923
|
_context10.next = 9;
|
|
@@ -1162,7 +1174,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1162
1174
|
}, {
|
|
1163
1175
|
key: "syncOrdersMap",
|
|
1164
1176
|
value: function syncOrdersMap() {
|
|
1165
|
-
var
|
|
1177
|
+
var _this11 = this;
|
|
1166
1178
|
this.store.map.clear();
|
|
1167
1179
|
this.resourceIdIndex.clear();
|
|
1168
1180
|
var _iterator7 = _createForOfIteratorHelper(this.store.list),
|
|
@@ -1170,22 +1182,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1170
1182
|
try {
|
|
1171
1183
|
var _loop = function _loop() {
|
|
1172
1184
|
var order = _step7.value;
|
|
1173
|
-
var primaryIdentity =
|
|
1185
|
+
var primaryIdentity = _this11.getOrderMapKey(order);
|
|
1174
1186
|
if (!primaryIdentity) return 1; // continue
|
|
1175
|
-
|
|
1176
|
-
var resourceIds =
|
|
1187
|
+
_this11.store.map.set(primaryIdentity, order);
|
|
1188
|
+
var resourceIds = _this11.extractResourceIds(order);
|
|
1177
1189
|
var _iterator8 = _createForOfIteratorHelper(resourceIds),
|
|
1178
1190
|
_step8;
|
|
1179
1191
|
try {
|
|
1180
1192
|
for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
|
|
1181
1193
|
var resourceId = _step8.value;
|
|
1182
1194
|
var key = String(resourceId);
|
|
1183
|
-
var existing =
|
|
1195
|
+
var existing = _this11.resourceIdIndex.get(key) || [];
|
|
1184
1196
|
if (existing.some(function (eid) {
|
|
1185
|
-
return
|
|
1197
|
+
return _this11.getIdKey(eid) === primaryIdentity;
|
|
1186
1198
|
})) continue;
|
|
1187
1199
|
existing.push(primaryIdentity);
|
|
1188
|
-
|
|
1200
|
+
_this11.resourceIdIndex.set(key, existing);
|
|
1189
1201
|
}
|
|
1190
1202
|
} catch (err) {
|
|
1191
1203
|
_iterator8.e(err);
|
|
@@ -1223,7 +1235,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1223
1235
|
}, {
|
|
1224
1236
|
key: "getOrderIdentityEntries",
|
|
1225
1237
|
value: function getOrderIdentityEntries(order) {
|
|
1226
|
-
var
|
|
1238
|
+
var _this12 = this;
|
|
1227
1239
|
if (!order) return [];
|
|
1228
1240
|
var record = order;
|
|
1229
1241
|
var candidates = [{
|
|
@@ -1242,8 +1254,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1242
1254
|
var entries = [];
|
|
1243
1255
|
var _loop2 = function _loop2() {
|
|
1244
1256
|
var candidate = _candidates[_i];
|
|
1245
|
-
if (
|
|
1246
|
-
var key =
|
|
1257
|
+
if (_this12.isBlankIdentityValue(candidate.value)) return 0; // continue
|
|
1258
|
+
var key = _this12.getIdKey(candidate.value);
|
|
1247
1259
|
if (entries.some(function (entry) {
|
|
1248
1260
|
return entry.field === candidate.field && entry.key === key;
|
|
1249
1261
|
})) return 0; // continue
|
|
@@ -1329,7 +1341,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1329
1341
|
}, {
|
|
1330
1342
|
key: "setupOrderSync",
|
|
1331
1343
|
value: function setupOrderSync() {
|
|
1332
|
-
var
|
|
1344
|
+
var _this13 = this;
|
|
1333
1345
|
if (!this.orderDataSource) return;
|
|
1334
1346
|
this.orderDataSource.run({
|
|
1335
1347
|
pubsub: {
|
|
@@ -1337,22 +1349,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1337
1349
|
var _message$id, _message$order_id, _message$type;
|
|
1338
1350
|
console.log('orderDataSource', res);
|
|
1339
1351
|
var pubsubReceivedAt = Date.now();
|
|
1340
|
-
var message =
|
|
1352
|
+
var message = _this13.normalizeOrderSyncMessage(res);
|
|
1341
1353
|
if (!message) return;
|
|
1342
1354
|
message._pubsubReceivedAt = pubsubReceivedAt;
|
|
1343
|
-
|
|
1344
|
-
var throttleMs =
|
|
1345
|
-
var routeInfo =
|
|
1346
|
-
|
|
1355
|
+
_this13.pendingSyncMessages.push(message);
|
|
1356
|
+
var throttleMs = _this13.getOrderSyncThrottleMs();
|
|
1357
|
+
var routeInfo = _this13.resolveSyncMessageRoute(message);
|
|
1358
|
+
_this13.logInfo('orderSync-收到消息并入队', {
|
|
1347
1359
|
id: (_message$id = message.id) !== null && _message$id !== void 0 ? _message$id : null,
|
|
1348
1360
|
order_id: (_message$order_id = message.order_id) !== null && _message$order_id !== void 0 ? _message$order_id : null,
|
|
1349
1361
|
type: (_message$type = message.type) !== null && _message$type !== void 0 ? _message$type : null,
|
|
1350
|
-
pendingCount:
|
|
1362
|
+
pendingCount: _this13.pendingSyncMessages.length,
|
|
1351
1363
|
throttleMs: throttleMs,
|
|
1352
1364
|
pubsubReceivedAt: new Date(pubsubReceivedAt).toISOString(),
|
|
1353
1365
|
fullMessage: JSON.stringify(message)
|
|
1354
1366
|
});
|
|
1355
|
-
|
|
1367
|
+
_this13.scheduleOrderSyncThrottle();
|
|
1356
1368
|
}
|
|
1357
1369
|
}
|
|
1358
1370
|
}).catch(function () {
|
|
@@ -1369,7 +1381,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1369
1381
|
}, {
|
|
1370
1382
|
key: "scheduleOrderSyncThrottle",
|
|
1371
1383
|
value: function scheduleOrderSyncThrottle() {
|
|
1372
|
-
var
|
|
1384
|
+
var _this14 = this;
|
|
1373
1385
|
if (this.isProcessingSyncBatch) return;
|
|
1374
1386
|
if (this.isIdlePhase) {
|
|
1375
1387
|
this.isIdlePhase = false;
|
|
@@ -1380,8 +1392,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1380
1392
|
if (this.syncTimer) return;
|
|
1381
1393
|
var throttleMs = this.getOrderSyncThrottleMs();
|
|
1382
1394
|
this.syncTimer = setTimeout(function () {
|
|
1383
|
-
|
|
1384
|
-
void
|
|
1395
|
+
_this14.syncTimer = undefined;
|
|
1396
|
+
void _this14.flushOrderSyncMessagesByThrottle();
|
|
1385
1397
|
}, throttleMs);
|
|
1386
1398
|
}
|
|
1387
1399
|
|
|
@@ -1449,7 +1461,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1449
1461
|
key: "processOrderSyncMessages",
|
|
1450
1462
|
value: (function () {
|
|
1451
1463
|
var _processOrderSyncMessages = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14() {
|
|
1452
|
-
var
|
|
1464
|
+
var _this15 = this;
|
|
1453
1465
|
var messages, batchProcessStartAt, earliestReceivedAt, upsertOrders, refreshIds, uniqueRefreshIds, upsertList, _this$filterRedundant, toFetch, skipped, freshOrders, batchProcessEndAt;
|
|
1454
1466
|
return _regeneratorRuntime().wrap(function _callee14$(_context14) {
|
|
1455
1467
|
while (1) switch (_context14.prev = _context14.next) {
|
|
@@ -1476,13 +1488,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1476
1488
|
upsertOrders = new Map();
|
|
1477
1489
|
refreshIds = [];
|
|
1478
1490
|
messages.forEach(function (msg, msgIndex) {
|
|
1479
|
-
var routeInfo =
|
|
1491
|
+
var routeInfo = _this15.resolveSyncMessageRoute(msg);
|
|
1480
1492
|
var hasBatchIds = routeInfo.hasBatchIds;
|
|
1481
1493
|
var singleId = routeInfo.singleId;
|
|
1482
1494
|
var hasSingleId = routeInfo.hasSingleId;
|
|
1483
|
-
var normalizedBody =
|
|
1495
|
+
var normalizedBody = _this15.normalizeOrderSyncPayload(msg.body || msg.data);
|
|
1484
1496
|
if (routeInfo.route === 'bodyUpsert' && normalizedBody) {
|
|
1485
|
-
upsertOrders.set(
|
|
1497
|
+
upsertOrders.set(_this15.getIdKey(normalizedBody.order_id), normalizedBody);
|
|
1486
1498
|
return;
|
|
1487
1499
|
}
|
|
1488
1500
|
if (hasBatchIds) refreshIds.push.apply(refreshIds, _toConsumableArray(routeInfo.batchIds));else if (routeInfo.route === 'httpRefresh.singleId' && singleId !== null) refreshIds.push(singleId);else if (routeInfo.route === 'httpRefresh.relationIds') refreshIds.push.apply(refreshIds, _toConsumableArray(routeInfo.batchIds));
|
|
@@ -1797,12 +1809,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1797
1809
|
}, {
|
|
1798
1810
|
key: "isOrderLookupMatch",
|
|
1799
1811
|
value: function isOrderLookupMatch(order, lookupKey) {
|
|
1800
|
-
var
|
|
1812
|
+
var _this16 = this;
|
|
1801
1813
|
if (!order || !lookupKey) return false;
|
|
1802
1814
|
var candidates = [order.order_id, order.external_sale_number, order.order_number, order.shop_order_number, order.shop_full_order_number];
|
|
1803
1815
|
return candidates.some(function (value) {
|
|
1804
1816
|
if (value === undefined || value === null || value === '') return false;
|
|
1805
|
-
return
|
|
1817
|
+
return _this16.getIdKey(value) === lookupKey;
|
|
1806
1818
|
});
|
|
1807
1819
|
}
|
|
1808
1820
|
|
|
@@ -1845,10 +1857,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1845
1857
|
}, {
|
|
1846
1858
|
key: "findOrderIndexByIdentity",
|
|
1847
1859
|
value: function findOrderIndexByIdentity(orders, target) {
|
|
1848
|
-
var
|
|
1860
|
+
var _this17 = this;
|
|
1849
1861
|
if (this.getOrderIdentityMatchKeys(target).length === 0) return -1;
|
|
1850
1862
|
return orders.findIndex(function (order) {
|
|
1851
|
-
return
|
|
1863
|
+
return _this17.doOrdersShareIdentity(order, target);
|
|
1852
1864
|
});
|
|
1853
1865
|
}
|
|
1854
1866
|
}, {
|
|
@@ -2137,9 +2149,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2137
2149
|
}, {
|
|
2138
2150
|
key: "mergeRemoteSnapshotWithPendingOrders",
|
|
2139
2151
|
value: function mergeRemoteSnapshotWithPendingOrders(remoteOrders, existingOrders) {
|
|
2140
|
-
var
|
|
2152
|
+
var _this18 = this;
|
|
2141
2153
|
var merged = remoteOrders.map(function (order) {
|
|
2142
|
-
return
|
|
2154
|
+
return _this18.normalizeRemoteSyncedOrder(order);
|
|
2143
2155
|
});
|
|
2144
2156
|
var _iterator16 = _createForOfIteratorHelper(existingOrders),
|
|
2145
2157
|
_step16;
|
|
@@ -2208,7 +2220,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2208
2220
|
key: "patchOrdersInSQLite",
|
|
2209
2221
|
value: (function () {
|
|
2210
2222
|
var _patchOrdersInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(orders, source) {
|
|
2211
|
-
var
|
|
2223
|
+
var _this19 = this;
|
|
2212
2224
|
var mergeActions,
|
|
2213
2225
|
ordersSnapshot,
|
|
2214
2226
|
_this$filterRedundant2,
|
|
@@ -2227,7 +2239,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2227
2239
|
return _context20.abrupt("return");
|
|
2228
2240
|
case 3:
|
|
2229
2241
|
ordersSnapshot = cloneDeep(orders).filter(function (order) {
|
|
2230
|
-
return
|
|
2242
|
+
return _this19.getOrderStorageKey(order);
|
|
2231
2243
|
});
|
|
2232
2244
|
if (!(ordersSnapshot.length === 0)) {
|
|
2233
2245
|
_context20.next = 6;
|
|
@@ -2257,34 +2269,34 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2257
2269
|
while (1) switch (_context19.prev = _context19.next) {
|
|
2258
2270
|
case 0:
|
|
2259
2271
|
writeMethod = 'none';
|
|
2260
|
-
|
|
2272
|
+
_this19.logInfo('patchOrdersInSQLite-开始', {
|
|
2261
2273
|
source: source,
|
|
2262
2274
|
count: compactedToWrite.length,
|
|
2263
2275
|
dedupedCount: skipped.length
|
|
2264
2276
|
});
|
|
2265
|
-
if (!(typeof
|
|
2277
|
+
if (!(typeof _this19.dbManager.bulkUpdate === 'function')) {
|
|
2266
2278
|
_context19.next = 8;
|
|
2267
2279
|
break;
|
|
2268
2280
|
}
|
|
2269
2281
|
writeMethod = 'bulkUpdate';
|
|
2270
2282
|
_context19.next = 6;
|
|
2271
|
-
return
|
|
2283
|
+
return _this19.dbManager.bulkUpdate(INDEXDB_STORE_NAME, compactedToWrite);
|
|
2272
2284
|
case 6:
|
|
2273
2285
|
_context19.next = 33;
|
|
2274
2286
|
break;
|
|
2275
2287
|
case 8:
|
|
2276
|
-
if (!(typeof
|
|
2288
|
+
if (!(typeof _this19.dbManager.bulkAdd === 'function')) {
|
|
2277
2289
|
_context19.next = 14;
|
|
2278
2290
|
break;
|
|
2279
2291
|
}
|
|
2280
2292
|
writeMethod = 'bulkAdd';
|
|
2281
2293
|
_context19.next = 12;
|
|
2282
|
-
return
|
|
2294
|
+
return _this19.dbManager.bulkAdd(INDEXDB_STORE_NAME, compactedToWrite);
|
|
2283
2295
|
case 12:
|
|
2284
2296
|
_context19.next = 33;
|
|
2285
2297
|
break;
|
|
2286
2298
|
case 14:
|
|
2287
|
-
if (!(typeof
|
|
2299
|
+
if (!(typeof _this19.dbManager.update === 'function')) {
|
|
2288
2300
|
_context19.next = 33;
|
|
2289
2301
|
break;
|
|
2290
2302
|
}
|
|
@@ -2299,7 +2311,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2299
2311
|
}
|
|
2300
2312
|
order = _step17.value;
|
|
2301
2313
|
_context19.next = 23;
|
|
2302
|
-
return
|
|
2314
|
+
return _this19.dbManager.update(INDEXDB_STORE_NAME, order);
|
|
2303
2315
|
case 23:
|
|
2304
2316
|
_context19.next = 19;
|
|
2305
2317
|
break;
|
|
@@ -2315,8 +2327,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2315
2327
|
_iterator17.f();
|
|
2316
2328
|
return _context19.finish(30);
|
|
2317
2329
|
case 33:
|
|
2318
|
-
|
|
2319
|
-
|
|
2330
|
+
_this19.recordRecentSqliteWrite(source, compactedToWrite);
|
|
2331
|
+
_this19.logInfo('patchOrdersInSQLite-完成', {
|
|
2320
2332
|
source: source,
|
|
2321
2333
|
count: compactedToWrite.length,
|
|
2322
2334
|
writeMethod: writeMethod,
|
|
@@ -2360,7 +2372,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2360
2372
|
key: "updateOrderInSQLite",
|
|
2361
2373
|
value: (function () {
|
|
2362
2374
|
var _updateOrderInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(order, source) {
|
|
2363
|
-
var
|
|
2375
|
+
var _this20 = this;
|
|
2364
2376
|
var orderSnapshot, _orderSnapshot$order_3;
|
|
2365
2377
|
return _regeneratorRuntime().wrap(function _callee22$(_context22) {
|
|
2366
2378
|
while (1) switch (_context22.prev = _context22.next) {
|
|
@@ -2381,43 +2393,43 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2381
2393
|
while (1) switch (_context21.prev = _context21.next) {
|
|
2382
2394
|
case 0:
|
|
2383
2395
|
writeMethod = 'none';
|
|
2384
|
-
|
|
2396
|
+
_this20.logInfo('updateOrderInSQLite-开始', {
|
|
2385
2397
|
source: source,
|
|
2386
2398
|
orderId: (_orderSnapshot$order_ = orderSnapshot.order_id) !== null && _orderSnapshot$order_ !== void 0 ? _orderSnapshot$order_ : null,
|
|
2387
|
-
storageKey:
|
|
2399
|
+
storageKey: _this20.getOrderStorageKey(orderSnapshot)
|
|
2388
2400
|
});
|
|
2389
|
-
if (!(typeof
|
|
2401
|
+
if (!(typeof _this20.dbManager.update === 'function')) {
|
|
2390
2402
|
_context21.next = 8;
|
|
2391
2403
|
break;
|
|
2392
2404
|
}
|
|
2393
2405
|
writeMethod = 'update';
|
|
2394
2406
|
_context21.next = 6;
|
|
2395
|
-
return
|
|
2407
|
+
return _this20.dbManager.update(INDEXDB_STORE_NAME, orderSnapshot);
|
|
2396
2408
|
case 6:
|
|
2397
2409
|
_context21.next = 18;
|
|
2398
2410
|
break;
|
|
2399
2411
|
case 8:
|
|
2400
|
-
if (!(typeof
|
|
2412
|
+
if (!(typeof _this20.dbManager.bulkUpdate === 'function')) {
|
|
2401
2413
|
_context21.next = 14;
|
|
2402
2414
|
break;
|
|
2403
2415
|
}
|
|
2404
2416
|
writeMethod = 'bulkUpdate';
|
|
2405
2417
|
_context21.next = 12;
|
|
2406
|
-
return
|
|
2418
|
+
return _this20.dbManager.bulkUpdate(INDEXDB_STORE_NAME, [orderSnapshot]);
|
|
2407
2419
|
case 12:
|
|
2408
2420
|
_context21.next = 18;
|
|
2409
2421
|
break;
|
|
2410
2422
|
case 14:
|
|
2411
|
-
if (!(typeof
|
|
2423
|
+
if (!(typeof _this20.dbManager.bulkAdd === 'function')) {
|
|
2412
2424
|
_context21.next = 18;
|
|
2413
2425
|
break;
|
|
2414
2426
|
}
|
|
2415
2427
|
writeMethod = 'bulkAdd';
|
|
2416
2428
|
_context21.next = 18;
|
|
2417
|
-
return
|
|
2429
|
+
return _this20.dbManager.bulkAdd(INDEXDB_STORE_NAME, [orderSnapshot]);
|
|
2418
2430
|
case 18:
|
|
2419
|
-
|
|
2420
|
-
|
|
2431
|
+
_this20.recordRecentSqliteWrite(source, [orderSnapshot]);
|
|
2432
|
+
_this20.logInfo('updateOrderInSQLite-完成', {
|
|
2421
2433
|
source: source,
|
|
2422
2434
|
orderId: (_orderSnapshot$order_2 = orderSnapshot.order_id) !== null && _orderSnapshot$order_2 !== void 0 ? _orderSnapshot$order_2 : null,
|
|
2423
2435
|
writeMethod: writeMethod
|
|
@@ -2460,7 +2472,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2460
2472
|
key: "replaceOrdersSnapshotInSQLite",
|
|
2461
2473
|
value: (function () {
|
|
2462
2474
|
var _replaceOrdersSnapshotInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(orderList, source) {
|
|
2463
|
-
var
|
|
2475
|
+
var _this21 = this;
|
|
2464
2476
|
var remoteSnapshot, mergedSnapshot;
|
|
2465
2477
|
return _regeneratorRuntime().wrap(function _callee24$(_context24) {
|
|
2466
2478
|
while (1) switch (_context24.prev = _context24.next) {
|
|
@@ -2470,12 +2482,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2470
2482
|
break;
|
|
2471
2483
|
}
|
|
2472
2484
|
return _context24.abrupt("return", this.compactOrderListByIdentity(orderList.map(function (order) {
|
|
2473
|
-
return
|
|
2485
|
+
return _this21.normalizeRemoteSyncedOrder(order);
|
|
2474
2486
|
}), "".concat(source, ".snapshotNoDb")).list);
|
|
2475
2487
|
case 2:
|
|
2476
2488
|
remoteSnapshot = cloneDeep(orderList);
|
|
2477
2489
|
mergedSnapshot = this.compactOrderListByIdentity(remoteSnapshot.map(function (order) {
|
|
2478
|
-
return
|
|
2490
|
+
return _this21.normalizeRemoteSyncedOrder(order);
|
|
2479
2491
|
}), "".concat(source, ".remoteSnapshot")).list;
|
|
2480
2492
|
_context24.prev = 4;
|
|
2481
2493
|
_context24.next = 7;
|
|
@@ -2484,12 +2496,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2484
2496
|
return _regeneratorRuntime().wrap(function _callee23$(_context23) {
|
|
2485
2497
|
while (1) switch (_context23.prev = _context23.next) {
|
|
2486
2498
|
case 0:
|
|
2487
|
-
if (!(typeof
|
|
2499
|
+
if (!(typeof _this21.dbManager.getAll === 'function')) {
|
|
2488
2500
|
_context23.next = 6;
|
|
2489
2501
|
break;
|
|
2490
2502
|
}
|
|
2491
2503
|
_context23.next = 3;
|
|
2492
|
-
return
|
|
2504
|
+
return _this21.dbManager.getAll(INDEXDB_STORE_NAME);
|
|
2493
2505
|
case 3:
|
|
2494
2506
|
_context23.t0 = _context23.sent;
|
|
2495
2507
|
_context23.next = 7;
|
|
@@ -2498,18 +2510,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2498
2510
|
_context23.t0 = [];
|
|
2499
2511
|
case 7:
|
|
2500
2512
|
existingOrders = _context23.t0;
|
|
2501
|
-
orderListSnapshot =
|
|
2502
|
-
mergedSnapshot =
|
|
2503
|
-
|
|
2513
|
+
orderListSnapshot = _this21.mergeRemoteSnapshotWithPendingOrders(remoteSnapshot, existingOrders || []);
|
|
2514
|
+
mergedSnapshot = _this21.compactOrderListByIdentity(orderListSnapshot, "".concat(source, ".sqliteSnapshot")).list;
|
|
2515
|
+
_this21.logInfo('replaceOrdersSnapshotInSQLite-开始', {
|
|
2504
2516
|
source: source,
|
|
2505
2517
|
count: mergedSnapshot.length,
|
|
2506
2518
|
remoteCount: remoteSnapshot.length,
|
|
2507
2519
|
preservedPendingCount: mergedSnapshot.length - remoteSnapshot.length
|
|
2508
2520
|
});
|
|
2509
2521
|
_context23.next = 13;
|
|
2510
|
-
return
|
|
2522
|
+
return _this21.dbManager.clear(INDEXDB_STORE_NAME);
|
|
2511
2523
|
case 13:
|
|
2512
|
-
|
|
2524
|
+
_this21.logInfo('replaceOrdersSnapshotInSQLite-clear完成', {
|
|
2513
2525
|
count: mergedSnapshot.length
|
|
2514
2526
|
});
|
|
2515
2527
|
if (!(mergedSnapshot.length === 0)) {
|
|
@@ -2519,10 +2531,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2519
2531
|
return _context23.abrupt("return");
|
|
2520
2532
|
case 16:
|
|
2521
2533
|
_context23.next = 18;
|
|
2522
|
-
return
|
|
2534
|
+
return _this21.dbManager.bulkAdd(INDEXDB_STORE_NAME, mergedSnapshot);
|
|
2523
2535
|
case 18:
|
|
2524
|
-
|
|
2525
|
-
|
|
2536
|
+
_this21.recordRecentSqliteWrite(source, mergedSnapshot);
|
|
2537
|
+
_this21.logInfo('replaceOrdersSnapshotInSQLite-bulkAdd完成', {
|
|
2526
2538
|
source: source,
|
|
2527
2539
|
count: mergedSnapshot.length
|
|
2528
2540
|
});
|
|
@@ -2566,7 +2578,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2566
2578
|
key: "clear",
|
|
2567
2579
|
value: (function () {
|
|
2568
2580
|
var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26() {
|
|
2569
|
-
var
|
|
2581
|
+
var _this22 = this;
|
|
2570
2582
|
return _regeneratorRuntime().wrap(function _callee26$(_context26) {
|
|
2571
2583
|
while (1) switch (_context26.prev = _context26.next) {
|
|
2572
2584
|
case 0:
|
|
@@ -2583,7 +2595,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2583
2595
|
while (1) switch (_context25.prev = _context25.next) {
|
|
2584
2596
|
case 0:
|
|
2585
2597
|
_context25.next = 2;
|
|
2586
|
-
return
|
|
2598
|
+
return _this22.dbManager.clear(INDEXDB_STORE_NAME);
|
|
2587
2599
|
case 2:
|
|
2588
2600
|
case "end":
|
|
2589
2601
|
return _context25.stop();
|
package/lib/server/index.js
CHANGED
|
@@ -2382,7 +2382,7 @@ var Server = class {
|
|
|
2382
2382
|
}
|
|
2383
2383
|
return next;
|
|
2384
2384
|
}
|
|
2385
|
-
if (!this.order || typeof this.order.
|
|
2385
|
+
if (!this.order || typeof this.order.getLocalOrderFromMemoryByLookup !== "function") {
|
|
2386
2386
|
if (shouldClearLocalOrderId) {
|
|
2387
2387
|
this.logInfo(`${title}: checkout 本地订单号已清理`, {
|
|
2388
2388
|
original_order_id: data.order_id,
|
|
@@ -2392,7 +2392,7 @@ var Server = class {
|
|
|
2392
2392
|
return next;
|
|
2393
2393
|
}
|
|
2394
2394
|
try {
|
|
2395
|
-
const localOrder =
|
|
2395
|
+
const localOrder = this.order.getLocalOrderFromMemoryByLookup(externalSaleNumber);
|
|
2396
2396
|
if (!localOrder) {
|
|
2397
2397
|
if (shouldClearLocalOrderId) {
|
|
2398
2398
|
this.logInfo(`${title}: checkout 本地订单号已清理`, {
|
|
@@ -79,6 +79,7 @@ export declare class OrderModule extends BaseModule implements Module {
|
|
|
79
79
|
getOrderById(id: OrderId): OrderData | undefined;
|
|
80
80
|
/** 按 order_id 查询内存订单。 */
|
|
81
81
|
getOrderByOrderId(orderId: OrderId): OrderData | undefined;
|
|
82
|
+
getLocalOrderFromMemoryByLookup(lookup: OrderId): OrderData | null;
|
|
82
83
|
getLocalOrderByLookup(lookup: OrderId): Promise<OrderData | null>;
|
|
83
84
|
loadOrdersByServer(): Promise<OrderData[]>;
|
|
84
85
|
/**
|
|
@@ -379,6 +379,14 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
379
379
|
getOrderByOrderId(orderId) {
|
|
380
380
|
return this.store.map.get(this.getIdKey(orderId));
|
|
381
381
|
}
|
|
382
|
+
getLocalOrderFromMemoryByLookup(lookup) {
|
|
383
|
+
const key = this.getIdKey(lookup);
|
|
384
|
+
const memoryOrderById = this.store.map.get(key);
|
|
385
|
+
if (memoryOrderById)
|
|
386
|
+
return memoryOrderById;
|
|
387
|
+
const memoryOrder = this.store.list.find((order) => this.isOrderLookupMatch(order, key));
|
|
388
|
+
return memoryOrder || null;
|
|
389
|
+
}
|
|
382
390
|
async getLocalOrderByLookup(lookup) {
|
|
383
391
|
const key = this.getIdKey(lookup);
|
|
384
392
|
const memoryOrderById = this.store.map.get(key);
|
|
@@ -1721,7 +1721,6 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
1721
1721
|
const params = {
|
|
1722
1722
|
product_id: identity.product_id,
|
|
1723
1723
|
product_variant_id: identity.product_variant_id,
|
|
1724
|
-
// TODO: 改成对象
|
|
1725
1724
|
updates: { note: String(note || "") }
|
|
1726
1725
|
};
|
|
1727
1726
|
if (identity.unique_identification_number !== void 0) {
|