@pisell/pisellos 2.2.247 → 2.2.249

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.
@@ -480,6 +480,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
480
480
  recalcOnHydrate?: boolean;
481
481
  }): Promise<OrderTempOrder>;
482
482
  private normalizeTempOrderForRuntime;
483
+ private hydrateLinkedBookingIdentity;
483
484
  private pickHydratedDisplayText;
484
485
  private formatHydratedNamePair;
485
486
  private buildHydratedProductOptionString;
@@ -445,7 +445,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
445
445
  value: function () {
446
446
  var _loadDiscountConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(params) {
447
447
  var _this$store$tempOrder, _this$store$discount, _this$store$tempOrder2;
448
- var orderId, discountList, _this$store$discount2, _this$store$discount3, _this$store$discount4, currentEditDiscounts, currentEditDiscountIds, mergedDiscountList;
448
+ var orderId, discountList, _this$store$discount2, _this$store$discount3, _this$store$discount4, currentEditDiscounts, runtimeDiscountIds, runtimeDiscounts, mergedDiscountList;
449
449
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
450
450
  while (1) switch (_context3.prev = _context3.next) {
451
451
  case 0:
@@ -464,29 +464,30 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
464
464
  case 3:
465
465
  discountList = _context3.sent;
466
466
  if (!discountList) {
467
- _context3.next = 12;
467
+ _context3.next = 13;
468
468
  break;
469
469
  }
470
470
  currentEditDiscounts = (((_this$store$discount2 = this.store.discount) === null || _this$store$discount2 === void 0 ? void 0 : _this$store$discount2.getDiscountList()) || []).filter(function (discount) {
471
471
  return discount === null || discount === void 0 ? void 0 : discount.isEditMode;
472
472
  });
473
- currentEditDiscountIds = new Set(currentEditDiscounts.map(function (discount) {
474
- return discount === null || discount === void 0 ? void 0 : discount.id;
475
- }));
476
- mergedDiscountList = [].concat(_toConsumableArray(currentEditDiscounts), _toConsumableArray(discountList.filter(function (discount) {
477
- return !currentEditDiscountIds.has(discount === null || discount === void 0 ? void 0 : discount.id);
478
- })));
479
- _context3.next = 10;
473
+ runtimeDiscountIds = new Set();
474
+ runtimeDiscounts = discountList.filter(function (discount) {
475
+ if (runtimeDiscountIds.has(discount === null || discount === void 0 ? void 0 : discount.id)) return false;
476
+ runtimeDiscountIds.add(discount === null || discount === void 0 ? void 0 : discount.id);
477
+ return true;
478
+ });
479
+ mergedDiscountList = [].concat(_toConsumableArray(currentEditDiscounts), _toConsumableArray(runtimeDiscounts));
480
+ _context3.next = 11;
480
481
  return (_this$store$discount3 = this.store.discount) === null || _this$store$discount3 === void 0 ? void 0 : _this$store$discount3.setOriginalDiscountList(mergedDiscountList);
481
- case 10:
482
- _context3.next = 12;
482
+ case 11:
483
+ _context3.next = 13;
483
484
  return (_this$store$discount4 = this.store.discount) === null || _this$store$discount4 === void 0 ? void 0 : _this$store$discount4.setDiscountList(mergedDiscountList);
484
- case 12:
485
+ case 13:
485
486
  if (params.apply !== false && (_this$store$tempOrder2 = this.store.tempOrder) !== null && _this$store$tempOrder2 !== void 0 && (_this$store$tempOrder2 = _this$store$tempOrder2.products) !== null && _this$store$tempOrder2 !== void 0 && _this$store$tempOrder2.length) {
486
487
  this.applyDiscount();
487
488
  }
488
489
  return _context3.abrupt("return", this.getDiscountList());
489
- case 14:
490
+ case 15:
490
491
  case "end":
491
492
  return _context3.stop();
492
493
  }
@@ -5140,12 +5141,54 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5140
5141
  _iterator22.f();
5141
5142
  }
5142
5143
  tempOrderExtend.productsByUid = productsByUid;
5144
+ this.hydrateLinkedBookingIdentity(nextTempOrder);
5143
5145
  if ((options === null || options === void 0 ? void 0 : options.ensureIdentity) !== false) {
5144
5146
  this.ensureExternalSaleNumber(nextTempOrder);
5145
5147
  }
5146
5148
  nextTempOrder.vouchers = raw.vouchers || [];
5147
5149
  return nextTempOrder;
5148
5150
  }
