@pisell/pisellos 2.1.128 → 2.1.130

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 (46) hide show
  1. package/dist/model/strategy/adapter/promotion/index.js +0 -9
  2. package/dist/modules/Order/index.d.ts +4 -0
  3. package/dist/modules/Order/index.js +18 -1
  4. package/dist/modules/Order/types.d.ts +9 -1
  5. package/dist/modules/Order/utils.d.ts +7 -0
  6. package/dist/modules/Order/utils.js +27 -11
  7. package/dist/solution/ScanOrder/index.d.ts +27 -3
  8. package/dist/solution/ScanOrder/index.js +865 -481
  9. package/dist/solution/ScanOrder/types.d.ts +34 -24
  10. package/dist/solution/ScanOrder/types.js +5 -1
  11. package/dist/solution/ScanOrder/utils.d.ts +13 -1
  12. package/dist/solution/ScanOrder/utils.js +45 -6
  13. package/dist/solution/VenueBooking/index.d.ts +28 -5
  14. package/dist/solution/VenueBooking/index.js +463 -227
  15. package/dist/solution/VenueBooking/types.d.ts +23 -0
  16. package/dist/solution/VenueBooking/utils/dateSummary.d.ts +1 -1
  17. package/dist/solution/VenueBooking/utils/dateSummary.js +1 -1
  18. package/dist/solution/VenueBooking/utils/resource.d.ts +11 -1
  19. package/dist/solution/VenueBooking/utils/resource.js +57 -21
  20. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +5 -0
  21. package/dist/solution/VenueBooking/utils/slotMerge.js +33 -12
  22. package/dist/solution/VenueBooking/utils/timeSlot.d.ts +1 -1
  23. package/dist/solution/VenueBooking/utils/timeSlot.js +259 -62
  24. package/lib/model/strategy/adapter/promotion/index.js +49 -0
  25. package/lib/modules/Order/index.d.ts +4 -0
  26. package/lib/modules/Order/index.js +14 -1
  27. package/lib/modules/Order/types.d.ts +9 -1
  28. package/lib/modules/Order/utils.d.ts +7 -0
  29. package/lib/modules/Order/utils.js +22 -12
  30. package/lib/solution/ScanOrder/index.d.ts +27 -3
  31. package/lib/solution/ScanOrder/index.js +409 -114
  32. package/lib/solution/ScanOrder/types.d.ts +34 -24
  33. package/lib/solution/ScanOrder/utils.d.ts +13 -1
  34. package/lib/solution/ScanOrder/utils.js +37 -0
  35. package/lib/solution/VenueBooking/index.d.ts +28 -5
  36. package/lib/solution/VenueBooking/index.js +203 -58
  37. package/lib/solution/VenueBooking/types.d.ts +23 -0
  38. package/lib/solution/VenueBooking/utils/dateSummary.d.ts +1 -1
  39. package/lib/solution/VenueBooking/utils/dateSummary.js +1 -1
  40. package/lib/solution/VenueBooking/utils/resource.d.ts +11 -1
  41. package/lib/solution/VenueBooking/utils/resource.js +15 -4
  42. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +5 -0
  43. package/lib/solution/VenueBooking/utils/slotMerge.js +29 -12
  44. package/lib/solution/VenueBooking/utils/timeSlot.d.ts +1 -1
  45. package/lib/solution/VenueBooking/utils/timeSlot.js +182 -43
  46. package/package.json +1 -1
@@ -994,7 +994,7 @@ export var VenueBookingImpl = /*#__PURE__*/function (_BaseModule) {
994
994
  key: "fetchResourceAvailability",
995
995
  value: function () {
996
996
  var _fetchResourceAvailability = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(params) {
997
- var venueProducts, resourceIds, config, crossDay, effectiveEndDate, res, rawData, _iterator2, _step2, item, _i2, _rawData, _item, mapping;
997
+ var venueProducts, resourceIds, config, crossDay, effectiveEndDate, res, rawData, _iterator2, _step2, item, _i2, _rawData, _item, mappings, _iterator3, _step3, mapping;
998
998
  return _regeneratorRuntime().wrap(function _callee15$(_context15) {
999
999
  while (1) switch (_context15.prev = _context15.next) {
1000
1000
  case 0:
@@ -1062,35 +1062,56 @@ export var VenueBookingImpl = /*#__PURE__*/function (_BaseModule) {
1062
1062
  }
1063
1063
  }
1064
1064
  this.store.rawResourceData = rawData;
1065
- for (_i2 = 0, _rawData = rawData; _i2 < _rawData.length; _i2++) {
1066
- _item = _rawData[_i2];
1067
- mapping = this.resourceProductMap.get(_item.resourceId);
1068
- if (mapping && _item.main_field) {
1069
- mapping.resourceName = _item.main_field;
1070
- }
1071
- if (mapping && _item.resource_form_id) {
1072
- mapping.formId = _item.resource_form_id;
1065
+ _i2 = 0, _rawData = rawData;
1066
+ case 24:
1067
+ if (!(_i2 < _rawData.length)) {
1068
+ _context15.next = 34;
1069
+ break;
1070
+ }
1071
+ _item = _rawData[_i2];
1072
+ mappings = this.resourceProductMap.get(_item.resourceId);
1073
+ if (mappings) {
1074
+ _context15.next = 29;
1075
+ break;
1076
+ }
1077
+ return _context15.abrupt("continue", 31);
1078
+ case 29:
1079
+ _iterator3 = _createForOfIteratorHelper(mappings);
1080
+ try {
1081
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
1082
+ mapping = _step3.value;
1083
+ if (_item.main_field) mapping.resourceName = _item.main_field;
1084
+ if (_item.resource_form_id) mapping.formId = _item.resource_form_id;
1073
1085
  }
1086
+ } catch (err) {
1087
+ _iterator3.e(err);
1088
+ } finally {
1089
+ _iterator3.f();
1074
1090
  }
1091
+ case 31:
1092
+ _i2++;
1093
+ _context15.next = 24;
1094
+ break;
1095
+ case 34:
1075
1096
  this.logMethodSuccess('fetchResourceAvailability', {
1076
1097
  resourceCount: rawData.length,
1077
1098
  totalTimes: rawData.reduce(function (sum, r) {
1078
1099
  return sum + r.times.length;
1079
1100
  }, 0)
1080
1101
  });
1081
- _context15.next = 32;
1102
+ _context15.next = 42;
1082
1103
  break;
1083
- case 27:
1084
- _context15.prev = 27;
1104
+ case 37:
1105
+ _context15.prev = 37;
1085
1106
  _context15.t0 = _context15["catch"](1);
1086
1107
  this.store.rawResourceData = [];
1087
1108
  this.logMethodError('fetchResourceAvailability', _context15.t0);
1088
1109
  throw _context15.t0;
1089
- case 32:
1110
+ case 42:
1090
1111
  case "end":
1091
1112
  return _context15.stop();
1092
1113
  }
1093
- }, _callee15, this, [[1, 27]]);
1114
+ }, _callee15, this, [[1, 37]]);
1094
1115
  }));
1095
1116
  function fetchResourceAvailability(_x7) {
1096
1117
  return _fetchResourceAvailability.apply(this, arguments);
@@ -1124,18 +1145,18 @@ export var VenueBookingImpl = /*#__PURE__*/function (_BaseModule) {
1124
1145
  var timeRangeMap = calcMinTimeMaxTimeBySchedules(scheduleList, undefined, date);
1125
1146
  var earliestStart = null;
1126
1147
  var latestEnd = null;
1127
- var _iterator3 = _createForOfIteratorHelper(scheduleList),
1128
- _step3;
1148
+ var _iterator4 = _createForOfIteratorHelper(scheduleList),
1149
+ _step4;
1129
1150
  try {
1130
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
1151
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
1131
1152
  var _timeRangeMap$schedul;
1132
- var schedule = _step3.value;
1153
+ var schedule = _step4.value;
1133
1154
  var dateRangeList = (timeRangeMap === null || timeRangeMap === void 0 || (_timeRangeMap$schedul = timeRangeMap[schedule.id]) === null || _timeRangeMap$schedul === void 0 ? void 0 : _timeRangeMap$schedul.dateRangeFormat) || [];
1134
- var _iterator4 = _createForOfIteratorHelper(dateRangeList),
1135
- _step4;
1155
+ var _iterator5 = _createForOfIteratorHelper(dateRangeList),
1156
+ _step5;
1136
1157
  try {
1137
- for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
1138
- var range = _step4.value;
1158
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
1159
+ var range = _step5.value;
1139
1160
  var start = dayjs(range === null || range === void 0 ? void 0 : range.start);
1140
1161
  var end = dayjs(range === null || range === void 0 ? void 0 : range.end);
1141
1162
  if (!start.isValid() || !end.isValid()) continue;
@@ -1147,15 +1168,15 @@ export var VenueBookingImpl = /*#__PURE__*/function (_BaseModule) {
1147
1168
  }
1148
1169
  }
1149
1170
  } catch (err) {
1150
- _iterator4.e(err);
1171
+ _iterator5.e(err);
1151
1172
  } finally {
1152
- _iterator4.f();
1173
+ _iterator5.f();
1153
1174
  }
1154
1175
  }
1155
1176
  } catch (err) {
1156
- _iterator3.e(err);
1177
+ _iterator4.e(err);
1157
1178
  } finally {
1158
- _iterator3.f();
1179
+ _iterator4.f();
1159
1180
  }
