@pisell/pisellos 2.2.215 → 2.2.217

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.
@@ -181,6 +181,18 @@ var OrderModule = class extends import_BaseModule.BaseModule {
181
181
  } catch {
182
182
  }
183
183
  }
184
+ logWarning(title, metadata) {
185
+ try {
186
+ if (this.logger) {
187
+ this.logger.addLog({
188
+ type: "warning",
189
+ title: `[OrderServerModule] ${title}`,
190
+ metadata: metadata || {}
191
+ });
192
+ }
193
+ } catch {
194
+ }
195
+ }
184
196
  /**
185
197
  * 记录订单最近一次 SQLite 写入,供 pubsub 回声去重使用。
186
198
  *
@@ -586,33 +598,28 @@ var OrderModule = class extends import_BaseModule.BaseModule {
586
598
  this.logInfo("upsertPendingSyncOrders-开始", { count: pendingMap.size });
587
599
  const patchedOrders = [...pendingMap.values()];
588
600
  const mergeActions = {};
589
- const updatedList = this.store.list.map((order) => {
590
- const storageKey = this.getOrderStorageKey(order);
591
- if (!storageKey || !pendingMap.has(storageKey))
592
- return order;
593
- const pendingOrder = memoryPendingMap.get(storageKey);
601
+ const updatedList = [...this.store.list];
602
+ for (const [storageKey, pendingOrder] of memoryPendingMap.entries()) {
603
+ const matchIndex = this.findOrderIndexByIdentity(updatedList, pendingOrder);
604
+ if (matchIndex < 0)
605
+ continue;
606
+ updatedList[matchIndex] = this.mergeOrderRecords(updatedList[matchIndex], pendingOrder);
594
607
  pendingMap.delete(storageKey);
595
608
  memoryPendingMap.delete(storageKey);
596
609
  mergeActions[storageKey] = "update";
597
- return pendingOrder;
598
- });
610
+ }
599
611
  for (const [storageKey, order] of memoryPendingMap.entries()) {
600
612
  mergeActions[storageKey] = "insert";
601
613
  updatedList.push(order);
602
614
  }
603
- this.store.list = updatedList;
615
+ this.store.list = this.compactOrderListByIdentity(updatedList, "upsertPendingSyncOrders.store").list;
604
616
  this.syncOrdersMap();
605
617
  await this.patchOrdersInSQLite(patchedOrders, "upsertPendingSyncOrders", mergeActions);
606
618
  this.logInfo("upsertPendingSyncOrders-结束", {
607
619
  count: patchedOrders.length,
608
620
  storeOrderCountAfter: this.store.list.length
609
621
  });
610
- this.emitOrdersChanged(patchedOrders, "upsertPendingSyncOrders");
611
- await this.core.effects.emit(import_types.OrderHooks.onOrdersChanged, {
612
- list: this.store.list,
613
- changedOrders: patchedOrders.map((order) => this.normalizeOrderForMemoryList(order)),
614
- source: "upsertPendingSyncOrders"
615
- });
622
+ await this.emitOrdersChanged(patchedOrders, "upsertPendingSyncOrders");
616
623
  }
617
624
  /**
618
625
  * 通过 SSE 按自定义 query 拉取订单(支持 select/with 精简字段)
@@ -649,14 +656,11 @@ var OrderModule = class extends import_BaseModule.BaseModule {
649
656
  this.store.map.clear();
650
657
  this.resourceIdIndex.clear();
651
658
  for (const order of this.store.list) {
652
- const identityKeys = this.getOrderIdentityKeys(order);
653
- if (identityKeys.length === 0)
659
+ const primaryIdentity = this.getOrderMapKey(order);
660
+ if (!primaryIdentity)
654
661
  continue;
655
- for (const identityKey of identityKeys) {
656
- this.store.map.set(identityKey, order);
657
- }
662
+ this.store.map.set(primaryIdentity, order);
658
663
  const resourceIds = this.extractResourceIds(order);
659
- const primaryIdentity = identityKeys[0];
660
664
  for (const resourceId of resourceIds) {
661
665
  const key = String(resourceId);
662
666
  const existing = this.resourceIdIndex.get(key) || [];
@@ -667,17 +671,48 @@ var OrderModule = class extends import_BaseModule.BaseModule {
667
671
  }
668
672
  }
669
673
  }
674
+ getOrderMapKey(order) {
675
+ if (!order)
676
+ return "";
677
+ if (!this.isBlankIdentityValue(order.order_id)) {
678
+ return this.getIdKey(order.order_id);
679
+ }
680
+ const externalSaleNumber = order.external_sale_number;
681
+ if (!this.isBlankIdentityValue(externalSaleNumber)) {
682
+ return this.getIdKey(externalSaleNumber);
683
+ }
684
+ return "";
685
+ }
686
+ isBlankIdentityValue(value) {
687
+ return value === void 0 || value === null || value === "";
688
+ }
689
+ getOrderIdentityEntries(order) {
690
+ if (!order)
691
+ return [];
692
+ const record = order;
693
+ const candidates = [
694
+ { field: "order_id", value: order.order_id },
695
+ { field: "external_sale_number", value: record.external_sale_number },
696
+ { field: "order_number", value: record.order_number },
697
+ { field: "shop_order_number", value: record.shop_order_number },
698
+ { field: "shop_full_order_number", value: record.shop_full_order_number }
699
+ ];
700
+ const entries = [];
701
+ for (const candidate of candidates) {
702
+ if (this.isBlankIdentityValue(candidate.value))
703
+ continue;
704
+ const key = this.getIdKey(candidate.value);
705
+ if (entries.some((entry) => entry.field === candidate.field && entry.key === key))
706
+ continue;
707
+ entries.push({ field: candidate.field, key });
708
+ }
709
+ return entries;
710
+ }
670
711
  getOrderIdentityKeys(order) {
671
712
  const keys = [];
672
- const id = order.order_id;
673
- if (id !== void 0 && id !== null && id !== "") {
674
- keys.push(this.getIdKey(id));
675
- }
676
- const externalSaleNumber = order == null ? void 0 : order.external_sale_number;
677
- if (externalSaleNumber !== void 0 && externalSaleNumber !== null && externalSaleNumber !== "") {
678
- const externalKey = this.getIdKey(externalSaleNumber);
679
- if (!keys.includes(externalKey))
680
- keys.push(externalKey);
713
+ for (const entry of this.getOrderIdentityEntries(order)) {
714
+ if (!keys.includes(entry.key))
715
+ keys.push(entry.key);
681
716
  }
682
717
  return keys;
683
718
  }
@@ -920,65 +955,51 @@ var OrderModule = class extends import_BaseModule.BaseModule {
920
955
  freshOrderCount: freshOrders.length,
921
956
  storeOrderCountBefore: this.store.list.length
922
957
  });
923
- const freshMap = /* @__PURE__ */ new Map();
958
+ this.logDuplicateOrders(`${source}.beforeMerge`, this.store.list);
959
+ const normalizedFreshOrders = [];
924
960
  for (const order of freshOrders) {
925
961
  const id = order == null ? void 0 : order.order_id;
926
962
  if (id === void 0 || id === null)
927
963
  continue;
928
- freshMap.set(this.getIdKey(id), this.normalizeRemoteSyncedOrder(order));
964
+ normalizedFreshOrders.push(this.normalizeRemoteSyncedOrder(order));
929
965
  }
