@pisell/pisellos 0.10.95 → 0.10.97

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 (31) hide show
  1. package/dist/model/strategy/adapter/promotion/index.js +9 -0
  2. package/dist/modules/OpenData/index.d.ts +3 -0
  3. package/dist/modules/OpenData/index.js +160 -84
  4. package/dist/modules/Order/index.d.ts +1 -1
  5. package/dist/server/index.d.ts +3 -0
  6. package/dist/server/index.js +857 -598
  7. package/dist/server/modules/order/index.d.ts +1 -0
  8. package/dist/server/modules/order/index.js +51 -51
  9. package/dist/solution/BookingByStep/index.d.ts +2 -2
  10. package/dist/solution/BookingTicket/index.d.ts +1 -1
  11. package/dist/solution/BookingTicket/utils/redeemArrival.d.ts +16 -16
  12. package/dist/solution/Sales/index.d.ts +2 -1
  13. package/dist/solution/Sales/index.js +123 -49
  14. package/dist/solution/Sales/types.d.ts +6 -0
  15. package/dist/solution/Sales/types.js +2 -0
  16. package/lib/model/strategy/adapter/promotion/index.js +46 -1
  17. package/lib/modules/OpenData/index.d.ts +3 -0
  18. package/lib/modules/OpenData/index.js +51 -18
  19. package/lib/modules/Order/index.d.ts +1 -1
  20. package/lib/server/index.d.ts +3 -0
  21. package/lib/server/index.js +155 -18
  22. package/lib/server/modules/order/index.d.ts +1 -0
  23. package/lib/server/modules/order/index.js +4 -3
  24. package/lib/solution/BookingByStep/index.d.ts +2 -2
  25. package/lib/solution/BookingTicket/index.d.ts +1 -1
  26. package/lib/solution/BookingTicket/utils/redeemArrival.d.ts +16 -16
  27. package/lib/solution/Sales/index.d.ts +2 -1
  28. package/lib/solution/Sales/index.js +28 -1
  29. package/lib/solution/Sales/types.d.ts +6 -0
  30. package/lib/solution/Sales/types.js +1 -0
  31. package/package.json +1 -1
@@ -34,7 +34,6 @@ export * from "./types";
34
34
  var UNPAID_PAYMENT_STATUSES = new Set(['unpaid', 'partially_paid', 'payment_processing']);
35
35
  var INVOICE_OPEN_DATA_SECTION_CODES = ['documents'];
36
36
  var INVOICE_OPEN_DATA_CACHE_TTL = 5 * 60 * 1000;
