@pisell/pisellos 0.0.505 → 0.0.506

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.
@@ -87,11 +87,11 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
87
87
  key: "serializeError",
88
88
  value: function serializeError(error) {
89
89
  if (error instanceof Error) {
90
- return {
90
+ return JSON.stringify({
91
91
  name: error.name,
92
92
  message: error.message,
93
93
  stack: error.stack
94
- };
94
+ });
95
95
  }
96
96
  return {
97
97
  message: String(error)
@@ -761,8 +761,20 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
761
761
  var ruleProduct = this.enabledReservationRuleProducts[0];
762
762
  var resourceState = this.store.resource;
763
763
  var resourceSelectType = resourceState === null || resourceState === void 0 ? void 0 : resourceState.resourceSelectType;
764
+
765
+ // single 预约独占整张桌台,capacity 取 form_record.capacity;其他情况(multiple / capacity / undefined)占 1 个容量位
766
+ var resolveResourceCapacity = function resolveResourceCapacity() {
767
+ if (resourceSelectType === 'single') {
768
+ var _resourceState$table_;
769
+ var raw = resourceState === null || resourceState === void 0 || (_resourceState$table_ = resourceState.table_form_record) === null || _resourceState$table_ === void 0 ? void 0 : _resourceState$table_.capacity;
770
+ var num = Number(raw);
771
+ if (Number.isFinite(num) && num > 0) return num;
772
+ return 1;
773
+ }
774
+ return 1;
775
+ };
764
776
  return function (payload, _ref) {
765
- var _tempOrder$resource_i, _ref2, _pickOriginal, _resourceState$table_, _resourceState$relati;
777
+ var _tempOrder$resource_i, _ref2, _pickOriginal, _resourceState$table_2, _resourceState$relati;
766
778
  var bookingUuid = _ref.bookingUuid,
767
779
  tempOrder = _ref.tempOrder;
768
780
  var resourceId = (_tempOrder$resource_i = tempOrder.resource_id) !== null && _tempOrder$resource_i !== void 0 ? _tempOrder$resource_i : resourceState === null || resourceState === void 0 ? void 0 : resourceState.relationId;
@@ -773,7 +785,7 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
773
785
  }
774
786
  return undefined;
775
787
  };
776
- var mainField = (_ref2 = (_pickOriginal = pickOriginal(tempOrder.table_number)) !== null && _pickOriginal !== void 0 ? _pickOriginal : pickOriginal(resourceState === null || resourceState === void 0 || (_resourceState$table_ = resourceState.table_form_record) === null || _resourceState$table_ === void 0 ? void 0 : _resourceState$table_.name)) !== null && _ref2 !== void 0 ? _ref2 : '';
788
+ var mainField = (_ref2 = (_pickOriginal = pickOriginal(tempOrder.table_number)) !== null && _pickOriginal !== void 0 ? _pickOriginal : pickOriginal(resourceState === null || resourceState === void 0 || (_resourceState$table_2 = resourceState.table_form_record) === null || _resourceState$table_2 === void 0 ? void 0 : _resourceState$table_2.name)) !== null && _ref2 !== void 0 ? _ref2 : '';
777
789
  var resourceEntry = resourceState && resourceId ? {
778
790
  relation_type: 'form',
779
791
  like_status: 'common',
@@ -781,15 +793,22 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
781
793
  main_field: mainField,
782
794
  form_id: resourceState.tableFormId,
783
795
  relation_id: (_resourceState$relati = resourceState.relationId) !== null && _resourceState$relati !== void 0 ? _resourceState$relati : resourceId,
784
- capacity: 1,
796
+ capacity: resolveResourceCapacity(),
785
797
  metadata: {}
786
798
  } : undefined;
787
799
  var ruleProductUid = ruleProduct ? createUuidV4() : undefined;
800
+ var bookingCapacityValue = resolveResourceCapacity();
788
801
  var nextBookings = (payload.bookings || []).map(function (booking, idx) {
789
802
  return _objectSpread(_objectSpread(_objectSpread({}, booking), {}, {
790
803
  appointment_status: 'started',
791
- metadata: _objectSpread(_objectSpread({}, booking.metadata || {}), resourceSelectType ? {
804
+ metadata: _objectSpread(_objectSpread(_objectSpread({}, booking.metadata || {}), resourceSelectType ? {
792
805
  resource_select_type: resourceSelectType
806
+ } : {}), resourceSelectType ? {
807
+ capacity: [{
808
+ id: 0,
809
+ value: bookingCapacityValue,
810
+ name: ''
811
+ }]
793
812
  } : {})
794
813
  }, idx === 0 && resourceEntry ? {
795
814
  resources: [resourceEntry]
@@ -1789,20 +1808,17 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
1789
1808
  }
1790
1809
  } else if (lastOrderId) {
1791
1810
  // 如果有其他人点的单
1792
- // TODO: 是否独占?如果非独占,其他人点的单应该不影响我下单
1793
- availabilityInfo = allowSnack ? {
1794
- mode: deskmateValid ? 'additional_order_with_code' : 'additional_order',
1795
- order_id: lastOrderId,
1796
- relation_id: relationId,
1797
- table_form_id: tableFormId,
1798
- deskmate_valid: deskmateValid
1799
- } : {
1800
- mode: 'resource_busy',
1801
- order_id: lastOrderId,
1802
- relation_id: relationId,
1803
- table_form_id: tableFormId,
1804
- deskmate_valid: deskmateValid
1805
- };
1811
+ // multiple 预约且容量仍有剩余时,其他人的单不影响当前用户下单,保持 idle 走正常下单流程
1812
+ var canFallthroughToIdle = resourceSelectType === 'multiple' && !isFull;
1813
+ if (!canFallthroughToIdle) {
1814
+ availabilityInfo = {
1815
+ mode: 'resource_busy',
1816
+ order_id: '0',
1817
+ relation_id: relationId,
1818
+ table_form_id: tableFormId,
1819
+ deskmate_valid: deskmateValid
1820
+ };
1821
+ }
1806
1822
  }
1807
1823
  return _objectSpread(_objectSpread({}, availabilityInfo), {}, {
1808
1824
  currentOrderId: currentOrderId,
@@ -2146,7 +2162,7 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
2146
2162
  case 78:
2147
2163
  _context28.prev = 78;
2148
2164
  _context28.t0 = _context28["catch"](1);
2149
- this.logMethodError('checkResourceAvailable', _context28.t0, {
2165
+ this.logMethodError('checkResourceAvailable', _context28.t0.message, {
2150
2166
  resourceId: resourceId
2151
2167
  });
2152
2168
  throw _context28.t0;
@@ -2225,7 +2241,7 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
2225
2241
  case 11:
2226
2242
  _context30.prev = 11;
2227
2243
  _context30.t0 = _context30["catch"](2);
2228
- this.logMethodError('getProductList', _context30.t0);
2244
+ this.logMethodError('getProductList', _context30.t0.message);
2229
2245
  throw _context30.t0;
2230
2246
  case 15:
2231
2247
  case "end":
@@ -0,0 +1,49 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/model/strategy/adapter/promotion/index.ts
30
+ var promotion_exports = {};
31
+ __export(promotion_exports, {
32
+ BUY_X_GET_Y_FREE_STRATEGY: () => import_examples.BUY_X_GET_Y_FREE_STRATEGY,
33
+ PromotionAdapter: () => import_adapter.PromotionAdapter,
34
+ PromotionEvaluator: () => import_evaluator.PromotionEvaluator,
35
+ X_ITEMS_FOR_Y_PRICE_STRATEGY: () => import_examples.X_ITEMS_FOR_Y_PRICE_STRATEGY,
36
+ default: () => import_adapter2.default
37
+ });
38
+ module.exports = __toCommonJS(promotion_exports);
39
+ var import_evaluator = require("./evaluator");
40
+ var import_adapter = require("./adapter");
41
+ var import_adapter2 = __toESM(require("./adapter"));
42
+ var import_examples = require("./examples");
43
+ // Annotate the CommonJS export names for ESM import in node:
44
+ 0 && (module.exports = {
45
+ BUY_X_GET_Y_FREE_STRATEGY,
46
+ PromotionAdapter,
47
+ PromotionEvaluator,
48
+ X_ITEMS_FOR_Y_PRICE_STRATEGY
49
+ });
@@ -84,11 +84,11 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
84
84
  }
85
85
  serializeError(error) {
86
86
  if (error instanceof Error) {
87
- return {
87
+ return JSON.stringify({
88
88
  name: error.name,
89
89
  message: error.message,
90
90
  stack: error.stack
91
- };
91
+ });
92
92
  }
93
93
  return {
94
94
  message: String(error)
@@ -503,6 +503,17 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
503
503
  const ruleProduct = this.enabledReservationRuleProducts[0];
504
504
  const resourceState = this.store.resource;
505
505
  const resourceSelectType = resourceState == null ? void 0 : resourceState.resourceSelectType;
506
+ const resolveResourceCapacity = () => {
507
+ var _a;
508
+ if (resourceSelectType === "single") {
509
+ const raw = (_a = resourceState == null ? void 0 : resourceState.table_form_record) == null ? void 0 : _a.capacity;
510
+ const num = Number(raw);
511
+ if (Number.isFinite(num) && num > 0)
512
+ return num;
513
+ return 1;
514
+ }
515
+ return 1;
516
+ };
506
517
  return (payload, { bookingUuid, tempOrder }) => {
507
518
  var _a;
508
519
  const resourceId = tempOrder.resource_id ?? (resourceState == null ? void 0 : resourceState.relationId);
@@ -521,16 +532,18 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
521
532
  main_field: mainField,
522
533
  form_id: resourceState.tableFormId,
523
534
  relation_id: resourceState.relationId ?? resourceId,
524
- capacity: 1,
535
+ capacity: resolveResourceCapacity(),
525
536
  metadata: {}
526
537
  } : void 0;
527
538
  const ruleProductUid = ruleProduct ? (0, import_utils2.createUuidV4)() : void 0;
539
+ const bookingCapacityValue = resolveResourceCapacity();
528
540
  const nextBookings = (payload.bookings || []).map((booking, idx) => ({
529
541
  ...booking,
530
542
  appointment_status: "started",
531
543
  metadata: {
532
544
  ...booking.metadata || {},
533
- ...resourceSelectType ? { resource_select_type: resourceSelectType } : {}
545
+ ...resourceSelectType ? { resource_select_type: resourceSelectType } : {},
546
+ ...resourceSelectType ? { capacity: [{ id: 0, value: bookingCapacityValue, name: "" }] } : {}
534
547
  },
535
548
  ...idx === 0 && resourceEntry ? { resources: [resourceEntry] } : {},
536
549
  ...idx === 0 && ruleProductUid ? { product_uid: ruleProductUid } : {}
@@ -1054,19 +1067,16 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
1054
1067
  };
1055
1068
  }
1056
1069
  } else if (lastOrderId) {
1057
- availabilityInfo = allowSnack ? {
1058
- mode: deskmateValid ? "additional_order_with_code" : "additional_order",
1059
- order_id: lastOrderId,
1060
- relation_id: relationId,
1061
- table_form_id: tableFormId,
1062
- deskmate_valid: deskmateValid
1063
- } : {
1064
- mode: "resource_busy",
1065
- order_id: lastOrderId,
1066
- relation_id: relationId,
1067
- table_form_id: tableFormId,
1068
- deskmate_valid: deskmateValid
1069
- };
1070
+ const canFallthroughToIdle = resourceSelectType === "multiple" && !isFull;
1071
+ if (!canFallthroughToIdle) {
1072
+ availabilityInfo = {
1073
+ mode: "resource_busy",
1074
+ order_id: "0",
1075
+ relation_id: relationId,
1076
+ table_form_id: tableFormId,
1077
+ deskmate_valid: deskmateValid
1078
+ };
1079
+ }
1070
1080
  }
1071
1081
  return {
1072
1082
  ...availabilityInfo,
@@ -1319,7 +1329,7 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
1319
1329
  });
1320
1330
  return availabilityInfo;
1321
1331
  } catch (error) {
1322
- this.logMethodError("checkResourceAvailable", error, {
1332
+ this.logMethodError("checkResourceAvailable", error.message, {
1323
1333
  resourceId
1324
1334
  });
1325
1335
  throw error;
@@ -1362,7 +1372,7 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
1362
1372
  });
1363
1373
  return formattedRes;
1364
1374
  } catch (error) {
1365
- this.logMethodError("getProductList", error);
1375
+ this.logMethodError("getProductList", error.message);
1366
1376
  throw error;
1367
1377
  }
1368
1378
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.505",
4
+ "version": "0.0.506",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",