930
- const freshStorageKeyMap = /* @__PURE__ */ new Map();
931
- for (const order of freshMap.values()) {
932
- const storageKey = this.getOrderStorageKey(order);
933
- if (!storageKey)
934
- continue;
935
- freshStorageKeyMap.set(storageKey, order);
936
- }
937
- const uniqueFreshCount = freshMap.size;
938
- const patchedOrders = [...freshMap.values()];
966
+ const uniqueFreshOrders = this.compactOrderListByIdentity(
967
+ normalizedFreshOrders,
968
+ `${source}.incoming`
969
+ ).list;
970
+ const uniqueFreshCount = uniqueFreshOrders.length;
971
+ const patchedOrders = [];
939
972
  const mergeActions = {};
940
- const updatedList = this.store.list.map((order) => {
941
- const storageKey = this.getOrderStorageKey(order);
942
- if (storageKey && freshStorageKeyMap.has(storageKey)) {
943
- const fresh2 = freshStorageKeyMap.get(storageKey);
944
- freshStorageKeyMap.delete(storageKey);
945
- const freshId = fresh2.order_id;
946
- if (freshId !== void 0 && freshId !== null) {
947
- freshMap.delete(this.getIdKey(freshId));
948
- mergeActions[this.getIdKey(freshId)] = "update";
949
- } else {
950
- mergeActions[storageKey] = "update";
951
- }
952
- return fresh2;
953
- }
954
- const id = order.order_id;
955
- if (id === void 0 || id === null)
956
- return order;
957
- const key = this.getIdKey(id);
958
- if (!freshMap.has(key))
959
- return order;
960
- const fresh = freshMap.get(key);
961
- freshMap.delete(key);
962
- mergeActions[key] = "update";
963
- return fresh;
964
- });
965
- for (const order of freshMap.values()) {
966
- const id = order.order_id;
967
- if (id !== void 0 && id !== null) {
968
- mergeActions[this.getIdKey(id)] = "insert";
973
+ const updatedList = [...this.store.list];
974
+ for (const fresh of uniqueFreshOrders) {
975
+ const matchIndex = this.findOrderIndexByIdentity(updatedList, fresh);
976
+ const storageKey = this.getOrderStorageKey(fresh);
977
+ const mergeKey = storageKey || (fresh.order_id !== void 0 && fresh.order_id !== null ? this.getIdKey(fresh.order_id) : "");
978
+ if (matchIndex >= 0) {
979
+ const mergedOrder = this.mergeOrderRecords(updatedList[matchIndex], fresh);
980
+ updatedList[matchIndex] = mergedOrder;
981
+ patchedOrders.push(mergedOrder);
982
+ if (mergeKey)
983
+ mergeActions[mergeKey] = "update";
984
+ continue;
969
985
  }
970
- updatedList.push(order);
986
+ updatedList.push(fresh);
987
+ patchedOrders.push(fresh);
988
+ if (mergeKey)
989
+ mergeActions[mergeKey] = "insert";
971
990
  }
972
991
  const insertCount = Object.values(mergeActions).filter((v) => v === "insert").length;
973
992
  const updateCount = Object.values(mergeActions).filter((v) => v === "update").length;
974
- this.store.list = updatedList;
993
+ this.store.list = this.compactOrderListByIdentity(updatedList, `${source}.store`).list;
975
994
  this.syncOrdersMap();
976
995
  await this.patchOrdersInSQLite(patchedOrders, source, mergeActions);
977
996
  this.logInfo("mergeOrdersToStore-结束", {
978
997
  uniqueFreshCount,
979
- storeOrderCountAfter: this.store.list.length
998
+ storeOrderCountAfter: this.store.list.length,
999
+ insertCount,
1000
+ updateCount
980
1001
  });
981
- this.emitOrdersChanged(patchedOrders, source);
1002
+ await this.emitOrdersChanged(patchedOrders, source);
982
1003
  }
983
1004
  normalizeOrderSyncMessage(res) {
984
1005
  const data = (res == null ? void 0 : res.data) || res;
@@ -1057,6 +1078,129 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1057
1078
  }
1058
1079
  return "";
1059
1080
  }