37
-
38
37
  /**
39
38
  * Sales 解决方案基础骨架
40
39
  *
@@ -463,6 +462,81 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
463
462
  return _printLocalOrderReceipt.apply(this, arguments);
464
463
  }
465
464
  return printLocalOrderReceipt;
465
+ }()
466
+ }, {
467
+ key: "printCloudOrderInvoice",
468
+ value: function () {
469
+ var _printCloudOrderInvoice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(input) {
470
+ var _lookup$data;
471
+ var orderId, channel, openData, requestOptions, lookup, businessCode, settings, result;
472
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
473
+ while (1) switch (_context7.prev = _context7.next) {
474
+ case 0:
475
+ orderId = input === null || input === void 0 ? void 0 : input.order_id;
476
+ channel = typeof (input === null || input === void 0 ? void 0 : input.channel) === 'string' ? input.channel.trim() : '';
477
+ if (channel) {
478
+ _context7.next = 4;
479
+ break;
480
+ }
481
+ throw new Error('Cloud Invoice requires a channel');
482
+ case 4:
483
+ openData = this.invoiceOpenDataModule;
484
+ if (openData) {
485
+ _context7.next = 7;
486
+ break;
487
+ }
488
+ throw new Error('Cloud Invoice is not initialized');
489
+ case 7:
490
+ requestOptions = {
491
+ osServer: true,
492
+ customToast: function customToast() {}
493
+ };
494
+ _context7.next = 10;
495
+ return this.request.post('/shop/local/cloud-order-invoice/lookup', {
496
+ order_id: orderId
497
+ }, requestOptions);
498
+ case 10:
499
+ lookup = _context7.sent;
500
+ if (!((lookup === null || lookup === void 0 ? void 0 : lookup.status) !== true || lookup.code !== 200)) {
501
+ _context7.next = 13;
502
+ break;
503
+ }
504
+ throw new Error((lookup === null || lookup === void 0 ? void 0 : lookup.message) || 'Cloud Invoice order lookup failed');
505
+ case 13:
506
+ businessCode = (_lookup$data = lookup.data) === null || _lookup$data === void 0 || (_lookup$data = _lookup$data.business_code) === null || _lookup$data === void 0 ? void 0 : _lookup$data.trim();
507
+ if (businessCode) {
508
+ _context7.next = 16;
509
+ break;
510
+ }
511
+ throw new Error('Cloud Invoice order has no business_code');
512
+ case 16:
513
+ _context7.next = 18;
514
+ return openData.loadCloudInvoiceTemplate("".concat(businessCode, "+").concat(channel));
515
+ case 18:
516
+ settings = _context7.sent;
517
+ _context7.next = 21;
518
+ return this.request.post('/shop/local/cloud-order-invoice/submit', {
519
+ order_id: orderId,
520
+ business_code: businessCode,
521
+ template_settings: settings
522
+ }, requestOptions);
523
+ case 21:
524
+ result = _context7.sent;
525
+ if (!((result === null || result === void 0 ? void 0 : result.status) !== true || result.code !== 200)) {
526
+ _context7.next = 24;
527
+ break;
528
+ }
529
+ throw new Error((result === null || result === void 0 ? void 0 : result.message) || 'Cloud Invoice dispatch failed');
530
+ case 24:
531
+ case "end":
532
+ return _context7.stop();
533
+ }
534
+ }, _callee7, this);
535
+ }));
536
+ function printCloudOrderInvoice(_x10) {
537
+ return _printCloudOrderInvoice.apply(this, arguments);
538
+ }
539
+ return printCloudOrderInvoice;
466
540
  }() /** 清除独立 Documents 缓存;下一次打印会按当前 target 重新获取。 */
467
541
  }, {
468
542
  key: "clearOpenDataCache",
@@ -480,38 +554,38 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
480
554
  }, {
481
555
  key: "destroy",
482
556
  value: function () {
483
- var _destroy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
557
+ var _destroy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
484
558
  var invoiceOpenDataModule;
485
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
486
- while (1) switch (_context7.prev = _context7.next) {
559
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
560
+ while (1) switch (_context8.prev = _context8.next) {
487
561
  case 0:
488
562
  this.clearOpenDataCache();
489
563
  invoiceOpenDataModule = this.invoiceOpenDataModule;
490
564
  this.invoiceOpenDataModule = null;
491
565
  if (!invoiceOpenDataModule) {
492
- _context7.next = 12;
566
+ _context8.next = 12;
493
567
  break;
494
568
  }
495
- _context7.prev = 4;
496
- _context7.next = 7;
569
+ _context8.prev = 4;
570
+ _context8.next = 7;
497
571
  return invoiceOpenDataModule.destroy();
498
572
  case 7:
499
- _context7.next = 12;
573
+ _context8.next = 12;
500
574
  break;
501
575
  case 9:
502
- _context7.prev = 9;
503
- _context7.t0 = _context7["catch"](4);
504
- console.warn('[Sales] Invoice OpenData 子模块销毁失败', _context7.t0);
576
+ _context8.prev = 9;
577
+ _context8.t0 = _context8["catch"](4);
578
+ console.warn('[Sales] Invoice OpenData 子模块销毁失败', _context8.t0);
505
579
  case 12:
506
- _context7.next = 14;
580
+ _context8.next = 14;
507
581
  return this.core.effects.emit("".concat(this.name, ":onDestroy"), {});
508
582
  case 14:
509
583
  _get(_getPrototypeOf(SalesImpl.prototype), "destroy", this).call(this);
510
584
  case 15:
511
585
  case "end":
512
- return _context7.stop();
586
+ return _context8.stop();
513
587
  }
514
- }, _callee7, this, [[4, 9]]);
588
+ }, _callee8, this, [[4, 9]]);
515
589
  }));
