@pisell/pisellos 0.0.549 → 0.0.551

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.
@@ -57,6 +57,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
57
57
  private getTempOrderStorageKey;
58
58
  private restoreTempOrderFromStorage;
59
59
  persistTempOrder(): void;
60
+ notifyTempOrderChanged(): void;
60
61
  private createDefaultTempOrderInstance;
61
62
  ensureTempOrder(): ScanOrderTempOrder;
62
63
  restoreOrder(): ScanOrderTempOrder;
@@ -25,7 +25,7 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
25
25
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
26
26
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
27
27
  import { BaseModule } from "../BaseModule";
28
- import { generateDuration, getAllDiscountList, mergeRelationForms, buildSubmitPayload, createDefaultTempOrder, createDefaultOrderRulesHooks, createEmptySummary, createUuidV4, formatDateTime, filterProductsForScanOrderMore, isTempOrder } from "./utils";
28
+ import { generateDuration, getAllDiscountList, mergeRelationForms, ensureCartItemOriginHolder, buildSubmitPayload, createDefaultTempOrder, createDefaultOrderRulesHooks, createEmptySummary, createUuidV4, formatDateTime, filterProductsForScanOrderMore, isTempOrder } from "./utils";
29
29
  import { isNormalProduct } from "../Product/utils";
30
30
  import dayjs from 'dayjs';
31
31
  import { buildProductLineFingerprint, getProductIdentityIndex, getSafeProductNum, isIdentityMatch, normalizeOrderProduct } from "../../solution/ScanOrder/utils";
@@ -438,6 +438,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
438
438
  if (!this.window) return;
439
439
  this.window.localStorage.setItem(key, JSON.stringify(this.store.tempOrder));
440
440
  }