1160
1181
  if (!earliestStart || !latestEnd) return nextSlotConfig;
1161
1182
  return _objectSpread(_objectSpread({}, nextSlotConfig), {}, {
@@ -1192,7 +1213,7 @@ export var VenueBookingImpl = /*#__PURE__*/function (_BaseModule) {
1192
1213
  var resolvedSlotConfig = this.syncOperatingHoursToSlotConfig(date);
1193
1214
  var quotationPriceMap;
1194
1215
  if (this.store.quotation) {
1195
- var productIds = _toConsumableArray(new Set(_toConsumableArray(this.resourceProductMap.values()).map(function (m) {
1216
+ var productIds = _toConsumableArray(new Set(_toConsumableArray(this.resourceProductMap.values()).flat().map(function (m) {
1196
1217
  return m.productId;
1197
1218
  })));
1198
1219
  var timeLabels = generateTimeLabels(resolvedSlotConfig);
@@ -1218,34 +1239,47 @@ export var VenueBookingImpl = /*#__PURE__*/function (_BaseModule) {
1218
1239
  /**
1219
1240
  * 切换单个时段的选中状态(选中/取消)。
1220
1241
  * 内部自动处理连续时段的合并与拆分,订单是唯一真相源。
1242
+ *
1243
+ * slot.productId 指定当前操作针对的是该 resourceId 下的哪一个商品。
1244
+ * 同一资源下不同 productId 之间互相隔离,不会相互合并。
1221
1245
  */
1222
1246
  }, {
1223
1247
  key: "toggleSlot",
1224
1248
  value: function () {
1225
1249
  var _toggleSlot = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(slot) {
1226
- var mapping, currentSlots, existIndex, nextSlots, products;
1250
+ var mappings, mapping, currentSlots, existIndex, nextSlots, products;
1227
1251
  return _regeneratorRuntime().wrap(function _callee16$(_context16) {
1228
1252
  while (1) switch (_context16.prev = _context16.next) {
1229
1253
  case 0:
1230
1254
  this.logMethodStart('toggleSlot', {
1231
1255
  resourceId: slot.resourceId,
1256
+ productId: slot.productId,
1232
1257
  startTime: slot.startTime
1233
1258
  });
1234
1259
  _context16.prev = 1;
1235
- mapping = this.resourceProductMap.get(slot.resourceId);
1236
- if (mapping) {
1260
+ mappings = this.resourceProductMap.get(slot.resourceId);
1261
+ if (!(!mappings || !mappings.length)) {
1237
1262
  _context16.next = 5;
1238
1263
  break;
1239
1264
  }
1240
1265
  throw new Error("\u672A\u627E\u5230\u8D44\u6E90 ".concat(slot.resourceId, " \u7684\u5546\u54C1\u6620\u5C04"));
1241
1266
  case 5:
1267
+ mapping = mappings.find(function (m) {
1268
+ return m.productId === slot.productId;
1269
+ });
1270
+ if (mapping) {
1271
+ _context16.next = 8;
1272
+ break;
1273
+ }
1274
+ throw new Error("\u8D44\u6E90 ".concat(slot.resourceId, " \u672A\u5173\u8054\u5546\u54C1 ").concat(slot.productId));
1275
+ case 8:
1242
1276
  if (this.store.order) {
1243
- _context16.next = 7;
1277
+ _context16.next = 10;
1244
1278
  break;
1245
1279
  }
1246
1280
  throw new Error('order 模块未初始化');
1247
- case 7:
1248
- currentSlots = this.getSelectedSlotsForResource(slot.resourceId);
1281
+ case 10:
1282
+ currentSlots = this.getSelectedSlotsForResourceProduct(slot.resourceId, slot.productId);
1249
1283
  existIndex = currentSlots.findIndex(function (s) {
1250
1284
  return s.startTime === slot.startTime;
1251
1285
  });
@@ -1256,32 +1290,33 @@ export var VenueBookingImpl = /*#__PURE__*/function (_BaseModule) {
1256
1290
  } else {
1257
1291
  nextSlots = [].concat(_toConsumableArray(currentSlots), [slot]);
1258
1292
  }
1259
- _context16.next = 12;
1260
- return this.reconcileOrderForResource(slot.resourceId, nextSlots);
1261
- case 12:
1262
- products = this.store.order.getOrderProducts();
1263
1293
  _context16.next = 15;
1264
- return this.refreshItemRuleQuantityLimits();
1294
+ return this.reconcileOrderForResourceProduct(slot.resourceId, slot.productId, nextSlots);
1265
1295
  case 15:
1266
- _context16.next = 17;
1296
+ products = this.store.order.getOrderProducts();
1297
+ _context16.next = 18;
1298
+ return this.refreshItemRuleQuantityLimits();
1299
+ case 18:
1300
+ _context16.next = 20;
1267
1301
  return this.refreshCartValidationPassed();
1268
- case 17:
1302
+ case 20:
1269
1303
  this.logMethodSuccess('toggleSlot', {
1270
1304
  action: existIndex !== -1 ? 'remove' : 'add',
1271
1305
  resourceId: slot.resourceId,
1306
+ productId: slot.productId,
1272
1307
  slotCount: nextSlots.length
1273
1308
  });
1274
1309
  return _context16.abrupt("return", products);
1275
- case 21:
1276
- _context16.prev = 21;
1310
+ case 24:
1311
+ _context16.prev = 24;
1277
1312
  _context16.t0 = _context16["catch"](1);
1278
1313
  this.logMethodError('toggleSlot', _context16.t0);
1279
1314
  throw _context16.t0;
1280
- case 25:
1315
+ case 28:
1281
1316
  case "end":
1282
1317
  return _context16.stop();
1283
1318
  }
1284
- }, _callee16, this, [[1, 21]]);
1319
+ }, _callee16, this, [[1, 24]]);
1285
1320
  }));
1286
1321
  function toggleSlot(_x8) {
1287
1322
  return _toggleSlot.apply(this, arguments);
@@ -1290,49 +1325,169 @@ export var VenueBookingImpl = /*#__PURE__*/function (_BaseModule) {
1290
1325
  }()
1291
1326
  /**
1292
1327
  * 获取某资源当前选中的所有独立时段(从订单中解析)。
1328
+ * 不传 productId 时返回该资源下所有商品的选中时段;传了则精确匹配。
1293
1329
  */
1294
1330
  }, {
1295
1331
  key: "getSelectedSlotsForResource",
1296
- value: function getSelectedSlotsForResource(resourceId) {
1332
+ value: function getSelectedSlotsForResource(resourceId, productId) {
1297
1333
  var _this$store$order3;
1298
1334
  var tempOrder = (_this$store$order3 = this.store.order) === null || _this$store$order3 === void 0 ? void 0 : _this$store$order3.getTempOrder();
1299
1335
  if (!tempOrder) return [];
1300
1336
  var venueProducts = tempOrder.products.filter(function (p) {
1301
1337
  var _p$metadata, _p$metadata2;
1302
- return ((_p$metadata = p.metadata) === null || _p$metadata === void 0 ? void 0 : _p$metadata.venue_booking) && String((_p$metadata2 = p.metadata) === null || _p$metadata2 === void 0 ? void 0 : _p$metadata2.resource_id) === String(resourceId);
1338
+ if (!((_p$metadata = p.metadata) !== null && _p$metadata !== void 0 && _p$metadata.venue_booking)) return false;
1339
+ if (String((_p$metadata2 = p.metadata) === null || _p$metadata2 === void 0 ? void 0 : _p$metadata2.resource_id) !== String(resourceId)) return false;
1340
+ if (productId != null && Number(p.product_id) !== Number(productId)) return false;
1341
+ return true;
1303
1342
  });
1304
1343
  var slotDuration = this.store.slotConfig.slotDurationMinutes;
1305
1344
  var slots = [];
1306
- var _iterator5 = _createForOfIteratorHelper(venueProducts),
1307
- _step5;
1345
+ var _iterator6 = _createForOfIteratorHelper(venueProducts),
1346
+ _step6;
1308
1347
  try {
1309
- for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
1310
- var product = _step5.value;
1311
- slots.push.apply(slots, _toConsumableArray(expandMergedSlotToIndividual(product, slotDuration)));
1348
+ var _loop = function _loop() {
1349
+ var product = _step6.value;
1350
+ slots.push.apply(slots, _toConsumableArray(expandMergedSlotToIndividual(product, slotDuration).map(function (s) {
1351
+ return _objectSpread(_objectSpread({}, s), {}, {
1352
+ productId: Number(product.product_id)
1353
+ });
1354
+ })));
1355
+ };
1356
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
1357
+ _loop();
1312
1358
  }
1313
1359
  } catch (err) {
1314
- _iterator5.e(err);
1360
+ _iterator6.e(err);
1315
1361
  } finally {
1316
- _iterator5.f();
1362
+ _iterator6.f();
1317
1363
  }
1318
1364
  return slots.sort(function (a, b) {
1319
1365
  return a.startTime.localeCompare(b.startTime);
1320
1366
  });
1321
1367
  }
1322
1368
 
1369
+ /** getSelectedSlotsForResource 的 (resourceId, productId) 精确版,内部使用。 */
1370
+ }, {
1371
+ key: "getSelectedSlotsForResourceProduct",
1372
+ value: function getSelectedSlotsForResourceProduct(resourceId, productId) {
1373
+ return this.getSelectedSlotsForResource(resourceId, productId);
1374
+ }
1375
+
1323
1376
  /**
1324
1377
  * 判断某个时段是否已选中。
1378
+ * 不传 productId 时:只要该资源下任一商品在 startTime 被选中即返回 true;传了则精确匹配。
1325
1379
  */
1326
1380
  }, {
1327
1381
  key: "isSlotSelected",
1328
- value: function isSlotSelected(resourceId, startTime) {
1329
- return this.getSelectedSlotsForResource(resourceId).some(function (s) {
1382
+ value: function isSlotSelected(resourceId, startTime, productId) {
1383
+ return this.getSelectedSlotsForResource(resourceId, productId).some(function (s) {
1330
1384
  return s.startTime === startTime;
1331
1385
  });
1332
1386
  }
1333
1387
 
1334
1388
  /**
1335
- * 获取所有已选时段(按资源分组)。
1389
+ * 判断指定 (resourceId, productId, startTime) 格子是否应因其它已选项而被禁用。
1390
+ * 规则:
1391
+ * 1) 同一 resourceId 下若已选了另一个 productId 的同 startTime → 禁用
1392
+ * 2) 当前 resource 是组合资源:若其任一 child resource 在 startTime 被选中 → 禁用
1393
+ * 3) 当前 resource 是某些组合资源的 child:若该组合资源在 startTime 被选中 → 禁用
1394
+ * 4) 两个组合资源的 child 集合有交集,且对方在该 startTime 被选中 → 禁用
1395
+ */
1396
+ }, {
1397
+ key: "isSlotDisabledBySelection",
1398
+ value: function isSlotDisabledBySelection(params) {
1399
+ var _this7 = this;
1400
+ var resourceId = params.resourceId,
1401
+ productId = params.productId,
1402
+ startTime = params.startTime;
1403
+ var allSelected = this.getAllSelectedSlots();
1404
+ var getSelectedAt = function getSelectedAt(resId) {
1405
+ var list = allSelected.get(resId) || [];
1406
+ return list.filter(function (s) {
1407
+ return s.startTime === startTime;
1408
+ });
1409
+ };
1410
+
1411
+ // 规则 1:同场地、不同 productId 的已选
1412
+ var sameResourceSelections = getSelectedAt(resourceId);
1413
+ if (sameResourceSelections.some(function (s) {
1414
+ return Number(s.productId) !== Number(productId);
1415
+ })) {
1416
+ return true;
1417
+ }
1418
+
1419
+ // 组合资源字段缓存
1420
+ var getCombinedChildIds = function getCombinedChildIds(resId) {
1421
+ var raw = _this7.store.rawResourceData.find(function (r) {
1422
+ return String(r.resourceId) === String(resId);
1423
+ });
1424
+ var combined = raw === null || raw === void 0 ? void 0 : raw.combined_resource;
1425
+ if (combined && combined.status === 1 && Array.isArray(combined.resource_ids)) {
1426
+ return combined.resource_ids;
1427
+ }
1428
+ return [];
1429
+ };
1430
+ var currentChildIds = getCombinedChildIds(resourceId);
1431
+ var currentIsCombined = currentChildIds.length > 0;
1432
+
1433
+ // 规则 2:当前是组合资源,任一子资源被选 → 禁用
1434
+ if (currentIsCombined) {
1435
+ var _iterator7 = _createForOfIteratorHelper(currentChildIds),
1436
+ _step7;
1437
+ try {
1438
+ for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
1439
+ var childId = _step7.value;
1440
+ if (getSelectedAt(childId).length > 0) return true;
1441
+ }
1442
+ } catch (err) {
1443
+ _iterator7.e(err);
1444
+ } finally {
1445
+ _iterator7.f();
1446
+ }
1447
+ }
1448
+
1449
+ // 规则 3 & 4:扫描所有已选的 (resId),若是组合资源,检查其 children 是否包含当前 resourceId 或与当前 child 集合有交集
1450
+ var _iterator8 = _createForOfIteratorHelper(allSelected),
1451
+ _step8;
1452
+ try {
1453
+ for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
1454
+ var _step8$value = _slicedToArray(_step8.value, 2),
1455
+ selectedResId = _step8$value[0],
1456
+ slots = _step8$value[1];
1457
+ if (!slots.some(function (s) {
1458
+ return s.startTime === startTime;
1459
+ })) continue;
1460
+ if (String(selectedResId) === String(resourceId)) continue;
1461
+ var selectedChildIds = getCombinedChildIds(selectedResId);
1462
+ if (selectedChildIds.length === 0) continue;
1463
+
1464
+ // 对方是组合资源,其 children 包含当前 resourceId(规则 3)
1465
+ if (selectedChildIds.some(function (id) {
1466
+ return String(id) === String(resourceId);
1467
+ })) {
1468
+ return true;
1469
+ }
1470
+
1471
+ // 双方都是组合资源,child 集合有交集(规则 4)
1472
+ if (currentIsCombined) {
1473
+ var intersect = selectedChildIds.some(function (id) {
1474
+ return currentChildIds.some(function (cid) {
1475
+ return String(cid) === String(id);
1476
+ });
1477
+ });
1478
+ if (intersect) return true;
1479
+ }
1480
+ }
1481
+ } catch (err) {
1482
+ _iterator8.e(err);
1483
+ } finally {
1484
+ _iterator8.f();
1485
+ }
1486
+ return false;
1487
+ }
1488
+
1489
+ /**
1490
+ * 获取所有已选时段(按资源分组)。每个 slot 上带 productId,便于 UI 做 per-product 判定。
1336
1491
  */
1337
1492
  }, {
1338
1493
  key: "getAllSelectedSlots",
@@ -1346,87 +1501,112 @@ export var VenueBookingImpl = /*#__PURE__*/function (_BaseModule) {
1346
1501
  return (_p$metadata3 = p.metadata) === null || _p$metadata3 === void 0 ? void 0 : _p$metadata3.venue_booking;
1347
1502
  });
1348
1503
  var slotDuration = this.store.slotConfig.slotDurationMinutes;
1349
- var _iterator6 = _createForOfIteratorHelper(venueProducts),
1350
- _step6;
1504
+ var _iterator9 = _createForOfIteratorHelper(venueProducts),
1505
+ _step9;
1351
1506
  try {
1352
- for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
1507
+ var _loop2 = function _loop2() {
1353
1508
  var _product$metadata;
1354
- var product = _step6.value;
1509
+ var product = _step9.value;
1355
1510
  var resourceId = (_product$metadata = product.metadata) === null || _product$metadata === void 0 ? void 0 : _product$metadata.resource_id;
1356
- if (resourceId == null) continue;
1511
+ if (resourceId == null) return 1; // continue
1512
+ var productId = Number(product.product_id);
1357
1513
  var existing = result.get(resourceId) || [];
1358
- existing.push.apply(existing, _toConsumableArray(expandMergedSlotToIndividual(product, slotDuration)));
1514
+ existing.push.apply(existing, _toConsumableArray(expandMergedSlotToIndividual(product, slotDuration).map(function (s) {
1515
+ return _objectSpread(_objectSpread({}, s), {}, {
1516
+ productId: productId
1517
+ });
1518
+ })));
1359
1519
  result.set(resourceId, existing);
1520
+ };
1521
+ for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
1522
+ if (_loop2()) continue;
1360
1523
  }
1361
1524
  } catch (err) {
1362
- _iterator6.e(err);
1525
+ _iterator9.e(err);
1363
1526
  } finally {
1364
- _iterator6.f();
1527
+ _iterator9.f();
1365
1528
  }
1366
- var _iterator7 = _createForOfIteratorHelper(result),
1367
- _step7;
1529
+ var _iterator10 = _createForOfIteratorHelper(result),
1530
+ _step10;
1368
1531
  try {
1369
- for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
1370
- var _step7$value = _slicedToArray(_step7.value, 2),
1371
- key = _step7$value[0],
1372
- slots = _step7$value[1];
1532
+ for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
1533
+ var _step10$value = _slicedToArray(_step10.value, 2),
1534
+ key = _step10$value[0],
1535
+ slots = _step10$value[1];
1373
1536
  result.set(key, slots.sort(function (a, b) {
1374
1537
  return a.startTime.localeCompare(b.startTime);
1375
1538
  }));
1376
1539
  }
1377
1540
  } catch (err) {
1378
- _iterator7.e(err);
1541
+ _iterator10.e(err);
1379
1542
  } finally {
1380
- _iterator7.f();
1543
+ _iterator10.f();
1381
1544
  }
1382
1545
  return result;
1383
1546
  }
1384
1547
 
1385
1548
  /**
1386
- * 对指定资源的订单商品进行 reconcile:
1549
+ * 对指定 (resourceId, productId) 的订单商品进行 reconcile:
1387
1550
  * 清除旧商品 → 合并连续时段 → 重新写入。
1551
+ * 同一场地下不同商品互不干扰,各自单独 reconcile。
1388
1552
  */
1389
1553
  }, {
1390
- key: "reconcileOrderForResource",
1554
+ key: "reconcileOrderForResourceProduct",
1391
1555
  value: (function () {
1392
- var _reconcileOrderForResource = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(resourceId, slots) {
1393
- var mapping, tempOrder, merged, rawResource, venueProduct, i, _venueProduct$is_char, _rawResource$form_id, group, identityKey, bookingUuid, startMoment, endMoment, duration, customDepositData, booking;
1556
+ var _reconcileOrderForResourceProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(resourceId, productId, slots) {
1557
+ var mappings, mapping, tempOrder, matchesCurrent, merged, rawResource, childRawResources, venueProduct, i, _rawResource$form_id, _venueProduct$is_char, group, identityKey, bookingUuid, startMoment, endMoment, duration, customDepositData, resourceEntry, booking;
1394
1558
  return _regeneratorRuntime().wrap(function _callee17$(_context17) {
1395
1559
  while (1) switch (_context17.prev = _context17.next) {
1396
1560
  case 0:
1397
- mapping = this.resourceProductMap.get(resourceId);
1398
- if (!(!mapping || !this.store.order)) {
1561
+ mappings = this.resourceProductMap.get(resourceId);
1562
+ if (!(!mappings || !mappings.length || !this.store.order)) {
1399
1563
  _context17.next = 3;
1400
1564
  break;
1401
1565
  }
1402
1566
  return _context17.abrupt("return");
1403
1567
  case 3:
1568
+ mapping = mappings.find(function (m) {
1569
+ return m.productId === productId;
1570
+ });
1571
+ if (mapping) {
1572
+ _context17.next = 6;
1573
+ break;
1574
+ }
1575
+ return _context17.abrupt("return");
1576
+ case 6:
1404
1577
  tempOrder = this.store.order.ensureTempOrder();
1578
+ matchesCurrent = function matchesCurrent(meta, pid) {
1579
+ return !!(meta !== null && meta !== void 0 && meta.venue_booking) && String(meta === null || meta === void 0 ? void 0 : meta.resource_id) === String(resourceId) && Number(pid) === Number(productId);
1580
+ };
1405
1581
  tempOrder.products = tempOrder.products.filter(function (p) {
1406
- var _p$metadata4, _p$metadata5;
1407
- return !((_p$metadata4 = p.metadata) !== null && _p$metadata4 !== void 0 && _p$metadata4.venue_booking && String((_p$metadata5 = p.metadata) === null || _p$metadata5 === void 0 ? void 0 : _p$metadata5.resource_id) === String(resourceId));
1582
+ return !matchesCurrent(p.metadata, p.product_id);
1408
1583
  });
1409
1584
  tempOrder.bookings = (tempOrder.bookings || []).filter(function (b) {
1410
- var _b$metadata, _b$metadata2;
1411
- return !((_b$metadata = b.metadata) !== null && _b$metadata !== void 0 && _b$metadata.venue_booking && String((_b$metadata2 = b.metadata) === null || _b$metadata2 === void 0 ? void 0 : _b$metadata2.resource_id) === String(resourceId));
1585
+ var _b$metadata, _b$metadata2, _b$metadata$product_i, _b$metadata3, _b$product;
1586
+ if (!((_b$metadata = b.metadata) !== null && _b$metadata !== void 0 && _b$metadata.venue_booking)) return true;
1587
+ if (String((_b$metadata2 = b.metadata) === null || _b$metadata2 === void 0 ? void 0 : _b$metadata2.resource_id) !== String(resourceId)) return true;
1588
+ var bookingProductId = (_b$metadata$product_i = (_b$metadata3 = b.metadata) === null || _b$metadata3 === void 0 ? void 0 : _b$metadata3.product_id) !== null && _b$metadata$product_i !== void 0 ? _b$metadata$product_i : b === null || b === void 0 || (_b$product = b.product) === null || _b$product === void 0 ? void 0 : _b$product.product_id;
1589
+ if (bookingProductId == null) return false;
1590
+ return Number(bookingProductId) !== Number(productId);
1412
1591
  });
1413
1592
  if (slots.length) {
1414
- _context17.next = 12;
1593
+ _context17.next = 16;
1415
1594
  break;
1416
1595
  }
1417
1596
  this.store.order.applyDiscount();
1418
- _context17.next = 10;
1597
+ _context17.next = 14;
1419
1598
  return this.store.order.recalculateSummary({
1420
1599
  createIfMissing: true
1421
1600
  });
1422
- case 10:
1601
+ case 14:
1423
1602
  this.store.order.persistTempOrder();
1424
1603
  return _context17.abrupt("return");
1425
- case 12:
1604
+ case 16:
1426
1605
  merged = mergeConsecutiveSlots(slots);
1427
1606
  rawResource = this.store.rawResourceData.find(function (r) {
1428
1607
  return String(r.resourceId) === String(resourceId);
1429
1608
  });
1609
+ childRawResources = this.getCombinedChildRawResources(rawResource);
1430
1610
  venueProduct = this.getVenueProducts().find(function (p) {
1431
1611
  return p.id === mapping.productId;
1432
1612
  });
@@ -1439,6 +1619,31 @@ export var VenueBookingImpl = /*#__PURE__*/function (_BaseModule) {
1439
1619
  endMoment = dayjs(group.endTime, 'YYYY-MM-DD HH:mm');
1440
1620
  duration = endMoment.diff(startMoment, 'minute');
1441
1621
  customDepositData = cloneCustomDepositData(venueProduct === null || venueProduct === void 0 ? void 0 : venueProduct.custom_deposit_data);
1622
+ resourceEntry = {
1623
+ relation_type: 'form',
1624
+ like_status: 'common',
1625
+ id: resourceId,
1626
+ main_field: mapping.resourceName,
1627
+ form_id: (_rawResource$form_id = rawResource === null || rawResource === void 0 ? void 0 : rawResource.form_id) !== null && _rawResource$form_id !== void 0 ? _rawResource$form_id : mapping.formId,
1628
+ relation_id: resourceId,
1629
+ capacity: 1,
1630
+ metadata: {}
1631
+ };
1632
+ if (childRawResources && childRawResources.length) {
1633
+ resourceEntry.children = childRawResources.map(function (child) {
1634
+ var _child$form_id, _child$capacity;
1635
+ return {
1636
+ relation_type: 'form',
1637
+ like_status: 'common',
1638
+ id: child.resourceId,
1639
+ main_field: child.main_field || '',
1640
+ form_id: (_child$form_id = child.form_id) !== null && _child$form_id !== void 0 ? _child$form_id : child.formId,
1641
+ relation_id: child.resourceId,
1642
+ capacity: (_child$capacity = child.capacity) !== null && _child$capacity !== void 0 ? _child$capacity : 1,
1643
+ metadata: {}
1644
+ };
1645
+ });
1646
+ }
1442
1647
  tempOrder.products.push(normalizeOrderProduct({
1443
1648
  product_id: mapping.productId,
1444
1649
  product_variant_id: 0,
@@ -1484,16 +1689,7 @@ export var VenueBookingImpl = /*#__PURE__*/function (_BaseModule) {
1484
1689
  sub_type: 'minutes',
1485
1690
  duration: duration,
1486
1691
  like_status: 'common',
1487
- resources: [{
1488
- relation_type: 'form',
1489
- like_status: 'common',
1490
- id: resourceId,
1491
- main_field: mapping.resourceName,
1492
- form_id: (_rawResource$form_id = rawResource === null || rawResource === void 0 ? void 0 : rawResource.form_id) !== null && _rawResource$form_id !== void 0 ? _rawResource$form_id : mapping.formId,
1493
- relation_id: resourceId,
1494
- capacity: 1,
1495
- metadata: {}
1496
- }],
1692
+ resources: [resourceEntry],
1497
1693
  schedule_id: 0,
1498
1694
  select_date: startMoment.format('YYYY-MM-DD'),
1499
1695
  start_date: startMoment.format('YYYY-MM-DD'),
@@ -1513,29 +1709,61 @@ export var VenueBookingImpl = /*#__PURE__*/function (_BaseModule) {
1513
1709
  mapping: mapping,
1514
1710
  rawResource: rawResource,
1515
1711
  bookingUuid: bookingUuid,
1516
- productUid: identityKey
1712
+ productUid: identityKey,
1713
+ childResources: childRawResources
1517
1714
  });
1518
1715
  tempOrder.bookings.push(booking);
1519
1716
  }
1520
1717
  this.store.order.applyDiscount();
1521
- _context17.next = 20;
1718
+ _context17.next = 25;
1522
1719
  return this.store.order.recalculateSummary({
1523
1720
  createIfMissing: true
1524
1721
  });
1525
- case 20:
1722
+ case 25:
1526
1723
  this.store.order.persistTempOrder();
1527
- case 21:
1724
+ case 26:
1528
1725
  case "end":
1529
1726
  return _context17.stop();
1530
1727
  }
1531
1728
  }, _callee17, this);
1532
1729
  }));
1533
- function reconcileOrderForResource(_x9, _x10) {
1534
- return _reconcileOrderForResource.apply(this, arguments);
1730
+ function reconcileOrderForResourceProduct(_x9, _x10, _x11) {
1731
+ return _reconcileOrderForResourceProduct.apply(this, arguments);
1732
+ }
1733
+ return reconcileOrderForResourceProduct;
1734
+ }() /** 给定一个父 rawResource,返回其 combined_resource.resource_ids 对应的子 rawResource 列表。 */)
1735
+ }, {
1736
+ key: "getCombinedChildRawResources",
1737
+ value: function getCombinedChildRawResources(rawResource) {
1738
+ var _this8 = this;
1739
+ if (!rawResource) return undefined;
1740
+ var combined = rawResource.combined_resource;
1741
+ if (!combined || combined.status !== 1 || !Array.isArray(combined.resource_ids) || !combined.resource_ids.length) {
1742
+ return undefined;
1743
+ }
1744
+ var children = [];
1745
+ var _iterator11 = _createForOfIteratorHelper(combined.resource_ids),
1746
+ _step11;
1747
+ try {
1748
+ var _loop3 = function _loop3() {
1749
+ var id = _step11.value;
1750
+ var child = _this8.store.rawResourceData.find(function (r) {
1751
+ return String(r.resourceId) === String(id);
1752
+ });
1753
+ if (child) children.push(child);
1754
+ };
1755
+ for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
1756
+ _loop3();
1757
+ }
1758
+ } catch (err) {
1759
+ _iterator11.e(err);
1760
+ } finally {
1761
+ _iterator11.f();
1535
1762
  }
1536
- return reconcileOrderForResource;
1537
- }() // ─── 配置 ───
1538
- )
1763
+ return children.length ? children : undefined;
1764
+ }
1765
+
1766
+ // ─── 配置 ───
1539
1767
  }, {
1540
1768
  key: "setSlotConfig",
1541
1769
  value: function setSlotConfig(config) {
@@ -1590,10 +1818,10 @@ export var VenueBookingImpl = /*#__PURE__*/function (_BaseModule) {
1590
1818
  }, {
1591
1819
  key: "injectScheduleResolverToQuotation",
1592
1820
  value: function injectScheduleResolverToQuotation() {
1593
- var _this7 = this;
1821
+ var _this9 = this;
1594
1822
  if (this.store.quotation && this.store.schedule) {
1595
1823
  this.store.quotation.setScheduleResolver(function (id) {
1596
- return _this7.store.schedule.getScheduleListByIds([id])[0];
1824
+ return _this9.store.schedule.getScheduleListByIds([id])[0];
1597
1825
  });
1598
1826
  }
1599
1827
  }
@@ -1662,7 +1890,7 @@ export var VenueBookingImpl = /*#__PURE__*/function (_BaseModule) {
1662
1890
  }
1663
1891
  }, _callee19, this, [[1, 7]]);
1664
1892
  }));
1665
- function onCustomerLogin(_x11) {
1893
+ function onCustomerLogin(_x12) {
1666
1894
  return _onCustomerLogin.apply(this, arguments);
1667
1895
  }
1668
1896
  return onCustomerLogin;
@@ -1671,60 +1899,67 @@ export var VenueBookingImpl = /*#__PURE__*/function (_BaseModule) {
1671
1899
  key: "recalculateOrderPricesFromQuotation",
1672
1900
  value: function recalculateOrderPricesFromQuotation() {
1673
1901
  var _tempOrder$products,
1674
- _this8 = this;
1902
+ _this10 = this;
1675
1903
  if (!this.store.order || !this.store.quotation) return;
1676
1904
  var tempOrder = this.store.order.getTempOrder();
1677
1905
  if (!(tempOrder !== null && tempOrder !== void 0 && (_tempOrder$products = tempOrder.products) !== null && _tempOrder$products !== void 0 && _tempOrder$products.length)) return;
1678
1906
  var now = dayjs().format('YYYY-MM-DD HH:mm:ss');
1679
- var _iterator8 = _createForOfIteratorHelper(tempOrder.products),
1680
- _step8;
1907
+ var _iterator12 = _createForOfIteratorHelper(tempOrder.products),
1908
+ _step12;
1681
1909
  try {
1682
- var _loop = function _loop() {
1683
- var _product$metadata2;
1684
- var product = _step8.value;
1685
- if ((_product$metadata2 = product.metadata) !== null && _product$metadata2 !== void 0 && _product$metadata2.venue_booking) {
1686
- var mapping = _this8.resourceProductMap.get(product.metadata.resource_id);
1687
- if (!mapping) return 1; // continue
1688
- var slots = expandMergedSlotToIndividual(product, _this8.store.slotConfig.slotDurationMinutes);
1689
- var updatedSlots = slots.map(function (slot) {
1690
- var _getPriceForProduct;
1691
- return _objectSpread(_objectSpread({}, slot), {}, {
1692
- price: (_getPriceForProduct = _this8.store.quotation.getPriceForProduct({
1910
+ var _loop4 = function _loop4() {
1911
+ var _product$metadata2;
1912
+ var product = _step12.value;
1913
+ if ((_product$metadata2 = product.metadata) !== null && _product$metadata2 !== void 0 && _product$metadata2.venue_booking) {
1914
+ var mappings = _this10.resourceProductMap.get(product.metadata.resource_id);
1915
+ if (!mappings || !mappings.length) return 0; // continue
1916
+ var mapping = mappings.find(function (m) {
1917
+ return Number(m.productId) === Number(product.product_id);
1918
+ }) || mappings[0];
1919
+ if (!mapping) return 0; // continue
1920
+ var slots = expandMergedSlotToIndividual(product, _this10.store.slotConfig.slotDurationMinutes);
1921
+ var updatedSlots = slots.map(function (slot) {
1922
+ var _getPriceForProduct;
1923
+ return _objectSpread(_objectSpread({}, slot), {}, {
1693
1924
  productId: mapping.productId,
1694
- datetime: slot.startTime
1695
- })) !== null && _getPriceForProduct !== void 0 ? _getPriceForProduct : mapping.price
1925
+ price: (_getPriceForProduct = _this10.store.quotation.getPriceForProduct({
1926
+ productId: mapping.productId,
1927
+ datetime: slot.startTime
1928
+ })) !== null && _getPriceForProduct !== void 0 ? _getPriceForProduct : mapping.price
1929
+ });
1696
1930
  });
1697
- });
1698
- var merged = mergeConsecutiveSlots(updatedSlots);
1699
- if (merged.length === 1) {
1700
- product.selling_price = merged[0].totalPrice;
1701
- product.original_price = merged[0].totalPrice;
1702
- product.metadata.price_breakdown = buildPriceBreakdown({
1703
- group: merged[0],
1704
- productId: mapping.productId,
1705
- quotation: _this8.store.quotation
1931
+ var merged = mergeConsecutiveSlots(updatedSlots);
1932
+ if (merged.length === 1) {
1933
+ product.selling_price = merged[0].totalPrice;
1934
+ product.original_price = merged[0].totalPrice;
1935
+ product.metadata.price_breakdown = buildPriceBreakdown({
1936
+ group: merged[0],
1937
+ productId: mapping.productId,
1938
+ quotation: _this10.store.quotation
1939
+ });
1940
+ }
1941
+ } else if (product.product_id != null) {
1942
+ var _product$product_vari;
1943
+ var quotationPrice = _this10.store.quotation.getPriceForProduct({
1944
+ productId: product.product_id,
1945
+ variantId: (_product$product_vari = product.product_variant_id) !== null && _product$product_vari !== void 0 ? _product$product_vari : undefined,
1946
+ datetime: now
1706
1947
  });
1948
+ if (quotationPrice !== null) {
1949
+ product.selling_price = quotationPrice;
1950
+ product.original_price = quotationPrice;
1951
+ }
1707
1952
  }
1708
- } else if (product.product_id != null) {
1709
- var _product$product_vari;
1710
- var quotationPrice = _this8.store.quotation.getPriceForProduct({
1711
- productId: product.product_id,
1712
- variantId: (_product$product_vari = product.product_variant_id) !== null && _product$product_vari !== void 0 ? _product$product_vari : undefined,
1713
- datetime: now
1714
- });
1715
- if (quotationPrice !== null) {
1716
- product.selling_price = quotationPrice;
1717
- product.original_price = quotationPrice;
1718
- }
1719
- }
1720
- };
1721
- for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
1722
- if (_loop()) continue;
1953
+ },
1954
+ _ret;
1955
+ for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) {
1956
+ _ret = _loop4();
1957
+ if (_ret === 0) continue;
1723
1958
  }
1724
1959
  } catch (err) {
1725
- _iterator8.e(err);
1960
+ _iterator12.e(err);
1726
1961
  } finally {
1727
- _iterator8.f();
1962
+ _iterator12.f();
1728
1963
  }
1729
1964
  }
1730
1965
  }, {
@@ -1775,7 +2010,7 @@ export var VenueBookingImpl = /*#__PURE__*/function (_BaseModule) {
1775
2010
  }
1776
2011
  }, _callee20, this, [[1, 15]]);
1777
2012
  }));
1778
- function scanCode(_x12, _x13) {
2013
+ function scanCode(_x13, _x14) {
1779
2014
  return _scanCode.apply(this, arguments);
1780
2015
  }
1781
2016
  return scanCode;
@@ -1792,7 +2027,7 @@ export var VenueBookingImpl = /*#__PURE__*/function (_BaseModule) {
1792
2027
  key: "setDiscountSelected",
1793
2028
  value: (function () {
1794
2029
  var _setDiscountSelected = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(params) {
1795
- var _tempOrder$holder, _this$store$order$get, _this$store$order$get2, list, beforeTarget, updated, updatedTarget, tempOrder, orderStore, discountModule, rulesModule, holders, nextDiscountList, _tempOrder$holder2, result, beforeSelectedIds, _iterator9, _step9, d, selectedResourceIds, _iterator10, _step10, _product$discount_lis, product, before, totalPerUnitDiscount, newSellingPrice, afterApplyTarget, finalSummary, finalProduct, finalTarget;
2030
+ var _tempOrder$holder, _this$store$order$get, _this$store$order$get2, list, beforeTarget, updated, updatedTarget, tempOrder, orderStore, discountModule, rulesModule, holders, nextDiscountList, _tempOrder$holder2, result, beforeSelectedIds, _iterator13, _step13, d, selectedResourceIds, _iterator14, _step14, _product$_origin, product, totalPerUnitDiscount, newSellingPrice, afterApplyTarget, finalSummary, finalProduct, finalTarget;
1796
2031
  return _regeneratorRuntime().wrap(function _callee21$(_context21) {
1797
2032
  while (1) switch (_context21.prev = _context21.next) {
1798
2033
  case 0:
@@ -1852,18 +2087,18 @@ export var VenueBookingImpl = /*#__PURE__*/function (_BaseModule) {
1852
2087
  }).map(function (d) {
1853
2088
  return d.id;
1854
2089
  }));
1855
- _iterator9 = _createForOfIteratorHelper(nextDiscountList);
2090
+ _iterator13 = _createForOfIteratorHelper(nextDiscountList);
1856
2091
  try {
1857
- for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
1858
- d = _step9.value;
2092
+ for (_iterator13.s(); !(_step13 = _iterator13.n()).done;) {
2093
+ d = _step13.value;
1859
2094
  if (d.isSelected && !beforeSelectedIds.has(d.id)) {
1860
2095
  d.isSelected = false;
1861
2096
  }
1862
2097
  }
1863
2098
  } catch (err) {
1864
- _iterator9.e(err);
2099
+ _iterator13.e(err);
1865
2100
  } finally {
1866
- _iterator9.f();
2101
+ _iterator13.f();
1867
2102
  }
1868
2103
  }
1869
2104
  }
@@ -1872,70 +2107,71 @@ export var VenueBookingImpl = /*#__PURE__*/function (_BaseModule) {
1872
2107
  return d.isSelected;
1873
2108
  }).map(function (d) {
1874
2109
  return d.id;
1875
- }));
1876
- _iterator10 = _createForOfIteratorHelper(tempOrder.products);
2110
+ })); // 无条件归一化:不论 Rules 是否清空 discount_list、长度是否变化,
2111
+ // 都以 original_price - Σ (当前选中 discount_list.amount) 重算 selling_price。
2112
+ // 目的:避免 unselect 后 selling_price 残留、reselect 时把残留价带进下一轮 Rules 造成双折扣。
2113
+ // 手动改价商品(_origin.isManualDiscount=true)不参与券流程归一化,保留手工价。
2114
+ _iterator14 = _createForOfIteratorHelper(tempOrder.products);
1877
2115
  _context21.prev = 19;
1878
- _iterator10.s();
2116
+ _iterator14.s();
1879
2117
  case 21:
1880
- if ((_step10 = _iterator10.n()).done) {
1881
- _context21.next = 30;
2118
+ if ((_step14 = _iterator14.n()).done) {
2119
+ _context21.next = 32;
1882
2120
  break;
1883
2121
  }
1884
- product = _step10.value;
1885
- if ((_product$discount_lis = product.discount_list) !== null && _product$discount_lis !== void 0 && _product$discount_lis.length) {
2122
+ product = _step14.value;
2123
+ if (!((_product$_origin = product._origin) !== null && _product$_origin !== void 0 && _product$_origin.isManualDiscount)) {
1886
2124
  _context21.next = 25;
1887
2125
  break;
1888
2126
  }
1889
- return _context21.abrupt("continue", 28);
2127
+ return _context21.abrupt("continue", 30);
1890
2128
  case 25:
1891
- before = product.discount_list.length;
1892
- product.discount_list = product.discount_list.filter(function (pd) {
2129
+ // 1. product.discount_list 和当前选中的 discount 对齐(剔除已取消的券)
2130
+ product.discount_list = (product.discount_list || []).filter(function (pd) {
1893
2131
  var _pd$discount$resource, _pd$discount;
1894
2132
  var rid = (_pd$discount$resource = (_pd$discount = pd.discount) === null || _pd$discount === void 0 ? void 0 : _pd$discount.resource_id) !== null && _pd$discount$resource !== void 0 ? _pd$discount$resource : pd.id;
1895
2133
  return rid != null && selectedResourceIds.has(rid);
1896
2134
  });
1897
- if (product.discount_list.length < before) {
1898
- // 基于剩余的 discount_list 重算 selling_price
1899
- // 约定:pd.amount per-unit 折扣额,remaining 加总即单品券后总折扣。
1900
- totalPerUnitDiscount = product.discount_list.reduce(function (sum, pd) {
1901
- return sum + (pd.amount || 0);
1902
- }, 0);
1903
- newSellingPrice = new Decimal(product.original_price || product.selling_price || 0).minus(totalPerUnitDiscount).toDecimalPlaces(2).toString();
1904
- product.selling_price = newSellingPrice;
1905
- if (product.metadata) {
1906
- product.metadata.main_product_selling_price = newSellingPrice;
1907
- }
2135
+
2136
+ // 2. original_price 为基准重算 selling_price
2137
+ totalPerUnitDiscount = (product.discount_list || []).reduce(function (sum, pd) {
2138
+ return sum + (pd.amount || 0);
2139
+ }, 0);
2140
+ newSellingPrice = new Decimal(product.original_price || 0).minus(totalPerUnitDiscount).toDecimalPlaces(2).toString();
2141
+ product.selling_price = newSellingPrice;
2142
+ if (product.metadata) {
2143
+ product.metadata.main_product_selling_price = newSellingPrice;
1908
2144
  }
1909
- case 28:
1910
- _context21.next = 21;
1911
- break;
1912
2145
  case 30:
1913
- _context21.next = 35;
2146
+ _context21.next = 21;
1914
2147
  break;
1915
2148
  case 32:
1916
- _context21.prev = 32;
2149
+ _context21.next = 37;
2150
+ break;
2151
+ case 34:
2152
+ _context21.prev = 34;
1917
2153
  _context21.t0 = _context21["catch"](19);
1918
- _iterator10.e(_context21.t0);
1919
- case 35:
1920
- _context21.prev = 35;
1921
- _iterator10.f();
1922
- return _context21.finish(35);
1923
- case 38:
2154
+ _iterator14.e(_context21.t0);
2155
+ case 37:
2156
+ _context21.prev = 37;
2157
+ _iterator14.f();
2158
+ return _context21.finish(37);
2159
+ case 40:
1924
2160
  OrderModule.populateSavedAmounts(tempOrder.products, nextDiscountList);
1925
- _context21.next = 41;
2161
+ _context21.next = 43;
1926
2162
  return discountModule === null || discountModule === void 0 ? void 0 : discountModule.setDiscountList(nextDiscountList);
1927
- case 41:
2163
+ case 43:
1928
2164
  tempOrder.discount_list = (nextDiscountList || []).filter(function (d) {
1929
2165
  return d.isSelected;
1930
2166
  });
1931
2167
  afterApplyTarget = this.store.order.getDiscountList().find(function (d) {
1932
2168
  return d.id === params.discountId;
1933
2169
  }) || null;
1934
- _context21.next = 45;
2170
+ _context21.next = 47;
1935
2171
  return this.store.order.recalculateSummary({
1936
2172
  createIfMissing: true
1937
2173
  });
1938
- case 45:
2174
+ case 47:
1939
2175
  this.store.order.persistTempOrder();
1940
2176
  finalSummary = ((_this$store$order$get = this.store.order.getTempOrder()) === null || _this$store$order$get === void 0 ? void 0 : _this$store$order$get.summary) || null;
1941
2177
  finalProduct = ((_this$store$order$get2 = this.store.order.getTempOrder()) === null || _this$store$order$get2 === void 0 || (_this$store$order$get2 = _this$store$order$get2.products) === null || _this$store$order$get2 === void 0 ? void 0 : _this$store$order$get2[0]) || null;
@@ -1944,18 +2180,18 @@ export var VenueBookingImpl = /*#__PURE__*/function (_BaseModule) {
1944
2180
  return d.id === params.discountId;
1945
2181
  }) || null;
1946
2182
  return _context21.abrupt("return", this.store.order.getDiscountList());
1947
- case 53:
1948
- _context21.prev = 53;
2183
+ case 55:
2184
+ _context21.prev = 55;
1949
2185
  _context21.t1 = _context21["catch"](1);
1950
2186
  this.logMethodError('setDiscountSelected', _context21.t1);
1951
2187
  throw _context21.t1;
1952
- case 57:
2188
+ case 59:
1953
2189
  case "end":
1954
2190
  return _context21.stop();
1955
2191
  }
1956
- }, _callee21, this, [[1, 53], [19, 32, 35, 38]]);
2192
+ }, _callee21, this, [[1, 55], [19, 34, 37, 40]]);
1957
2193
  }));
