@pisell/pisellos 0.0.285 → 0.0.287

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.
@@ -3,6 +3,7 @@ import { BaseModule } from '../BaseModule';
3
3
  import { CartItem, CartModuleAPI, ECartItemCheckType, ECartItemInfoType, IAddItemParams, IUpdateItemParams } from './types';
4
4
  import { Account } from '../Account';
5
5
  export * from './types';
6
+ export { getProductDeposit } from './utils';
6
7
  /**
7
8
  * 购物车模块实现
8
9
  */
@@ -29,6 +29,7 @@ import { createCartItemOrigin, deleteHolderFromCartItem, deleteRelationFormsFrom
29
29
  import { cloneDeep } from 'lodash-es';
30
30
  import { isNormalProduct } from "../Product/utils";
31
31
  export * from "./types";
32
+ export { getProductDeposit } from "./utils";
32
33
 
33
34
  /**
34
35
  * 购物车模块实现
@@ -80,8 +80,8 @@ export var formatResourceToCartItemOrigin = function formatResourceToCartItemOri
80
80
  origin.end_date = null;
81
81
  origin.end_time = null;
82
82
  }
83
- origin.relation_type = '';
84
- origin.relation_id = 0;
83
+ // origin.relation_type = '';
84
+ // origin.relation_id = 0;
85
85
  return origin;
86
86
  };
87
87
 
@@ -289,18 +289,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
289
289
  bookings: [],
290
290
  relation_products: [],
291
291
  relation_forms: [],
292
- payments: []
292
+ payments: [],
293
+ is_full_overwrite_flag: 1
293
294
  }, params);
294
295
  if ((_orderData$payments = orderData.payments) !== null && _orderData$payments !== void 0 && _orderData$payments.length) {
295
296
  orderData.small_ticket_data_flag = 1;
296
297
  }
297
298
 
298
- // 如果进来的order_id 是真实的,则不需要再传递 bookings 和 relation_products
299
- if (params.order_id) {
300
- orderData.bookings = [];
301
- orderData.relation_products = [];
302
- }
303
-
304
299
  // 兜底策略,如果是第一次下单,没有 order_id,且没有 schedule_date,则设置为当前时间
305
300
  if (!params.order_id && !orderData.schedule_date) {
306
301
  orderData.schedule_date = dayjs().format('YYYY-MM-DD HH:mm:ss');
@@ -347,9 +342,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
347
342
  });
348
343
 
349
344
  // 调用后端接口
350
- _context3.next = 11;
345
+ _context3.next = 10;
351
346
  return this.request.post('/order/checkout', orderData);
352
- case 11:
347
+ case 10:
353
348
  response = _context3.sent;
354
349
  this.logInfo('Order API called successfully', {
355
350
  response: response
@@ -359,19 +354,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
359
354
  hasOrderId: !!(response !== null && response !== void 0 && (_response$data = response.data) !== null && _response$data !== void 0 && _response$data.order_id || response !== null && response !== void 0 && response.order_id)
360
355
  });
361
356
  return _context3.abrupt("return", response);
362
- case 17:
363
- _context3.prev = 17;
357
+ case 16:
358
+ _context3.prev = 16;
364
359
  _context3.t0 = _context3["catch"](2);
365
360
  console.error('[Order] createOrderByCheckout 创建订单失败:', _context3.t0);
366
361
  this.logInfo('Order API called failed', {
367
362
  error: _context3.t0 instanceof Error ? _context3.t0.message : String(_context3.t0)
368
363
  });
369
364
  throw _context3.t0;
370
- case 22:
365
+ case 21:
371
366
  case "end":
372
367
  return _context3.stop();
373
368
  }
374
- }, _callee3, this, [[2, 17]]);
369
+ }, _callee3, this, [[2, 16]]);
375
370
  }));
376
371
  function createOrderByCheckout(_x4) {
377
372
  return _createOrderByCheckout.apply(this, arguments);
@@ -1291,9 +1291,10 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1291
1291
  }
1292
1292
  throw new Error("\u8BA2\u5355\u4E0D\u5B58\u5728: ".concat(orderUuid));
1293
1293
  case 7:
1294
- // 1. 查找所有现有的代金券类支付项(带 voucher_id 且状态不是 voided
1294
+ // 1. 查找所有现有的代金券类支付项(带 voucher_id 且状态不是 voided)并且还没有同步给后端
1295
+ // 如果同步给了后端的voucher 不允许删除
1295
1296
  existingVoucherItems = order.payment.filter(function (payment) {
1296
- return payment.voucher_id && payment.status !== 'voided';
1297
+ return payment.voucher_id && payment.status !== 'voided' && !payment.isSynced;
1297
1298
  });
1298
1299
  console.log('[PaymentModule] 发现现有代金券支付项:', {
1299
1300
  orderUuid: orderUuid,
@@ -1303,7 +1304,8 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1303
1304
  uuid: item.uuid,
1304
1305
  code: item.code,
1305
1306
  amount: item.amount,
1306
- voucher_id: item.voucher_id
1307
+ voucher_id: item.voucher_id,
1308
+ isSynced: item.isSynced
1307
1309
  };
1308
1310
  })
1309
1311
  });
@@ -129,6 +129,15 @@ export interface PaymentItem {
129
129
  origin_amount?: string;
130
130
  /** 订单支付类型 */
131
131
  order_payment_type?: 'normal' | 'deposit';
132
+ /** 本支付项是否已成功同步到后端 */
133
+ isSynced?: boolean;
134
+ /** 最近一次同步失败信息(存在则代表同步失败过) */
135
+ syncError?: {
136
+ error: string;
137
+ errorCode?: string;
138
+ statusCode?: number;
139
+ timestamp: number;
140
+ };
132
141
  }