1081
+ getOrderIdentityMatchKeys(order) {
1082
+ return this.getOrderIdentityEntries(order).map((entry) => `${entry.field}:${entry.key}`);
1083
+ }
1084
+ doOrdersShareIdentity(left, right) {
1085
+ const leftKeys = new Set(this.getOrderIdentityMatchKeys(left));
1086
+ if (leftKeys.size === 0)
1087
+ return false;
1088
+ return this.getOrderIdentityMatchKeys(right).some((key) => leftKeys.has(key));
1089
+ }
1090
+ findOrderIndexByIdentity(orders, target) {
1091
+ if (this.getOrderIdentityMatchKeys(target).length === 0)
1092
+ return -1;
1093
+ return orders.findIndex((order) => this.doOrdersShareIdentity(order, target));
1094
+ }
1095
+ getOrderCompletenessScore(order) {
1096
+ const record = order;
1097
+ let score = this.isPendingSyncOrder(order) ? 0 : 100;
1098
+ if (!this.isBlankIdentityValue(order.order_id) && order.order_id !== record.external_sale_number)
1099
+ score += 30;
1100
+ score += this.getOrderIdentityMatchKeys(order).length * 5;
1101
+ if (Array.isArray(order.products))
1102
+ score += Math.min(order.products.length, 10);
1103
+ if (Array.isArray(order.bookings))
1104
+ score += Math.min(order.bookings.length, 10);
1105
+ if (Array.isArray(order.payments))
1106
+ score += Math.min(order.payments.length, 10);
1107
+ if (record.updated_at)
1108
+ score += 1;
1109
+ return score;
1110
+ }
1111
+ pickPreferredOrder(left, right) {
1112
+ const leftScore = this.getOrderCompletenessScore(left);
1113
+ const rightScore = this.getOrderCompletenessScore(right);
1114
+ if (rightScore >= leftScore)
1115
+ return right;
1116
+ return left;
1117
+ }
1118
+ mergeOrderRecords(existing, incoming) {
1119
+ const preferred = this.pickPreferredOrder(existing, incoming);
1120
+ const secondary = preferred === existing ? incoming : existing;
1121
+ const merged = {
1122
+ ...secondary,
1123
+ ...preferred
1124
+ };
1125
+ const fieldsToPreserve = [
1126
+ "order_id",
1127
+ "external_sale_number",
1128
+ "order_number",
1129
+ "shop_order_number",
1130
+ "shop_full_order_number"
1131
+ ];
1132
+ const mergedRecord = merged;
1133
+ const preferredRecord = preferred;
1134
+ const secondaryRecord = secondary;
1135
+ for (const field of fieldsToPreserve) {
1136
+ if (!this.isBlankIdentityValue(preferredRecord[field])) {
1137
+ mergedRecord[field] = preferredRecord[field];
1138
+ continue;
1139
+ }
1140
+ if (!this.isBlankIdentityValue(secondaryRecord[field])) {
1141
+ mergedRecord[field] = secondaryRecord[field];
1142
+ }
1143
+ }
1144
+ if (!this.isPendingSyncOrder(preferred) || !this.isPendingSyncOrder(secondary)) {
1145
+ merged.need_sync = 0;
1146
+ }
1147
+ return merged;
1148
+ }
1149
+ summarizeDuplicateOrders(orders) {
1150
+ const groups = /* @__PURE__ */ new Map();
1151
+ for (const order of orders) {
1152
+ for (const key of this.getOrderIdentityMatchKeys(order)) {
1153
+ const group = groups.get(key) || [];
1154
+ group.push(order);
1155
+ groups.set(key, group);
1156
+ }
1157
+ }
1158
+ return [...groups.entries()].filter(([, group]) => group.length > 1).slice(0, 20).map(([key, group]) => ({
1159
+ key,
1160
+ count: group.length,
1161
+ orders: group.map((order) => ({
1162
+ order_id: order.order_id ?? null,
1163
+ external_sale_number: order.external_sale_number ?? null,
1164
+ shop_order_number: order.shop_order_number ?? null,
1165
+ shop_full_order_number: order.shop_full_order_number ?? null,
1166
+ need_sync: order.need_sync ?? null
1167
+ }))
1168
+ }));
1169
+ }
1170
+ logDuplicateOrders(source, orders) {
1171
+ const duplicateGroups = this.summarizeDuplicateOrders(orders);
1172
+ if (duplicateGroups.length === 0)
1173
+ return;
1174
+ this.logWarning("检测到重复订单身份键", {
1175
+ source,
1176
+ duplicateGroupCount: duplicateGroups.length,
1177
+ duplicateGroups
1178
+ });
1179
+ }
1180
+ compactOrderListByIdentity(orders, source) {
1181
+ const list = [];
1182
+ let removedCount = 0;
1183
+ for (const order of orders) {
1184
+ const matchIndex = this.findOrderIndexByIdentity(list, order);
1185
+ if (matchIndex < 0) {
1186
+ list.push(order);
1187
+ continue;
1188
+ }
1189
+ list[matchIndex] = this.mergeOrderRecords(list[matchIndex], order);
1190
+ removedCount += 1;
1191
+ }
1192
+ if (removedCount > 0) {
1193
+ this.logWarning("订单列表重复项已压缩", {
1194
+ source,
1195
+ beforeCount: orders.length,
1196
+ afterCount: list.length,
1197
+ removedCount
1198
+ });
1199
+ } else {
1200
+ this.logDuplicateOrders(source, orders);
1201
+ }
1202
+ return { list, removedCount };
1203
+ }
1060
1204
  /**
1061
1205
  * 当前订单拉取窗口:
1062
1206
  * - 优先使用 createdAtQuery.sales_time_between(已按营业日边界初始化)
@@ -1140,19 +1284,19 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1140
1284
  }
1141
1285
  mergeRemoteSnapshotWithPendingOrders(remoteOrders, existingOrders) {
1142
1286
  const merged = remoteOrders.map((order) => this.normalizeRemoteSyncedOrder(order));
1143
- const remoteStorageKeys = new Set(
1144
- merged.map((order) => this.getOrderStorageKey(order)).filter(Boolean)
1145
- );
1146
1287
  for (const order of existingOrders) {
1147
1288
  if (!this.isPendingSyncOrder(order))
1148
1289
  continue;
1149
- const storageKey = this.getOrderStorageKey(order);
1150
- if (!storageKey || remoteStorageKeys.has(storageKey))
1290
+ const matchIndex = this.findOrderIndexByIdentity(merged, order);
1291
+ if (matchIndex >= 0) {
1292
+ merged[matchIndex] = this.mergeOrderRecords(order, merged[matchIndex]);
1293
+ continue;
1294
+ }
1295
+ if (!this.getOrderStorageKey(order))
1151
1296
  continue;
1152
1297
  merged.push(order);
1153
- remoteStorageKeys.add(storageKey);
1154
1298
  }
1155
- return merged;
1299
+ return this.compactOrderListByIdentity(merged, "mergeRemoteSnapshotWithPendingOrders").list;
1156
1300
  }
1157
1301
  /**
1158
1302
  * 串行执行订单 SQLite 写入任务,避免快照替换与增量 upsert 并发交错。
@@ -1189,30 +1333,34 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1189
1333
  if (toWrite.length === 0) {
1190
1334
  return;
1191
1335
  }
1336
+ const compactedToWrite = this.compactOrderListByIdentity(toWrite, `${source}.sqlitePatch`).list;
1337
+ if (compactedToWrite.length === 0) {
1338
+ return;
1339
+ }
1192
1340
  try {
1193
1341
  await this.runInOrderSQLiteSaveQueue(async () => {
1194
1342
  let writeMethod = "none";
1195
1343
  this.logInfo("patchOrdersInSQLite-开始", {
1196
1344
  source,
1197
- count: toWrite.length,
1345
+ count: compactedToWrite.length,
1198
1346
  dedupedCount: skipped.length
1199
1347
  });
1200
1348
  if (typeof this.dbManager.bulkUpdate === "function") {
1201
1349
  writeMethod = "bulkUpdate";
1202
- await this.dbManager.bulkUpdate(INDEXDB_STORE_NAME, toWrite);
1350
+ await this.dbManager.bulkUpdate(INDEXDB_STORE_NAME, compactedToWrite);
1203
1351
  } else if (typeof this.dbManager.bulkAdd === "function") {
1204
1352
  writeMethod = "bulkAdd";
1205
- await this.dbManager.bulkAdd(INDEXDB_STORE_NAME, toWrite);
1353
+ await this.dbManager.bulkAdd(INDEXDB_STORE_NAME, compactedToWrite);
1206
1354
  } else if (typeof this.dbManager.update === "function") {
1207
1355
  writeMethod = "update";
1208
- for (const order of toWrite) {
1356
+ for (const order of compactedToWrite) {
1209
1357
  await this.dbManager.update(INDEXDB_STORE_NAME, order);
1210
1358
  }
1211
1359
  }
1212
- this.recordRecentSqliteWrite(source, toWrite);
1360
+ this.recordRecentSqliteWrite(source, compactedToWrite);
1213
1361
  this.logInfo("patchOrdersInSQLite-完成", {
1214
1362
  source,
1215
- count: toWrite.length,
1363
+ count: compactedToWrite.length,
1216
1364
  writeMethod,
1217
1365
  dedupedCount: skipped.length
1218
1366
  });
@@ -1275,10 +1423,16 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1275
1423
  */
