@pisell/pisellos 0.10.16 → 0.10.18

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.
Files changed (63) hide show
  1. package/dist/model/strategy/adapter/promotion/index.js +9 -0
  2. package/dist/modules/OpenData/index.d.ts +5 -2
  3. package/dist/modules/OpenData/index.js +27 -12
  4. package/dist/modules/OpenData/types.d.ts +42 -0
  5. package/dist/modules/OpenData/types.js +7 -1
  6. package/dist/modules/OpenData/utils.d.ts +15 -1
  7. package/dist/modules/OpenData/utils.js +85 -0
  8. package/dist/modules/Order/index.d.ts +3 -1
  9. package/dist/modules/Order/index.js +68 -44
  10. package/dist/modules/Order/types.d.ts +3 -0
  11. package/dist/modules/Order/types.js +1 -0
  12. package/dist/modules/ProductList/index.js +96 -74
  13. package/dist/modules/Rules/index.js +11 -8
  14. package/dist/modules/SalesSummary/index.js +6 -4
  15. package/dist/server/index.d.ts +11 -0
  16. package/dist/server/index.js +845 -481
  17. package/dist/server/modules/order/index.d.ts +8 -0
  18. package/dist/server/modules/order/index.js +251 -215
  19. package/dist/server/utils/small-ticket.d.ts +9 -1
  20. package/dist/server/utils/small-ticket.js +117 -43
  21. package/dist/solution/BaseSales/index.d.ts +7 -0
  22. package/dist/solution/BaseSales/index.js +251 -144
  23. package/dist/solution/BookingByStep/index.d.ts +2 -2
  24. package/dist/solution/BookingTicket/index.d.ts +14 -19
  25. package/dist/solution/BookingTicket/index.js +545 -429
  26. package/dist/solution/Sales/index.d.ts +20 -4
  27. package/dist/solution/Sales/index.js +348 -75
  28. package/dist/solution/Sales/types.d.ts +10 -0
  29. package/dist/solution/UnifiedBookingSales/index.d.ts +5 -4
  30. package/dist/solution/UnifiedBookingSales/index.js +495 -422
  31. package/dist/solution/UnifiedBookingSales/types.d.ts +7 -1
  32. package/lib/model/strategy/adapter/promotion/index.js +1 -46
  33. package/lib/modules/OpenData/index.d.ts +5 -2
  34. package/lib/modules/OpenData/index.js +50 -3
  35. package/lib/modules/OpenData/types.d.ts +42 -0
  36. package/lib/modules/OpenData/types.js +9 -1
  37. package/lib/modules/OpenData/utils.d.ts +15 -1
  38. package/lib/modules/OpenData/utils.js +85 -0
  39. package/lib/modules/Order/index.d.ts +3 -1
  40. package/lib/modules/Order/index.js +41 -21
  41. package/lib/modules/Order/types.d.ts +3 -0
  42. package/lib/modules/Order/types.js +1 -0
  43. package/lib/modules/ProductList/index.js +9 -6
  44. package/lib/modules/Rules/index.js +8 -6
  45. package/lib/modules/SalesSummary/index.js +3 -1
  46. package/lib/server/index.d.ts +11 -0
  47. package/lib/server/index.js +395 -96
  48. package/lib/server/modules/order/index.d.ts +8 -0
  49. package/lib/server/modules/order/index.js +23 -0
  50. package/lib/server/utils/small-ticket.d.ts +9 -1
  51. package/lib/server/utils/small-ticket.js +107 -35
  52. package/lib/solution/BaseSales/index.d.ts +7 -0
  53. package/lib/solution/BaseSales/index.js +125 -28
  54. package/lib/solution/BookingByStep/index.d.ts +2 -2
  55. package/lib/solution/BookingTicket/index.d.ts +14 -19
  56. package/lib/solution/BookingTicket/index.js +70 -17
  57. package/lib/solution/Sales/index.d.ts +20 -4
  58. package/lib/solution/Sales/index.js +183 -15
  59. package/lib/solution/Sales/types.d.ts +10 -0
  60. package/lib/solution/UnifiedBookingSales/index.d.ts +5 -4
  61. package/lib/solution/UnifiedBookingSales/index.js +41 -15
  62. package/lib/solution/UnifiedBookingSales/types.d.ts +7 -1
  63. package/package.json +1 -1
@@ -0,0 +1,9 @@
1
+ // 导出评估器
2
+ export { PromotionEvaluator } from "./evaluator";
3
+
4
+ // 导出适配器
5
+ export { PromotionAdapter } from "./adapter";
6
+ export { default } from "./adapter";
7
+
8
+ // 导出策略配置示例常量
9
+ export { X_ITEMS_FOR_Y_PRICE_STRATEGY, BUY_X_GET_Y_FREE_STRATEGY, ITEM_REWARD_STRATEGY } from "./examples";
@@ -1,9 +1,9 @@
1
1
  import { Module, PisellCore, ModuleOptions } from '../../types';
2
2
  import { BaseModule } from '../BaseModule';
3
3
  import type { ScheduleModule } from '../Schedule';