133
142
  /**
134
143
  * 订单信息
@@ -614,6 +623,8 @@ export interface WalletDeductionRecommendParams {
614
623
  amount: number;
615
624
  tag: string;
616
625
  }[];
626
+ /** 订单ID */
627
+ payment_order_id?: string;
617
628
  }
618
629
  /**
619
630
  * 钱包初始化业务数据接口
@@ -635,6 +646,8 @@ export interface WalletInitBusinessData {
635
646
  selling_price: number;
636
647
  }[];
637
648
  order_wait_pay_amount?: number;
649
+ /** 订单ID */
650
+ payment_order_id?: string;
638
651
  }
639
652
  /**
640
653
  * 查询用户识别码列表请求参数
@@ -652,6 +665,8 @@ export interface UserIdentificationCodeParams extends WalletDeductionRecommendPa
652
665
  amount: number;
653
666
  tag: string;
654
667
  }[];
668
+ /** 订单ID */
669
+ payment_order_id?: string;
655
670
  }
656
671
  /**
657
672
  * 钱包推荐扣款响应数据
@@ -703,6 +718,8 @@ export interface UserIdentificationCodeItem {
703
718
  export interface SearchIdentificationCodeParams extends WalletDeductionRecommendParams {
704
719
  /** 识别码 */
705
720
  code: string;
721
+ /** 订单ID */
722
+ payment_order_id?: string;
706
723
  }