1958
- function setDiscountSelected(_x14) {
2194
+ function setDiscountSelected(_x15) {
1959
2195
  return _setDiscountSelected.apply(this, arguments);
1960
2196
  }
1961
2197
  return setDiscountSelected;
@@ -2153,7 +2389,7 @@ export var VenueBookingImpl = /*#__PURE__*/function (_BaseModule) {
2153
2389
  }
2154
2390
  }, _callee25, this, [[1, 16]]);
2155
2391
  }));
2156
- function addProductToOrder(_x15) {
2392
+ function addProductToOrder(_x16) {
2157
2393
  return _addProductToOrder.apply(this, arguments);
2158
2394
  }
2159
2395
  return addProductToOrder;
@@ -2202,7 +2438,7 @@ export var VenueBookingImpl = /*#__PURE__*/function (_BaseModule) {
2202
2438
  }
2203
2439
  }, _callee26, this, [[1, 15]]);
2204
2440
  }));
2205
- function updateProductInOrder(_x16) {
2441
+ function updateProductInOrder(_x17) {
2206
2442
  return _updateProductInOrder.apply(this, arguments);
2207
2443
  }
2208
2444
  return updateProductInOrder;
@@ -2251,7 +2487,7 @@ export var VenueBookingImpl = /*#__PURE__*/function (_BaseModule) {
2251
2487
  }
2252
2488
  }, _callee27, this, [[1, 15]]);
