@pisell/pisellos 0.10.95 → 0.10.96
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.
- package/dist/modules/OpenData/index.d.ts +13 -0
- package/dist/modules/OpenData/index.js +243 -93
- package/dist/modules/Order/index.d.ts +1 -1
- package/dist/server/index.d.ts +7 -0
- package/dist/server/index.js +1036 -598
- package/dist/server/modules/order/index.d.ts +1 -0
- package/dist/server/modules/order/index.js +51 -51
- package/dist/solution/BookingByStep/index.d.ts +2 -2
- package/dist/solution/BookingTicket/index.d.ts +1 -1
- package/dist/solution/BookingTicket/utils/redeemArrival.d.ts +16 -16
- package/dist/solution/Sales/index.d.ts +2 -1
- package/dist/solution/Sales/index.js +154 -48
- package/dist/solution/Sales/types.d.ts +12 -0
- package/dist/solution/Sales/types.js +2 -0
- package/lib/modules/OpenData/index.d.ts +13 -0
- package/lib/modules/OpenData/index.js +97 -18
- package/lib/modules/Order/index.d.ts +1 -1
- package/lib/server/index.d.ts +7 -0
- package/lib/server/index.js +240 -18
- package/lib/server/modules/order/index.d.ts +1 -0
- package/lib/server/modules/order/index.js +4 -3
- package/lib/solution/BookingByStep/index.d.ts +2 -2
- package/lib/solution/BookingTicket/index.d.ts +1 -1
- package/lib/solution/BookingTicket/utils/redeemArrival.d.ts +16 -16
- package/lib/solution/Sales/index.d.ts +2 -1
- package/lib/solution/Sales/index.js +53 -0
- package/lib/solution/Sales/types.d.ts +12 -0
- package/lib/solution/Sales/types.js +1 -0
- package/package.json +1 -1
|
@@ -463,6 +463,112 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
463
463
|
return _printLocalOrderReceipt.apply(this, arguments);
|
|
464
464
|
}
|
|
465
465
|
return printLocalOrderReceipt;
|
|
466
|
+
}()
|
|
467
|
+
}, {
|
|
468
|
+
key: "printCloudOrderInvoice",
|
|
469
|
+
value: function () {
|
|
470
|
+
var _printCloudOrderInvoice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(input) {
|
|
471
|
+
var _lookup$data, _lookup$data2, _lookup$data3, _submitted$data;
|
|
472
|
+
var openData, orderId, channel, messageUuid, scope, event, requestOptions, lookup, accepted, rawBusinessCode, businessCode, deviceId, settings, submitted, taskUuid;
|
|
473
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
474
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
475
|
+
case 0:
|
|
476
|
+
openData = this.invoiceOpenDataModule;
|
|
477
|
+
if (openData) {
|
|
478
|
+
_context7.next = 3;
|
|
479
|
+
break;
|
|
480
|
+
}
|
|
481
|
+
throw new Error('Cloud Invoice is not initialized');
|
|
482
|
+
case 3:
|
|
483
|
+
orderId = typeof (input === null || input === void 0 ? void 0 : input.order_id) === 'string' ? input.order_id.trim() : Number.isSafeInteger(input === null || input === void 0 ? void 0 : input.order_id) ? String(input.order_id) : '';
|
|
484
|
+
channel = typeof (input === null || input === void 0 ? void 0 : input.channel) === 'string' ? input.channel.trim() : '';
|
|
485
|
+
messageUuid = typeof (input === null || input === void 0 ? void 0 : input.message_uuid) === 'string' ? input.message_uuid.trim() : '';
|
|
486
|
+
if (!(!/^[1-9]\d*$/.test(orderId) || !channel || !messageUuid)) {
|
|
487
|
+
_context7.next = 8;
|
|
488
|
+
break;
|
|
489
|
+
}
|
|
490
|
+
throw new Error('Cloud Invoice requires order_id, channel and message_uuid');
|
|
491
|
+
case 8:
|
|
492
|
+
scope = openData.captureCloudInvoiceScope(input.shop_id);
|
|
493
|
+
event = {
|
|
494
|
+
order_id: orderId,
|
|
495
|
+
channel: channel,
|
|
496
|
+
message_uuid: messageUuid,
|
|
497
|
+
shop_id: scope.shopId
|
|
498
|
+
};
|
|
499
|
+
requestOptions = {
|
|
500
|
+
osServer: true,
|
|
501
|
+
customToast: function customToast() {}
|
|
502
|
+
};
|
|
503
|
+
_context7.next = 13;
|
|
504
|
+
return this.request.post('/shop/local/cloud-order-invoice/lookup', event, requestOptions);
|
|
505
|
+
case 13:
|
|
506
|
+
lookup = _context7.sent;
|
|
507
|
+
scope.assertCurrent();
|
|
508
|
+
if (!((lookup === null || lookup === void 0 ? void 0 : lookup.status) !== true || lookup.code !== 200)) {
|
|
509
|
+
_context7.next = 17;
|
|
510
|
+
break;
|
|
511
|
+
}
|
|
512
|
+
throw new Error((lookup === null || lookup === void 0 ? void 0 : lookup.message) || 'Cloud Invoice order lookup failed');
|
|
513
|
+
case 17:
|
|
514
|
+
accepted = (_lookup$data = lookup.data) === null || _lookup$data === void 0 ? void 0 : _lookup$data.task_uuid;
|
|
515
|
+
if (!(typeof accepted === 'string' && accepted.trim())) {
|
|
516
|
+
_context7.next = 20;
|
|
517
|
+
break;
|
|
518
|
+
}
|
|
519
|
+
return _context7.abrupt("return", {
|
|
520
|
+
task_uuid: accepted
|
|
521
|
+
});
|
|
522
|
+
case 20:
|
|
523
|
+
rawBusinessCode = (_lookup$data2 = lookup.data) === null || _lookup$data2 === void 0 ? void 0 : _lookup$data2.business_code;
|
|
524
|
+
businessCode = typeof rawBusinessCode === 'string' ? rawBusinessCode.trim() : '';
|
|
525
|
+
if (businessCode) {
|
|
526
|
+
_context7.next = 24;
|
|
527
|
+
break;
|
|
528
|
+
}
|
|
529
|
+
throw new Error('Cloud Invoice order has no business_code');
|
|
530
|
+
case 24:
|
|
531
|
+
deviceId = (_lookup$data3 = lookup.data) === null || _lookup$data3 === void 0 ? void 0 : _lookup$data3.device_id;
|
|
532
|
+
if (!(typeof deviceId !== 'string' || !deviceId.trim())) {
|
|
533
|
+
_context7.next = 27;
|
|
534
|
+
break;
|
|
535
|
+
}
|
|
536
|
+
throw new Error('Cloud Invoice lookup has no device_id');
|
|
537
|
+
case 27:
|
|
538
|
+
_context7.next = 29;
|
|
539
|
+
return openData.loadCloudInvoiceTemplate("".concat(businessCode, "+").concat(channel), scope);
|
|
540
|
+
case 29:
|
|
541
|
+
settings = _context7.sent;
|
|
542
|
+
scope.assertCurrent();
|
|
543
|
+
_context7.next = 33;
|
|
544
|
+
return this.request.post('/shop/local/cloud-order-invoice/submit', _objectSpread(_objectSpread({}, event), {}, {
|
|
545
|
+
business_code: businessCode,
|
|
546
|
+
device_id: deviceId,
|
|
547
|
+
template_settings: cloneDeep(settings)
|
|
548
|
+
}), requestOptions);
|
|
549
|
+
case 33:
|
|
550
|
+
submitted = _context7.sent;
|
|
551
|
+
scope.assertCurrent();
|
|
552
|
+
taskUuid = submitted === null || submitted === void 0 || (_submitted$data = submitted.data) === null || _submitted$data === void 0 ? void 0 : _submitted$data.task_uuid;
|
|
553
|
+
if (!((submitted === null || submitted === void 0 ? void 0 : submitted.status) !== true || submitted.code !== 200 || typeof taskUuid !== 'string' || !taskUuid.trim())) {
|
|
554
|
+
_context7.next = 38;
|
|
555
|
+
break;
|
|
556
|
+
}
|
|
557
|
+
throw new Error((submitted === null || submitted === void 0 ? void 0 : submitted.message) || 'Cloud Invoice task was not accepted');
|
|
558
|
+
case 38:
|
|
559
|
+
return _context7.abrupt("return", {
|
|
560
|
+
task_uuid: taskUuid
|
|
561
|
+
});
|
|
562
|
+
case 39:
|
|
563
|
+
case "end":
|
|
564
|
+
return _context7.stop();
|
|
565
|
+
}
|
|
566
|
+
}, _callee7, this);
|
|
567
|
+
}));
|
|
568
|
+
function printCloudOrderInvoice(_x10) {
|
|
569
|
+
return _printCloudOrderInvoice.apply(this, arguments);
|
|
570
|
+
}
|
|
571
|
+
return printCloudOrderInvoice;
|
|
466
572
|
}() /** 清除独立 Documents 缓存;下一次打印会按当前 target 重新获取。 */
|
|
467
573
|
}, {
|
|
468
574
|
key: "clearOpenDataCache",
|
|
@@ -480,38 +586,38 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
480
586
|
}, {
|
|
481
587
|
key: "destroy",
|
|
482
588
|
value: function () {
|
|
483
|
-
var _destroy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
589
|
+
var _destroy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
|
|
484
590
|
var invoiceOpenDataModule;
|
|
485
|
-
return _regeneratorRuntime().wrap(function
|
|
486
|
-
while (1) switch (
|
|
591
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
592
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
487
593
|
case 0:
|
|
488
594
|
this.clearOpenDataCache();
|
|
489
595
|
invoiceOpenDataModule = this.invoiceOpenDataModule;
|
|
490
596
|
this.invoiceOpenDataModule = null;
|
|
491
597
|
if (!invoiceOpenDataModule) {
|
|
492
|
-
|
|
598
|
+
_context8.next = 12;
|
|
493
599
|
break;
|
|
494
600
|
}
|
|
495
|
-
|
|
496
|
-
|
|
601
|
+
_context8.prev = 4;
|
|
602
|
+
_context8.next = 7;
|
|
497
603
|
return invoiceOpenDataModule.destroy();
|
|
498
604
|
case 7:
|
|
499
|
-
|
|
605
|
+
_context8.next = 12;
|
|
500
606
|
break;
|
|
501
607
|
case 9:
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
console.warn('[Sales] Invoice OpenData 子模块销毁失败',
|
|
608
|
+
_context8.prev = 9;
|
|
609
|
+
_context8.t0 = _context8["catch"](4);
|
|
610
|
+
console.warn('[Sales] Invoice OpenData 子模块销毁失败', _context8.t0);
|
|
505
611
|
case 12:
|
|
506
|
-
|
|
612
|
+
_context8.next = 14;
|
|
507
613
|
return this.core.effects.emit("".concat(this.name, ":onDestroy"), {});
|
|
508
614
|
case 14:
|
|
509
615
|
_get(_getPrototypeOf(SalesImpl.prototype), "destroy", this).call(this);
|
|
510
616
|
case 15:
|
|
511
617
|
case "end":
|
|
512
|
-
return
|
|
618
|
+
return _context8.stop();
|
|
513
619
|
}
|
|
514
|
-
},
|
|
620
|
+
}, _callee8, this, [[4, 9]]);
|
|
515
621
|
}));
|
|
516
622
|
function destroy() {
|
|
517
623
|
return _destroy.apply(this, arguments);
|
|
@@ -1103,7 +1209,7 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1103
1209
|
}, {
|
|
1104
1210
|
key: "getResourceBookingList",
|
|
1105
1211
|
value: function () {
|
|
1106
|
-
var _getResourceBookingList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1212
|
+
var _getResourceBookingList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(currentTime) {
|
|
1107
1213
|
var _resourceResponse$dat,
|
|
1108
1214
|
_resourceResponse$dat2,
|
|
1109
1215
|
_this8 = this;
|
|
@@ -1117,28 +1223,28 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1117
1223
|
rawBookingMap,
|
|
1118
1224
|
bookingMap,
|
|
1119
1225
|
list,
|
|
1120
|
-
|
|
1121
|
-
return _regeneratorRuntime().wrap(function
|
|
1122
|
-
while (1) switch (
|
|
1226
|
+
_args9 = arguments;
|
|
1227
|
+
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
1228
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
1123
1229
|
case 0:
|
|
1124
|
-
bookingList =
|
|
1125
|
-
deviceTime =
|
|
1230
|
+
bookingList = _args9.length > 1 && _args9[1] !== undefined ? _args9[1] : [];
|
|
1231
|
+
deviceTime = _args9.length > 2 && _args9[2] !== undefined ? _args9[2] : currentTime;
|
|
1126
1232
|
// currentTime 约定为完整 datetime;非法值直接返回空,避免误判
|
|
1127
1233
|
current = dayjs(currentTime);
|
|
1128
1234
|
if (current.isValid()) {
|
|
1129
|
-
|
|
1235
|
+
_context9.next = 5;
|
|
1130
1236
|
break;
|
|
1131
1237
|
}
|
|
1132
|
-
return
|
|
1238
|
+
return _context9.abrupt("return", []);
|
|
1133
1239
|
case 5:
|
|
1134
1240
|
deviceCurrent = dayjs(deviceTime);
|
|
1135
1241
|
if (deviceCurrent.isValid()) {
|
|
1136
|
-
|
|
1242
|
+
_context9.next = 8;
|
|
1137
1243
|
break;
|
|
1138
1244
|
}
|
|
1139
|
-
return
|
|
1245
|
+
return _context9.abrupt("return", []);
|
|
1140
1246
|
case 8:
|
|
1141
|
-
|
|
1247
|
+
_context9.next = 10;
|
|
1142
1248
|
return this.request.get('/shop/form/resource/page', {
|
|
1143
1249
|
skip: 1,
|
|
1144
1250
|
num: 999
|
|
@@ -1149,13 +1255,13 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1149
1255
|
isShopApi: true
|
|
1150
1256
|
});
|
|
1151
1257
|
case 10:
|
|
1152
|
-
resourceResponse =
|
|
1258
|
+
resourceResponse = _context9.sent;
|
|
1153
1259
|
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
1260
|
if (!(!Array.isArray(resourceList) || resourceList.length === 0)) {
|
|
1155
|
-
|
|
1261
|
+
_context9.next = 14;
|
|
1156
1262
|
break;
|
|
1157
1263
|
}
|
|
1158
|
-
return
|
|
1264
|
+
return _context9.abrupt("return", []);
|
|
1159
1265
|
case 14:
|
|
1160
1266
|
// 全局先做 booking 标准化 + start_time 升序,后续映射直接复用
|
|
1161
1267
|
normalizedBookings = this.normalizeResourceBookings(current, deviceCurrent, bookingList); // 建立 resourceId -> bookings[] 倒排索引,加速资源匹配
|
|
@@ -1190,14 +1296,14 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1190
1296
|
list: list === null || list === void 0 ? void 0 : list.length
|
|
1191
1297
|
}
|
|
1192
1298
|
});
|
|
1193
|
-
return
|
|
1299
|
+
return _context9.abrupt("return", list);
|
|
1194
1300
|
case 20:
|
|
1195
1301
|
case "end":
|
|
1196
|
-
return
|
|
1302
|
+
return _context9.stop();
|
|
1197
1303
|
}
|
|
1198
|
-
},
|
|
1304
|
+
}, _callee9, this);
|
|
1199
1305
|
}));
|
|
1200
|
-
function getResourceBookingList(
|
|
1306
|
+
function getResourceBookingList(_x11) {
|
|
1201
1307
|
return _getResourceBookingList.apply(this, arguments);
|
|
1202
1308
|
}
|
|
1203
1309
|
return getResourceBookingList;
|
|
@@ -1205,30 +1311,30 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1205
1311
|
}, {
|
|
1206
1312
|
key: "getResourceBookingItem",
|
|
1207
1313
|
value: function () {
|
|
1208
|
-
var _getResourceBookingItem = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1314
|
+
var _getResourceBookingItem = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(params) {
|
|
1209
1315
|
var _resourceResponse$dat3,
|
|
1210
1316
|
_resourceResponse$dat4,
|
|
1211
1317
|
_this9 = this,
|
|
1212
1318
|
_params$bookingList;
|
|
1213
1319
|
var current, deviceCurrent, resourceResponse, resourceList, targetResource, resourceId, matchedBookingList, statsBookingList, completedBookingList, unpaidBookingList, bookings, completedBookings, unpaidBookings, orderCount, bookingCount, compeleteBookingCount;
|
|
1214
|
-
return _regeneratorRuntime().wrap(function
|
|
1215
|
-
while (1) switch (
|
|
1320
|
+
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
1321
|
+
while (1) switch (_context10.prev = _context10.next) {
|
|
1216
1322
|
case 0:
|
|
1217
1323
|
current = dayjs(params.currentTime);
|
|
1218
1324
|
if (current.isValid()) {
|
|
1219
|
-
|
|
1325
|
+
_context10.next = 3;
|
|
1220
1326
|
break;
|
|
1221
1327
|
}
|
|
1222
|
-
return
|
|
1328
|
+
return _context10.abrupt("return", null);
|
|
1223
1329
|
case 3:
|
|
1224
1330
|
deviceCurrent = dayjs(params.deviceTime || params.currentTime);
|
|
1225
1331
|
if (deviceCurrent.isValid()) {
|
|
1226
|
-
|
|
1332
|
+
_context10.next = 6;
|
|
1227
1333
|
break;
|
|
1228
1334
|
}
|
|
1229
|
-
return
|
|
1335
|
+
return _context10.abrupt("return", null);
|
|
1230
1336
|
case 6:
|
|
1231
|
-
|
|
1337
|
+
_context10.next = 8;
|
|
1232
1338
|
return this.request.get('/shop/form/resource/page', {
|
|
1233
1339
|
skip: 1,
|
|
1234
1340
|
num: 999
|
|
@@ -1239,22 +1345,22 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1239
1345
|
isShopApi: true
|
|
1240
1346
|
});
|
|
1241
1347
|
case 8:
|
|
1242
|
-
resourceResponse =
|
|
1348
|
+
resourceResponse = _context10.sent;
|
|
1243
1349
|
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
1350
|
if (!(!Array.isArray(resourceList) || resourceList.length === 0)) {
|
|
1245
|
-
|
|
1351
|
+
_context10.next = 12;
|
|
1246
1352
|
break;
|
|
1247
1353
|
}
|
|
1248
|
-
return
|
|
1354
|
+
return _context10.abrupt("return", null);
|
|
1249
1355
|
case 12:
|
|
1250
1356
|
targetResource = resourceList.find(function (resource) {
|
|
1251
1357
|
return String(_this9.getResourceId(resource)) === String(params.resourceId);
|
|
1252
1358
|
});
|
|
1253
1359
|
if (targetResource) {
|
|
1254
|
-
|
|
1360
|
+
_context10.next = 15;
|
|
1255
1361
|
break;
|
|
1256
1362
|
}
|
|
1257
|
-
return
|
|
1363
|
+
return _context10.abrupt("return", null);
|
|
1258
1364
|
case 15:
|
|
1259
1365
|
resourceId = this.getResourceId(targetResource);
|
|
1260
1366
|
matchedBookingList = params.bookingList.filter(function (booking) {
|
|
@@ -1305,7 +1411,7 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1305
1411
|
compeleteBookingCount: compeleteBookingCount
|
|
1306
1412
|
}
|
|
1307
1413
|
});
|
|
1308
|
-
return
|
|
1414
|
+
return _context10.abrupt("return", _objectSpread(_objectSpread({}, targetResource), {}, {
|
|
1309
1415
|
resource_id: resourceId,
|
|
1310
1416
|
orderCount: orderCount,
|
|
1311
1417
|
bookingCount: bookingCount,
|
|
@@ -1316,11 +1422,11 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1316
1422
|
}));
|
|
1317
1423
|
case 28:
|
|
1318
1424
|
case "end":
|
|
1319
|
-
return
|
|
1425
|
+
return _context10.stop();
|
|
1320
1426
|
}
|
|
1321
|
-
},
|
|
1427
|
+
}, _callee10, this);
|
|
1322
1428
|
}));
|
|
1323
|
-
function getResourceBookingItem(
|
|
1429
|
+
function getResourceBookingItem(_x12) {
|
|
1324
1430
|
return _getResourceBookingItem.apply(this, arguments);
|
|
1325
1431
|
}
|
|
1326
1432
|
return getResourceBookingItem;
|
|
@@ -56,6 +56,17 @@ export interface SalesPrintLocalOrderReceiptOptions {
|
|
|
56
56
|
/** 当前销售入口;缺失或为 system 时按 pos 处理。 */
|
|
57
57
|
channel?: string;
|
|
58
58
|
}
|
|
59
|
+
/** Order and delivery identity supplied by the native cloud-print listener. */
|
|
60
|
+
export interface CloudOrderInvoiceRequest {
|
|
61
|
+
shop_id: string | number;
|
|
62
|
+
order_id: string | number;
|
|
63
|
+
message_uuid: string;
|
|
64
|
+
channel: string;
|
|
65
|
+
}
|
|
66
|
+
export interface CloudOrderInvoiceResult {
|
|
67
|
+
/** DeviceTask accepted for this message on the current device. */
|
|
68
|
+
task_uuid: string;
|
|
69
|
+
}
|
|
59
70
|
/**
|
|
60
71
|
* Sales 解决方案状态
|
|
61
72
|
*
|
|
@@ -90,6 +101,7 @@ export interface SalesModuleAPI {
|
|
|
90
101
|
changeBookingStatus: (params: ChangeBookingStatusParams) => Promise<any>;
|
|
91
102
|
/** 按本地订单标识打印小票;本地未命中时由 OS Server 负责远端兜底。 */
|
|
92
103
|
printLocalOrderReceipt: <T = any>(lookup: string | number, options: SalesPrintLocalOrderReceiptOptions) => Promise<T>;
|
|
104
|
+
printCloudOrderInvoice: (request: CloudOrderInvoiceRequest) => Promise<CloudOrderInvoiceResult>;
|
|
93
105
|
/** 清除 Legacy Sales 独立维护的 Documents OpenData 缓存。 */
|
|
94
106
|
clearOpenDataCache: () => void;
|
|
95
107
|
/** 获取资源维度的预约占用列表 */
|
|
@@ -6,6 +6,13 @@ export * from './types';
|
|
|
6
6
|
export * from './contactInfo';
|
|
7
7
|
export * from './salesSettings';
|
|
8
8
|
export { computeAvailability, getDefaultInvoiceLayoutConfig, getDefaultInvoiceTemplateSettings, normalizeInvoiceLayoutConfig, normalizeInvoiceLayoutFromTemplateSettings, normalizeInvoiceTemplateSettings, normalizeRawInvoiceTemplateSettings, resolveInvoiceReceiptLocales, } from './utils';
|
|
9
|
+
interface InvoiceShopScope {
|
|
10
|
+
shopId: string;
|
|
11
|
+
tenantId: string;
|
|
12
|
+
}
|
|
13
|
+
interface CloudInvoiceScope extends InvoiceShopScope {
|
|
14
|
+
assertCurrent(): void;
|
|
15
|
+
}
|
|
9
16
|
export declare class OpenDataModule extends BaseModule implements Module {
|
|
10
17
|
protected defaultName: string;
|
|
11
18
|
protected defaultVersion: string;
|
|
@@ -19,6 +26,7 @@ export declare class OpenDataModule extends BaseModule implements Module {
|
|
|
19
26
|
private otherParams;
|
|
20
27
|
private fetchRevision;
|
|
21
28
|
private invoiceTemplateCacheRevision;
|
|
29
|
+
private cloudInvoiceTemplates;
|
|
22
30
|
private invoiceTemplateDocumentCache;
|
|
23
31
|
private invoiceTemplateDocumentInFlight;
|
|
24
32
|
constructor(name?: string, version?: string);
|
|
@@ -32,6 +40,11 @@ export declare class OpenDataModule extends BaseModule implements Module {
|
|
|
32
40
|
updateOtherParams(params: Record<string, any>): void;
|
|
33
41
|
private shouldSkipInvoiceTemplateDocument;
|
|
34
42
|
fetchOpenData(params: OpenDataFetchParams): Promise<OpenDataConfig>;
|
|
43
|
+
private requestOpenData;
|
|
44
|
+
/** Bind every stage of a cloud print to the same authenticated shop and cache generation. */
|
|
45
|
+
captureCloudInvoiceScope(expectedShopId: string | number): CloudInvoiceScope;
|
|
46
|
+
loadCloudInvoiceTemplate(target: string, scope: CloudInvoiceScope): Promise<InvoiceTemplateSettings>;
|
|
47
|
+
private fetchCloudInvoiceTemplate;
|
|
35
48
|
getOpenData(): OpenDataConfig | null;
|
|
36
49
|
getInvoiceLayoutConfig(): InvoiceLayoutConfig;
|
|
37
50
|
getInvoiceTemplateSettings(): InvoiceTemplateSettings;
|
|
@@ -120,6 +120,13 @@ function isLegacyInvoiceTemplate(value) {
|
|
|
120
120
|
const numericLike = /^[+-]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?$/i;
|
|
121
121
|
return !numericLike.test(normalized);
|
|
122
122
|
}
|
|
123
|
+
function readInvoiceShopScope(app) {
|
|
124
|
+
const getData = app?.getData?.();
|
|
125
|
+
return {
|
|
126
|
+
shopId: String(getData?.('shop_id') ?? '').trim(),
|
|
127
|
+
tenantId: String(getData?.('tenant_id') ?? '').trim()
|
|
128
|
+
};
|
|
129
|
+
}
|
|
123
130
|
class OpenDataModule extends _BaseModule.BaseModule {
|
|
124
131
|
defaultName = 'openData';
|
|
125
132
|
defaultVersion = '1.0.0';
|
|
@@ -133,6 +140,9 @@ class OpenDataModule extends _BaseModule.BaseModule {
|
|
|
133
140
|
otherParams = {};
|
|
134
141
|
fetchRevision = 0;
|
|
135
142
|
invoiceTemplateCacheRevision = 0;
|
|
143
|
+
// Cloud printing only caches successful resolutions. Regular sales screens
|
|
144
|
+
// deliberately retain DEFAULT after a failed Document lookup.
|
|
145
|
+
cloudInvoiceTemplates = new Map();
|
|
136
146
|
invoiceTemplateDocumentCache = new Map();
|
|
137
147
|
invoiceTemplateDocumentInFlight = new Map();
|
|
138
148
|
constructor(name, version) {
|
|
@@ -182,22 +192,7 @@ class OpenDataModule extends _BaseModule.BaseModule {
|
|
|
182
192
|
}
|
|
183
193
|
async fetchOpenData(params) {
|
|
184
194
|
const fetchRevision = ++this.fetchRevision;
|
|
185
|
-
const
|
|
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
|
-
});
|
|
195
|
+
const response = await this.requestOpenData(params, readInvoiceShopScope(this.appPlugin));
|
|
201
196
|
if (response?.status === false) {
|
|
202
197
|
throw new Error(response?.message || '获取 OpenData 配置失败');
|
|
203
198
|
}
|
|
@@ -211,6 +206,82 @@ class OpenDataModule extends _BaseModule.BaseModule {
|
|
|
211
206
|
}
|
|
212
207
|
return data;
|
|
213
208
|
}
|
|
209
|
+
requestOpenData(params, scope, background = false) {
|
|
210
|
+
if (!scope.shopId) throw new Error('[OpenDataModule] 无法获取 shop_id');
|
|
211
|
+
return this.request.post(`/open/my-pisell/${encodeURIComponent(scope.shopId)}/setting`, {
|
|
212
|
+
scope: params.scope,
|
|
213
|
+
target: params.target,
|
|
214
|
+
section_code: params.section_code
|
|
215
|
+
}, {
|
|
216
|
+
pisell2: true,
|
|
217
|
+
isPisell2: true,
|
|
218
|
+
prefix: false,
|
|
219
|
+
headers: scope.tenantId ? {
|
|
220
|
+
'Tenant-Id': scope.tenantId
|
|
221
|
+
} : {},
|
|
222
|
+
...(background ? {
|
|
223
|
+
customToast: () => {},
|
|
224
|
+
manualErrorHandling: true,
|
|
225
|
+
skipErrorHandler: true
|
|
226
|
+
} : {})
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/** Bind every stage of a cloud print to the same authenticated shop and cache generation. */
|
|
231
|
+
captureCloudInvoiceScope(expectedShopId) {
|
|
232
|
+
const scope = readInvoiceShopScope(this.appPlugin);
|
|
233
|
+
if (!scope.shopId || scope.shopId !== String(expectedShopId).trim()) {
|
|
234
|
+
throw new Error('Cloud Invoice shop does not match the active shop');
|
|
235
|
+
}
|
|
236
|
+
const revision = this.invoiceTemplateCacheRevision;
|
|
237
|
+
return {
|
|
238
|
+
...scope,
|
|
239
|
+
assertCurrent: () => {
|
|
240
|
+
const current = readInvoiceShopScope(this.appPlugin);
|
|
241
|
+
if (revision !== this.invoiceTemplateCacheRevision || current.shopId !== scope.shopId || current.tenantId !== scope.tenantId) {
|
|
242
|
+
throw new Error('Cloud Invoice shop context changed');
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
async loadCloudInvoiceTemplate(target, scope) {
|
|
248
|
+
scope.assertCurrent();
|
|
249
|
+
const key = JSON.stringify([scope.tenantId, scope.shopId, target]);
|
|
250
|
+
const existing = this.cloudInvoiceTemplates.get(key);
|
|
251
|
+
if (existing && existing.expiresAt > Date.now()) return existing.request;
|
|
252
|
+
const request = this.fetchCloudInvoiceTemplate(target, scope);
|
|
253
|
+
const entry = {
|
|
254
|
+
request,
|
|
255
|
+
expiresAt: Infinity
|
|
256
|
+
};
|
|
257
|
+
this.cloudInvoiceTemplates.set(key, entry);
|
|
258
|
+
try {
|
|
259
|
+
const settings = await request;
|
|
260
|
+
scope.assertCurrent();
|
|
261
|
+
entry.expiresAt = Date.now() + 5 * 60 * 1000;
|
|
262
|
+
return settings;
|
|
263
|
+
} catch (error) {
|
|
264
|
+
if (this.cloudInvoiceTemplates.get(key) === entry) this.cloudInvoiceTemplates.delete(key);
|
|
265
|
+
throw error;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
async fetchCloudInvoiceTemplate(target, scope) {
|
|
269
|
+
const response = await this.requestOpenData({
|
|
270
|
+
scope: 'board',
|
|
271
|
+
target,
|
|
272
|
+
section_code: ['documents']
|
|
273
|
+
}, scope, true);
|
|
274
|
+
scope.assertCurrent();
|
|
275
|
+
if (response?.status !== true || response.code !== 200 || !isRecord(response.data)) {
|
|
276
|
+
throw new Error(response?.message || 'Cloud Invoice settings unavailable');
|
|
277
|
+
}
|
|
278
|
+
const raw = response.data['documents.invoice_template'];
|
|
279
|
+
const documentId = resolveInvoiceDocumentId(raw);
|
|
280
|
+
if (documentId) return this.fetchInvoiceTemplateDocument(documentId, true);
|
|
281
|
+
if (raw == null || typeof raw === 'string' && !raw.trim()) return (0, _utils.getDefaultInvoiceTemplateSettings)();
|
|
282
|
+
if (isLegacyInvoiceTemplate(raw)) return (0, _utils.normalizeInvoiceTemplateSettings)(response.data);
|
|
283
|
+
throw new Error('Cloud Invoice template identifier is invalid');
|
|
284
|
+
}
|
|
214
285
|
getOpenData() {
|
|
215
286
|
return this.store.data;
|
|
216
287
|
}
|
|
@@ -326,14 +397,18 @@ class OpenDataModule extends _BaseModule.BaseModule {
|
|
|
326
397
|
const getData = this.appPlugin?.getData?.();
|
|
327
398
|
return JSON.stringify([getData?.('tenant_id') ?? null, getData?.('shop_id') ?? null, target, documentId]);
|
|
328
399
|
}
|
|
329
|
-
async fetchInvoiceTemplateDocument(documentId) {
|
|
400
|
+
async fetchInvoiceTemplateDocument(documentId, strict = false) {
|
|
330
401
|
const response = await this.request.get(`/document:get?filterByTk=${encodeURIComponent(documentId)}`, {}, {
|
|
331
402
|
isNocobase: true,
|
|
332
403
|
prefix: false,
|
|
333
404
|
headers: {
|
|
334
405
|
'x-data-source': 'pisell2'
|
|
335
406
|
},
|
|
336
|
-
customToast: () => {}
|
|
407
|
+
customToast: () => {},
|
|
408
|
+
...(strict ? {
|
|
409
|
+
manualErrorHandling: true,
|
|
410
|
+
skipErrorHandler: true
|
|
411
|
+
} : {})
|
|
337
412
|
});
|
|
338
413
|
const document = response?.data;
|
|
339
414
|
if (!document || resolveInvoiceDocumentId(document.id) !== documentId) {
|
|
@@ -345,6 +420,9 @@ class OpenDataModule extends _BaseModule.BaseModule {
|
|
|
345
420
|
if (!isRecord(document.data) || !isRecord(document.data.template_settings)) {
|
|
346
421
|
throw new Error(`Invoice Document ${documentId} 缺少 template_settings`);
|
|
347
422
|
}
|
|
423
|
+
if (strict && (typeof document.data.template_settings.template !== 'string' || !document.data.template_settings.template.trim())) {
|
|
424
|
+
throw new Error(`Invoice Document ${documentId} 缺少 template`);
|
|
425
|
+
}
|
|
348
426
|
return (0, _utils.normalizeRawInvoiceTemplateSettings)(document.data.template_settings);
|
|
349
427
|
}
|
|
350
428
|
logInvoiceTemplateDocumentFallback(error, target, documentId) {
|
|
@@ -362,6 +440,7 @@ class OpenDataModule extends _BaseModule.BaseModule {
|
|
|
362
440
|
clearCache() {
|
|
363
441
|
this.fetchRevision += 1;
|
|
364
442
|
this.invoiceTemplateCacheRevision += 1;
|
|
443
|
+
this.cloudInvoiceTemplates.clear();
|
|
365
444
|
this.invoiceTemplateDocumentCache.clear();
|
|
366
445
|
this.invoiceTemplateDocumentInFlight.clear();
|
|
367
446
|
this.store.data = null;
|
|
@@ -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: "
|
|
643
|
+
type: "appointment_booking" | "virtual";
|
|
644
644
|
platform: string;
|
|
645
645
|
sales_channel: string;
|
|
646
646
|
order_sales_channel: string;
|
package/lib/server/index.d.ts
CHANGED
|
@@ -66,6 +66,7 @@ declare class Server {
|
|
|
66
66
|
private localPaymentUpdateQueues;
|
|
67
67
|
private paymentIdentityRefreshes;
|
|
68
68
|
private receiptFulfillmentConfigInFlight;
|
|
69
|
+
private cloudInvoiceSubmissions;
|
|
69
70
|
private floorPlanQuerySubscribers;
|
|
70
71
|
private moduleRegistry;
|
|
71
72
|
constructor(core: PisellCore);
|
|
@@ -547,8 +548,14 @@ declare class Server {
|
|
|
547
548
|
private shouldLookupLocalPrintOrder;
|
|
548
549
|
private getLocalPrintOrderLookup;
|
|
549
550
|
private mergeLocalPrintOrderInput;
|
|
551
|
+
private getCloudInvoiceDevice;
|
|
552
|
+
private assertCloudInvoiceContext;
|
|
553
|
+
private loadCloudInvoiceOrder;
|
|
554
|
+
private resolveCloudOrderInvoice;
|
|
555
|
+
private handleCloudOrderInvoice;
|
|
550
556
|
private handleLocalPrintOrder;
|
|
551
557
|
private normalizeRequestedReceiptLocales;
|
|
558
|
+
private rebuildOrderReceipt;
|
|
552
559
|
private handleLocalOrderReceiptSnapshot;
|
|
553
560
|
private handleMachinecodeBatchMeta;
|
|
554
561
|
private resolveMachinecodeBatchMetadataLookup;
|