516
590
  function destroy() {
517
591
  return _destroy.apply(this, arguments);
@@ -1103,7 +1177,7 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
1103
1177
  }, {
1104
1178
  key: "getResourceBookingList",
1105
1179
  value: function () {
1106
- var _getResourceBookingList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(currentTime) {
1180
+ var _getResourceBookingList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(currentTime) {
1107
1181
  var _resourceResponse$dat,
1108
1182
  _resourceResponse$dat2,
1109
1183
  _this8 = this;
@@ -1117,28 +1191,28 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
1117
1191
  rawBookingMap,
1118
1192
  bookingMap,
1119
1193
  list,
1120
- _args8 = arguments;
1121
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
1122
- while (1) switch (_context8.prev = _context8.next) {
1194
+ _args9 = arguments;
1195
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
1196
+ while (1) switch (_context9.prev = _context9.next) {
1123
1197
  case 0:
1124
- bookingList = _args8.length > 1 && _args8[1] !== undefined ? _args8[1] : [];
1125
- deviceTime = _args8.length > 2 && _args8[2] !== undefined ? _args8[2] : currentTime;
1198
+ bookingList = _args9.length > 1 && _args9[1] !== undefined ? _args9[1] : [];
1199
+ deviceTime = _args9.length > 2 && _args9[2] !== undefined ? _args9[2] : currentTime;
1126
1200
  // currentTime 约定为完整 datetime;非法值直接返回空,避免误判
1127
1201
  current = dayjs(currentTime);
1128
1202
  if (current.isValid()) {
1129
- _context8.next = 5;
1203
+ _context9.next = 5;
1130
1204
  break;
1131
1205
  }
1132
- return _context8.abrupt("return", []);
1206
+ return _context9.abrupt("return", []);
1133
1207
  case 5:
1134
1208
  deviceCurrent = dayjs(deviceTime);
1135
1209
  if (deviceCurrent.isValid()) {
1136
- _context8.next = 8;
1210
+ _context9.next = 8;
1137
1211
  break;
1138
1212
  }
1139
- return _context8.abrupt("return", []);
1213
+ return _context9.abrupt("return", []);
1140
1214
  case 8:
1141
- _context8.next = 10;
1215
+ _context9.next = 10;
1142
1216
  return this.request.get('/shop/form/resource/page', {
1143
1217
  skip: 1,
1144
1218
  num: 999
@@ -1149,13 +1223,13 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
1149
1223
  isShopApi: true
1150
1224
  });
1151
1225
  case 10:
1152
- resourceResponse = _context8.sent;
1226
+ resourceResponse = _context9.sent;
1153
1227
  resourceList = (_resourceResponse$dat = resourceResponse === null || resourceResponse === void 0 || (_resourceResponse$dat2 = resourceResponse.data) === null || _resourceResponse$dat2 === void 0 ? void 0 : _resourceResponse$dat2.list) !== null && _resourceResponse$dat !== void 0 ? _resourceResponse$dat : [];
1154
1228
  if (!(!Array.isArray(resourceList) || resourceList.length === 0)) {
1155
- _context8.next = 14;
1229
+ _context9.next = 14;
1156
1230
  break;
1157
1231
  }
1158
- return _context8.abrupt("return", []);
1232
+ return _context9.abrupt("return", []);
1159
1233
  case 14:
1160
1234
  // 全局先做 booking 标准化 + start_time 升序,后续映射直接复用
1161
1235
  normalizedBookings = this.normalizeResourceBookings(current, deviceCurrent, bookingList); // 建立 resourceId -> bookings[] 倒排索引,加速资源匹配
@@ -1190,14 +1264,14 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
1190
1264
  list: list === null || list === void 0 ? void 0 : list.length
1191
1265
  }
1192
1266
  });
1193
- return _context8.abrupt("return", list);
1267
+ return _context9.abrupt("return", list);
1194
1268
  case 20:
1195
1269
  case "end":
1196
- return _context8.stop();
1270
+ return _context9.stop();
1197
1271
  }
1198
- }, _callee8, this);
1272
+ }, _callee9, this);
1199
1273
  }));
