@pisell/pisellos 2.2.327 → 2.2.329

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.
@@ -342,7 +342,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
342
342
  date: string;
343
343
  status: string;
344
344
  week: string;
345
- weekNum: 0 | 2 | 1 | 6 | 4 | 5 | 3;
345
+ weekNum: 0 | 1 | 2 | 3 | 4 | 5 | 6;
346
346
  }[]>;
347
347
  submitTimeSlot(timeSlots: TimeSliceItem): void;
348
348
  private getScheduleDataByIds;
@@ -44,7 +44,7 @@ export declare class DataVariantEvaluator {
44
44
  * 返回 null 表示接口没有提供该字段;空 Map 表示已计算但没有任何命中。
45
45
  */
46
46
  private getAuthoritativeVariantPriorities;
47
- private normalizeDataVariantId;
47
+ private normalizeId;
48
48
  private buildGlobalEffectiveRuleMap;
49
49
  private resolveProduct;
50
50
  /**
@@ -90,6 +90,7 @@ export declare class DataVariantEvaluator {
90
90
  private timeToMinutes;
91
91
  private isProductInMenuScope;
92
92
  private mergeMatchedVariants;
93
+ private mergeSkuVariants;
93
94
  private getProductDataVariants;
94
95
  private normalizeStrategyConfigs;
95
96
  private isStrategyActive;
@@ -158,14 +158,14 @@ class DataVariantEvaluator {
158
158
  const orderedIds = [];
159
159
  const seen = new Set();
160
160
  for (const rawId of rawIds) {
161
- const id = this.normalizeDataVariantId(rawId);
161
+ const id = this.normalizeId(rawId);
162
162
  if (id === null || seen.has(id)) continue;
163
163
  seen.add(id);
164
164
  orderedIds.push(id);
165
165
  }
166
166
  return new Map(orderedIds.map((id, index) => [id, orderedIds.length - index]));
167
167
  }
168
- normalizeDataVariantId(value) {
168
+ normalizeId(value) {
169
169
  if (value === undefined || value === null) return null;
170
170
  const normalized = String(value).trim();
171
171
  return normalized || null;
@@ -206,7 +206,7 @@ class DataVariantEvaluator {
206
206
  for (const variant of dataVariants) {
207
207
  if (variant.business_type === 'multi_currency_settlement') continue;
208
208
  if (authoritativeVariantPriorities !== null) {
209
- const variantId = this.normalizeDataVariantId(variant.id);
209
+ const variantId = this.normalizeId(variant.id);
210
210
  const priority = variantId === null ? undefined : authoritativeVariantPriorities.get(variantId);
211
211
  if (priority === undefined) continue;
212
212
  matchedVariants.push({
@@ -250,7 +250,7 @@ class DataVariantEvaluator {
250
250
  const ruleId = String(variant.data_variant_rule_id);
251
251
  const isDefault = Number(variant.data_variant_rule_id) === 0;
252
252
  const rule = isDefault ? undefined : globalEffectiveRuleMap.get(ruleId);
253
- const variantId = this.normalizeDataVariantId(variant.id);
253
+ const variantId = this.normalizeId(variant.id);
254
254
  const authoritativePriority = variantId === null ? undefined : authoritativeVariantPriorities?.get(variantId);
255
255
  let available;
256
256
  let priority;
@@ -575,20 +575,54 @@ class DataVariantEvaluator {
575
575
  const appliedFields = new Set();
576
576
  for (const matched of sortedVariants) {
577
577
  for (const [key, value] of Object.entries(matched.data)) {
578
- if (value === undefined) continue;
578
+ if (value === undefined || key === 'variant_overrides') continue;
579
579
  result[key] = value;
580
580
  appliedFields.add(key);
581
581
  }
582
+ const mergedVariants = this.mergeSkuVariants(result.variant, matched.data.variant_overrides);
583
+ if (mergedVariants) {
584
+ result.variant = mergedVariants;
585
+ appliedFields.add('variant');
586
+ }
582
587
  appliedRuleIds.push(matched.ruleId);
583
588
  }
584
589
  result._dataVariant = {
585
590
  appliedRuleIds,
586
- appliedVariantIds: Array.from(new Set([...sortedVariants].reverse().map(matched => this.normalizeDataVariantId(matched.variant.id)).filter(id => id !== null))),
591
+ appliedVariantIds: Array.from(new Set([...sortedVariants].reverse().map(matched => this.normalizeId(matched.variant.id)).filter(id => id !== null))),
587
592
  appliedFields: Array.from(appliedFields),
588
593
  original
589
594
  };
590
595
  return result;
591
596
  }
597
+ mergeSkuVariants(variants, overrides) {
598
+ if (!Array.isArray(variants) || !Array.isArray(overrides)) return;
599
+ const overridesById = new Map();
600
+ for (const override of overrides) {
601
+ const rawId = override?.id;
602
+ if (typeof rawId !== 'number' && typeof rawId !== 'string') continue;
603
+ const id = this.normalizeId(rawId);
604
+ if (id === null) continue;
605
+ const fields = Object.entries(override).filter(([key, value]) => key !== 'id' && value !== undefined);
606
+ if (fields.length === 0) continue;
607
+ overridesById.set(id, {
608
+ ...overridesById.get(id),
609
+ ...Object.fromEntries(fields)
610
+ });
611
+ }
612
+ if (overridesById.size === 0) return;
613
+ let hasUpdates = false;
614
+ const merged = variants.map(variant => {
615
+ const id = this.normalizeId(variant?.id);
616
+ const fields = id === null ? undefined : overridesById.get(id);
617
+ if (!fields) return variant;
618
+ hasUpdates = true;
619
+ return {
620
+ ...variant,
621
+ ...fields
622
+ };
623
+ });
624
+ return hasUpdates ? merged : undefined;
625
+ }
592
626
  getProductDataVariants(product) {
593
627
  return Array.isArray(product.data_variants) ? product.data_variants : [];
594
628
  }
@@ -1724,6 +1724,34 @@ class OrderModule extends _BaseModule.BaseModule {
1724
1724
  * 将增量订单合并到 store
1725
1725
  */
1726
1726
  async mergeOrdersToStore(freshOrders, source) {
1727
+ if (this.isRemoteEchoMergeSource(source)) {
1728
+ const cancelledOrders = freshOrders.filter(order => order?.status === 'cancelled' && order.order_id != null);
1729
+ if (cancelledOrders.length) {
1730
+ const ids = new Set(cancelledOrders.map(order => this.getIdKey(order.order_id)));
1731
+ const cloudOrders = cancelledOrders.map(order => this.normalizeRemoteSyncedOrder(order));
1732
+ await this.runInOrderSQLiteSaveQueue(async () => {
1733
+ if (this.dbManager) {
1734
+ const stored = await this.dbManager.getAll(INDEXDB_STORE_NAME);
1735
+ const keys = new Set((stored || []).filter(order => order.order_id != null && ids.has(this.getIdKey(order.order_id))).map(order => this.getPersistedOrderStorageKey(order)).filter(Boolean));
1736
+ for (const key of keys) {
1737
+ await this.dbManager.delete(INDEXDB_STORE_NAME, key);
1738
+ this.recentSqliteWriteByStorageKey.delete(key);
1739
+ }
1740
+ await this.writeOrderRowsToSQLite(cloudOrders);
1741
+ this.recordRecentSqliteWrite(source, cloudOrders);
1742
+ }
1743
+ this.store.list = this.store.list.filter(order => order.order_id == null || !ids.has(this.getIdKey(order.order_id))).concat(cloudOrders);
1744
+ this.syncOrdersMap();
1745
+ });
1746
+ this.logInfo('取消订单已清理本地副本并采用云端数据', {
1747
+ source,
1748
+ order_ids: [...ids]
1749
+ });
1750
+ await this.emitOrdersChanged(cloudOrders, source);
1751
+ freshOrders = freshOrders.filter(order => order.order_id == null || !ids.has(this.getIdKey(order.order_id)));
1752
+ }
1753
+ }
1754
+ if (!freshOrders.length) return;
1727
1755
  const storeOrderCountBefore = this.store.list.length;
1728
1756
  this.logInfo('mergeOrdersToStore-开始', {
1729
1757
  freshOrderCount: freshOrders.length,
@@ -342,7 +342,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
342
342
  date: string;
343
343
  status: string;
344
344
  week: string;
345
- weekNum: 0 | 2 | 1 | 6 | 4 | 5 | 3;
345
+ weekNum: 0 | 1 | 2 | 3 | 4 | 5 | 6;
346
346
  }[]>;
347
347
  submitTimeSlot(timeSlots: TimeSliceItem): void;
348
348
  private getScheduleDataByIds;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.2.327",
4
+ "version": "2.2.329",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",