@pisell/pisellos 0.0.311 → 0.0.313

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.
@@ -326,7 +326,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
326
326
  };
327
327
  setOtherData(key: string, value: any): void;
328
328
  getOtherData(key: string): any;
329
- getProductTypeById(id: number): Promise<"duration" | "session" | "normal">;
329
+ getProductTypeById(id: number): Promise<"normal" | "duration" | "session">;
330
330
  /**
331
331
  * 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
332
332
  *
@@ -677,7 +677,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
677
677
  value: (function () {
678
678
  var _updateLocalOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(params) {
679
679
  var _params$orderData6, _params$orderData7, _params$cartSummary2, _params$totalInfo5, _params$totalInfo6, _params$totalInfo7, _params$totalInfo8;
680
- var validation, amountInfo, customerInfo, allOrders, existingOrder, _updated$payment, totalAmount, activePayments, paidAmount, remaining, _isNeedDeposit, updated, syncedAmount, remainingExpectAmount, isNeedDeposit, created;
680
+ var validation, amountInfo, customerInfo, allOrders, existingOrder, _updated$payment, totalAmount, activePayments, paidAmount, remaining, _isNeedDeposit, updated, syncedAmount, remainingExpectAmount, depositDiffAmount, isNeedDeposit, created;
681
681
  return _regeneratorRuntime().wrap(function _callee10$(_context10) {
682
682
  while (1) switch (_context10.prev = _context10.next) {
683
683
  case 0:
@@ -730,7 +730,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
730
730
  return String(o.id) === String(params.orderId) || String(o.order_id) === String(params.orderId);
731
731
  });
732
732
  if (!existingOrder) {
733
- _context10.next = 42;
733
+ _context10.next = 44;
734
734
  break;
735
735
  }
736
736
  // 基于现有支付项计算新的 expect_amount
@@ -798,15 +798,19 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
798
798
  var rounding = new Decimal(p.rounding_amount || '0').abs();
799
799
  return sum.plus(amt).plus(rounding);
800
800
  }, new Decimal(0));
801
- remainingExpectAmount = Decimal.max(0, totalAmount.minus(syncedAmount)).toFixed(2);
801
+ remainingExpectAmount = Decimal.max(0, totalAmount.minus(syncedAmount)).toFixed(2); // 要计算一个总价的差值和一个定金的差值,如果定金的差值>0,则需要使用定金的差值,否则使用总价的差值
802
+ depositDiffAmount = new Decimal(0).toFixed(2);
803
+ if (updated.is_deposit === 1) {
804
+ depositDiffAmount = new Decimal(updated.deposit_amount).minus(syncedAmount).toFixed(2);
805
+ }
802
806
  this.initWalletData({
803
- order_wait_pay_amount: Number(remainingExpectAmount)
807
+ order_wait_pay_amount: Number(depositDiffAmount) > 0 ? Number(depositDiffAmount) : Number(remainingExpectAmount)
804
808
  });
805
809
  return _context10.abrupt("return", updated);
806
- case 42:
810
+ case 44:
807
811
  // 计算是否需要支付定金,如果需要默认切换到定金模式,以及记录定金总金额,并把当前默认待付金额调整为定金总金额
808
812
  isNeedDeposit = this.checkIsNeedDepositAsync(params.orderData.bookings, params.orderData.relation_products); // 没找到现有订单时,回退为创建逻辑(用于异常兜底)
809
- _context10.next = 45;
813
+ _context10.next = 47;
810
814
  return this.payment.createPaymentOrderAsync({
811
815
  order_id: String(params.orderId),
812
816
  total_amount: amountInfo.totalAmount,
@@ -823,12 +827,12 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
823
827
  amount_breakdown: amountInfo
824
828
  }
825
829
  });
826
- case 45:
830
+ case 47:
827
831
  created = _context10.sent;
828
832
  this.store.currentOrder = created;
829
833
  this.initWalletData();
830
834
  return _context10.abrupt("return", created);
831
- case 49:
835
+ case 51:
832
836
  case "end":
833
837
  return _context10.stop();
834
838
  }
@@ -3287,6 +3291,16 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3287
3291
  return sum.plus(amt).plus(rounding);
3288
3292
  }, new Decimal(0)).toFixed(2);
3289
3293
  }
3294
+ // 如果当前是定金支付,并且定金额度已经大于等于了订单总计,则 finalDepositAmount 为实际付出去的定金金额
3295
+ if (this.store.currentOrder.is_deposit === 1 && new Decimal(finalDepositAmount).gte(new Decimal(this.store.currentOrder.total_amount))) {
3296
+ finalDepositAmount = processedPaymentItems.filter(function (item) {
3297
+ return item.status !== 'voided' && item.order_payment_type === 'deposit';
3298
+ }).reduce(function (sum, item) {
3299
+ var amt = new Decimal(item.amount || '0');
3300
+ var rounding = new Decimal(item.rounding_amount || '0').abs();
3301
+ return sum.plus(amt).plus(rounding);
3302
+ }, new Decimal(0)).toFixed(2);
3303
+ }
3290
3304
  this.logInfo('定金金额确定结果', {
3291
3305
  depositPaymentItemsCount: processedPaymentItems.length,
3292
3306
  depositPaymentItems: processedPaymentItems.map(function (item) {
@@ -3354,7 +3368,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3354
3368
 
3355
3369
  // 发送下单接口请求开始事件
3356
3370
  startTime = Date.now();
3357
- _context36.next = 26;
3371
+ _context36.next = 27;
3358
3372
  return this.core.effects.emit(CheckoutHooks.OnOrderSubmitStart, {
3359
3373
  orderUuid: this.store.currentOrder.uuid,
3360
3374
  operation: isUpdateOperation ? 'update' : 'create',
@@ -3362,9 +3376,9 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3362
3376
  paymentItemCount: paymentItems.length,
3363
3377
  timestamp: startTime
3364
3378
  });
3365
- case 26:
3379
+ case 27:
3366
3380
  submitSuccess = false;
3367
- _context36.prev = 27;
3381
+ _context36.prev = 28;
3368
3382
  // 记录接口调用参数
3369
3383
  this.logInfo('Calling backend checkout API', _objectSpread({
3370
3384
  url: '/order/checkout',
@@ -3372,23 +3386,23 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3372
3386
  }, orderParams));
3373
3387
 
3374
3388
  // 调用 Order 模块的专用 createOrderByCheckout 方法
3375
- _context36.next = 31;
3389
+ _context36.next = 32;
3376
3390
  return this.order.createOrderByCheckout(orderParams);
3377
- case 31:
3391
+ case 32:
3378
3392
  checkoutResponse = _context36.sent;
3379
3393
  submitSuccess = true;
3380
3394
  this.logInfo('下单接口调用成功', checkoutResponse);
3381
- _context36.next = 44;
3395
+ _context36.next = 45;
3382
3396
  break;
3383
- case 36:
3384
- _context36.prev = 36;
3385
- _context36.t1 = _context36["catch"](27);
3397
+ case 37:
3398
+ _context36.prev = 37;
3399
+ _context36.t1 = _context36["catch"](28);
3386
3400
  submitSuccess = false;
3387
3401
  submitError = _context36.t1 instanceof Error ? _context36.t1.message : String(_context36.t1);
3388
3402
  this.logError('下单接口调用失败:', submitError);
3389
3403
 
3390
3404
  // 发送订单同步失败事件(网络错误或请求失败)
3391
- _context36.next = 43;
3405
+ _context36.next = 44;
3392
3406
  return this.core.effects.emit(CheckoutHooks.OnOrderSyncFailed, {
3393
3407
  orderUuid: this.store.currentOrder.uuid,
3394
3408
  operation: isUpdateOperation ? 'update' : 'create',
@@ -3398,11 +3412,11 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3398
3412
  duration: Date.now() - startTime,
3399
3413
  timestamp: Date.now()
3400
3414
  });
3401
- case 43:
3402
- throw _context36.t1;
3403
3415
  case 44:
3404
- _context36.prev = 44;
3405
- _context36.next = 47;
3416
+ throw _context36.t1;
3417
+ case 45:
3418
+ _context36.prev = 45;
3419
+ _context36.next = 48;
3406
3420
  return this.core.effects.emit(CheckoutHooks.OnOrderSubmitEnd, {
3407
3421
  success: submitSuccess,
3408
3422
  orderUuid: this.store.currentOrder.uuid,
@@ -3413,18 +3427,18 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3413
3427
  duration: Date.now() - startTime,
3414
3428
  timestamp: Date.now()
3415
3429
  });
3416
- case 47:
3417
- return _context36.finish(44);
3418
3430
  case 48:
3431
+ return _context36.finish(45);
3432
+ case 49:
3419
3433
  // 检查响应状态是否为成功状态
3420
3434
  responseStatus = (_checkoutResponse3 = checkoutResponse) === null || _checkoutResponse3 === void 0 ? void 0 : _checkoutResponse3.status;
3421
3435
  isSuccessResponse = responseStatus === true || responseStatus === 200 || responseStatus === 'success' || responseStatus === 1 && ((_checkoutResponse4 = checkoutResponse) === null || _checkoutResponse4 === void 0 ? void 0 : _checkoutResponse4.code) === 200;
3422
3436
  if (isSuccessResponse) {
3423
- _context36.next = 55;
3437
+ _context36.next = 56;
3424
3438
  break;
3425
3439
  }
3426
3440
  errorMessage = ((_checkoutResponse5 = checkoutResponse) === null || _checkoutResponse5 === void 0 ? void 0 : _checkoutResponse5.message) || '订单同步失败,后端返回非成功状态'; // 发送订单同步失败事件
3427
- _context36.next = 54;
3441
+ _context36.next = 55;
3428
3442
  return this.core.effects.emit(CheckoutHooks.OnOrderSyncFailed, {
3429
3443
  orderUuid: this.store.currentOrder.uuid,
3430
3444
  operation: isUpdateOperation ? 'update' : 'create',
@@ -3435,18 +3449,18 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3435
3449
  duration: Date.now() - startTime,
3436
3450
  timestamp: Date.now()
3437
3451
  });
3438
- case 54:
3439
- throw new Error(errorMessage);
3440
3452
  case 55:
3453
+ throw new Error(errorMessage);
3454
+ case 56:
3441
3455
  if (!isUpdateOperation) {
3442
- _context36.next = 59;
3456
+ _context36.next = 60;
3443
3457
  break;
3444
3458
  }
3445
3459
  // 更新操作:使用现有的订单ID
3446
3460
  realOrderId = currentOrderId;
3447
- _context36.next = 78;
3461
+ _context36.next = 79;
3448
3462
  break;
3449
- case 59:
3463
+ case 60:
3450
3464
  // 创建操作:从响应中提取新的订单ID
3451
3465
  extractedOrderId = (_checkoutResponse6 = checkoutResponse) === null || _checkoutResponse6 === void 0 || (_checkoutResponse6 = _checkoutResponse6.data) === null || _checkoutResponse6 === void 0 ? void 0 : _checkoutResponse6.order_id; // 如果data.order_id不存在,尝试直接从根级获取
3452
3466
  if (!extractedOrderId) {
@@ -3468,10 +3482,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3468
3482
  oldOrderId: this.store.currentOrder.order_id,
3469
3483
  newOrderId: realOrderId
3470
3484
  });
3471
- _context36.prev = 65;
3472
- _context36.next = 68;
3485
+ _context36.prev = 66;
3486
+ _context36.next = 69;
3473
3487
  return this.payment.replaceOrderIdByUuidAsync(this.store.currentOrder.uuid, realOrderId);
3474
- case 68:
3488
+ case 69:
3475
3489
  updatedOrder = _context36.sent;
3476
3490
  this.logInfo('Payment模块替换订单ID结果:', {
3477
3491
  wasSuccessful: !!updatedOrder,
@@ -3498,66 +3512,66 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3498
3512
  目标ID: realOrderId
3499
3513
  });
3500
3514
  }
3501
- _context36.next = 78;
3515
+ _context36.next = 79;
3502
3516
  break;
3503
- case 73:
3504
- _context36.prev = 73;
3505
- _context36.t2 = _context36["catch"](65);
3517
+ case 74:
3518
+ _context36.prev = 74;
3519
+ _context36.t2 = _context36["catch"](66);
3506
3520
  this.logError('调用Payment模块替换订单ID时发生错误:', _context36.t2);
3507
3521
 
3508
3522
  // 发生错误时也进行手动替换
3509
3523
  this.store.currentOrder.order_id = realOrderId;
3510
3524
  this.logInfo('错误恢复:手动设置订单ID:', realOrderId);
3511
- case 78:
3512
- _context36.prev = 78;
3525
+ case 79:
3526
+ _context36.prev = 79;
3513
3527
  syncedPaymentUuids = processedPaymentItems.filter(function (item) {
3514
3528
  return item.status !== 'voided';
3515
3529
  }).map(function (item) {
3516
3530
  return item.uuid;
3517
3531
  }).filter(Boolean);
3518
3532
  _iterator3 = _createForOfIteratorHelper(syncedPaymentUuids);
3519
- _context36.prev = 81;
3533
+ _context36.prev = 82;
3520
3534
  _iterator3.s();
3521
- case 83:
3535
+ case 84:
3522
3536
  if ((_step3 = _iterator3.n()).done) {
3523
- _context36.next = 89;
3537
+ _context36.next = 90;
3524
3538
  break;
3525
3539
  }
3526
3540
  paymentUuid = _step3.value;
3527
- _context36.next = 87;
3541
+ _context36.next = 88;
3528
3542
  return this.payment.updatePaymentAsync(this.store.currentOrder.uuid, paymentUuid, {
3529
3543
  isSynced: true,
3530
3544
  syncError: undefined
3531
3545
  });
3532
- case 87:
3533
- _context36.next = 83;
3546
+ case 88:
3547
+ _context36.next = 84;
3534
3548
  break;
3535
- case 89:
3536
- _context36.next = 94;
3549
+ case 90:
3550
+ _context36.next = 95;
3537
3551
  break;
3538
- case 91:
3539
- _context36.prev = 91;
3540
- _context36.t3 = _context36["catch"](81);
3552
+ case 92:
3553
+ _context36.prev = 92;
3554
+ _context36.t3 = _context36["catch"](82);
3541
3555
  _iterator3.e(_context36.t3);
3542
- case 94:
3543
- _context36.prev = 94;
3556
+ case 95:
3557
+ _context36.prev = 95;
3544
3558
  _iterator3.f();
3545
- return _context36.finish(94);
3546
- case 97:
3547
- _context36.next = 102;
3559
+ return _context36.finish(95);
3560
+ case 98:
3561
+ _context36.next = 103;
3548
3562
  break;
3549
- case 99:
3550
- _context36.prev = 99;
3551
- _context36.t4 = _context36["catch"](78);
3563
+ case 100:
3564
+ _context36.prev = 100;
3565
+ _context36.t4 = _context36["catch"](79);
3552
3566
  this.logWarning('标记支付项已同步失败(不阻塞主流程)', {
3553
3567
  error: _context36.t4
3554
3568
  });
3555
- case 102:
3569
+ case 103:
3556
3570
  // 标记订单已同步
3557
3571
  this.store.isOrderSynced = true;
3558
3572
 
3559
3573
  // 触发订单同步完成事件
3560
- _context36.next = 105;
3574
+ _context36.next = 106;
3561
3575
  return this.core.effects.emit(CheckoutHooks.OnOrderSynced, {
3562
3576
  orderUuid: this.store.currentOrder.uuid,
3563
3577
  realOrderId: realOrderId,
@@ -3566,18 +3580,18 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3566
3580
  isManual: isManual,
3567
3581
  response: checkoutResponse
3568
3582
  });
3569
- case 105:
3583
+ case 106:
3570
3584
  return _context36.abrupt("return", {
3571
3585
  success: true,
3572
3586
  orderId: realOrderId,
3573
3587
  orderUuid: this.store.currentOrder.uuid,
3574
3588
  response: checkoutResponse
3575
3589
  });
3576
- case 106:
3590
+ case 107:
3577
3591
  case "end":
3578
3592
  return _context36.stop();
3579
3593
  }
3580
- }, _callee36, this, [[27, 36, 44, 48], [65, 73], [78, 99], [81, 91, 94, 97]]);
3594
+ }, _callee36, this, [[28, 37, 45, 49], [66, 74], [79, 100], [82, 92, 95, 98]]);
3581
3595
  }));
3582
3596
  function syncOrderToBackendWithReturn() {
3583
3597
  return _syncOrderToBackendWithReturn.apply(this, arguments);
@@ -326,7 +326,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
326
326
  };
327
327
  setOtherData(key: string, value: any): void;
328
328
  getOtherData(key: string): any;
329
- getProductTypeById(id: number): Promise<"duration" | "session" | "normal">;
329
+ getProductTypeById(id: number): Promise<"normal" | "duration" | "session">;
330
330
  /**
331
331
  * 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
332
332
  *
@@ -530,8 +530,12 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
530
530
  const remainingExpectAmount = import_decimal.default.max(0, totalAmount.minus(syncedAmount)).toFixed(
531
531
  2
532
532
  );
533
+ let depositDiffAmount = new import_decimal.default(0).toFixed(2);
534
+ if (updated.is_deposit === 1) {
535
+ depositDiffAmount = new import_decimal.default(updated.deposit_amount).minus(syncedAmount).toFixed(2);
536
+ }
533
537
  this.initWalletData({
534
- order_wait_pay_amount: Number(remainingExpectAmount)
538
+ order_wait_pay_amount: Number(depositDiffAmount) > 0 ? Number(depositDiffAmount) : Number(remainingExpectAmount)
535
539
  });
536
540
  return updated;
537
541
  }
@@ -2035,6 +2039,13 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
2035
2039
  return sum.plus(amt).plus(rounding);
2036
2040
  }, new import_decimal.default(0)).toFixed(2);
2037
2041
  }
2042
+ if (this.store.currentOrder.is_deposit === 1 && new import_decimal.default(finalDepositAmount).gte(new import_decimal.default(this.store.currentOrder.total_amount))) {
2043
+ finalDepositAmount = processedPaymentItems.filter((item) => item.status !== "voided" && item.order_payment_type === "deposit").reduce((sum, item) => {
2044
+ const amt = new import_decimal.default(item.amount || "0");
2045
+ const rounding = new import_decimal.default(item.rounding_amount || "0").abs();
2046
+ return sum.plus(amt).plus(rounding);
2047
+ }, new import_decimal.default(0)).toFixed(2);
2048
+ }
2038
2049
  this.logInfo("定金金额确定结果", {
2039
2050
  depositPaymentItemsCount: processedPaymentItems.length,
2040
2051
  depositPaymentItems: processedPaymentItems.map((item) => ({
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.311",
4
+ "version": "0.0.313",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",