1200
- function getResourceBookingList(_x10) {
1274
+ function getResourceBookingList(_x11) {
1201
1275
  return _getResourceBookingList.apply(this, arguments);
1202
1276
  }
1203
1277
  return getResourceBookingList;
@@ -1205,30 +1279,30 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
1205
1279
  }, {
1206
1280
  key: "getResourceBookingItem",
1207
1281
  value: function () {
1208
- var _getResourceBookingItem = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(params) {
1282
+ var _getResourceBookingItem = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(params) {
1209
1283
  var _resourceResponse$dat3,
1210
1284
  _resourceResponse$dat4,
1211
1285
  _this9 = this,
1212
1286
  _params$bookingList;
1213
1287
  var current, deviceCurrent, resourceResponse, resourceList, targetResource, resourceId, matchedBookingList, statsBookingList, completedBookingList, unpaidBookingList, bookings, completedBookings, unpaidBookings, orderCount, bookingCount, compeleteBookingCount;
1214
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
1215
- while (1) switch (_context9.prev = _context9.next) {
1288
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
1289
+ while (1) switch (_context10.prev = _context10.next) {
1216
1290
  case 0:
1217
1291
  current = dayjs(params.currentTime);
1218
1292
  if (current.isValid()) {
1219
- _context9.next = 3;
1293
+ _context10.next = 3;
1220
1294
  break;
1221
1295
  }
1222
- return _context9.abrupt("return", null);
1296
+ return _context10.abrupt("return", null);
1223
1297
  case 3:
1224
1298
  deviceCurrent = dayjs(params.deviceTime || params.currentTime);
1225
1299
  if (deviceCurrent.isValid()) {
1226
- _context9.next = 6;
1300
+ _context10.next = 6;
1227
1301
  break;
1228
1302
  }
1229
- return _context9.abrupt("return", null);
1303
+ return _context10.abrupt("return", null);
1230
1304
  case 6:
1231
- _context9.next = 8;
1305
+ _context10.next = 8;
1232
1306
  return this.request.get('/shop/form/resource/page', {
1233
1307
  skip: 1,
1234
1308
  num: 999
@@ -1239,22 +1313,22 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
1239
1313
  isShopApi: true
1240
1314
  });
1241
1315
  case 8:
1242
- resourceResponse = _context9.sent;
1316
+ resourceResponse = _context10.sent;
1243
1317
  resourceList = (_resourceResponse$dat3 = resourceResponse === null || resourceResponse === void 0 || (_resourceResponse$dat4 = resourceResponse.data) === null || _resourceResponse$dat4 === void 0 ? void 0 : _resourceResponse$dat4.list) !== null && _resourceResponse$dat3 !== void 0 ? _resourceResponse$dat3 : [];
1244
1318
  if (!(!Array.isArray(resourceList) || resourceList.length === 0)) {
1245
- _context9.next = 12;
1319
+ _context10.next = 12;
1246
1320
  break;
1247
1321
  }
1248
- return _context9.abrupt("return", null);
1322
+ return _context10.abrupt("return", null);
1249
1323
  case 12:
1250
1324
  targetResource = resourceList.find(function (resource) {
1251
1325
  return String(_this9.getResourceId(resource)) === String(params.resourceId);
1252
1326
  });
1253
1327
  if (targetResource) {
1254
- _context9.next = 15;
1328
+ _context10.next = 15;
1255
1329
  break;
1256
1330
  }
1257
- return _context9.abrupt("return", null);
1331
+ return _context10.abrupt("return", null);
1258
1332
  case 15:
1259
1333
  resourceId = this.getResourceId(targetResource);
1260
1334
  matchedBookingList = params.bookingList.filter(function (booking) {
@@ -1305,7 +1379,7 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
1305
1379
  compeleteBookingCount: compeleteBookingCount
1306
1380
  }
1307
1381
  });
1308
- return _context9.abrupt("return", _objectSpread(_objectSpread({}, targetResource), {}, {
1382
+ return _context10.abrupt("return", _objectSpread(_objectSpread({}, targetResource), {}, {
1309
1383
  resource_id: resourceId,
1310
1384
  orderCount: orderCount,
1311
1385
  bookingCount: bookingCount,
@@ -1316,11 +1390,11 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
1316
1390
  }));
1317
1391
  case 28:
1318
1392
  case "end":
1319
- return _context9.stop();
1393
+ return _context10.stop();
1320
1394
  }
1321
- }, _callee9, this);
1395
+ }, _callee10, this);
1322
1396
  }));