1276
1424
  async replaceOrdersSnapshotInSQLite(orderList, source) {
1277
1425
  if (!this.dbManager) {
1278
- return orderList.map((order) => this.normalizeRemoteSyncedOrder(order));
1426
+ return this.compactOrderListByIdentity(
1427
+ orderList.map((order) => this.normalizeRemoteSyncedOrder(order)),
1428
+ `${source}.snapshotNoDb`
1429
+ ).list;
1279
1430
  }
1280
1431
  const remoteSnapshot = (0, import_lodash_es.cloneDeep)(orderList);
1281
- let mergedSnapshot = remoteSnapshot.map((order) => this.normalizeRemoteSyncedOrder(order));
1432
+ let mergedSnapshot = this.compactOrderListByIdentity(
1433
+ remoteSnapshot.map((order) => this.normalizeRemoteSyncedOrder(order)),
1434
+ `${source}.remoteSnapshot`
1435
+ ).list;
1282
1436
  try {
1283
1437
  await this.runInOrderSQLiteSaveQueue(async () => {
1284
1438
  const existingOrders = typeof this.dbManager.getAll === "function" ? await this.dbManager.getAll(INDEXDB_STORE_NAME) : [];
@@ -1286,25 +1440,25 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1286
1440
  remoteSnapshot,
1287
1441
  existingOrders || []
1288
1442
  );
1289
- mergedSnapshot = orderListSnapshot;
1443
+ mergedSnapshot = this.compactOrderListByIdentity(orderListSnapshot, `${source}.sqliteSnapshot`).list;
1290
1444
  this.logInfo("replaceOrdersSnapshotInSQLite-开始", {
1291
1445
  source,
1292
- count: orderListSnapshot.length,
1446
+ count: mergedSnapshot.length,
1293
1447
  remoteCount: remoteSnapshot.length,
1294
- preservedPendingCount: orderListSnapshot.length - remoteSnapshot.length
1448
+ preservedPendingCount: mergedSnapshot.length - remoteSnapshot.length
1295
1449
  });
1296
1450
  await this.dbManager.clear(INDEXDB_STORE_NAME);
1297
1451
  this.logInfo("replaceOrdersSnapshotInSQLite-clear完成", {
1298
- count: orderListSnapshot.length
1452
+ count: mergedSnapshot.length
1299
1453
  });
1300
- if (orderListSnapshot.length === 0) {
1454
+ if (mergedSnapshot.length === 0) {
1301
1455
  return;
1302
1456
  }
1303
- await this.dbManager.bulkAdd(INDEXDB_STORE_NAME, orderListSnapshot);
1304
- this.recordRecentSqliteWrite(source, orderListSnapshot);
1457
+ await this.dbManager.bulkAdd(INDEXDB_STORE_NAME, mergedSnapshot);
1458
+ this.recordRecentSqliteWrite(source, mergedSnapshot);
1305
1459
  this.logInfo("replaceOrdersSnapshotInSQLite-bulkAdd完成", {
1306
1460
  source,
1307
- count: orderListSnapshot.length
1461
+ count: mergedSnapshot.length
1308
1462
  });
1309
1463
  });
1310
1464
  } catch (error) {
@@ -70,14 +70,54 @@ function preserveManualProductDiscountProducts(previousProducts, nextProducts) {
70
70
  return previous && isBaseSalesManualProductDiscountProduct(previous) ? previous : product;
71
71
  });
72
72
  }