2253
2489
  }));
2254
- function removeProductFromOrder(_x17) {
2490
+ function removeProductFromOrder(_x18) {
2255
2491
  return _removeProductFromOrder.apply(this, arguments);
2256
2492
  }
2257
2493
  return removeProductFromOrder;
@@ -2290,7 +2526,7 @@ export var VenueBookingImpl = /*#__PURE__*/function (_BaseModule) {
2290
2526
  key: "loadOpenDataConfig",
2291
2527
  value: function () {
2292
2528
  var _loadOpenDataConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29() {
2293
- var _this9 = this;
2529
+ var _this11 = this;
2294
2530
  var lastFetchedAt, cachedData;
2295
2531
  return _regeneratorRuntime().wrap(function _callee29$(_context29) {
2296
2532
  while (1) switch (_context29.prev = _context29.next) {
@@ -2321,10 +2557,10 @@ export var VenueBookingImpl = /*#__PURE__*/function (_BaseModule) {
2321
2557
  target: 'venue_booking+online_store',
2322
2558
  section_code: [].concat(OPEN_DATA_SECTION_CODES)
2323
2559
  }).then(function (openDataConfig) {
2324
- _this9.otherParams.openData = openDataConfig;
2560
+ _this11.otherParams.openData = openDataConfig;
2325
2561
  return openDataConfig;
2326
2562
  }).finally(function () {
2327
- _this9.loadOpenDataConfigInFlight = null;
2563
+ _this11.loadOpenDataConfigInFlight = null;
2328
2564
  });
2329
2565
  return _context29.abrupt("return", this.loadOpenDataConfigInFlight);
2330
2566
  case 11:
@@ -2421,7 +2657,7 @@ export var VenueBookingImpl = /*#__PURE__*/function (_BaseModule) {
2421
2657
  }
2422
2658
  }, _callee31, this, [[3, 13]]);
2423
2659
  }));
2424
- function fetchItemRuleConfigsByModelIds(_x18) {
2660
+ function fetchItemRuleConfigsByModelIds(_x19) {
2425
2661
  return _fetchItemRuleConfigsByModelIds.apply(this, arguments);
2426
2662
  }
2427
2663
  return fetchItemRuleConfigsByModelIds;
@@ -2453,17 +2689,17 @@ export var VenueBookingImpl = /*#__PURE__*/function (_BaseModule) {
2453
2689
  if (visited.has(value)) return;
2454
2690
  visited.add(value);
2455
2691
  if (Array.isArray(value)) {
2456
- var _iterator11 = _createForOfIteratorHelper(value),
2457
- _step11;
2692
+ var _iterator15 = _createForOfIteratorHelper(value),
2693
+ _step15;
2458
2694
  try {
2459
- for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
2460
- var item = _step11.value;
2695
+ for (_iterator15.s(); !(_step15 = _iterator15.n()).done;) {
2696
+ var item = _step15.value;
2461
2697
  collectFromValue(item);
2462
2698
  }
2463
2699
  } catch (err) {
2464
- _iterator11.e(err);
2700
+ _iterator15.e(err);
2465
2701
  } finally {
2466
- _iterator11.f();
2702
+ _iterator15.f();
2467
2703
  }
2468
2704
  return;
2469
2705
  }
@@ -2511,7 +2747,7 @@ export var VenueBookingImpl = /*#__PURE__*/function (_BaseModule) {
2511
2747
  key: "ensureItemRuleConfigsLoaded",
2512
2748
  value: function () {
2513
2749
  var _ensureItemRuleConfigsLoaded = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34() {
2514
- var _this10 = this;
2750
+ var _this12 = this;
2515
2751
  return _regeneratorRuntime().wrap(function _callee34$(_context34) {
2516
2752
  while (1) switch (_context34.prev = _context34.next) {
2517
2753
  case 0:
@@ -2532,19 +2768,19 @@ export var VenueBookingImpl = /*#__PURE__*/function (_BaseModule) {
2532
2768
  return _regeneratorRuntime().wrap(function _callee33$(_context33) {
2533
2769
  while (1) switch (_context33.prev = _context33.next) {
2534
2770
  case 0:
2535
- runtimeConfig = _this10.getItemRuleRuntimeConfig();
2771
+ runtimeConfig = _this12.getItemRuleRuntimeConfig();
2536
2772
  staticConfigs = normalizeItemRuleStrategies(runtimeConfig.strategyConfigs);
2537
2773
  if (!(staticConfigs.length > 0)) {
2538
2774
  _context33.next = 6;
2539
2775
  break;
2540
2776
  }
2541
- _this10.itemRuleConfigs = staticConfigs;
2542
- _this10.itemRuleEvaluator.setStrategyConfigs(staticConfigs);
2543
- return _context33.abrupt("return", _this10.itemRuleConfigs);
2777
+ _this12.itemRuleConfigs = staticConfigs;
2778
+ _this12.itemRuleEvaluator.setStrategyConfigs(staticConfigs);
2779
+ return _context33.abrupt("return", _this12.itemRuleConfigs);
2544
2780
  case 6:
2545
- _this10.itemRuleConfigs = [];
2546
- _this10.itemRuleEvaluator.setStrategyConfigs([]);
2547
- return _context33.abrupt("return", _this10.itemRuleConfigs);
2781
+ _this12.itemRuleConfigs = [];
2782
+ _this12.itemRuleEvaluator.setStrategyConfigs([]);
2783
+ return _context33.abrupt("return", _this12.itemRuleConfigs);
2548
2784
  case 9:
2549
2785
  case "end":
2550
2786
  return _context33.stop();
@@ -2618,7 +2854,7 @@ export var VenueBookingImpl = /*#__PURE__*/function (_BaseModule) {
2618
2854
  key: "applyPrefillByItemRule",
2619
2855
  value: function () {
2620
2856
  var _applyPrefillByItemRule = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36() {
2621
- var strategyConfigs, businessData, prefillItems, productSourceMap, tempOrder, hasChanges, _iterator12, _step12, _prefillItem$product_, _targetProduct$_origi, prefillItem, productId, productVariantId, targetQuantity, sourceItem, productIndex, _sourceItem$price, sellingPrice, targetProduct, existedQuantity, delta, nextProduct;
2857
+ var strategyConfigs, businessData, prefillItems, productSourceMap, tempOrder, hasChanges, _iterator16, _step16, _prefillItem$product_, _targetProduct$_origi, prefillItem, productId, productVariantId, targetQuantity, sourceItem, productIndex, _sourceItem$price, sellingPrice, targetProduct, existedQuantity, delta, nextProduct;
2622
2858
  return _regeneratorRuntime().wrap(function _callee36$(_context36) {
2623
2859
  while (1) switch (_context36.prev = _context36.next) {
2624
2860
  case 0:
@@ -2663,15 +2899,15 @@ export var VenueBookingImpl = /*#__PURE__*/function (_BaseModule) {
2663
2899
  productSourceMap = _context36.sent;
2664
2900
  tempOrder = this.ensureTempOrder();
2665
2901
  hasChanges = false;
2666
- _iterator12 = _createForOfIteratorHelper(prefillItems);
2902
+ _iterator16 = _createForOfIteratorHelper(prefillItems);
2667
2903
  _context36.prev = 20;
2668
- _iterator12.s();
2904
+ _iterator16.s();
2669
2905
  case 22:
2670
- if ((_step12 = _iterator12.n()).done) {
2906
+ if ((_step16 = _iterator16.n()).done) {
2671
2907
  _context36.next = 45;
2672
2908
  break;
2673
2909
  }
2674
- prefillItem = _step12.value;
2910
+ prefillItem = _step16.value;
2675
2911
  productId = Number(prefillItem.product_id);
2676
2912
  productVariantId = Number((_prefillItem$product_ = prefillItem.product_variant_id) !== null && _prefillItem$product_ !== void 0 ? _prefillItem$product_ : 0);
2677
2913
  targetQuantity = toNonNegativeInt(prefillItem.quantity);
@@ -2740,10 +2976,10 @@ export var VenueBookingImpl = /*#__PURE__*/function (_BaseModule) {
2740
2976
  case 47:
2741
2977
  _context36.prev = 47;
2742
2978
  _context36.t0 = _context36["catch"](20);
2743
- _iterator12.e(_context36.t0);
2979
+ _iterator16.e(_context36.t0);
2744
2980
  case 50:
2745
2981
  _context36.prev = 50;
2746
- _iterator12.f();
2982
+ _iterator16.f();
2747
2983
  return _context36.finish(50);
2748
2984
  case 53:
2749
2985
  if (!hasChanges) {
@@ -3095,7 +3331,7 @@ export var VenueBookingImpl = /*#__PURE__*/function (_BaseModule) {
3095
3331
  }
3096
3332
  }, _callee43, this);
3097
3333
  }));
3098
- function setOtherParams(_x19) {
3334
+ function setOtherParams(_x20) {
3099
3335
  return _setOtherParams.apply(this, arguments);
3100
3336
  }
3101
3337
  return setOtherParams;