1323
- function getResourceBookingItem(_x11) {
1397
+ function getResourceBookingItem(_x12) {
1324
1398
  return _getResourceBookingItem.apply(this, arguments);
1325
1399
  }
1326
1400
  return getResourceBookingItem;
@@ -56,6 +56,11 @@ export interface SalesPrintLocalOrderReceiptOptions {
56
56
  /** 当前销售入口;缺失或为 system 时按 pos 处理。 */
57
57
  channel?: string;
58
58
  }
59
+ /** Native cloud-order notification. */
60
+ export interface CloudOrderInvoiceRequest {
61
+ order_id: string | number;
62
+ channel: string;
63
+ }
59
64
  /**
60
65
  * Sales 解决方案状态
61
66
  *
@@ -90,6 +95,7 @@ export interface SalesModuleAPI {
90
95
  changeBookingStatus: (params: ChangeBookingStatusParams) => Promise<any>;
91
96
  /** 按本地订单标识打印小票;本地未命中时由 OS Server 负责远端兜底。 */
92
97
  printLocalOrderReceipt: <T = any>(lookup: string | number, options: SalesPrintLocalOrderReceiptOptions) => Promise<T>;
98
+ printCloudOrderInvoice: (request: CloudOrderInvoiceRequest) => Promise<void>;
93
99
  /** 清除 Legacy Sales 独立维护的 Documents OpenData 缓存。 */
94
100
  clearOpenDataCache: () => void;
95
101
  /** 获取资源维度的预约占用列表 */
@@ -14,6 +14,8 @@ export var SalesHooks = /*#__PURE__*/function (SalesHooks) {
14
14
  * 当前不要直接把 OrderData 当作最终 UI 数据结构。
15
15
  */
16
16
 
17
+ /** Native cloud-order notification. */
18
+
17
19
  /**
18
20
  * Sales 解决方案状态
19
21
  *
@@ -1 +1,46 @@
1
- "use strict";
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "BUY_X_GET_Y_FREE_STRATEGY", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _examples.BUY_X_GET_Y_FREE_STRATEGY;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "ITEM_REWARD_STRATEGY", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _examples.ITEM_REWARD_STRATEGY;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "PromotionAdapter", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _adapter.PromotionAdapter;
22
+ }
23
+ });
24
+ Object.defineProperty(exports, "PromotionEvaluator", {
25
+ enumerable: true,
26
+ get: function () {
27
+ return _evaluator.PromotionEvaluator;
28
+ }
29
+ });
30
+ Object.defineProperty(exports, "X_ITEMS_FOR_Y_PRICE_STRATEGY", {
31
+ enumerable: true,
32
+ get: function () {
33
+ return _examples.X_ITEMS_FOR_Y_PRICE_STRATEGY;
34
+ }
35
+ });
36
+ Object.defineProperty(exports, "default", {
37
+ enumerable: true,
38
+ get: function () {
39
+ return _adapter.default;
40
+ }
41
+ });
42
+ var _evaluator = require("./evaluator");
43
+ var _adapter = _interopRequireWildcard(require("./adapter"));
44
+ var _examples = require("./examples");
45
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
46
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
@@ -32,6 +32,9 @@ export declare class OpenDataModule extends BaseModule implements Module {
32
32
  updateOtherParams(params: Record<string, any>): void;
33
33
  private shouldSkipInvoiceTemplateDocument;
34
34
  fetchOpenData(params: OpenDataFetchParams): Promise<OpenDataConfig>;
35
+ private requestOpenData;
36
+ /** Cloud orders must resolve their own channel's template before printing. */
37
+ loadCloudInvoiceTemplate(target: string): Promise<InvoiceTemplateSettings>;
35
38
  getOpenData(): OpenDataConfig | null;
36
39
  getInvoiceLayoutConfig(): InvoiceLayoutConfig;
37
40
  getInvoiceTemplateSettings(): InvoiceTemplateSettings;
@@ -182,22 +182,7 @@ class OpenDataModule extends _BaseModule.BaseModule {
182
182
  }
183
183
  async fetchOpenData(params) {
184
184
  const fetchRevision = ++this.fetchRevision;
185
- const getData = this.appPlugin?.getData?.();
186
- const shopId = getData?.('shop_id');
187
- if (!shopId) throw new Error('[OpenDataModule] 无法获取 shop_id');
188
- const tenantId = getData?.('tenant_id');
189
- const headers = {};
190
- if (tenantId) headers['Tenant-Id'] = String(tenantId);
191
- const response = await this.request.post(`/open/my-pisell/${shopId}/setting`, {
192
- scope: params.scope,
193
- target: params.target,
194
- section_code: params.section_code
195
- }, {
196
- pisell2: true,
197
- isPisell2: true,
198
- prefix: false,
199
- headers
200
- });
185
+ const response = await this.requestOpenData(params);
201
186
  if (response?.status === false) {
202
187
  throw new Error(response?.message || '获取 OpenData 配置失败');
203
188
  }
@@ -211,6 +196,47 @@ class OpenDataModule extends _BaseModule.BaseModule {
211
196
  }
212
197
  return data;
213
198
  }
199
+ requestOpenData(params, background = false) {
200
+ const getData = this.appPlugin?.getData?.();
201
+ const shopId = getData?.('shop_id');
202
+ const tenantId = getData?.('tenant_id');
203
+ if (!shopId) throw new Error('[OpenDataModule] 无法获取 shop_id');
204
+ return this.request.post(`/open/my-pisell/${encodeURIComponent(String(shopId))}/setting`, {
205
+ scope: params.scope,
206
+ target: params.target,
207
+ section_code: params.section_code
208
+ }, {
209
+ pisell2: true,
210
+ isPisell2: true,
211
+ prefix: false,
212
+ headers: tenantId ? {
213
+ 'Tenant-Id': String(tenantId)
214
+ } : {},
215
+ ...(background ? {
216
+ customToast: () => {},
217
+ manualErrorHandling: true,
218
+ skipErrorHandler: true
219
+ } : {})
220
+ });
221
+ }
222
+
223
+ /** Cloud orders must resolve their own channel's template before printing. */
224
+ async loadCloudInvoiceTemplate(target) {
225
+ const response = await this.requestOpenData({
226
+ scope: 'board',
227
+ target,
228
+ section_code: ['documents']
229
+ }, true);
230
+ if (response?.status !== true || response.code !== 200 || !isRecord(response.data)) {
231
+ throw new Error(response?.message || 'Cloud Invoice settings unavailable');
232
+ }
233
+ const raw = response.data['documents.invoice_template'];
234
+ const documentId = resolveInvoiceDocumentId(raw);
235
+ if (documentId) return this.fetchInvoiceTemplateDocument(documentId, true);
236
+ if (raw == null || typeof raw === 'string' && !raw.trim()) return (0, _utils.getDefaultInvoiceTemplateSettings)();
237
+ if (isLegacyInvoiceTemplate(raw)) return (0, _utils.normalizeInvoiceTemplateSettings)(response.data);
238
+ throw new Error('Cloud Invoice template identifier is invalid');
239
+ }
214
240
  getOpenData() {
215
241
  return this.store.data;
216
242
  }
@@ -326,14 +352,18 @@ class OpenDataModule extends _BaseModule.BaseModule {
326
352
  const getData = this.appPlugin?.getData?.();
327
353
  return JSON.stringify([getData?.('tenant_id') ?? null, getData?.('shop_id') ?? null, target, documentId]);
328
354
  }
329
- async fetchInvoiceTemplateDocument(documentId) {
355
+ async fetchInvoiceTemplateDocument(documentId, strict = false) {
330
356
  const response = await this.request.get(`/document:get?filterByTk=${encodeURIComponent(documentId)}`, {}, {
331
357
  isNocobase: true,
332
358
  prefix: false,
333
359
  headers: {
334
360
  'x-data-source': 'pisell2'
335
361
  },
336
- customToast: () => {}
362
+ customToast: () => {},
363
+ ...(strict ? {
364
+ manualErrorHandling: true,
365
+ skipErrorHandler: true
366
+ } : {})
337
367
  });
338
368
  const document = response?.data;
339
369
  if (!document || resolveInvoiceDocumentId(document.id) !== documentId) {
@@ -345,6 +375,9 @@ class OpenDataModule extends _BaseModule.BaseModule {
345
375
  if (!isRecord(document.data) || !isRecord(document.data.template_settings)) {
346
376
  throw new Error(`Invoice Document ${documentId} 缺少 template_settings`);
347
377
  }
378
+ if (strict && (typeof document.data.template_settings.template !== 'string' || !document.data.template_settings.template.trim())) {
379
+ throw new Error(`Invoice Document ${documentId} 缺少 template`);
380
+ }
348
381
  return (0, _utils.normalizeRawInvoiceTemplateSettings)(document.data.template_settings);
349
382
  }
350
383
  logInvoiceTemplateDocumentFallback(error, target, documentId) {
@@ -640,7 +640,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
640
640
  generateIdempotencyToken(): string;
641
641
  syncPaymentsToOrder<T = any>(params: SyncPaymentsToOrderParams): Promise<SyncPaymentsToOrderResult<T>>;
642
642
  createOrder(params: CommitOrderParams['query']): {
643
- type: "virtual" | "appointment_booking";
643
+ type: "appointment_booking" | "virtual";
644
644
  platform: string;
645
645
  sales_channel: string;
646
646
  order_sales_channel: string;
@@ -547,8 +547,11 @@ declare class Server {
547
547
  private shouldLookupLocalPrintOrder;
548
548
  private getLocalPrintOrderLookup;
549
549
  private mergeLocalPrintOrderInput;
550
+ private loadCloudInvoiceOrder;
551
+ private handleCloudOrderInvoice;
550
552
  private handleLocalPrintOrder;
551
553
  private normalizeRequestedReceiptLocales;
554
+ private rebuildOrderReceipt;
552
555
  private handleLocalOrderReceiptSnapshot;
553
556
  private handleMachinecodeBatchMeta;
554
557
  private resolveMachinecodeBatchMetadataLookup;