707
724
  /**
708
725
  * 搜索识别码响应数据
@@ -59,7 +59,8 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
59
59
  var customer_id = businessData.customer_id,
60
60
  amountInfo = businessData.amountInfo,
61
61
  products = businessData.products,
62
- order_wait_pay_amount = businessData.order_wait_pay_amount;
62
+ order_wait_pay_amount = businessData.order_wait_pay_amount,
63
+ payment_order_id = businessData.payment_order_id;
63
64
 
64
65
  // 转换金额为数字类型
65
66
  var totalAmount = Number(amountInfo.totalAmount);
@@ -75,7 +76,8 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
75
76
  order_wait_pay_amount: order_wait_pay_amount || totalAmount,
76
77
  // order_behavior_count_customer_id: 1,
77
78
  products: products,
78
- prepare_payments: []
79
+ prepare_payments: [],
80
+ payment_order_id: payment_order_id
79
81
  };
80
82
 
81
83
  // 存储生成的参数到模块中
@@ -252,7 +254,7 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
252
254
  key: "getWalletPassRecommendListAsync",
253
255
  value: function () {
254
256
  var _getWalletPassRecommendListAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(params) {
255
- var response;
257
+ var _this$walletParams, response;
256
258
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
257
259
  while (1) switch (_context3.prev = _context3.next) {
258
260
  case 0:
@@ -260,7 +262,8 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
260
262
  this.paymentModule.logInfo('[WalletPass] 开始获取钱包推荐列表', {
261
263
  customer_id: params.customer_id,
262
264
  order_expect_amount: params.order_expect_amount,
263
- sale_channel: params.sale_channel
265
+ sale_channel: params.sale_channel,
266
+ payment_order_id: (_this$walletParams = this.walletParams) === null || _this$walletParams === void 0 ? void 0 : _this$walletParams.payment_order_id
264
267
  });
265
268
  _context3.next = 4;
266
269
  return this.paymentModule.request.post('/machinecode/prepare/deduction/recommend', params // 将 params 作为请求体数据
@@ -315,7 +318,7 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
315
318
  key: "getUserIdentificationCodeListAsync",
316
319
  value: function () {
317
320
  var _getUserIdentificationCodeListAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(params) {
318
- var _newParams$prepare_pa, newParams, response, sortedData;
321
+ var _newParams$prepare_pa, _this$walletParams2, newParams, response, sortedData;
319
322
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
320
323
  while (1) switch (_context4.prev = _context4.next) {
321
324
  case 0:
@@ -325,7 +328,8 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
325
328
  customer_id: newParams.customer_id,
326
329
  available: newParams.available,
327
330
  prepare_payments_count: ((_newParams$prepare_pa = newParams.prepare_payments) === null || _newParams$prepare_pa === void 0 ? void 0 : _newParams$prepare_pa.length) || 0,
328
- filter_prepare_wallet_pass: newParams.filter_prepare_wallet_pass
331
+ filter_prepare_wallet_pass: newParams.filter_prepare_wallet_pass,
332
+ payment_order_id: (_this$walletParams2 = this.walletParams) === null || _this$walletParams2 === void 0 ? void 0 : _this$walletParams2.payment_order_id
329
333
  });
330
334
  _context4.next = 5;
331
335
  return this.paymentModule.request.post('/machinecode/prepare/deduction', newParams);
@@ -452,13 +456,15 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
452
456
  prepare_payments: params.prepare_payments || (baseWalletParams === null || baseWalletParams === void 0 ? void 0 : baseWalletParams.prepare_payments),
453
457
  multiple: 1,
454
458
  // 搜索特有参数
455
- code: params.code
459
+ code: params.code,
460
+ payment_order_id: baseWalletParams === null || baseWalletParams === void 0 ? void 0 : baseWalletParams.payment_order_id
456
461
  };
457
462
  this.paymentModule.logInfo('[WalletPass] 搜索普通识别码', {
458
463
  code: searchParams.code,
459
464
  customer_id: searchParams.customer_id,
460
465
  order_expect_amount: searchParams.order_expect_amount,
461
- multiple: searchParams.multiple
466
+ multiple: searchParams.multiple,
467
+ payment_order_id: baseWalletParams === null || baseWalletParams === void 0 ? void 0 : baseWalletParams.payment_order_id
462
468
  });
463
469
  _context5.next = 19;
464
470
  return this.paymentModule.request.post('/machinecode/prepare/deduction/search', searchParams);
@@ -2061,7 +2061,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2061
2061
  // item._origin.resources?.forEach((n: any) => {
2062
2062
  // resourceIds.push(n.relation_id);
2063
2063
  // });
2064
- if (item.resource_id) {
2064
+ if (item.resource_id && !resourceIds.includes(item.resource_id)) {
2065
2065
  resourceIds.push(item.resource_id);
2066
2066
  }
2067
2067
  resourcesTypeId = item === null || item === void 0 || (_item$_productOrigin8 = item._productOrigin) === null || _item$_productOrigin8 === void 0 || (_item$_productOrigin8 = _item$_productOrigin8.product_resource) === null || _item$_productOrigin8 === void 0 || (_item$_productOrigin8 = _item$_productOrigin8.resources) === null || _item$_productOrigin8 === void 0 || (_item$_productOrigin8 = _item$_productOrigin8.find(function (n) {
@@ -2156,6 +2156,26 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2156
2156
  return 0;
2157
2157
  }, 0);
2158
2158
  }
2159
+ // 计算容量的辅助函数
2160
+ var calculateCapacityFromCartItems = function calculateCapacityFromCartItems(items) {
2161
+ return items.reduce(function (total, item) {
2162
+ return total + (getCapacityInfoByCartItem(item).currentCapacity || 0);
2163
+ }, 0);
2164
+ };
2165
+
2166
+ // 如果是多个预约,去要求助几个 holder 下最大的需求容量capacity
2167
+ var maxCapacity = 1;
2168
+ if (cartItems !== null && cartItems !== void 0 && cartItems[0].holder_id) {
2169
+ accountList.forEach(function (account) {
2170
+ var accountCartItems = _this12.store.cart.getCartByAccount(account.getId());
2171
+ var currentCapacity = calculateCapacityFromCartItems(accountCartItems);
2172
+ if (currentCapacity > maxCapacity) {
2173
+ maxCapacity = currentCapacity;
2174
+ }
2175
+ });
2176
+ } else {
2177
+ maxCapacity = calculateCapacityFromCartItems(cartItems);
2178
+ }
2159
2179
  var timeSlots = getTimeSlicesByResources({
2160
2180
  resourceIds: resourceIds,
2161
2181
  resourcesMap: resourcesMap,
@@ -2163,6 +2183,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2163
2183
  currentDate: dateRange[0].date,
2164
2184
  split: 10,
2165
2185
  resourcesUseableMap: resourcesUseableMap,
2186
+ capacity: maxCapacity,
2166
2187
  cut_off_time: maxCutOffTime,
2167
2188
  hasFlexibleDuration: hasFlexibleDuration,
2168
2189
  operating_day_boundary: operating_day_boundary,
@@ -245,17 +245,28 @@ export function checkTimeSlotCapacity(timeSlotStart, timeSlotEnd, cartItems, all
245
245
  var _getCapacityInfoByCar2 = getCapacityInfoByCartItem(cartItem),
246
246
  currentCapacity = _getCapacityInfoByCar2.currentCapacity;
247
247
  Object.keys(resourceTypeMap).forEach(function (formId) {
248
+ var _cartItem$_productOri;
248
249
  var resourcesInType = resourceTypeMap[formId];
249
250
  var resourceIdsInType = resourcesInType.map(function (r) {
250
251
  return r.id;
251
252
  });
253
+ var selectType = (_cartItem$_productOri = cartItem._productOrigin) === null || _cartItem$_productOri === void 0 || (_cartItem$_productOri = _cartItem$_productOri.product_resource) === null || _cartItem$_productOri === void 0 || (_cartItem$_productOri = _cartItem$_productOri.resources) === null || _cartItem$_productOri === void 0 || (_cartItem$_productOri = _cartItem$_productOri.find(function (r) {
254
+ var _r$id;
255
+ return ((_r$id = r.id) === null || _r$id === void 0 ? void 0 : _r$id.toString()) === formId;
256
+ })) === null || _cartItem$_productOri === void 0 ? void 0 : _cartItem$_productOri.type;
252
257
 
253
258
  // 检查该商品是否需要这种类型的资源
254
259
  var needsThisResourceType = productResourceIds.some(function (id) {
255
260
  return resourceIdsInType.includes(id);
256
261
  });
257
262
  if (needsThisResourceType) {
258
- requiredCapacityByType[formId] = (requiredCapacityByType[formId] || 0) + currentCapacity;
263
+ // 需要判断是单个预约还是多个预约,如果是单个预约,不用加 capacity,只用+1
264
+ if (selectType === 'single') {
265
+ requiredCapacityByType[formId] = (requiredCapacityByType[formId] || 0) + 1;
266
+ } else {
267
+ requiredCapacityByType[formId] = (requiredCapacityByType[formId] || 0) + currentCapacity;
268
+ }
269
+ // requiredCapacityByType[formId] = (requiredCapacityByType[formId] || 0) + currentCapacity;
259
270
  }
260
271
  });
261
272
  });
@@ -275,12 +286,12 @@ export function checkTimeSlotCapacity(timeSlotStart, timeSlotEnd, cartItems, all
275
286
  _step2;
276
287
  try {
277
288
  for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
278
- var _cartItem$_productOri;
289
+ var _cartItem$_productOri2;
279
290
  var cartItem = _step2.value;
280
- if ((_cartItem$_productOri = cartItem._productOrigin) !== null && _cartItem$_productOri !== void 0 && (_cartItem$_productOri = _cartItem$_productOri.product_resource) !== null && _cartItem$_productOri !== void 0 && _cartItem$_productOri.resources) {
291
+ if ((_cartItem$_productOri2 = cartItem._productOrigin) !== null && _cartItem$_productOri2 !== void 0 && (_cartItem$_productOri2 = _cartItem$_productOri2.product_resource) !== null && _cartItem$_productOri2 !== void 0 && _cartItem$_productOri2.resources) {
281
292
  resourceTypeConfig = cartItem._productOrigin.product_resource.resources.find(function (r) {
282
- var _r$id;
283
- return ((_r$id = r.id) === null || _r$id === void 0 ? void 0 : _r$id.toString()) === formId && r.status === 1;
293
+ var _r$id2;
294
+ return ((_r$id2 = r.id) === null || _r$id2 === void 0 ? void 0 : _r$id2.toString()) === formId && r.status === 1;
284
295
  });
285
296
  if (resourceTypeConfig) break;
286
297
  }
@@ -2,7 +2,7 @@ import { Module, PisellCore, ModuleOptions } from '../../types';
2
2
  import { BaseModule } from '../../modules/BaseModule';
3
3
  import { OrderModule } from '../../modules/Order';
4
4
  import { PaymentModule } from '../../modules/Payment';
5
- import { CheckoutModuleAPI, CheckoutInitParams, CreateLocalOrderParams, CurrentOrderInfo, CartSummaryItem, SendCustomerPayLinkParams } from './types';
5
+ import { CheckoutModuleAPI, CheckoutInitParams, CreateLocalOrderParams, UpdateLocalOrderParams, CurrentOrderInfo, CartSummaryItem, SendCustomerPayLinkParams } from './types';
6
6
  import { PaymentOrder, PaymentMethod, PaymentItem, PaymentItemInput } from '../../modules/Payment/types';
7
7
  export * from './types';
8
8
  /**
@@ -64,6 +64,13 @@ export declare class CheckoutImpl extends BaseModule implements Module, Checkout
64
64
  * 方法会记录参数并创建本地虚拟订单,然后用 Payment 模块管理支付流程。
65
65
  */
66
66
  createLocalOrderAsync(params: CreateLocalOrderParams): Promise<PaymentOrder>;
67
+ /**
68
+ * 更新本地订单(已同步后端的订单)并设置为当前订单
69
+ *
70
+ * 通过传入真实的 orderId,对已缓存的订单数据进行更新,
71
+ * 会覆盖 order_info 与金额等字段,并重新计算待付金额,最后设置为 currentOrder。
72
+ */
73
+ updateLocalOrderAsync(params: UpdateLocalOrderParams): Promise<PaymentOrder>;
67
74
  /**
68
75
  * 完成结账
69
76
  */