4
- import type { OpenDataConfig, OpenDataFetchParams, OpenDataAvailabilityResult } from './types';
4
+ import type { OpenDataConfig, OpenDataFetchParams, OpenDataAvailabilityResult, InvoiceLayoutConfig, InvoiceTemplateSettings } from './types';
5
5
  export * from './types';
6
- export { computeAvailability } from './utils';
6
+ export { computeAvailability, getDefaultInvoiceLayoutConfig, getDefaultInvoiceTemplateSettings, normalizeInvoiceLayoutConfig, normalizeInvoiceTemplateSettings, normalizeRawInvoiceTemplateSettings, } from './utils';
7
7
  export declare class OpenDataModule extends BaseModule implements Module {
8
8
  protected defaultName: string;
9
9
  protected defaultVersion: string;
@@ -15,6 +15,7 @@ export declare class OpenDataModule extends BaseModule implements Module {
15
15
  private openCache;
16
16
  private fatherModule;
17
17
  private otherParams;
18
+ private fetchRevision;
18
19
  constructor(name?: string, version?: string);
19
20
  initialize(core: PisellCore, options: ModuleOptions): Promise<void>;
20
21
  /**
@@ -26,6 +27,8 @@ export declare class OpenDataModule extends BaseModule implements Module {
26
27
  updateOtherParams(params: Record<string, any>): void;
27
28
  fetchOpenData(params: OpenDataFetchParams): Promise<OpenDataConfig>;
28
29
  getOpenData(): OpenDataConfig | null;
30
+ getInvoiceLayoutConfig(): InvoiceLayoutConfig;
31
+ getInvoiceTemplateSettings(): InvoiceTemplateSettings;
29
32
  getLastFetchedAt(): number | null;
30
33
  /** 清除内存与 sessionStorage 镜像中的 OpenData,供宿主切店时调用。 */
31
34
  clearCache(): void;
@@ -16,9 +16,9 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
16
16
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
17
17
  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); }
18
18
  import { BaseModule } from "../BaseModule";
19
- import { computeAvailability } from "./utils";
19
+ import { computeAvailability, normalizeInvoiceLayoutConfig, normalizeInvoiceTemplateSettings } from "./utils";
20
20
  export * from "./types";
