@pisell/pisellos 2.2.170 → 2.2.172

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.
@@ -49,6 +49,7 @@ __export(utils_exports, {
49
49
  mergeRelationForms: () => mergeRelationForms,
50
50
  normalizeBookingIsAll: () => normalizeBookingIsAll,
51
51
  normalizeBookingSubType: () => normalizeBookingSubType,
52
+ normalizeOrderProductDiscountList: () => normalizeOrderProductDiscountList,
52
53
  normalizeSubmitBooking: () => normalizeSubmitBooking,
53
54
  normalizeSubmitCollectPaxValue: () => normalizeSubmitCollectPaxValue,
54
55
  resolveManualDiscountMessage: () => import_manualProductDiscount.resolveManualDiscountMessage,
@@ -106,6 +107,42 @@ function resolveRulesManualDiscountFlag(metadata) {
106
107
  }
107
108
  return void 0;
108
109
  }
110
+ function normalizeOrderProductDiscountAmount(amount) {
111
+ if (amount === void 0 || amount === null)
112
+ return void 0;
113
+ return String(amount);
114
+ }
115
+ function normalizeOrderProductDiscountList(discountList) {
116
+ if (!Array.isArray(discountList))
117
+ return [];
118
+ return discountList.filter((item) => !!item && typeof item === "object").map((item) => {
119
+ const normalized = {
120
+ discount_id: Number.isFinite(Number(item.discount_id)) ? Number(item.discount_id) : 0
121
+ };
122
+ if (item.order_discount_id === null) {
123
+ normalized.order_discount_id = null;
124
+ } else if (item.order_discount_id !== void 0) {
125
+ const orderDiscountId = Number(item.order_discount_id);
126
+ if (Number.isFinite(orderDiscountId)) {
127
+ normalized.order_discount_id = orderDiscountId;
128
+ }
129
+ }
130
+ if (item.type !== void 0)
131
+ normalized.type = item.type;
132
+ const amount = normalizeOrderProductDiscountAmount(item.amount);
133
+ if (amount !== void 0)
134
+ normalized.amount = amount;
135
+ if (item.discount && typeof item.discount === "object") {
136
+ normalized.discount = { ...item.discount };
137
+ }
138
+ if (item.metadata === null) {
139
+ normalized.metadata = null;
140
+ } else if (item.metadata && typeof item.metadata === "object") {
141
+ normalized.metadata = { ...item.metadata };
142
+ }
143
+ return normalized;
144
+ });
145
+ }
109
146
  function resolveManualOverrideLineOriginalPrice(params, fallbackCompositeOriginal) {
110
147
  var _a, _b;
111
148
  const metadata = params.metadata || {};
@@ -426,7 +463,7 @@ function normalizeSubmitProduct(product) {
426
463
  ...bookingUid ? { booking_uid: bookingUid } : {},
427
464
  product_quantity: toBundleNumber(num ?? submitProduct.product_quantity, 1),
428
465
  product_sku: productSku,
429
- discount_list: submitProduct.discount_list || [],
466
+ discount_list: normalizeOrderProductDiscountList(submitProduct.discount_list),
430
467
  product_bundle: formatSubmitBundleItems(submitProduct.product_bundle),
431
468
  metadata: cleanMetadata,
432
469
  // 出站兼容:后端消费 payment_price 字段,这里从 selling_price 直接派生。
@@ -521,7 +558,6 @@ function createDefaultTempOrder(params) {
521
558
  bookings: [],
522
559
  payments: [],
523
560
  surcharges: [],
524
- discount_list: [],
525
561
  relation_forms: [],
526
562
  contacts: [],
527
563
  contacts_info: null,
@@ -559,6 +595,7 @@ function buildSubmitPayload(params) {
559
595
  shop_service_type: _shopServiceType,
560
596
  start_time: _startTime,
561
597
  customer: _customer,
598
+ discount_list: _discountList,
562
599
  tax_fee: _rootTaxFee,
563
600
  total_amount: _totalAmount,
564
601
  total_refund_amount: _totalRefundAmount,
@@ -603,7 +640,6 @@ function buildSubmitPayload(params) {
603
640
  (booking) => Number(booking.parent_id) !== 0
604
641
  ).map((booking) => normalizeSubmitBooking(booking)),
605
642
  payments: tempOrder.payments || [],
606
- // discount_list: tempOrder.discount_list || [],
607
643
  relation_forms: tempOrder.relation_forms || [],
608
644
  // contacts: tempOrder.contacts || [],
609
645
  contacts_info: tempOrder.contacts_info && !Array.isArray(tempOrder.contacts_info) ? tempOrder.contacts_info : null,
@@ -706,6 +742,7 @@ function formatV1Product(products) {
706
742
  mergeRelationForms,
707
743
  normalizeBookingIsAll,
708
744
  normalizeBookingSubType,
745
+ normalizeOrderProductDiscountList,
709
746
  normalizeSubmitBooking,
710
747
  normalizeSubmitCollectPaxValue,
711
748
  resolveManualDiscountMessage,
@@ -74,9 +74,11 @@ var QuotationModule = class extends import_BaseModule.BaseModule {
74
74
  getPriceForProduct(params) {
75
75
  const { productId, variantId, datetime, customer_id } = params;
76
76
  for (const quotation of this.store.list) {
77
- if (!this.isQuotationVisibleForCustomer(quotation, customer_id))
77
+ const visible = this.isQuotationVisibleForCustomer(quotation, customer_id);
78
+ if (!visible)
78
79
  continue;
79
- if (!this.isQuotationActiveAt(quotation, datetime))
80
+ const active = this.isQuotationActiveAt(quotation, datetime);
81
+ if (!active)
80
82
  continue;
81
83
  const match = this.findProductData(quotation.product_data, productId, variantId);
82
84
  if (!match)
@@ -148,18 +150,27 @@ var QuotationModule = class extends import_BaseModule.BaseModule {
148
150
  var _a;
149
151
  if (!((_a = quotation.schedule) == null ? void 0 : _a.length))
150
152
  return false;
151
- const scheduleItems = quotation.schedule.map((s) => {
153
+ const scheduleItems = [];
154
+ quotation.schedule.forEach((s) => {
152
155
  var _a2;
153
156
  const full = (_a2 = this.scheduleResolver) == null ? void 0 : _a2.call(this, s.id);
154
- if (full)
155
- return full;
156
- return {
157
+ if (full) {
158
+ scheduleItems.push(full);
159
+ return;
160
+ }
161
+ if (this.scheduleResolver) {
162
+ return;
163
+ }
164
+ const fallbackSchedule = {
157
165
  ...s,
158
166
  repeat_type: s.repeat_type || "none",
159
167
  repeat_rule: s.repeat_rule || null,
160
168
  time_slot: s.time_slot || []
161
169
  };
170
+ scheduleItems.push(fallbackSchedule);
162
171
  });
172
+ if (!scheduleItems.length)
173
+ return false;
163
174
  return (0, import_getDateIsInSchedule.getDateIsInSchedule)(datetime, scheduleItems);
164
175
  }
165
176
  findProductData(productData, productId, variantId) {
@@ -135,7 +135,9 @@ var ScheduleModule = class extends import_BaseModule.BaseModule {
135
135
  return dates;
136
136
  }
137
137
  getScheduleListByIds(ids) {
138
- return this.store.scheduleList.filter((n) => ids.includes(n.id));
138
+ const idSet = new Set(ids.map((id) => String(id)));
139
+ const list = this.store.scheduleList.filter((n) => idSet.has(String(n.id)));
140
+ return list;
139
141
  }
140
142
  setAvailabilityScheduleDateList(list) {
141
143
  this.store.availabilityDateList = list;
@@ -931,6 +931,8 @@ var Server = class {
931
931
  return;
932
932
  }
933
933
  try {
934
+ await this.schedule.loadAllSchedule();
935
+ this.products.clearPriceCache();
934
936
  await this.products.setupQuotationPriceBridge({
935
937
  scheduleModule: this.schedule,
936
938
  channel: (_a = this.core.context) == null ? void 0 : _a.channel
@@ -177,7 +177,7 @@ var ProductsModule = class extends import_BaseModule.BaseModule {
177
177
  * Server 层负责传入完整 schedule 模块,Products 只负责把报价单计算结果转成价格响应形状。
178
178
  */
179
179
  async setupQuotationPriceBridge(params) {
180
- var _a, _b, _c;
180
+ var _a;
181
181
  if (!this.core) {
182
182
  this.logWarning("setupQuotationPriceBridge: core 尚未初始化");
183
183
  return;
@@ -190,15 +190,14 @@ var ProductsModule = class extends import_BaseModule.BaseModule {
190
190
  this.quotationPriceBridge = quotation;
191
191
  }
192
192
  if (params.scheduleModule) {
193
- const scheduleList = ((_c = (_b = params.scheduleModule).getScheduleList) == null ? void 0 : _c.call(_b)) || [];
194
- const scheduleMap = new Map(
195
- scheduleList.map((schedule) => [schedule.id, schedule])
196
- );
197
193
  this.quotationPriceBridge.setScheduleResolver((id) => {
198
- var _a2, _b2;
199
- if (scheduleMap.has(id))
200
- return scheduleMap.get(id);
201
- const schedules = ((_b2 = (_a2 = params.scheduleModule).getScheduleByIds) == null ? void 0 : _b2.call(_a2, [id])) || [];
194
+ var _a2, _b, _c, _d, _e, _f;
195
+ const scheduleId = String(id);
196
+ const scheduleList = ((_b = (_a2 = params.scheduleModule).getScheduleList) == null ? void 0 : _b.call(_a2)) || [];
197
+ const schedule = scheduleList.find((item) => String(item.id) === scheduleId);
198
+ if (schedule)
199
+ return schedule;
200
+ const schedules = ((_d = (_c = params.scheduleModule).getScheduleListByIds) == null ? void 0 : _d.call(_c, [id])) || ((_f = (_e = params.scheduleModule).getScheduleByIds) == null ? void 0 : _f.call(_e, [id])) || [];
202
201
  return schedules[0];
203
202
  });
204
203
  }
@@ -183,8 +183,9 @@ var ScheduleModuleEx = class extends import_BaseModule.BaseModule {
183
183
  return [];
184
184
  }
185
185
  const result = [];
186
+ const scheduleList = this.store.scheduleList || [];
186
187
  for (const id of ids) {
187
- const schedule = this.store.map.get(id);
188
+ const schedule = this.store.map.get(id) || scheduleList.find((item) => String(item.id) === String(id));
188
189
  if (schedule) {
189
190
  result.push(schedule);
190
191
  }
@@ -113,6 +113,24 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
113
113
  updateRemoteOrderNote(orderId: number | string, note: string): void;
114
114
  updateTempOrderShopDiscount(amount: string | number): string;
115
115
  updateTempOrderContactsInfo(contactsInfo: Record<string, any> | null): Record<string, any> | null;
116
+ /**
117
+ * 运行时切换 tempOrder 是否写入 localStorage(委托 OrderModule)。
118
+ * SalesSdk 等内存态场景可在挂载后设为 false,避免污染本地缓存。
119
+ *
120
+ * @example
121
+ * bookingTicket.setEnableTempOrderPersist(false);
122
+ * await bookingTicket.addProductToOrder(product);
123
+ */
124
+ setEnableTempOrderPersist(enabled: boolean): void;
125
+ /**
126
+ * 读取当前 tempOrder localStorage 持久化开关(委托 OrderModule)。
127
+ *
128
+ * @example
129
+ * if (bookingTicket.isTempOrderPersistEnabled()) {
130
+ * bookingTicket.restoreOrder();
131
+ * }
132
+ */
133
+ isTempOrderPersistEnabled(): boolean;
116
134
  private ensureTempOrder;
117
135
  addNewOrder(): Promise<OrderTempOrder>;
118
136
  saveDraft(): Promise<void>;
@@ -127,6 +145,7 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
127
145
  private getHistoricalProductDiscountList;
128
146
  private isPersistedOrderProduct;
129
147
  private mergeHistoricalDiscountList;
148
+ private mergeCurrentDiscountSelectionState;
130
149
  loadDiscountConfig(params?: {
131
150
  customerId?: number;
132
151
  action?: 'create' | 'edit';
@@ -417,6 +417,32 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
417
417
  throw new Error("order 模块未初始化");
418
418
  return this.store.order.updateTempOrderContactsInfo(contactsInfo);
419
419
  }
420
+ /**
421
+ * 运行时切换 tempOrder 是否写入 localStorage(委托 OrderModule)。
422
+ * SalesSdk 等内存态场景可在挂载后设为 false,避免污染本地缓存。
423
+ *
424
+ * @example
425
+ * bookingTicket.setEnableTempOrderPersist(false);
426
+ * await bookingTicket.addProductToOrder(product);
427
+ */
428
+ setEnableTempOrderPersist(enabled) {
429
+ if (!this.store.order)
430
+ throw new Error("order 模块未初始化");
431
+ this.store.order.setEnableTempOrderPersist(enabled);
432
+ }
433
+ /**
434
+ * 读取当前 tempOrder localStorage 持久化开关(委托 OrderModule)。
435
+ *
436
+ * @example
437
+ * if (bookingTicket.isTempOrderPersistEnabled()) {
438
+ * bookingTicket.restoreOrder();
439
+ * }
440
+ */
441
+ isTempOrderPersistEnabled() {
442
+ if (!this.store.order)
443
+ return true;
444
+ return this.store.order.isTempOrderPersistEnabled();
445
+ }
420
446
  ensureTempOrder() {
421
447
  if (!this.store.order)
422
448
  throw new Error("order 模块未初始化");
@@ -561,8 +587,35 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
561
587
  ...(discountList || []).filter((discount) => !historyIds.has(discount.id))
562
588
  ];
563
589
  }
590
+ mergeCurrentDiscountSelectionState(discountList, currentDiscountList) {
591
+ if (!currentDiscountList.length)
592
+ return discountList;
593
+ const currentDiscountMap = new Map(
594
+ currentDiscountList.map((discount) => [discount.id, discount])
595
+ );
596
+ return discountList.map((discount) => {
597
+ const currentDiscount = currentDiscountMap.get(discount.id);
598
+ if (!currentDiscount)
599
+ return discount;
600
+ if (currentDiscount.isManualSelect) {
601
+ return {
602
+ ...discount,
603
+ isSelected: false,
604
+ isManualSelect: true
605
+ };
606
+ }
607
+ if (currentDiscount.isSelected) {
608
+ return {
609
+ ...discount,
610
+ isSelected: true,
611
+ isManualSelect: false
612
+ };
613
+ }
614
+ return discount;
615
+ });
616
+ }
564
617
  async loadDiscountConfig(params) {
565
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
618
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
566
619
  if (!this.store.order)
567
620
  throw new Error("order 模块未初始化");
568
621
  const tempOrder = this.store.order.ensureTempOrder();
@@ -573,6 +626,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
573
626
  const customerId = Number(
574
627
  (params == null ? void 0 : params.customerId) || tempOrder.customer_id || ((_c = tempOrder.customer) == null ? void 0 : _c.id) || ((_e = (_d = tempOrder._extend) == null ? void 0 : _d.customerSnapshot) == null ? void 0 : _e.id) || ((_g = (_f = tempOrder._extend) == null ? void 0 : _f.customerSnapshot) == null ? void 0 : _g.customer_id) || 0
575
628
  );
629
+ const currentDiscountList = ((_h = discountModule == null ? void 0 : discountModule.getDiscountList) == null ? void 0 : _h.call(discountModule)) || [];
576
630
  let preparedDiscountList = [];
577
631
  if (customerId && customerId !== 1) {
578
632
  preparedDiscountList = await this.store.order.loadDiscountConfig({
@@ -581,21 +635,25 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
581
635
  orderId: Number(orderId) || void 0,
582
636
  apply: false
583
637
  });
584
- await ((_h = discountModule == null ? void 0 : discountModule.setOriginalDiscountList) == null ? void 0 : _h.call(discountModule, preparedDiscountList));
638
+ await ((_i = discountModule == null ? void 0 : discountModule.setOriginalDiscountList) == null ? void 0 : _i.call(discountModule, preparedDiscountList));
585
639
  }
586
640
  let nextDiscountList = this.mergeHistoricalDiscountList(
587
- preparedDiscountList || ((_i = discountModule == null ? void 0 : discountModule.getDiscountList) == null ? void 0 : _i.call(discountModule)) || [],
641
+ preparedDiscountList || ((_j = discountModule == null ? void 0 : discountModule.getDiscountList) == null ? void 0 : _j.call(discountModule)) || [],
588
642
  tempOrder.products || []
589
643
  );
644
+ nextDiscountList = this.mergeCurrentDiscountSelectionState(
645
+ nextDiscountList,
646
+ currentDiscountList
647
+ );
590
648
  await (discountModule == null ? void 0 : discountModule.setDiscountList(nextDiscountList));
591
649
  if (rulesModule) {
592
- const holders = ((_j = tempOrder.holder) == null ? void 0 : _j.form_record_id) ? [{ form_record_id: tempOrder.holder.form_record_id }] : [];
650
+ const holders = ((_k = tempOrder.holder) == null ? void 0 : _k.form_record_id) ? [{ form_record_id: tempOrder.holder.form_record_id }] : [];
593
651
  const result = rulesModule.calcDiscount({
594
652
  productList: tempOrder.products,
595
653
  discountList: nextDiscountList,
596
654
  holders,
597
- isFormSubject: !!((_k = tempOrder.holder) == null ? void 0 : _k.type) && tempOrder.holder.type === "form",
598
- orderTotalAmount: Number(((_l = orderStore.summary) == null ? void 0 : _l.total_amount) || 0)
655
+ isFormSubject: !!((_l = tempOrder.holder) == null ? void 0 : _l.type) && tempOrder.holder.type === "form",
656
+ orderTotalAmount: Number(((_m = orderStore.summary) == null ? void 0 : _m.total_amount) || 0)
599
657
  }) || { productList: tempOrder.products, discountList: nextDiscountList };
600
658
  if (result.productList) {
601
659
  tempOrder.products = result.productList;
@@ -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 | 4 | 5 | 6;
314
+ weekNum: 0 | 2 | 1 | 5 | 3 | 4 | 6;
315
315
  }[]>;
316
316
  submitTimeSlot(timeSlots: TimeSliceItem): void;
317
317
  private getScheduleDataByIds;
@@ -260,7 +260,7 @@ export declare class BookingTicketImpl extends BaseSalesImpl implements Module {
260
260
  * 获取当前的客户搜索条件
261
261
  * @returns 当前搜索条件
262
262
  */
263
- getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "skip" | "num">;
263
+ getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "num" | "skip">;
264
264
  /**
265
265
  * 获取客户列表状态(包含滚动加载相关状态)
266
266
  * @returns 客户状态
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.2.170",
4
+ "version": "2.2.172",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",