441
+ }, {
442
+ key: "notifyTempOrderChanged",
443
+ value: function notifyTempOrderChanged() {
444
+ if (!this.store.tempOrder) return;
445
+ this.store.tempOrder = _objectSpread(_objectSpread({}, this.store.tempOrder), {}, {
446
+ products: _toConsumableArray(this.store.tempOrder.products),
447
+ bookings: this.store.tempOrder.bookings ? _toConsumableArray(this.store.tempOrder.bookings) : []
448
+ });
449
+ this.persistTempOrder();
450
+ }
441
451
 
442
452
  // ─── TempOrder: 创建 & 获取 ───
443
453
  }, {
@@ -886,6 +896,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
886
896
  var discountList = getAllDiscountList(item);
887
897
  item._origin.product.discount_list = discountList;
888
898
 
899
+ // 为预约补齐 holder 信息
900
+ ensureCartItemOriginHolder(item);
901
+
889
902
  // 购物车是否为普通商品
890
903
  if (isNormalProduct(item._origin)) {
891
904
  var _order$relation_forms;
@@ -235,6 +235,8 @@ export interface OrderModuleAPI {
235
235
  updateProductInOrder: (params: UpdateProductInOrderParams) => Promise<ScanOrderOrderProduct[]>;
236
236
  removeProductFromOrder: (identity: ScanOrderOrderProductIdentity) => Promise<ScanOrderOrderProduct[]>;
237
237
  persistTempOrder: () => void;
238
+ /** 提交 tempOrder 变更并触发 `{moduleName}:changed` 事件 */
239
+ notifyTempOrderChanged: () => void;
238
240
  submitTempOrder: <T = any>(params?: {
239
241
  cacheId?: string;
240
242
  platform?: string;
@@ -86,6 +86,15 @@ export declare const mergeRelationForms: (relationForms: {
86
86
  form_id: number;
87
87
  form_record_ids: number[];
88
88
  }[];
89
+ export interface CartOrderHolder {
90
+ customer_id?: number;
91
+ form_id: number | string;
92
+ form_record: (number | string)[] | null;
93
+ }
94
+ /**
95
+ * 为购物车行补齐订单所需的 holder 信息(与 cartAccount 结构保持一致)
96
+ */
97
+ export declare function ensureCartItemOriginHolder(cartItem: CartItem): void;
89
98
  export declare const getAllDiscountList: (cartItem: CartItem) => any;
90
99
  export declare function createUuidV4(): string;
91
100
  export declare function isTempOrder(data: any): data is ScanOrderTempOrder;
@@ -18,6 +18,7 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
18
18
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
19
19
  import dayjs from "dayjs";
20
20
  import Decimal from 'decimal.js';
21
+ import { getProductHolderConfig } from "../Holder/utils";
21
22
  import { buildProductLineFingerprint, createEmptySummary } from "../../solution/ScanOrder/utils";
22
23
  /**
23
24
  * 把"含 option 的主商品单价"与 bundle 合成"单行 composite 单价"。
@@ -259,10 +260,37 @@ export var mergeRelationForms = function mergeRelationForms(relationForms) {
259
260
  return item.form_record_ids.length > 0;
260
261
  }); // 过滤掉没有有效记录的表单
261
262
  };
263
+ function resolveCartItemHolderCustomerId(cartItem) {
264
+ var _origin$metadata, _ref5, _origin$holder$custom, _origin$holder, _account$_origin;
265
+ var origin = cartItem._origin;
266
+ var account = origin === null || origin === void 0 || (_origin$metadata = origin.metadata) === null || _origin$metadata === void 0 ? void 0 : _origin$metadata.account;
267
+ return (_ref5 = (_origin$holder$custom = origin === null || origin === void 0 || (_origin$holder = origin.holder) === null || _origin$holder === void 0 ? void 0 : _origin$holder.customer_id) !== null && _origin$holder$custom !== void 0 ? _origin$holder$custom : account === null || account === void 0 || (_account$_origin = account._origin) === null || _account$_origin === void 0 ? void 0 : _account$_origin.customer_id) !== null && _ref5 !== void 0 ? _ref5 : account === null || account === void 0 ? void 0 : account.customer_id;
268
+ }
269
+
270
+ /**
271
+ * 为购物车行补齐订单所需的 holder 信息(与 cartAccount 结构保持一致)
272
+ */
273
+ export function ensureCartItemOriginHolder(cartItem) {
274
+ var _cartItem$_origin, _cartItem$_productIni;
275
+ if (cartItem !== null && cartItem !== void 0 && (_cartItem$_origin = cartItem._origin) !== null && _cartItem$_origin !== void 0 && _cartItem$_origin.holder) {
276
+ return;
277
+ }
278
+ var holderConfig = getProductHolderConfig((_cartItem$_productIni = cartItem === null || cartItem === void 0 ? void 0 : cartItem._productInit) !== null && _cartItem$_productIni !== void 0 ? _cartItem$_productIni : cartItem === null || cartItem === void 0 ? void 0 : cartItem._productOrigin);
279
+ var formRecordId = cartItem === null || cartItem === void 0 ? void 0 : cartItem.holder_id;
280
+ if (!(holderConfig !== null && holderConfig !== void 0 && holderConfig.resource_id) || formRecordId == null) {
281
+ return;
282
+ }
283
+ cartItem._origin.holder = {
284
+ customer_id: resolveCartItemHolderCustomerId(cartItem),
285
+ form_id: holderConfig.resource_id,
286
+ form_record: [formRecordId]
287
+ };
288
+ }
289
+ ;
262
290
  export var getAllDiscountList = function getAllDiscountList(cartItem) {
263
- var _cartItem$_origin, _cartItem$_origin2;
264
- var discountList = (cartItem === null || cartItem === void 0 || (_cartItem$_origin = cartItem._origin) === null || _cartItem$_origin === void 0 || (_cartItem$_origin = _cartItem$_origin.product) === null || _cartItem$_origin === void 0 ? void 0 : _cartItem$_origin.discount_list) || [];
265
- ((cartItem === null || cartItem === void 0 || (_cartItem$_origin2 = cartItem._origin) === null || _cartItem$_origin2 === void 0 || (_cartItem$_origin2 = _cartItem$_origin2.product) === null || _cartItem$_origin2 === void 0 ? void 0 : _cartItem$_origin2.product_bundle) || []).forEach(function (item) {
291
+ var _cartItem$_origin2, _cartItem$_origin3;
292
+ var discountList = (cartItem === null || cartItem === void 0 || (_cartItem$_origin2 = cartItem._origin) === null || _cartItem$_origin2 === void 0 || (_cartItem$_origin2 = _cartItem$_origin2.product) === null || _cartItem$_origin2 === void 0 ? void 0 : _cartItem$_origin2.discount_list) || [];
293
+ ((cartItem === null || cartItem === void 0 || (_cartItem$_origin3 = cartItem._origin) === null || _cartItem$_origin3 === void 0 || (_cartItem$_origin3 = _cartItem$_origin3.product) === null || _cartItem$_origin3 === void 0 ? void 0 : _cartItem$_origin3.product_bundle) || []).forEach(function (item) {
266
294
  discountList = [].concat(_toConsumableArray(discountList), _toConsumableArray((item === null || item === void 0 ? void 0 : item.discount_list) || []));
267
295
  item.discount_list = undefined;
268
296
  });
@@ -334,7 +362,7 @@ function toBundleCustomPriceString(value) {
334
362
  function formatSubmitBundleItems(bundle) {
335
363
  if (!Array.isArray(bundle)) return [];
336
364
  return bundle.map(function (b) {
337
- var _rawBundle$bundle_sel, _rawBundle$price_type, _rawBundle$surcharge_, _rawBundle$is_charge_, _rawBundle$bundle_var, _rawBundle$extension_, _rawBundle$extension_2, _rawBundle$price_type2, _ref5, _rawBundle$custom_pri;
365
+ var _rawBundle$bundle_sel, _rawBundle$price_type, _rawBundle$surcharge_, _rawBundle$is_charge_, _rawBundle$bundle_var, _rawBundle$extension_, _rawBundle$extension_2, _rawBundle$price_type2, _ref6, _rawBundle$custom_pri;
338
366
  var rawBundle = b && _typeof(b) === 'object' ? b : {};
339
367
  var existedMetadata = rawBundle.metadata && _typeof(rawBundle.metadata) === 'object' ? rawBundle.metadata : {};
340
368
  var sellingPriceNum = toBundleNumber((_rawBundle$bundle_sel = rawBundle.bundle_selling_price) !== null && _rawBundle$bundle_sel !== void 0 ? _rawBundle$bundle_sel : rawBundle.price, 0);
@@ -358,7 +386,7 @@ function formatSubmitBundleItems(bundle) {
358
386
  price_type: priceType,
359
387
  price_type_ext: (_rawBundle$price_type2 = rawBundle.price_type_ext) !== null && _rawBundle$price_type2 !== void 0 ? _rawBundle$price_type2 : '',
360
388
  // custom_price: customPriceStr,
361
- custom_price_type: (_ref5 = (_rawBundle$custom_pri = rawBundle.custom_price_type) !== null && _rawBundle$custom_pri !== void 0 ? _rawBundle$custom_pri : priceType) !== null && _ref5 !== void 0 ? _ref5 : '',
389
+ custom_price_type: (_ref6 = (_rawBundle$custom_pri = rawBundle.custom_price_type) !== null && _rawBundle$custom_pri !== void 0 ? _rawBundle$custom_pri : priceType) !== null && _ref6 !== void 0 ? _ref6 : '',
362
390
  bundle_selling_price: sellingPriceNum,
363
391
  option: formatSubmitOptionItems(rawBundle.option),
364
392
  bundle_group_id: rawBundle === null || rawBundle === void 0 ? void 0 : rawBundle.group_id,
@@ -520,7 +548,7 @@ export function createDefaultTempOrder(params) {
520
548
  };
521
549
  }
522
550
  export function buildSubmitPayload(params) {
523
- var _ref6, _ref7, _ref8, _tempOrder$is_price_i, _tempOrder$is_deposit;
551
+ var _ref7, _ref8, _ref9, _tempOrder$is_price_i, _tempOrder$is_deposit;
524
552
  var tempOrder = params.tempOrder,
525
553
  cacheId = params.cacheId,
526
554
  _params$now = params.now,
@@ -568,10 +596,10 @@ export function buildSubmitPayload(params) {
568
596
  var payload = _objectSpread(_objectSpread({}, tempOrderRest), {}, {
569
597
  platform: normalizeSubmitPlatform(platform !== null && platform !== void 0 ? platform : tempOrder.platform),
570
598
  request_unique_idempotency_token: cacheId,
571
- type: (_ref6 = type !== null && type !== void 0 ? type : tempOrder.type) !== null && _ref6 !== void 0 ? _ref6 : 'table-order',
572
- business_code: (_ref7 = businessCode !== null && businessCode !== void 0 ? businessCode : tempOrder.business_code) !== null && _ref7 !== void 0 ? _ref7 : 'table-order',
599
+ type: (_ref7 = type !== null && type !== void 0 ? type : tempOrder.type) !== null && _ref7 !== void 0 ? _ref7 : 'table-order',
600
+ business_code: (_ref8 = businessCode !== null && businessCode !== void 0 ? businessCode : tempOrder.business_code) !== null && _ref8 !== void 0 ? _ref8 : 'table-order',
573
601
  sales_channel: tempOrder.sales_channel || 'my_pisel',
574
- order_sales_channel: (_ref8 = channel !== null && channel !== void 0 ? channel : tempOrder.order_sales_channel) !== null && _ref8 !== void 0 ? _ref8 : 'online_store',
602
+ order_sales_channel: (_ref9 = channel !== null && channel !== void 0 ? channel : tempOrder.order_sales_channel) !== null && _ref9 !== void 0 ? _ref9 : 'online_store',
575
603
  status: tempOrder.status || 'normal',
576
604
  payment_status: tempOrder.payment_status || 'payment_processing',
577
605
  // shipping_status: tempOrder.shipping_status || 'unfulfilled',
@@ -595,10 +623,10 @@ export function buildSubmitPayload(params) {
595
623
  // holder: tempOrder.holder || null,
596
624
  // summary,
597
625
  metadata: function () {
598
- var _ref9 = tempOrder.metadata || {},
599
- _collectPax = _ref9.collect_pax,
600
- _tableOccupancyDuration = _ref9.table_occupancy_duration,
601
- rest = _objectWithoutProperties(_ref9, _excluded3);
626
+ var _ref10 = tempOrder.metadata || {},
627
+ _collectPax = _ref10.collect_pax,
628
+ _tableOccupancyDuration = _ref10.table_occupancy_duration,
629
+ rest = _objectWithoutProperties(_ref10, _excluded3);
602
630
  return _objectSpread({}, rest);
603
631
  }(),
604
632
  products: (tempOrder.products || []).map(function (product) {
@@ -16,6 +16,7 @@ export interface WindowPlugin extends Plugin {
16
16
  history: History;
17
17
  interaction?: any;
18
18
  getWalletPassEvaluator?: () => WalletPassEvaluator;
19
+ getLocalStorage?: (key: string) => string | null;
19
20
  }
20
21
  /**
21
22
  * 简单的 Storage 接口实现
@@ -367,7 +367,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
367
367
  };
368
368
  setOtherData(key: string, value: any): void;
369
369
  getOtherData(key: string): any;
370
- getProductTypeById(id: number): Promise<"normal" | "duration" | "session">;
370
+ getProductTypeById(id: number): Promise<"duration" | "session" | "normal">;
371
371
  /**
372
372
  * 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
373
373
  *
@@ -1213,13 +1213,16 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1213
1213
  }
1214
1214
  }
1215
1215
  try {
1216
- var _account;
1217
- this.store.holder.ensureFormByProduct({
1218
- product: productData,
1219
- customer_id: (_account = account) !== null && _account !== void 0 && _account.id ? Number(account.id) : 16121,
1220
- shop_id: (productData === null || productData === void 0 ? void 0 : productData.shop_id) || '',
1221
- useCache: true
1222
- });
1216
+ var _this$window, _this$window$getLocal;
1217
+ var customer = JSON.parse(((_this$window = this.window) === null || _this$window === void 0 || (_this$window$getLocal = _this$window.getLocalStorage) === null || _this$window$getLocal === void 0 ? void 0 : _this$window$getLocal.call(_this$window, 'customer')) || '{}');
1218
+ if (customer !== null && customer !== void 0 && customer.id) {
1219
+ this.store.holder.ensureFormByProduct({
1220
+ product: productData,
1221
+ customer_id: Number(customer.id),
1222
+ shop_id: (productData === null || productData === void 0 ? void 0 : productData.shop_id) || '',
1223
+ useCache: true
1224
+ });
1225
+ }
1223
1226
  } catch (error) {
1224
1227
  console.error('[BookingByStep] 加载 holder 表单失败', error);
1225
1228
  }
@@ -7,6 +7,7 @@ import type { OpenDataAvailabilityResult } from '../../modules/OpenData';
7
7
  import type { ProductData } from '../../modules/Product/types';
8
8
  import { type CartItemSummary, type PaxInfo, type QuantityCheckResult, type QuantityLimitResult } from '../../model/strategy/adapter/itemRule';
9
9
  import type { StrategyConfig } from '../../model/strategy/type';
10
+ import type { IAppendFormRecordParams } from '../../modules/Holder/types';
10
11
  export * from './types';
11
12
  interface VenueBookingItemRuleRuntimeConfig {
12
13
  strategyConfigs?: StrategyConfig[];
@@ -52,6 +53,13 @@ export declare class VenueBookingImpl extends BaseModule implements Module {
52
53
  constructor(name?: string, version?: string);
53
54
  private normalizeCustomerId;
54
55
  private resolveCustomerIdFromLoginPayload;
56
+ private resolveHolderCustomerId;
57
+ private ensureProductHolderForm;
58
+ /**
59
+ * 按商品 holder_config 预加载表单数据到 holderMap。
60
+ * appointment_booking 在加购时触发;venueBooking 在商品加载后预加载,避免 getHolderFormMap 为空。
61
+ */
62
+ private preloadHolderForms;
55
63
  private clearLoginEffectListeners;
56
64
  private registerLoginEffect;
57
65
  private registerCustomerLoginListeners;
@@ -193,6 +201,15 @@ export declare class VenueBookingImpl extends BaseModule implements Module {
193
201
  setUIState(key: string, value: any): void;
194
202
  getUIState<T = any>(key: string): T | undefined;
195
203
  deleteUIState(key: string): void;
204
+ setBookingHolder(bookingUid: string, holder: any): void;
205
+ /**
206
+ * 获取 holder 表单 map
207
+ */
208
+ getHolderFormMap(): import("../../modules/Holder").HolderFormMap;
209
+ /**
210
+ * 添加表单记录
211
+ */
212
+ appendFormRecord(params: IAppendFormRecordParams): import("../../modules/Holder").IFormRecord;
196
213
  checkOpenDataAvailability(): Promise<OpenDataAvailabilityResult>;
197
214
  setOtherParams(params: Record<string, any>, { cover }?: {
198
215
  cover?: boolean;