73
+ function getBaseSalesUniqueArrayMetadataKey(key) {
74
+ if (key === "products" || key === "bookings")
75
+ return "unique_identification_number";
76
+ if (key === "payments" || key === "payment")
77
+ return "unique_payment_number";
78
+ return null;
79
+ }
80
+ function getBaseSalesMetadataUid(item, metadataKey) {
81
+ var _a;
82
+ const uid = ((_a = item == null ? void 0 : item.metadata) == null ? void 0 : _a[metadataKey]) ?? (item == null ? void 0 : item[metadataKey]);
83
+ if (uid === void 0 || uid === null || uid === "")
84
+ return null;
85
+ return String(uid);
86
+ }
87
+ function mergeBaseSalesUniqueArray(currentValue, loadedValue, metadataKey) {
88
+ const result = [];
89
+ const indexByUid = /* @__PURE__ */ new Map();
90
+ const appendOrReplaceByUid = (item) => {
91
+ const clonedItem = (0, import_lodash_es.cloneDeep)(item);
92
+ const uid = getBaseSalesMetadataUid(clonedItem, metadataKey);
93
+ if (!uid) {
94
+ result.push(clonedItem);
95
+ return;
96
+ }
97
+ const existingIndex = indexByUid.get(uid);
98
+ if (existingIndex !== void 0) {
99
+ result[existingIndex] = clonedItem;
100
+ return;
101
+ }
102
+ indexByUid.set(uid, result.length);
103
+ result.push(clonedItem);
104
+ };
105
+ currentValue.forEach(appendOrReplaceByUid);
106
+ loadedValue.forEach(appendOrReplaceByUid);
107
+ return result;
108
+ }
73
109
  function mergeSalesDetailRecordWithTempOrder(currentTempOrder, loadedRecord) {
74
110
  if (!currentTempOrder)
75
111
  return loadedRecord;
76
112
  return (0, import_lodash_es.mergeWith)(
77
113
  (0, import_lodash_es.cloneDeep)(currentTempOrder),
78
114
  (0, import_lodash_es.cloneDeep)(loadedRecord || {}),
79
- (currentValue, loadedValue) => {
115
+ (currentValue, loadedValue, key) => {
80
116
  if (Array.isArray(currentValue) && Array.isArray(loadedValue)) {
117
+ const metadataKey = getBaseSalesUniqueArrayMetadataKey(key);
118
+ if (metadataKey) {
119
+ return mergeBaseSalesUniqueArray(currentValue, loadedValue, metadataKey);
120
+ }
81
121
  return [
82
122
  ...(0, import_lodash_es.cloneDeep)(currentValue),
83
123
  ...(0, import_lodash_es.cloneDeep)(loadedValue)
@@ -1205,7 +1245,6 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1205
1245
  if (!this.store.order) {
1206
1246
  throw new Error("BaseSales 解决方案需要 order 模块支持");
1207
1247
  }
1208
- this.store.order.persistTempOrder();
1209
1248
  const inferredPaymentStatus = this.getSubmitPaymentStatus(params == null ? void 0 : params.paymentStatus);
1210
1249
  const submitParams = {
1211
1250
  cacheId: this.cacheId,
@@ -311,7 +311,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
311
311
  date: string;
312
312
  status: string;
313
313
  week: string;
314
- weekNum: 0 | 1 | 2 | 3 | 5 | 4 | 6;
314
+ weekNum: 0 | 2 | 1 | 6 | 3 | 4 | 5;
315
315
  }[]>;
316
316
  submitTimeSlot(timeSlots: TimeSliceItem): void;
317
317
  private getScheduleDataByIds;
@@ -267,7 +267,6 @@ var BookingTicketImpl = class extends import_BaseSales.BaseSalesImpl {
267
267
  };
268
268
  customerModule.setSelectedCustomer(customer);
269
269
  this.setOrderCustomer(customer);
270
- await this.store.order.saveDraft();
271
270
  }
272
271
  return sales;
273
272
  }
@@ -477,7 +476,8 @@ var BookingTicketImpl = class extends import_BaseSales.BaseSalesImpl {
477
476
  throw new Error("refreshSalesDetail: tempOrder.order_id 缺失");
478
477
  }
479
478
  return this.loadSalesDetail({
480
- orderId: Number(orderId)
479
+ orderId: Number(orderId),
480
+ merge: true
481
481
  // forceRemote: true,
482
482
  });
483
483
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.2.215",
4
+ "version": "2.2.217",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",