5151
+ }, {
5152
+ key: "hydrateLinkedBookingIdentity",
5153
+ value: function hydrateLinkedBookingIdentity(tempOrder) {
5154
+ var bookingUidByProductUid = new Map();
5155
+ var productByUid = new Map();
5156
+ (tempOrder.products || []).forEach(function (product) {
5157
+ var _product$metadata9;
5158
+ var productUid = (product === null || product === void 0 || (_product$metadata9 = product.metadata) === null || _product$metadata9 === void 0 ? void 0 : _product$metadata9.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
5159
+ if (productUid !== undefined && productUid !== null && String(productUid) !== '') {
5160
+ productByUid.set(String(productUid), product);
5161
+ }
5162
+ });
5163
+ (tempOrder.bookings || []).forEach(function (booking) {
5164
+ var _matchedProduct$metad;
5165
+ if (!booking || _typeof(booking) !== 'object') return;
5166
+ if (!booking.metadata || _typeof(booking.metadata) !== 'object') {
5167
+ booking.metadata = {};
5168
+ }
5169
+ var productUid = booking.product_uid || booking.metadata.product_uid;
5170
+ if (productUid === undefined || productUid === null || String(productUid) === '') return;
5171
+ var matchedProduct = productByUid.get(String(productUid));
5172
+ var existedProductBookingUid = (matchedProduct === null || matchedProduct === void 0 ? void 0 : matchedProduct.booking_uid) || (matchedProduct === null || matchedProduct === void 0 || (_matchedProduct$metad = matchedProduct.metadata) === null || _matchedProduct$metad === void 0 ? void 0 : _matchedProduct$metad.booking_uid);
5173
+ // 客户端订单详情可能缺少 booking 自身 uid,这里补齐后才能反写到商品行。
5174
+ var bookingUid = String(booking.metadata.unique_identification_number || existedProductBookingUid || createUuidV4());
5175
+ booking.metadata.unique_identification_number = bookingUid;
5176
+ bookingUidByProductUid.set(String(productUid), bookingUid);
5177
+ });
5178
+ (tempOrder.products || []).forEach(function (product) {
5179
+ var _product$metadata10;
5180
+ var productUid = (product === null || product === void 0 || (_product$metadata10 = product.metadata) === null || _product$metadata10 === void 0 ? void 0 : _product$metadata10.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
5181
+ if (productUid === undefined || productUid === null || String(productUid) === '') return;
5182
+ var bookingUid = bookingUidByProductUid.get(String(productUid));
5183
+ if (!bookingUid) return;
5184
+ if (!product.metadata || _typeof(product.metadata) !== 'object') {
5185
+ product.metadata = {};
5186
+ }
5187
+ var linkedBookingUid = String(product.booking_uid || product.metadata.booking_uid || bookingUid);
5188
+ product.booking_uid = linkedBookingUid;
5189
+ product.metadata.booking_uid = linkedBookingUid;
5190
+ });
5191
+ }
5149
5192
  }, {
5150
5193
  key: "pickHydratedDisplayText",
5151
5194
  value: function pickHydratedDisplayText(value) {
@@ -5273,13 +5316,26 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5273
5316
  key: "populateSavedAmounts",
5274
5317
  value: function populateSavedAmounts(productList, discountList) {
5275
5318
  var savedMap = new Map();
5276
- var addDiscountAmount = function addDiscountAmount(discount, quantity) {
5319
+ var editModeSavedMap = new Map();
5320
+ var runtimeSavedMap = new Map();
5321
+ var editModeDiscountKeys = new Set((discountList || []).filter(function (discount) {
5322
+ return discount === null || discount === void 0 ? void 0 : discount.isEditMode;
5323
+ }).map(function (discount) {
5324
+ return discount === null || discount === void 0 ? void 0 : discount.id;
5325
+ }).filter(function (id) {
5326
+ return id !== undefined && id !== null;
5327
+ }));
5328
+ var addDiscountAmount = function addDiscountAmount(targetMap, discountKey, amount) {
5329
+ targetMap.set(discountKey, (targetMap.get(discountKey) || new Decimal(0)).plus(amount));
5330
+ };
5331
+ var addProductDiscountAmount = function addProductDiscountAmount(discount, quantity, isPersistedProduct) {
5277
5332
  var _discount$discount3, _discount$metadata;
5278
5333
  var discountKey = ((_discount$discount3 = discount.discount) === null || _discount$discount3 === void 0 ? void 0 : _discount$discount3.resource_id) || discount.id;
5279
5334
  if (discountKey == null) return;
5280
5335
  var qty = Number(quantity) || 1;
5281
5336
  var amount = new Decimal(discount.amount || 0).times(qty).plus(((_discount$metadata = discount.metadata) === null || _discount$metadata === void 0 ? void 0 : _discount$metadata.product_discount_difference) || 0);
5282
- savedMap.set(discountKey, (savedMap.get(discountKey) || new Decimal(0)).plus(amount));
5337
+ addDiscountAmount(savedMap, discountKey, amount);
5338
+ addDiscountAmount(isPersistedProduct || discount.order_discount_id != null ? editModeSavedMap : runtimeSavedMap, discountKey, amount);
5283
5339
  };
5284
5340
  var _iterator24 = _createForOfIteratorHelper(productList),
5285
5341
  _step24;
@@ -5287,12 +5343,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5287
5343
  for (_iterator24.s(); !(_step24 = _iterator24.n()).done;) {
5288
5344
  var product = _step24.value;
5289
5345
  var qty = product.num || 1;
5346
+ var isPersistedProduct = Boolean(product.order_detail_id || product.orderDetailId || product.booking_id);
5290
5347
  var _iterator26 = _createForOfIteratorHelper(product.discount_list || []),
5291
5348
  _step26;
5292
5349
  try {
5293
5350
  for (_iterator26.s(); !(_step26 = _iterator26.n()).done;) {
5294
5351
  var pd = _step26.value;
5295
- addDiscountAmount(pd, qty);
5352
+ addProductDiscountAmount(pd, qty, isPersistedProduct);
5296
5353
  }
5297
5354
  } catch (err) {
5298
5355
  _iterator26.e(err);
@@ -5305,13 +5362,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5305
5362
  for (_iterator27.s(); !(_step27 = _iterator27.n()).done;) {
5306
5363
  var _ref75, _bundle$num3;
5307
5364
  var bundle = _step27.value;
5365
+ var isPersistedBundleProduct = isPersistedProduct || Boolean((bundle === null || bundle === void 0 ? void 0 : bundle.order_detail_id) || (bundle === null || bundle === void 0 ? void 0 : bundle.orderDetailId) || (bundle === null || bundle === void 0 ? void 0 : bundle.booking_id));
5308
5366
  var bundleQty = new Decimal(Number(qty) || 1).times(Number((_ref75 = (_bundle$num3 = bundle === null || bundle === void 0 ? void 0 : bundle.num) !== null && _bundle$num3 !== void 0 ? _bundle$num3 : bundle === null || bundle === void 0 ? void 0 : bundle.quantity) !== null && _ref75 !== void 0 ? _ref75 : 1) || 1).toNumber();
5309
5367
  var _iterator28 = _createForOfIteratorHelper((bundle === null || bundle === void 0 ? void 0 : bundle.discount_list) || []),
5310
5368
  _step28;
5311
5369
  try {
5312
5370
  for (_iterator28.s(); !(_step28 = _iterator28.n()).done;) {
5313
5371
  var _pd = _step28.value;
5314
- addDiscountAmount(_pd, bundleQty);
5372
+ addProductDiscountAmount(_pd, bundleQty, isPersistedBundleProduct);
5315
5373
  }
5316
5374
  } catch (err) {
5317
5375
  _iterator28.e(err);
@@ -5336,7 +5394,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5336
5394
  for (_iterator25.s(); !(_step25 = _iterator25.n()).done;) {
5337
5395
  var d = _step25.value;
5338
5396
  var key = d.id;
5339
- d.savedAmount = d.isSelected && key != null && savedMap.has(key) ? savedMap.get(key).toNumber() : 0;
5397
+ var sourceMap = d.isEditMode ? editModeSavedMap : editModeDiscountKeys.has(key) ? runtimeSavedMap : savedMap;
5398
+ d.savedAmount = d.isSelected && key != null && sourceMap.has(key) ? sourceMap.get(key).toNumber() : 0;
5340
5399
  }
5341
5400
  } catch (err) {
5342
5401
  _iterator25.e(err);
@@ -422,6 +422,10 @@ declare class Server {
422
422
  private canAssignStringProductTitleToLocale;
423
423
  private hasCjkText;
424
424
  private resolveFirstProductTitleValue;
425
+ private getPaymentCodeKey;
426
+ private isBlankPaymentName;
427
+ private shouldLookupPaymentMethodNameByCode;
428
+ private enrichPaymentNamesByCode;
425
429
  private withLocalSmallTicketData;
426
430
  private handleOrderSalesDetail;
427
431
  /**