21
- export { computeAvailability } from "./utils";
21
+ export { computeAvailability, getDefaultInvoiceLayoutConfig, getDefaultInvoiceTemplateSettings, normalizeInvoiceLayoutConfig, normalizeInvoiceTemplateSettings, normalizeRawInvoiceTemplateSettings } from "./utils";
22
22
  export var OpenDataModule = /*#__PURE__*/function (_BaseModule) {
23
23
  _inherits(OpenDataModule, _BaseModule);
24
24
  var _super = _createSuper(OpenDataModule);
@@ -36,6 +36,7 @@ export var OpenDataModule = /*#__PURE__*/function (_BaseModule) {
36
36
  _defineProperty(_assertThisInitialized(_this), "openCache", false);
37
37
  _defineProperty(_assertThisInitialized(_this), "fatherModule", void 0);
38
38
  _defineProperty(_assertThisInitialized(_this), "otherParams", {});
39
+ _defineProperty(_assertThisInitialized(_this), "fetchRevision", 0);
39
40
  return _this;
40
41
  }
41
42
  _createClass(OpenDataModule, [{
@@ -104,22 +105,23 @@ export var OpenDataModule = /*#__PURE__*/function (_BaseModule) {
104
105
  value: function () {
105
106
  var _fetchOpenData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(params) {
106
107
  var _this$appPlugin, _this$appPlugin$getDa;
107
- var getData, shopId, tenantId, headers, response, data;
108
+ var fetchRevision, getData, shopId, tenantId, headers, response, data;
108
109
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
109
110
  while (1) switch (_context2.prev = _context2.next) {
110
111
  case 0:
112
+ fetchRevision = ++this.fetchRevision;
111
113
  getData = (_this$appPlugin = this.appPlugin) === null || _this$appPlugin === void 0 || (_this$appPlugin$getDa = _this$appPlugin.getData) === null || _this$appPlugin$getDa === void 0 ? void 0 : _this$appPlugin$getDa.call(_this$appPlugin);
112
114
  shopId = getData === null || getData === void 0 ? void 0 : getData('shop_id');
113
115
  if (shopId) {
114
- _context2.next = 4;
116
+ _context2.next = 5;
115
117
  break;
116
118
  }
117
119
  throw new Error('[OpenDataModule] 无法获取 shop_id');
118
- case 4:
120
+ case 5:
119
121
  tenantId = getData === null || getData === void 0 ? void 0 : getData('tenant_id');
120
122
  headers = {};
121
123
  if (tenantId) headers['Tenant-Id'] = String(tenantId);
122
- _context2.next = 9;
124
+ _context2.next = 10;
123
125
  return this.request.post("/open/my-pisell/".concat(shopId, "/setting"), {
124
126
  scope: params.scope,
125
127
  target: params.target,
@@ -130,17 +132,19 @@ export var OpenDataModule = /*#__PURE__*/function (_BaseModule) {
130
132
  prefix: false,
131
133
  headers: headers
132
134
  });
133
- case 9:
135
+ case 10:
134
136
  response = _context2.sent;
135
137
  if (!((response === null || response === void 0 ? void 0 : response.status) === false)) {
136
- _context2.next = 12;
138
+ _context2.next = 13;
137
139
  break;
138
140
  }
139
141
  throw new Error((response === null || response === void 0 ? void 0 : response.message) || '获取 OpenData 配置失败');
140
- case 12:
141
- data = (response === null || response === void 0 ? void 0 : response.data) || {};
142
- this.store.data = data;
143
- this.store.lastFetchedAt = Date.now();
142
+ case 13:
143
+ data = (response === null || response === void 0 ? void 0 : response.data) || {}; // clearCache() 或后续请求发生后,旧响应不得复活已失效的 target 配置。
144
+ if (fetchRevision === this.fetchRevision) {
145
+ this.store.data = data;
146
+ this.store.lastFetchedAt = Date.now();
147
+ }
144
148
  return _context2.abrupt("return", data);
145
149
  case 16:
146
150
  case "end":
@@ -158,6 +162,16 @@ export var OpenDataModule = /*#__PURE__*/function (_BaseModule) {
158
162
  value: function getOpenData() {
159
163
  return this.store.data;
160
164
  }
165
+ }, {
166
+ key: "getInvoiceLayoutConfig",
167
+ value: function getInvoiceLayoutConfig() {
168
+ return normalizeInvoiceLayoutConfig(this.store.data);
169
+ }
170
+ }, {
171
+ key: "getInvoiceTemplateSettings",
172
+ value: function getInvoiceTemplateSettings() {
173
+ return normalizeInvoiceTemplateSettings(this.store.data);
174
+ }
161
175
  }, {
162
176
  key: "getLastFetchedAt",
163
177
  value: function getLastFetchedAt() {
@@ -169,6 +183,7 @@ export var OpenDataModule = /*#__PURE__*/function (_BaseModule) {
169
183
  }, {
170
184
  key: "clearCache",
171
185
  value: function clearCache() {
186
+ this.fetchRevision += 1;
172
187
  this.store.data = null;
173
188
  this.store.lastFetchedAt = null;
174
189
  }
@@ -8,6 +8,40 @@ export interface MultiLangObject {
8
8
  original?: string;
9
9
  [key: string]: string | undefined;
10
10
  }
11
+ export declare const INVOICE_MODULE_KEYS: readonly ["reference", "brand", "custom_1", "order", "handover", "customer", "line_groups", "settlement", "custom_2", "payment", "card", "total_savings", "custom_3", "barcode"];
12
+ export type InvoiceModuleKey = (typeof INVOICE_MODULE_KEYS)[number];
13
+ /**
14
+ * Documents Registry 中的 Invoice 模块配置。
15
+ *
16
+ * 模块 key、显隐值及模块私有字段均由 Registry/Native 约定,OS 不做枚举收窄或改写。
17
+ */
18
+ export interface InvoiceTemplateModuleConfig {
19
+ key: string;
20
+ is_show?: unknown;
21
+ [key: string]: unknown;
22
+ }
23
+ export interface InvoiceModuleConfig extends InvoiceTemplateModuleConfig {
24
+ }
25
+ export interface InvoiceLayoutConfig {
26
+ locale?: string;
27
+ module: InvoiceModuleConfig[];
28
+ }
29
+ export interface InvoiceTemplateSettings {
30
+ template: string;
31
+ language: Record<string, number>;
32
+ modules: InvoiceTemplateModuleConfig[];
33
+ [key: string]: unknown;
34
+ }
35
+ export type RawInvoiceEditConfig = string | {
36
+ language?: unknown;
37
+ modules?: unknown;
38
+ [key: string]: unknown;
39
+ };
40
+ export type RawInvoiceLayoutConfig = string | {
41
+ locale?: unknown;
42
+ module?: unknown[];
43
+ [key: string]: unknown;
44
+ };
11
45
  export interface OpenDataConfig {
12
46
  'basic.enable'?: boolean;
13
47
  'basic.code'?: string | null;
@@ -45,6 +79,14 @@ export interface OpenDataConfig {
45
79
  label: string;
46
80
  value: number;
47
81
  }>;
82
+ 'documents.invoice_template'?: string;
83
+ 'documents.invoice_edit'?: RawInvoiceEditConfig;
84
+ /** @deprecated 仅保留旧调用方的类型兼容,Invoice 读取逻辑不再消费该字段。 */
85
+ 'documents.invoice'?: RawInvoiceLayoutConfig;
86
+ /** @deprecated Invoice 读取逻辑只消费扁平的 documents.invoice_* 字段。 */
87
+ documents?: {
88
+ invoice?: RawInvoiceLayoutConfig;
89
+ };
48
90
  [key: string]: any;
49
91
  }
50
92
  export interface OpenDataState {
@@ -1 +1,7 @@
1
- export {};
1
+ export var INVOICE_MODULE_KEYS = ['reference', 'brand', 'custom_1', 'order', 'handover', 'customer', 'line_groups', 'settlement', 'custom_2', 'payment', 'card', 'total_savings', 'custom_3', 'barcode'];
2
+
3
+ /**
4
+ * Documents Registry 中的 Invoice 模块配置。
5
+ *
6
+ * 模块 key、显隐值及模块私有字段均由 Registry/Native 约定,OS 不做枚举收窄或改写。
7
+ */
@@ -1,2 +1,16 @@
1
- import type { OpenDataAvailabilityResult, ComputeAvailabilityParams } from './types';
1
+ import type { OpenDataConfig, OpenDataAvailabilityResult, ComputeAvailabilityParams, InvoiceLayoutConfig, InvoiceTemplateSettings } from './types';
2
+ export declare function getDefaultInvoiceLayoutConfig(): InvoiceLayoutConfig;
3
+ export declare function getDefaultInvoiceTemplateSettings(): InvoiceTemplateSettings;
4
+ /**
5
+ * 规范化已经提取出的公开 template_settings 值,供打印入口复用。
6
+ */
7
+ export declare function normalizeRawInvoiceTemplateSettings(value: unknown): InvoiceTemplateSettings;
8
+ /**
9
+ * 从 OpenData Documents section 的两个扁平字段中构造 Native Invoice 配置。
10
+ */
11
+ export declare function normalizeInvoiceTemplateSettings(config: OpenDataConfig | null | undefined): InvoiceTemplateSettings;
12
+ /**
13
+ * 将 invoice_edit.modules 原样投影为 Web Invoice 使用的 module 字段。
14
+ */
15
+ export declare function normalizeInvoiceLayoutConfig(config: OpenDataConfig | null | undefined): InvoiceLayoutConfig;
2
16
  export declare function computeAvailability(params: ComputeAvailabilityParams): OpenDataAvailabilityResult;
@@ -1,6 +1,91 @@
1
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
2
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
3
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
4
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
5
+ 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); }
1
6
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
7
  import dayjs from 'dayjs';
3
8
  import { getDateIsInSchedule } from "../Schedule/getDateIsInSchedule";
9
+ function isRecord(value) {
10
+ return !!value && _typeof(value) === 'object' && !Array.isArray(value);
11
+ }
12
+ function parseInvoiceRecord(value) {
13
+ var parsed = value;
14
+ if (typeof parsed === 'string') {
15
+ try {
16
+ parsed = JSON.parse(parsed);
17
+ } catch (_unused) {
18
+ return null;
19
+ }
20
+ }
21
+ return isRecord(parsed) ? parsed : null;
22
+ }
23
+ export function getDefaultInvoiceLayoutConfig() {
24
+ return {
25
+ module: []
26
+ };
27
+ }
28
+ export function getDefaultInvoiceTemplateSettings() {
29
+ return {
30
+ template: 'DEFAULT',
31
+ language: {},
32
+ modules: []
33
+ };
34
+ }
35
+ function normalizeInvoiceTemplate(value) {
36
+ if (typeof value !== 'string' || value.trim().length === 0) return 'DEFAULT';
37
+ return value.trim().toUpperCase() === 'DEFAULT' ? 'DEFAULT' : value;
38
+ }
39
+ function normalizeInvoiceLanguage(value) {
40
+ if (!isRecord(value)) return {};
41
+ if (Object.values(value).some(function (item) {
42
+ return typeof item !== 'number';
43
+ })) return {};
44
+ return _objectSpread({}, value);
45
+ }
46
+ function normalizeInvoiceModules(value) {
47
+ if (!Array.isArray(value)) return [];
48
+ if (value.some(function (item) {
49
+ return !isRecord(item) || typeof item.key !== 'string';
50
+ })) {
51
+ return [];
52
+ }
53
+ return value.map(function (item) {
54
+ return _objectSpread({}, item);
55
+ });
56
+ }
57
+
58
+ /**
59
+ * 规范化已经提取出的公开 template_settings 值,供打印入口复用。
60
+ */
61
+ export function normalizeRawInvoiceTemplateSettings(value) {
62
+ var parsed = parseInvoiceRecord(value);
63
+ if (!parsed) return getDefaultInvoiceTemplateSettings();
64
+ return _objectSpread(_objectSpread({}, parsed), {}, {
65
+ template: normalizeInvoiceTemplate(parsed.template),
66
+ language: normalizeInvoiceLanguage(parsed.language),
67
+ modules: normalizeInvoiceModules(parsed.modules)
68
+ });
69
+ }
70
+
71
+ /**
72
+ * 从 OpenData Documents section 的两个扁平字段中构造 Native Invoice 配置。
73
+ */
74
+ export function normalizeInvoiceTemplateSettings(config) {
75
+ var parsedEdit = parseInvoiceRecord(config === null || config === void 0 ? void 0 : config['documents.invoice_edit']);
76
+ return normalizeRawInvoiceTemplateSettings(_objectSpread(_objectSpread({}, parsedEdit !== null && parsedEdit !== void 0 ? parsedEdit : {}), {}, {
77
+ template: normalizeInvoiceTemplate(config === null || config === void 0 ? void 0 : config['documents.invoice_template'])
78
+ }));
79
+ }
80
+
81
+ /**
82
+ * 将 invoice_edit.modules 原样投影为 Web Invoice 使用的 module 字段。
83
+ */
84
+ export function normalizeInvoiceLayoutConfig(config) {
85
+ return {
86
+ module: normalizeInvoiceTemplateSettings(config).modules
87
+ };
88
+ }
4
89
  function toBoolean(value) {
5
90
  if (typeof value === 'boolean') return value;
6
91
  if (typeof value === 'string') return value === 'true' || value === '1';
@@ -182,6 +182,8 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
182
182
  private calculateOrderPaidPaymentTotal;
183
183
  private getDepositAmount;
184
184
  private normalizeDepositAmount;
185
+ private normalizeDepositFlag;
186
+ private getHistoricalDepositSnapshot;
185
187
  private getLastOrderDepositSnapshot;
186
188
  private getLastOrderSubmitSnapshot;
187
189
  private applyDepositAmountToSummary;
@@ -526,7 +528,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
526
528
  generateIdempotencyToken(): string;
527
529
  syncPaymentsToOrder<T = any>(params: SyncPaymentsToOrderParams): Promise<SyncPaymentsToOrderResult<T>>;
528
530
  createOrder(params: CommitOrderParams['query']): {
529
- type: "appointment_booking" | "virtual";
531
+ type: "virtual" | "appointment_booking";
530
532
  platform: string;
531
533
  sales_channel: string;
532
534
  order_sales_channel: string;
@@ -1584,21 +1584,32 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1584
1584
  return Decimal.max(new Decimal(Number(amount) || 0), 0).toDecimalPlaces(2).toFixed(2);
1585
1585
  }
1586
1586
  }, {
1587
- key: "getLastOrderDepositSnapshot",
1588
- value: function getLastOrderDepositSnapshot() {
1589
- var _lastOrderInfo$deposi, _lastOrderInfo$summar;
1590
- var lastOrderInfo = this.store.lastOrderInfo;
1591
- if (!lastOrderInfo || _typeof(lastOrderInfo) !== 'object') return null;
1592
- var rawDepositAmount = (_lastOrderInfo$deposi = lastOrderInfo.deposit_amount) !== null && _lastOrderInfo$deposi !== void 0 ? _lastOrderInfo$deposi : (_lastOrderInfo$summar = lastOrderInfo.summary) === null || _lastOrderInfo$summar === void 0 ? void 0 : _lastOrderInfo$summar.deposit_amount;
1587
+ key: "normalizeDepositFlag",
1588
+ value: function normalizeDepositFlag(value) {
1589
+ if (value === 0 || value === '0') return 0;
1590
+ if (value === 1 || value === '1') return 1;
1591
+ return null;
1592
+ }
1593
+ }, {
1594
+ key: "getHistoricalDepositSnapshot",
1595
+ value: function getHistoricalDepositSnapshot(source) {
1596
+ var _record$deposit_amoun, _record$summary, _this$normalizeDeposi;
1597
+ if (!source || _typeof(source) !== 'object') return null;
1598
+ var record = source;
1599
+ var rawDepositAmount = (_record$deposit_amoun = record.deposit_amount) !== null && _record$deposit_amoun !== void 0 ? _record$deposit_amoun : (_record$summary = record.summary) === null || _record$summary === void 0 ? void 0 : _record$summary.deposit_amount;
1593
1600
  var depositAmount = this.normalizeDepositAmount(rawDepositAmount !== null && rawDepositAmount !== void 0 ? rawDepositAmount : 0);
1594
- var hasDepositAmount = new Decimal(depositAmount).gt(0);
1595
- var isDeposit = Number(lastOrderInfo.is_deposit) === 1 || hasDepositAmount;
1596
- if (!isDeposit || !hasDepositAmount) return null;
1601
+ if (!new Decimal(depositAmount).gt(0)) return null;
1597
1602
  return {
1598
- isDeposit: 1,
1603
+ // 兼容历史数据:旧快照缺少 is_deposit 时,沿用正定金金额的推导规则。
1604
+ isDeposit: (_this$normalizeDeposi = this.normalizeDepositFlag(record.is_deposit)) !== null && _this$normalizeDeposi !== void 0 ? _this$normalizeDeposi : 1,
1599
1605
  depositAmount: depositAmount
1600
1606
  };
1601
1607
  }
1608
+ }, {
1609
+ key: "getLastOrderDepositSnapshot",
1610
+ value: function getLastOrderDepositSnapshot() {
1611
+ return this.getHistoricalDepositSnapshot(this.store.lastOrderInfo);
1612
+ }
1602
1613
  }, {
1603
1614
  key: "getLastOrderSubmitSnapshot",
1604
1615
  value: function getLastOrderSubmitSnapshot() {
@@ -1645,7 +1656,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1645
1656
  })
1646
1657
  });
1647
1658
  tempOrder.deposit_amount = snapshot.depositAmount;
1648
- tempOrder.is_deposit = tempOrder.is_deposit === 0 && new Decimal(tempOrder.deposit_amount || 0).gt(0) ? 0 : snapshot.isDeposit;
1659
+ tempOrder.is_deposit = snapshot.isDeposit;
1649
1660
  return nextSummary;
1650
1661
  }
1651
1662
  }, {
@@ -2355,6 +2366,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2355
2366
  }, {
2356
2367
  key: "restoreOriginalSnapshotIfProductsUnchanged",
2357
2368
  value: function restoreOriginalSnapshotIfProductsUnchanged(tempOrder, snapshot) {
2369
+ var _historicalDepositSna;
2358
2370
  // merge hydrate 的商品集合包含本地未提交行,但 summary 仍来自远端旧订单,不能复用。
2359
2371
  if (snapshot.requiresFullSummaryRecalculation === true) return null;
2360
2372
  var currentFingerprint = this.buildOrderProductsFingerprint(tempOrder.products);
@@ -2366,10 +2378,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2366
2378
  }
2367
2379
  var summary = _objectSpread(_objectSpread({}, createEmptySummary()), cloneDeep(snapshot.summary || {}));
2368
2380
  var shouldUseManualDepositOverride = Boolean(manualDepositOverride && manualDepositOverride.productStructuralFingerprint === this.buildOrderProductsStructuralFingerprint(tempOrder.products));
2381
+ var historicalDepositSnapshot = this.getHistoricalDepositSnapshot(snapshot);
2369
2382
  if (shouldUseManualDepositOverride) {
2370
2383
  summary = this.applyDepositAmountToSummary(tempOrder, summary, manualDepositOverride.amount);
2371
- } else if (manualDepositOverride) {
2372
- this.clearManualDepositOverride(tempOrder);
2384
+ } else {
2385
+ if (manualDepositOverride) {
2386
+ this.clearManualDepositOverride(tempOrder);
2387
+ }
2388
+ if (historicalDepositSnapshot) {
2389
+ summary = this.applyDepositAmountToSummary(tempOrder, summary, historicalDepositSnapshot.depositAmount);
2390
+ tempOrder.is_deposit = historicalDepositSnapshot.isDeposit;
2391
+ }
2373
2392
  }
2374
2393
  var isPayableAmountUnchanged = this.isSnapshotPayableAmountUnchanged(tempOrder, snapshot, summary);
2375
2394
  if (!isPayableAmountUnchanged) return null;
@@ -2386,8 +2405,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2386
2405
  tempOrder.surcharges = cloneDeep(snapshot.surcharges);
2387
2406
  }
2388
2407
  tempOrder.surcharge_fee = summary.surcharge_fee || tempOrder.surcharge_fee;
2389
- tempOrder.deposit_amount = summary.deposit_amount || '0.00';
2390
- tempOrder.is_deposit = summary.deposit_amount !== '0.00' ? 1 : 0;
2408
+ tempOrder.deposit_amount = this.normalizeDepositAmount(summary.deposit_amount || 0);
2409
+ tempOrder.is_deposit = shouldUseManualDepositOverride ? new Decimal(tempOrder.deposit_amount).gt(0) ? 1 : 0 : (_historicalDepositSna = historicalDepositSnapshot === null || historicalDepositSnapshot === void 0 ? void 0 : historicalDepositSnapshot.isDeposit) !== null && _historicalDepositSna !== void 0 ? _historicalDepositSna : new Decimal(tempOrder.deposit_amount).gt(0) ? 1 : 0;
2391
2410
  var previousSummary = this.store.summary;
2392
2411
  this.store.summary = summary;
2393
2412
  this.updateTempOrderPaymentStatus(tempOrder, {
@@ -3049,7 +3068,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3049
3068
  var isExistingDepositDisabled = tempOrder.is_deposit === 0 && new Decimal(tempOrder.deposit_amount || 0).gt(0);
3050
3069
  tempOrder.deposit_amount = depositAmount;
3051
3070
  tempOrder.is_deposit = hasDepositAmount && !isExistingDepositDisabled ? 1 : 0;
3052
- return this.applyLastOrderDepositSnapshot(tempOrder, nextSummary);
3071
+ return shouldUseManualDepositOverride ? nextSummary : this.applyLastOrderDepositSnapshot(tempOrder, nextSummary);
3053
3072
  }
3054
3073
  }, {
3055
3074
  key: "recalculateSummary",
@@ -5714,7 +5733,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5714
5733
  var _syncPaymentsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35(params) {
5715
5734
  var _this32 = this,
5716
5735
  _params$confirmPendin;
5717
- var tempOrder, needsPaymentNumber, devicePrefix, mappedPayments, shouldConfirmPendingVoucherPayments, effectivePayments, completion, orderPaidPaymentTotal, paymentStatus, paymentSyncIdempotencyToken, submitParams, submitResult;
5736
+ var tempOrder, needsPaymentNumber, devicePrefix, mappedPayments, shouldConfirmPendingVoucherPayments, effectivePayments, completion, orderPaidPaymentTotal, paymentStatus, paymentSyncIdempotencyToken, enhancePayload, submitParams, submitResult;
5718
5737
  return _regeneratorRuntime().wrap(function _callee35$(_context38) {
5719
5738
  while (1) switch (_context38.prev = _context38.next) {
5720
5739
  case 0:
@@ -5767,6 +5786,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5767
5786
  case 25:
5768
5787
  this.store.syncState = 'submitting';
5769
5788
  paymentSyncIdempotencyToken = this.buildPaymentSyncIdempotencyToken(tempOrder, effectivePayments);
5789
+ enhancePayload = function enhancePayload(payload, ctx) {
5790
+ var enhancedPayload = params.enhancePayload ? params.enhancePayload(payload, ctx) : payload;
5791
+ return _objectSpread(_objectSpread({}, enhancedPayload), {}, {
5792
+ request_unique_idempotency_token: paymentSyncIdempotencyToken
5793
+ });
5794
+ };
5770
5795
  submitParams = {
5771
5796
  payments: effectivePayments,
5772
5797
  paymentStatus: paymentStatus,
@@ -5774,34 +5799,29 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5774
5799
  businessCode: params.businessCode,
5775
5800
  channel: params.channel,
5776
5801
  confirmPendingVoucherPayments: true,
5777
- enhancePayload: function enhancePayload(payload) {
5778
- var nextPayload = _objectSpread(_objectSpread({}, payload), {}, {
5779
- request_unique_idempotency_token: paymentSyncIdempotencyToken
5780
- });
5781
- return nextPayload;
5782
- }
5802
+ enhancePayload: enhancePayload
5783
5803
  };
5784
5804
  if (!(params.checkoutSyncTaskEnabled === false)) {
5785
- _context38.next = 34;
5805
+ _context38.next = 35;
5786
5806
  break;
5787
5807
  }
5788
- _context38.next = 31;
5808
+ _context38.next = 32;
5789
5809
  return this.submitTempOrderAsync(submitParams);
5790
- case 31:
5810
+ case 32:
5791
5811
  _context38.t1 = _context38.sent;
5792
- _context38.next = 37;
5812
+ _context38.next = 38;
5793
5813
  break;
5794
- case 34:
5795
- _context38.next = 36;
5814
+ case 35:
5815
+ _context38.next = 37;
5796
5816
  return this.submitTempOrder(submitParams);
5797
- case 36:
5798
- _context38.t1 = _context38.sent;
5799
5817
  case 37:
5818
+ _context38.t1 = _context38.sent;
5819
+ case 38:
5800
5820
  submitResult = _context38.t1;
5801
5821
  return _context38.abrupt("return", _objectSpread(_objectSpread({}, completion), {}, {
5802
5822
  submitResult: submitResult
5803
5823
  }));
5804
- case 39:
5824
+ case 40:
5805
5825
  case "end":
5806
5826
  return _context38.stop();
5807
5827
  }
@@ -6267,7 +6287,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6267
6287
  value: (function () {
6268
6288
  var _hydrateTempOrderFromRecord = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee43(record, options) {
6269
6289
  var _sourceRaw$_extend, _this$store$discount26;
6270
- var sourceRaw, duplicateProductIdentityRepair, duplicateIdentityReadySource, identityReadySource, normalizedCollections, raw, hasIdentityChanges, identityLogMetadata, hasIdentityWarnings, isSessionStorageHydrate, isMergedSalesDetailHydrate, nextTempOrder, _this$store$discount24, _this$store$discount25, restoredSessionDiscounts, nextExtend, sourceLastOrderInfo, isDraftOrder, syntheticIdentityOptions, rawSummary, summarySurcharges, hadSyntheticDraftOrderId, hydratedEditDiscounts, currentDiscounts, currentScanDiscounts, hydratedDiscountIds, retainedScanDiscounts, nextDiscounts, shouldSkipEmptyDiscountSync, _this$store$discount27, _this$store$discount28;
6290
+ var sourceRaw, duplicateProductIdentityRepair, duplicateIdentityReadySource, identityReadySource, normalizedCollections, raw, hasIdentityChanges, identityLogMetadata, hasIdentityWarnings, isSessionStorageHydrate, isMergedSalesDetailHydrate, nextTempOrder, _this$store$discount24, _this$store$discount25, restoredSessionDiscounts, nextExtend, sourceLastOrderInfo, isDraftOrder, syntheticIdentityOptions, rawSummary, historicalDepositSnapshot, summarySurcharges, hadSyntheticDraftOrderId, hydratedEditDiscounts, currentDiscounts, currentScanDiscounts, hydratedDiscountIds, retainedScanDiscounts, nextDiscounts, shouldSkipEmptyDiscountSync, _this$store$discount27, _this$store$discount28;
6271
6291
  return _regeneratorRuntime().wrap(function _callee43$(_context46) {
6272
6292
  while (1) switch (_context46.prev = _context46.next) {
6273
6293
  case 0:
@@ -6351,6 +6371,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6351
6371
  externalSaleNumber: nextTempOrder.external_sale_number
6352
6372
  };
6353
6373
  rawSummary = raw.summary && _typeof(raw.summary) === 'object' ? raw.summary : {};
6374
+ historicalDepositSnapshot = this.getHistoricalDepositSnapshot(sourceLastOrderInfo);
6354
6375
  summarySurcharges = Array.isArray(rawSummary.surcharges) ? rawSummary.surcharges.map(function (s) {
6355
6376
  return _objectSpread({}, s || {});
6356
6377
  }) : cloneDeep(nextTempOrder.surcharges || []);
@@ -6358,7 +6379,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6358
6379
  surcharges: summarySurcharges
6359
6380
  });
6360
6381
  nextTempOrder._extend = _objectSpread(_objectSpread({}, nextTempOrder._extend || {}), {}, {
6361
- originalSalesSnapshot: _objectSpread({
6382
+ originalSalesSnapshot: _objectSpread(_objectSpread({
6362
6383
  summary: cloneDeep(this.store.summary),
6363
6384
  products: cloneDeep(nextTempOrder.products || []),
6364
6385
  bookings: cloneDeep(nextTempOrder.bookings || []),
@@ -6366,7 +6387,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6366
6387
  surcharges: cloneDeep(nextTempOrder.surcharges || []),
6367
6388
  shop_discount: nextTempOrder.shop_discount || '0.00',
6368
6389
  productFingerprint: this.buildOrderProductsFingerprint(nextTempOrder.products || [])
6369
- }, isMergedSalesDetailHydrate ? {
6390
+ }, historicalDepositSnapshot ? {
6391
+ is_deposit: historicalDepositSnapshot.isDeposit,
6392
+ deposit_amount: historicalDepositSnapshot.depositAmount
6393
+ } : {}), isMergedSalesDetailHydrate ? {
6370
6394
  requiresFullSummaryRecalculation: true
6371
6395
  } : {})
6372
6396
  });
@@ -6389,28 +6413,28 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6389
6413
  nextDiscounts = [].concat(_toConsumableArray(hydratedEditDiscounts), _toConsumableArray(retainedScanDiscounts));
6390
6414
  shouldSkipEmptyDiscountSync = nextDiscounts.length === 0 && currentDiscounts.length === 0;
6391
6415
  if (shouldSkipEmptyDiscountSync) {
6392
- _context46.next = 53;
6416
+ _context46.next = 54;
6393
6417
  break;
6394
6418
  }
6395
6419
  OrderModule.populateSavedAmounts(nextTempOrder.products, nextDiscounts);
6396
- _context46.next = 51;
6420
+ _context46.next = 52;
6397
6421
  return (_this$store$discount27 = this.store.discount) === null || _this$store$discount27 === void 0 ? void 0 : _this$store$discount27.setOriginalDiscountList(nextDiscounts);
6398
- case 51:
6399
- _context46.next = 53;
6422
+ case 52:
6423
+ _context46.next = 54;
6400
6424
  return (_this$store$discount28 = this.store.discount) === null || _this$store$discount28 === void 0 ? void 0 : _this$store$discount28.setDiscountList(nextDiscounts);
6401
- case 53:
6425
+ case 54:
6402
6426
  if (!(options !== null && options !== void 0 && options.recalcOnHydrate)) {
6403
- _context46.next = 56;
6427
+ _context46.next = 57;
6404
6428
  break;
6405
6429
  }
6406
- _context46.next = 56;
6430
+ _context46.next = 57;
6407
6431
  return this.recalculateSummary({
6408
6432
  createIfMissing: false
6409
6433
  });
6410
- case 56:
6434
+ case 57:
6411
6435
  this.persistTempOrder();
6412
6436
  return _context46.abrupt("return", nextTempOrder);
6413
- case 58:
6437
+ case 59:
6414
6438
  case "end":
6415
6439
  return _context46.stop();
6416
6440
  }
@@ -157,11 +157,13 @@ export interface OrderCustomerPatch {
157
157
  * 下单客户变更事件 payload。
158
158
  * - `patch`:tempOrder 上的协议字段视图(会随订单提交)
159
159
  * - `snapshot`:UI 富字段快照(仅本地,不随订单提交)
160
+ * - `source`:缺省表示真实业务变更;`detailHydrate` 仅表示打开详情时快照已就绪
160
161
  * 清空时整个 payload 为 null。
161
162
  */
162
163
  export interface OrderCustomerChangePayload {
163
164
  patch: OrderCustomerView;
164
165
  snapshot: ICustomer | null;
166
+ source?: 'detailHydrate';
165
167
  }
166
168
  export interface OrderScanCodeResult {
167
169
  isAvailable: boolean;
@@ -612,6 +614,7 @@ export interface SyncPaymentsToOrderParams {
612
614
  businessCode?: string;
613
615
  channel?: string;
614
616
  confirmPendingVoucherPayments?: boolean;
617
+ enhancePayload?: SubmitPayloadEnhancer;
615
618
  }
616
619
  export interface SyncPaymentsToOrderResult<T = any> {
617
620
  isFullyPaid: boolean;
@@ -60,6 +60,7 @@ export var OrderHooks = /*#__PURE__*/function (OrderHooks) {
60
60
  * 下单客户变更事件 payload。
61
61
  * - `patch`:tempOrder 上的协议字段视图(会随订单提交)
62
62
  * - `snapshot`:UI 富字段快照(仅本地,不随订单提交)
63
+ * - `source`:缺省表示真实业务变更;`detailHydrate` 仅表示打开详情时快照已就绪
63
64
  * 清空时整个 payload 为 null。
64
65
  */
65
66