@pisell/pisellos 2.2.248 → 2.2.250

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.
@@ -193,8 +193,10 @@ export declare class OrderModule extends BaseModule implements Module {
193
193
  private findOrderIndexByIdentity;
194
194
  private getOrderCompletenessScore;
195
195
  private pickPreferredOrder;
196
- private getProductMergeKey;
196
+ private getProductIdentityKeys;
197
197
  private mergeOrderProductLists;
198
+ private getPaymentMergeKey;
199
+ private mergeOrderPaymentLists;
198
200
  private mergeOrderRecords;
199
201
  private summarizeDuplicateOrders;
200
202
  private logDuplicateOrders;
@@ -1899,20 +1899,21 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1899
1899
  return left;
1900
1900
  }
1901
1901
  }, {
1902
- key: "getProductMergeKey",
1903
- value: function getProductMergeKey(product) {
1902
+ key: "getProductIdentityKeys",
1903
+ value: function getProductIdentityKeys(product) {
1904
1904
  var _record$metadata;
1905
1905
  var record = product;
1906
- if (!record) return '';
1906
+ if (!record) return [];
1907
+ var keys = [];
1907
1908
  var metadataUid = (_record$metadata = record.metadata) === null || _record$metadata === void 0 ? void 0 : _record$metadata.unique_identification_number;
1908
- if (!this.isBlankIdentityValue(metadataUid)) return "uid:".concat(String(metadataUid));
1909
+ if (!this.isBlankIdentityValue(metadataUid)) keys.push("uid:".concat(String(metadataUid)));
1909
1910
  var topLevelUid = record.unique_identification_number;
1910
- if (!this.isBlankIdentityValue(topLevelUid)) return "uid:".concat(String(topLevelUid));
1911
+ if (!this.isBlankIdentityValue(topLevelUid)) keys.push("uid:".concat(String(topLevelUid)));
1911
1912
  var orderDetailId = record.order_detail_id;
1912
- if (!this.isBlankIdentityValue(orderDetailId)) return "detail:".concat(String(orderDetailId));
1913
+ if (!this.isBlankIdentityValue(orderDetailId)) keys.push("detail:".concat(String(orderDetailId)));
1913
1914
  var bookingUid = record.booking_uid;
1914
- if (!this.isBlankIdentityValue(bookingUid)) return "booking:".concat(String(bookingUid));
1915
- return '';
1915
+ if (!this.isBlankIdentityValue(bookingUid)) keys.push("booking:".concat(String(bookingUid)));
1916
+ return keys;
1916
1917
  }
1917
1918
  }, {
1918
1919
  key: "mergeOrderProductLists",
@@ -1927,8 +1928,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1927
1928
  try {
1928
1929
  for (_iterator13.s(); !(_step13 = _iterator13.n()).done;) {
1929
1930
  var item = _step13.value;
1930
- var key = this.getProductMergeKey(item);
1931
- if (key) seenKeys.add(key);
1931
+ var keys = this.getProductIdentityKeys(item);
1932
+ var _iterator15 = _createForOfIteratorHelper(keys),
1933
+ _step15;
1934
+ try {
1935
+ for (_iterator15.s(); !(_step15 = _iterator15.n()).done;) {
1936
+ var key = _step15.value;
1937
+ seenKeys.add(key);
1938
+ }
1939
+ } catch (err) {
1940
+ _iterator15.e(err);
1941
+ } finally {
1942
+ _iterator15.f();
1943
+ }
1932
1944
  }
1933
1945
  } catch (err) {
1934
1946
  _iterator13.e(err);
@@ -1941,9 +1953,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1941
1953
  try {
1942
1954
  for (_iterator14.s(); !(_step14 = _iterator14.n()).done;) {
1943
1955
  var _item = _step14.value;
1944
- var _key = this.getProductMergeKey(_item);
1945
- if (!_key || seenKeys.has(_key)) continue;
1946
- seenKeys.add(_key);
1956
+ var _keys = this.getProductIdentityKeys(_item);
1957
+ if (_keys.length === 0 || _keys.some(function (key) {
1958
+ return seenKeys.has(key);
1959
+ })) continue;
1960
+ var _iterator16 = _createForOfIteratorHelper(_keys),
1961
+ _step16;
1962
+ try {
1963
+ for (_iterator16.s(); !(_step16 = _iterator16.n()).done;) {
1964
+ var _key = _step16.value;
1965
+ seenKeys.add(_key);
1966
+ }
1967
+ } catch (err) {
1968
+ _iterator16.e(err);
1969
+ } finally {
1970
+ _iterator16.f();
1971
+ }
1947
1972
  result.push(cloneDeep(_item));
1948
1973
  }
1949
1974
  } catch (err) {
@@ -1953,6 +1978,58 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1953
1978
  }
1954
1979
  return result;
1955
1980
  }
1981
+ }, {
1982
+ key: "getPaymentMergeKey",
1983
+ value: function getPaymentMergeKey(payment) {
1984
+ var _record$metadata2;
1985
+ var record = payment;
1986
+ if (!record) return '';
1987
+ var uniquePaymentNumber = (_record$metadata2 = record.metadata) === null || _record$metadata2 === void 0 ? void 0 : _record$metadata2.unique_payment_number;
1988
+ if (!this.isBlankIdentityValue(uniquePaymentNumber)) {
1989
+ return "unique:".concat(String(uniquePaymentNumber));
1990
+ }
1991
+ var orderPaymentId = record.order_payment_id;
1992
+ if (!this.isBlankIdentityValue(orderPaymentId)) return "order_payment:".concat(String(orderPaymentId));
1993
+ var code = record.code;
1994
+ var customPaymentId = record.custom_payment_id;
1995
+ if (!this.isBlankIdentityValue(code) && !this.isBlankIdentityValue(customPaymentId)) {
1996
+ return "custom:".concat(String(code), "#").concat(String(customPaymentId));
1997
+ }
1998
+ return '';
1999
+ }
2000
+ }, {
2001
+ key: "mergeOrderPaymentLists",
2002
+ value: function mergeOrderPaymentLists(existing, incoming) {
2003
+ var _this18 = this;
2004
+ var existingList = Array.isArray(existing) ? existing : [];
2005
+ var incomingList = Array.isArray(incoming) ? incoming : [];
2006
+ if (incomingList.length === 0) return cloneDeep(existingList);
2007
+ if (existingList.length === 0) return cloneDeep(incomingList);
2008
+ var existingByKey = new Map();
2009
+ var _iterator17 = _createForOfIteratorHelper(existingList),
2010
+ _step17;
2011
+ try {
2012
+ for (_iterator17.s(); !(_step17 = _iterator17.n()).done;) {
2013
+ var payment = _step17.value;
2014
+ var key = this.getPaymentMergeKey(payment);
2015
+ if (!key) continue;
2016
+ existingByKey.set(key, payment);
2017
+ }
2018
+ } catch (err) {
2019
+ _iterator17.e(err);
2020
+ } finally {
2021
+ _iterator17.f();
2022
+ }
2023
+ return incomingList.map(function (payment) {
2024
+ var incomingPayment = payment;
2025
+ var key = _this18.getPaymentMergeKey(incomingPayment);
2026
+ var existingPayment = key ? existingByKey.get(key) : undefined;
2027
+ if (!existingPayment) return cloneDeep(incomingPayment);
2028
+ return _objectSpread(_objectSpread(_objectSpread({}, cloneDeep(existingPayment)), cloneDeep(incomingPayment)), {}, {
2029
+ metadata: _objectSpread(_objectSpread({}, cloneDeep(existingPayment.metadata || {})), cloneDeep(incomingPayment.metadata || {}))
2030
+ });
2031
+ });
2032
+ }
1956
2033
  }, {
1957
2034
  key: "mergeOrderRecords",
1958
2035
  value: function mergeOrderRecords(existing, incoming, options) {
@@ -1960,11 +2037,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1960
2037
  var secondary = preferred === existing ? incoming : existing;
1961
2038
  var merged = _objectSpread(_objectSpread({}, secondary), preferred);
1962
2039
  var fieldsToPreserve = ['order_id', 'external_sale_number', 'order_number', 'shop_order_number', 'shop_full_order_number'];
1963
- var incomingPatchFields = ['payment_status', 'status', 'shipping_status', 'updated_at', 'shop_discount', 'summary', 'payments', 'products', 'bookings'];
2040
+ var incomingPatchFields = ['payment_status', 'status', 'shipping_status', 'updated_at', 'shop_discount', 'summary', 'products', 'bookings'];
1964
2041
  var mergedRecord = merged;
1965
2042
  var preferredRecord = preferred;
1966
2043
  var secondaryRecord = secondary;
1967
2044
  var incomingRecord = incoming;
2045
+ var previousRecord = preferred === incoming ? secondaryRecord : preferredRecord;
1968
2046
  for (var _i3 = 0, _fieldsToPreserve = fieldsToPreserve; _i3 < _fieldsToPreserve.length; _i3++) {
1969
2047
  var field = _fieldsToPreserve[_i3];
1970
2048
  if (!this.isBlankIdentityValue(preferredRecord[field])) {
@@ -1985,6 +2063,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1985
2063
  mergedRecord[_field] = cloneDeep(incomingRecord[_field]);
1986
2064
  }
1987
2065
  mergedRecord.products = shouldUseIncomingProductsSnapshot ? cloneDeep(incomingRecord.products) : this.mergeOrderProductLists(preferredRecord.products, secondaryRecord.products);
2066
+ if (Object.prototype.hasOwnProperty.call(incomingRecord, 'payments')) {
2067
+ if (Array.isArray(incomingRecord.payments)) {
2068
+ mergedRecord.payments = this.mergeOrderPaymentLists(previousRecord.payments, incomingRecord.payments);
2069
+ } else if (incomingRecord.payments !== undefined && incomingRecord.payments !== null) {
2070
+ mergedRecord.payments = cloneDeep(incomingRecord.payments);
2071
+ }
2072
+ }
1988
2073
  if (!this.isPendingSyncOrder(preferred) || !this.isPendingSyncOrder(secondary)) {
1989
2074
  merged.need_sync = 0;
1990
2075
  }
@@ -1994,30 +2079,30 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1994
2079
  key: "summarizeDuplicateOrders",
1995
2080
  value: function summarizeDuplicateOrders(orders) {
1996
2081
  var groups = new Map();
1997
- var _iterator15 = _createForOfIteratorHelper(orders),
1998
- _step15;
2082
+ var _iterator18 = _createForOfIteratorHelper(orders),
2083
+ _step18;
1999
2084
  try {
2000
- for (_iterator15.s(); !(_step15 = _iterator15.n()).done;) {
2001
- var order = _step15.value;
2002
- var _iterator16 = _createForOfIteratorHelper(this.getOrderIdentityMatchKeys(order)),
2003
- _step16;
2085
+ for (_iterator18.s(); !(_step18 = _iterator18.n()).done;) {
2086
+ var order = _step18.value;
2087
+ var _iterator19 = _createForOfIteratorHelper(this.getOrderIdentityMatchKeys(order)),
2088
+ _step19;
2004
2089
  try {
2005
- for (_iterator16.s(); !(_step16 = _iterator16.n()).done;) {
2006
- var key = _step16.value;
2090
+ for (_iterator19.s(); !(_step19 = _iterator19.n()).done;) {
2091
+ var key = _step19.value;
2007
2092
  var group = groups.get(key) || [];
2008
2093
  group.push(order);
2009
2094
  groups.set(key, group);
2010
2095
  }
2011
2096
  } catch (err) {
2012
- _iterator16.e(err);
2097
+ _iterator19.e(err);
2013
2098
  } finally {
2014
- _iterator16.f();
2099
+ _iterator19.f();
2015
2100
  }
2016
2101
  }
2017
2102
  } catch (err) {
2018
- _iterator15.e(err);
2103
+ _iterator18.e(err);
2019
2104
  } finally {
2020
- _iterator15.f();
2105
+ _iterator18.f();
2021
2106
  }
2022
2107
  return _toConsumableArray(groups.entries()).filter(function (_ref2) {
2023
2108
  var _ref3 = _slicedToArray(_ref2, 2),
@@ -2059,11 +2144,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2059
2144
  value: function compactOrderListByIdentity(orders, source) {
2060
2145
  var list = [];
2061
2146
  var removedCount = 0;
2062
- var _iterator17 = _createForOfIteratorHelper(orders),
2063
- _step17;
2147
+ var _iterator20 = _createForOfIteratorHelper(orders),
2148
+ _step20;
2064
2149
  try {
2065
- for (_iterator17.s(); !(_step17 = _iterator17.n()).done;) {
2066
- var order = _step17.value;
2150
+ for (_iterator20.s(); !(_step20 = _iterator20.n()).done;) {
2151
+ var order = _step20.value;
2067
2152
  var matchIndex = this.findOrderIndexByIdentity(list, order);
2068
2153
  if (matchIndex < 0) {
2069
2154
  list.push(order);
@@ -2073,9 +2158,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2073
2158
  removedCount += 1;
2074
2159
  }
2075
2160
  } catch (err) {
2076
- _iterator17.e(err);
2161
+ _iterator20.e(err);
2077
2162
  } finally {
2078
- _iterator17.f();
2163
+ _iterator20.f();
2079
2164
  }
2080
2165
  if (removedCount > 0) {
2081
2166
  this.logWarning('订单列表重复项已压缩', {
@@ -2221,15 +2306,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2221
2306
  }, {
2222
2307
  key: "mergeRemoteSnapshotWithPendingOrders",
2223
2308
  value: function mergeRemoteSnapshotWithPendingOrders(remoteOrders, existingOrders) {
2224
- var _this18 = this;
2309
+ var _this19 = this;
2225
2310
  var merged = remoteOrders.map(function (order) {
2226
- return _this18.normalizeRemoteSyncedOrder(order);
2311
+ return _this19.normalizeRemoteSyncedOrder(order);
2227
2312
  });
2228
- var _iterator18 = _createForOfIteratorHelper(existingOrders),
2229
- _step18;
2313
+ var _iterator21 = _createForOfIteratorHelper(existingOrders),
2314
+ _step21;
2230
2315
  try {
2231
- for (_iterator18.s(); !(_step18 = _iterator18.n()).done;) {
2232
- var order = _step18.value;
2316
+ for (_iterator21.s(); !(_step21 = _iterator21.n()).done;) {
2317
+ var order = _step21.value;
2233
2318
  if (!this.isPendingSyncOrder(order)) continue;
2234
2319
  var matchIndex = this.findOrderIndexByIdentity(merged, order);
2235
2320
  if (matchIndex >= 0) {
@@ -2240,9 +2325,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2240
2325
  merged.push(order);
2241
2326
  }
2242
2327
  } catch (err) {
2243
- _iterator18.e(err);
2328
+ _iterator21.e(err);
2244
2329
  } finally {
2245
- _iterator18.f();
2330
+ _iterator21.f();
2246
2331
  }
2247
2332
  return this.compactOrderListByIdentity(merged, 'mergeRemoteSnapshotWithPendingOrders').list;
2248
2333
  }
@@ -2292,7 +2377,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2292
2377
  key: "patchOrdersInSQLite",
2293
2378
  value: (function () {
2294
2379
  var _patchOrdersInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(orders, source) {
2295
- var _this19 = this;
2380
+ var _this20 = this;
2296
2381
  var mergeActions,
2297
2382
  ordersSnapshot,
2298
2383
  _this$filterRedundant2,
@@ -2311,7 +2396,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2311
2396
  return _context20.abrupt("return");
2312
2397
  case 3:
2313
2398
  ordersSnapshot = cloneDeep(orders).filter(function (order) {
2314
- return _this19.getOrderStorageKey(order);
2399
+ return _this20.getOrderStorageKey(order);
2315
2400
  });
2316
2401
  if (!(ordersSnapshot.length === 0)) {
2317
2402
  _context20.next = 6;
@@ -2336,54 +2421,54 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2336
2421
  _context20.prev = 12;
2337
2422
  _context20.next = 15;
2338
2423
  return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19() {
2339
- var writeMethod, _iterator19, _step19, order;
2424
+ var writeMethod, _iterator22, _step22, order;
2340
2425
  return _regeneratorRuntime().wrap(function _callee19$(_context19) {
2341
2426
  while (1) switch (_context19.prev = _context19.next) {
2342
2427
  case 0:
2343
2428
  writeMethod = 'none';
2344
- _this19.logInfo('patchOrdersInSQLite-开始', {
2429
+ _this20.logInfo('patchOrdersInSQLite-开始', {
2345
2430
  source: source,
2346
2431
  count: compactedToWrite.length,
2347
2432
  dedupedCount: skipped.length
2348
2433
  });
2349
- if (!(typeof _this19.dbManager.bulkUpdate === 'function')) {
2434
+ if (!(typeof _this20.dbManager.bulkUpdate === 'function')) {
2350
2435
  _context19.next = 8;
2351
2436
  break;
2352
2437
  }
2353
2438
  writeMethod = 'bulkUpdate';
2354
2439
  _context19.next = 6;
2355
- return _this19.dbManager.bulkUpdate(INDEXDB_STORE_NAME, compactedToWrite);
2440
+ return _this20.dbManager.bulkUpdate(INDEXDB_STORE_NAME, compactedToWrite);
2356
2441
  case 6:
2357
2442
  _context19.next = 33;
2358
2443
  break;
2359
2444
  case 8:
2360
- if (!(typeof _this19.dbManager.bulkAdd === 'function')) {
2445
+ if (!(typeof _this20.dbManager.bulkAdd === 'function')) {
2361
2446
  _context19.next = 14;
2362
2447
  break;
2363
2448
  }
2364
2449
  writeMethod = 'bulkAdd';
2365
2450
  _context19.next = 12;
2366
- return _this19.dbManager.bulkAdd(INDEXDB_STORE_NAME, compactedToWrite);
2451
+ return _this20.dbManager.bulkAdd(INDEXDB_STORE_NAME, compactedToWrite);
2367
2452
  case 12:
2368
2453
  _context19.next = 33;
2369
2454
  break;
2370
2455
  case 14:
2371
- if (!(typeof _this19.dbManager.update === 'function')) {
2456
+ if (!(typeof _this20.dbManager.update === 'function')) {
2372
2457
  _context19.next = 33;
2373
2458
  break;
2374
2459
  }
2375
2460
  writeMethod = 'update';
2376
- _iterator19 = _createForOfIteratorHelper(compactedToWrite);
2461
+ _iterator22 = _createForOfIteratorHelper(compactedToWrite);
2377
2462
  _context19.prev = 17;
2378
- _iterator19.s();
2463
+ _iterator22.s();
2379
2464
  case 19:
2380
- if ((_step19 = _iterator19.n()).done) {
2465
+ if ((_step22 = _iterator22.n()).done) {
2381
2466
  _context19.next = 25;
2382
2467
  break;
2383
2468
  }
2384
- order = _step19.value;
2469
+ order = _step22.value;
2385
2470
  _context19.next = 23;
2386
- return _this19.dbManager.update(INDEXDB_STORE_NAME, order);
2471
+ return _this20.dbManager.update(INDEXDB_STORE_NAME, order);
2387
2472
  case 23:
2388
2473
  _context19.next = 19;
2389
2474
  break;
@@ -2393,14 +2478,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2393
2478
  case 27:
2394
2479
  _context19.prev = 27;
2395
2480
  _context19.t0 = _context19["catch"](17);
2396
- _iterator19.e(_context19.t0);
2481
+ _iterator22.e(_context19.t0);
2397
2482
  case 30:
2398
2483
  _context19.prev = 30;
2399
- _iterator19.f();
2484
+ _iterator22.f();
2400
2485
  return _context19.finish(30);
2401
2486
  case 33:
2402
- _this19.recordRecentSqliteWrite(source, compactedToWrite);
2403
- _this19.logInfo('patchOrdersInSQLite-完成', {
2487
+ _this20.recordRecentSqliteWrite(source, compactedToWrite);
2488
+ _this20.logInfo('patchOrdersInSQLite-完成', {
2404
2489
  source: source,
2405
2490
  count: compactedToWrite.length,
2406
2491
  writeMethod: writeMethod,
@@ -2444,7 +2529,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2444
2529
  key: "updateOrderInSQLite",
2445
2530
  value: (function () {
2446
2531
  var _updateOrderInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(order, source) {
2447
- var _this20 = this;
2532
+ var _this21 = this;
2448
2533
  var orderSnapshot, _orderSnapshot$order_3;
2449
2534
  return _regeneratorRuntime().wrap(function _callee22$(_context22) {
2450
2535
  while (1) switch (_context22.prev = _context22.next) {
@@ -2465,43 +2550,43 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2465
2550
  while (1) switch (_context21.prev = _context21.next) {
2466
2551
  case 0:
2467
2552
  writeMethod = 'none';
2468
- _this20.logInfo('updateOrderInSQLite-开始', {
2553
+ _this21.logInfo('updateOrderInSQLite-开始', {
2469
2554
  source: source,
2470
2555
  orderId: (_orderSnapshot$order_ = orderSnapshot.order_id) !== null && _orderSnapshot$order_ !== void 0 ? _orderSnapshot$order_ : null,
2471
- storageKey: _this20.getOrderStorageKey(orderSnapshot)
2556
+ storageKey: _this21.getOrderStorageKey(orderSnapshot)
2472
2557
  });
2473
- if (!(typeof _this20.dbManager.update === 'function')) {
2558
+ if (!(typeof _this21.dbManager.update === 'function')) {
2474
2559
  _context21.next = 8;
2475
2560
  break;
2476
2561
  }
2477
2562
  writeMethod = 'update';
2478
2563
  _context21.next = 6;
2479
- return _this20.dbManager.update(INDEXDB_STORE_NAME, orderSnapshot);
2564
+ return _this21.dbManager.update(INDEXDB_STORE_NAME, orderSnapshot);
2480
2565
  case 6:
2481
2566
  _context21.next = 18;
2482
2567
  break;
2483
2568
  case 8:
2484
- if (!(typeof _this20.dbManager.bulkUpdate === 'function')) {
2569
+ if (!(typeof _this21.dbManager.bulkUpdate === 'function')) {
2485
2570
  _context21.next = 14;
2486
2571
  break;
2487
2572
  }
2488
2573
  writeMethod = 'bulkUpdate';
2489
2574
  _context21.next = 12;
2490
- return _this20.dbManager.bulkUpdate(INDEXDB_STORE_NAME, [orderSnapshot]);
2575
+ return _this21.dbManager.bulkUpdate(INDEXDB_STORE_NAME, [orderSnapshot]);
2491
2576
  case 12:
2492
2577
  _context21.next = 18;
2493
2578
  break;
2494
2579
  case 14:
2495
- if (!(typeof _this20.dbManager.bulkAdd === 'function')) {
2580
+ if (!(typeof _this21.dbManager.bulkAdd === 'function')) {
2496
2581
  _context21.next = 18;
2497
2582
  break;
2498
2583
  }
2499
2584
  writeMethod = 'bulkAdd';
2500
2585
  _context21.next = 18;
2501
- return _this20.dbManager.bulkAdd(INDEXDB_STORE_NAME, [orderSnapshot]);
2586
+ return _this21.dbManager.bulkAdd(INDEXDB_STORE_NAME, [orderSnapshot]);
2502
2587
  case 18:
2503
- _this20.recordRecentSqliteWrite(source, [orderSnapshot]);
2504
- _this20.logInfo('updateOrderInSQLite-完成', {
2588
+ _this21.recordRecentSqliteWrite(source, [orderSnapshot]);
2589
+ _this21.logInfo('updateOrderInSQLite-完成', {
2505
2590
  source: source,
2506
2591
  orderId: (_orderSnapshot$order_2 = orderSnapshot.order_id) !== null && _orderSnapshot$order_2 !== void 0 ? _orderSnapshot$order_2 : null,
2507
2592
  writeMethod: writeMethod
@@ -2544,7 +2629,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2544
2629
  key: "replaceOrdersSnapshotInSQLite",
2545
2630
  value: (function () {
2546
2631
  var _replaceOrdersSnapshotInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(orderList, source) {
2547
- var _this21 = this;
2632
+ var _this22 = this;
2548
2633
  var remoteSnapshot, mergedSnapshot;
2549
2634
  return _regeneratorRuntime().wrap(function _callee24$(_context24) {
2550
2635
  while (1) switch (_context24.prev = _context24.next) {
@@ -2554,12 +2639,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2554
2639
  break;
2555
2640
  }
2556
2641
  return _context24.abrupt("return", this.compactOrderListByIdentity(orderList.map(function (order) {
2557
- return _this21.normalizeRemoteSyncedOrder(order);
2642
+ return _this22.normalizeRemoteSyncedOrder(order);
2558
2643
  }), "".concat(source, ".snapshotNoDb")).list);
2559
2644
  case 2:
2560
2645
  remoteSnapshot = cloneDeep(orderList);
2561
2646
  mergedSnapshot = this.compactOrderListByIdentity(remoteSnapshot.map(function (order) {
2562
- return _this21.normalizeRemoteSyncedOrder(order);
2647
+ return _this22.normalizeRemoteSyncedOrder(order);
2563
2648
  }), "".concat(source, ".remoteSnapshot")).list;
2564
2649
  _context24.prev = 4;
2565
2650
  _context24.next = 7;
@@ -2568,12 +2653,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2568
2653
  return _regeneratorRuntime().wrap(function _callee23$(_context23) {
2569
2654
  while (1) switch (_context23.prev = _context23.next) {
2570
2655
  case 0:
2571
- if (!(typeof _this21.dbManager.getAll === 'function')) {
2656
+ if (!(typeof _this22.dbManager.getAll === 'function')) {
2572
2657
  _context23.next = 6;
2573
2658
  break;
2574
2659
  }
2575
2660
  _context23.next = 3;
2576
- return _this21.dbManager.getAll(INDEXDB_STORE_NAME);
2661
+ return _this22.dbManager.getAll(INDEXDB_STORE_NAME);
2577
2662
  case 3:
2578
2663
  _context23.t0 = _context23.sent;
2579
2664
  _context23.next = 7;
@@ -2582,18 +2667,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2582
2667
  _context23.t0 = [];
2583
2668
  case 7:
2584
2669
  existingOrders = _context23.t0;
2585
- orderListSnapshot = _this21.mergeRemoteSnapshotWithPendingOrders(remoteSnapshot, existingOrders || []);
2586
- mergedSnapshot = _this21.compactOrderListByIdentity(orderListSnapshot, "".concat(source, ".sqliteSnapshot")).list;
2587
- _this21.logInfo('replaceOrdersSnapshotInSQLite-开始', {
2670
+ orderListSnapshot = _this22.mergeRemoteSnapshotWithPendingOrders(remoteSnapshot, existingOrders || []);
2671
+ mergedSnapshot = _this22.compactOrderListByIdentity(orderListSnapshot, "".concat(source, ".sqliteSnapshot")).list;
2672
+ _this22.logInfo('replaceOrdersSnapshotInSQLite-开始', {
2588
2673
  source: source,
2589
2674
  count: mergedSnapshot.length,
2590
2675
  remoteCount: remoteSnapshot.length,
2591
2676
  preservedPendingCount: mergedSnapshot.length - remoteSnapshot.length
2592
2677
  });
2593
2678
  _context23.next = 13;
2594
- return _this21.dbManager.clear(INDEXDB_STORE_NAME);
2679
+ return _this22.dbManager.clear(INDEXDB_STORE_NAME);
2595
2680
  case 13:
2596
- _this21.logInfo('replaceOrdersSnapshotInSQLite-clear完成', {
2681
+ _this22.logInfo('replaceOrdersSnapshotInSQLite-clear完成', {
2597
2682
  count: mergedSnapshot.length
2598
2683
  });
2599
2684
  if (!(mergedSnapshot.length === 0)) {
@@ -2603,10 +2688,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2603
2688
  return _context23.abrupt("return");
2604
2689
  case 16:
2605
2690
  _context23.next = 18;
2606
- return _this21.dbManager.bulkAdd(INDEXDB_STORE_NAME, mergedSnapshot);
2691
+ return _this22.dbManager.bulkAdd(INDEXDB_STORE_NAME, mergedSnapshot);
2607
2692
  case 18:
2608
- _this21.recordRecentSqliteWrite(source, mergedSnapshot);
2609
- _this21.logInfo('replaceOrdersSnapshotInSQLite-bulkAdd完成', {
2693
+ _this22.recordRecentSqliteWrite(source, mergedSnapshot);
2694
+ _this22.logInfo('replaceOrdersSnapshotInSQLite-bulkAdd完成', {
2610
2695
  source: source,
2611
2696
  count: mergedSnapshot.length
2612
2697
  });
@@ -2650,7 +2735,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2650
2735
  key: "clear",
2651
2736
  value: (function () {
2652
2737
  var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26() {
2653
- var _this22 = this;
2738
+ var _this23 = this;
2654
2739
  return _regeneratorRuntime().wrap(function _callee26$(_context26) {
2655
2740
  while (1) switch (_context26.prev = _context26.next) {
2656
2741
  case 0:
@@ -2667,7 +2752,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2667
2752
  while (1) switch (_context25.prev = _context25.next) {
2668
2753
  case 0:
2669
2754
  _context25.next = 2;
2670
- return _this22.dbManager.clear(INDEXDB_STORE_NAME);
2755
+ return _this23.dbManager.clear(INDEXDB_STORE_NAME);
2671
2756
  case 2:
2672
2757
  case "end":
2673
2758
  return _context25.stop();
@@ -2247,6 +2247,8 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2247
2247
  var _this$otherParams20,
2248
2248
  _paymentRecord$paymen,
2249
2249
  _paymentRecord$create,
2250
+ _ref13,
2251
+ _paymentRecord$origin,
2250
2252
  _this7 = this;
2251
2253
  if (!this.store.order) throw new Error('order 模块未初始化');
2252
2254
  var paymentRecord = payment;
@@ -2268,7 +2270,11 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2268
2270
  var paymentTimestamp = dayjs().format('YYYY-MM-DD HH:mm:ss');
2269
2271
  var paymentTime = (_paymentRecord$paymen = paymentRecord.payment_time) !== null && _paymentRecord$paymen !== void 0 ? _paymentRecord$paymen : paymentTimestamp;
2270
2272
  var createdAt = (_paymentRecord$create = paymentRecord.created_at) !== null && _paymentRecord$create !== void 0 ? _paymentRecord$create : paymentTimestamp;
2271
- var payments = this.store.order.addOrderPayment(_objectSpread(_objectSpread({}, paymentRecord), {}, {
2273
+ var serviceCharge = paymentRecord.service_charge && _typeof(paymentRecord.service_charge) === 'object' ? paymentRecord.service_charge : null;
2274
+ var calculatedServiceFee = serviceCharge ? new Decimal((_ref13 = (_paymentRecord$origin = paymentRecord.origin_amount) !== null && _paymentRecord$origin !== void 0 ? _paymentRecord$origin : paymentRecord.amount) !== null && _ref13 !== void 0 ? _ref13 : 0).times(serviceCharge.percentage || 0).plus(serviceCharge.amount || 0).toDecimalPlaces(2).toFixed(2) : undefined;
2275
+ var payments = this.store.order.addOrderPayment(_objectSpread(_objectSpread(_objectSpread({}, paymentRecord), calculatedServiceFee !== undefined ? {
2276
+ service_fee: calculatedServiceFee
2277
+ } : {}), {}, {
2272
2278
  metadata: metadata,
2273
2279
  payment_time: paymentTime,
2274
2280
  created_at: createdAt
@@ -2376,7 +2382,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2376
2382
  key: "initWalletData",
2377
2383
  value: function () {
2378
2384
  var _initWalletData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(params) {
2379
- var _params$order_wait_pa, _ref13, _tempOrder$is_price_i;
2385
+ var _params$order_wait_pa, _ref14, _tempOrder$is_price_i;
2380
2386
  var snapshot, tempOrder, amount, walletBusinessData, result;
2381
2387
  return _regeneratorRuntime().wrap(function _callee24$(_context24) {
2382
2388
  while (1) switch (_context24.prev = _context24.next) {
@@ -2419,7 +2425,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2419
2425
  },
2420
2426
  products: this.getWalletProductList(),
2421
2427
  order_wait_pay_amount: (_params$order_wait_pa = params === null || params === void 0 ? void 0 : params.order_wait_pay_amount) !== null && _params$order_wait_pa !== void 0 ? _params$order_wait_pa : Number(amount.amountGap || 0),
2422
- is_price_include_tax: (_ref13 = (_tempOrder$is_price_i = tempOrder.is_price_include_tax) !== null && _tempOrder$is_price_i !== void 0 ? _tempOrder$is_price_i : this.otherParams.is_price_include_tax) !== null && _ref13 !== void 0 ? _ref13 : 1
2428
+ is_price_include_tax: (_ref14 = (_tempOrder$is_price_i = tempOrder.is_price_include_tax) !== null && _tempOrder$is_price_i !== void 0 ? _tempOrder$is_price_i : this.otherParams.is_price_include_tax) !== null && _ref14 !== void 0 ? _ref14 : 1
2423
2429
  }, snapshot.identity.orderId ? {
2424
2430
  payment_order_id: String(snapshot.identity.orderId)
2425
2431
  } : {});
@@ -2550,7 +2556,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2550
2556
  key: "sendCustomerPayLink",
2551
2557
  value: (function () {
2552
2558
  var _sendCustomerPayLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(params) {
2553
- var orderIds, _ref14, _ref15, _submitResult$data$or, _submitResult$data, _submitResult$data2, submitResult, orderId;
2559
+ var orderIds, _ref15, _ref16, _submitResult$data$or, _submitResult$data, _submitResult$data2, submitResult, orderId;
2554
2560
  return _regeneratorRuntime().wrap(function _callee26$(_context26) {
2555
2561
  while (1) switch (_context26.prev = _context26.next) {
2556
2562
  case 0:
@@ -2571,7 +2577,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2571
2577
  });
2572
2578
  case 6:
2573
2579
  submitResult = _context26.sent;
2574
- orderId = (_ref14 = (_ref15 = (_submitResult$data$or = submitResult === null || submitResult === void 0 || (_submitResult$data = submitResult.data) === null || _submitResult$data === void 0 ? void 0 : _submitResult$data.order_id) !== null && _submitResult$data$or !== void 0 ? _submitResult$data$or : submitResult === null || submitResult === void 0 ? void 0 : submitResult.order_id) !== null && _ref15 !== void 0 ? _ref15 : submitResult === null || submitResult === void 0 || (_submitResult$data2 = submitResult.data) === null || _submitResult$data2 === void 0 ? void 0 : _submitResult$data2.id) !== null && _ref14 !== void 0 ? _ref14 : submitResult === null || submitResult === void 0 ? void 0 : submitResult.id;
2580
+ orderId = (_ref15 = (_ref16 = (_submitResult$data$or = submitResult === null || submitResult === void 0 || (_submitResult$data = submitResult.data) === null || _submitResult$data === void 0 ? void 0 : _submitResult$data.order_id) !== null && _submitResult$data$or !== void 0 ? _submitResult$data$or : submitResult === null || submitResult === void 0 ? void 0 : submitResult.order_id) !== null && _ref16 !== void 0 ? _ref16 : submitResult === null || submitResult === void 0 || (_submitResult$data2 = submitResult.data) === null || _submitResult$data2 === void 0 ? void 0 : _submitResult$data2.id) !== null && _ref15 !== void 0 ? _ref15 : submitResult === null || submitResult === void 0 ? void 0 : submitResult.id;
2575
2581
  if (orderId) {
2576
2582
  _context26.next = 10;
2577
2583
  break;
@@ -2997,14 +3003,14 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
2997
3003
  value: function () {
2998
3004
  var _setOtherParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36(params) {
2999
3005
  var _this$otherParams22;
3000
- var _ref16,
3001
- _ref16$cover,
3006
+ var _ref17,
3007
+ _ref17$cover,
3002
3008
  cover,
3003
3009
  _args36 = arguments;
3004
3010
  return _regeneratorRuntime().wrap(function _callee36$(_context36) {
3005
3011
  while (1) switch (_context36.prev = _context36.next) {
3006
3012
  case 0:
3007
- _ref16 = _args36.length > 1 && _args36[1] !== undefined ? _args36[1] : {}, _ref16$cover = _ref16.cover, cover = _ref16$cover === void 0 ? false : _ref16$cover;
3013
+ _ref17 = _args36.length > 1 && _args36[1] !== undefined ? _args36[1] : {}, _ref17$cover = _ref17.cover, cover = _ref17$cover === void 0 ? false : _ref17$cover;
3008
3014
  if (cover) {
3009
3015
  this.otherParams = _objectSpread({}, params);
3010
3016
  } else {
@@ -173,6 +173,10 @@ export function transformBaseProductToOrderProduct(params) {
173
173
  if (uniqueIdentificationNumber) {
174
174
  metadata.unique_identification_number = String(uniqueIdentificationNumber);
175
175
  }
176
+ // 从源头补充商品多语言标题
177
+ var productTitle = _objectSpread(_objectSpread({}, (sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.title_i18n) || {}), {}, {
178
+ original: (sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.title) || ''
179
+ });
176
180
  return {
177
181
  product_id: productId,
178
182
  product_variant_id: productVariantId,
@@ -190,6 +194,7 @@ export function transformBaseProductToOrderProduct(params) {
190
194
  is_charge_tax: toNumber((_ref32 = (_ref33 = (_payload$is_charge_ta = payload.is_charge_tax) !== null && _payload$is_charge_ta !== void 0 ? _payload$is_charge_ta : matchedVariant === null || matchedVariant === void 0 ? void 0 : matchedVariant.is_charge_tax) !== null && _ref33 !== void 0 ? _ref33 : origin === null || origin === void 0 ? void 0 : origin.is_charge_tax) !== null && _ref32 !== void 0 ? _ref32 : sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.is_charge_tax, 0),
191
195
  metadata: metadata,
192
196
  note: payload.note != null ? String(payload.note) : '',
197
+ product_title: productTitle,
193
198
  _origin: _objectSpread(_objectSpread({}, sourceProduct || {}), {}, {
194
199
  callbackData: payload
195
200
  })