@pisell/pisellos 0.10.8 → 0.10.9
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.
- package/dist/core/index.js +0 -1
- package/dist/model/strategy/adapter/dataVariant/evaluator.d.ts +18 -2
- package/dist/model/strategy/adapter/dataVariant/evaluator.js +287 -101
- package/dist/model/strategy/adapter/dataVariant/type.d.ts +25 -0
- package/dist/model/strategy/adapter/promotion/index.js +0 -9
- package/dist/model/strategy/adapter/walletPass/evaluator.js +0 -2
- package/dist/model/strategy/adapter/walletPass/type.d.ts +5 -0
- package/dist/model/strategy/adapter/walletPass/utils.js +57 -26
- package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +7 -3
- package/dist/modules/BookingContext/utils/productExtend.js +5 -9
- package/dist/modules/BookingContext/utils/timeSlices.js +24 -3
- package/dist/modules/Customer/index.d.ts +4 -0
- package/dist/modules/Customer/index.js +91 -59
- package/dist/modules/Customer/types.d.ts +2 -0
- package/dist/modules/Discount/index.d.ts +2 -0
- package/dist/modules/Discount/index.js +38 -5
- package/dist/modules/Discount/types.d.ts +11 -0
- package/dist/modules/Order/index.d.ts +20 -1
- package/dist/modules/Order/index.js +976 -730
- package/dist/modules/Order/types.d.ts +6 -1
- package/dist/modules/Order/utils/virtualSettlement.d.ts +56 -0
- package/dist/modules/Order/utils/virtualSettlement.js +271 -0
- package/dist/modules/Order/utils.js +89 -48
- package/dist/modules/Payment/types.d.ts +2 -0
- package/dist/modules/Payment/utils.js +4 -1
- package/dist/modules/Payment/walletpass.d.ts +11 -0
- package/dist/modules/Payment/walletpass.js +235 -60
- package/dist/modules/Product/types.d.ts +23 -0
- package/dist/modules/ProductList/index.d.ts +15 -2
- package/dist/modules/ProductList/index.js +92 -13
- package/dist/modules/SalesSummary/index.d.ts +1 -0
- package/dist/modules/SalesSummary/index.js +4 -3
- package/dist/modules/SalesSummary/types.d.ts +1 -0
- package/dist/modules/SalesSummary/utils.d.ts +1 -0
- package/dist/modules/SalesSummary/utils.js +21 -1
- package/dist/server/index.d.ts +9 -0
- package/dist/server/index.js +90 -58
- package/dist/server/modules/order/index.d.ts +1 -0
- package/dist/server/modules/order/index.js +252 -94
- package/dist/server/utils/small-ticket.js +2 -1
- package/dist/solution/BaseSales/index.d.ts +26 -2
- package/dist/solution/BaseSales/index.js +1310 -931
- package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +1 -0
- package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +78 -12
- package/dist/solution/BookingByStep/index.d.ts +3 -3
- package/dist/solution/BookingTicket/index.d.ts +5 -1
- package/dist/solution/BookingTicket/index.js +221 -159
- package/dist/solution/BookingTicket/utils/addProductDecision.js +2 -1
- package/dist/solution/ScanOrder/index.js +25 -64
- package/lib/core/index.js +0 -1
- package/lib/model/strategy/adapter/dataVariant/evaluator.d.ts +18 -2
- package/lib/model/strategy/adapter/dataVariant/evaluator.js +170 -7
- package/lib/model/strategy/adapter/dataVariant/type.d.ts +25 -0
- package/lib/model/strategy/adapter/walletPass/evaluator.js +0 -2
- package/lib/model/strategy/adapter/walletPass/type.d.ts +5 -0
- package/lib/model/strategy/adapter/walletPass/utils.js +62 -11
- package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +3 -0
- package/lib/modules/BookingContext/utils/productExtend.js +4 -3
- package/lib/modules/BookingContext/utils/timeSlices.js +18 -3
- package/lib/modules/Customer/index.d.ts +4 -0
- package/lib/modules/Customer/index.js +11 -0
- package/lib/modules/Customer/types.d.ts +2 -0
- package/lib/modules/Discount/index.d.ts +2 -0
- package/lib/modules/Discount/index.js +37 -3
- package/lib/modules/Discount/types.d.ts +11 -0
- package/lib/modules/Order/index.d.ts +20 -1
- package/lib/modules/Order/index.js +393 -128
- package/lib/modules/Order/types.d.ts +6 -1
- package/lib/modules/Order/utils/virtualSettlement.d.ts +56 -0
- package/lib/modules/Order/utils/virtualSettlement.js +300 -0
- package/lib/modules/Order/utils.js +65 -21
- package/lib/modules/Payment/types.d.ts +2 -0
- package/lib/modules/Payment/utils.js +5 -1
- package/lib/modules/Payment/walletpass.d.ts +11 -0
- package/lib/modules/Payment/walletpass.js +198 -17
- package/lib/modules/Product/types.d.ts +23 -0
- package/lib/modules/ProductList/index.d.ts +15 -2
- package/lib/modules/ProductList/index.js +85 -3
- package/lib/modules/SalesSummary/index.d.ts +1 -0
- package/lib/modules/SalesSummary/index.js +10 -2
- package/lib/modules/SalesSummary/types.d.ts +1 -0
- package/lib/modules/SalesSummary/utils.d.ts +1 -0
- package/lib/modules/SalesSummary/utils.js +25 -1
- package/lib/server/index.d.ts +9 -0
- package/lib/server/index.js +54 -14
- package/lib/server/modules/order/index.d.ts +1 -0
- package/lib/server/modules/order/index.js +66 -2
- package/lib/server/utils/small-ticket.js +1 -1
- package/lib/solution/BaseSales/index.d.ts +26 -2
- package/lib/solution/BaseSales/index.js +261 -23
- package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +1 -0
- package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +61 -11
- package/lib/solution/BookingByStep/index.d.ts +3 -3
- package/lib/solution/BookingTicket/index.d.ts +5 -1
- package/lib/solution/BookingTicket/index.js +30 -2
- package/lib/solution/BookingTicket/utils/addProductDecision.js +2 -1
- package/lib/solution/ScanOrder/index.js +17 -54
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CartItem } from '../Cart/types';
|
|
2
2
|
import type { DiscountModule } from '../Discount';
|
|
3
3
|
import type { RulesModule } from '../Rules';
|
|
4
|
-
import type { Discount } from '../Discount/types';
|
|
4
|
+
import type { Discount, VirtualCurrencyAsset } from '../Discount/types';
|
|
5
5
|
import type { UnavailableReason } from '../Rules/types';
|
|
6
6
|
import type { SubmitPayloadEnhancer } from './utils';
|
|
7
7
|
import type { PaymentItem } from '../Payment/types';
|
|
@@ -194,6 +194,7 @@ export interface OrderProduct extends OrderProductIdentity {
|
|
|
194
194
|
gift_card?: number;
|
|
195
195
|
selling_price: string;
|
|
196
196
|
original_price: string;
|
|
197
|
+
payment_price?: string;
|
|
197
198
|
tax_fee: string;
|
|
198
199
|
is_charge_tax: number;
|
|
199
200
|
discount_list: OrderProductDiscountItem[];
|
|
@@ -275,6 +276,7 @@ export interface OrderTempOrder {
|
|
|
275
276
|
products: OrderProduct[];
|
|
276
277
|
bookings: any[];
|
|
277
278
|
payments: any[];
|
|
279
|
+
refunds?: any[];
|
|
278
280
|
surcharges: any[];
|
|
279
281
|
discount_list?: any[];
|
|
280
282
|
relation_forms: any[];
|
|
@@ -312,6 +314,7 @@ export interface OrderState {
|
|
|
312
314
|
syncState?: OrderSyncState;
|
|
313
315
|
discountList: any[];
|
|
314
316
|
availableWalletIds?: number[];
|
|
317
|
+
virtualCurrencyList?: VirtualCurrencyAsset[];
|
|
315
318
|
discount: DiscountModule | null;
|
|
316
319
|
rules: RulesModule | null;
|
|
317
320
|
}
|
|
@@ -709,6 +712,8 @@ export interface OrderModuleAPI {
|
|
|
709
712
|
addNewOrder: () => Promise<OrderTempOrder>;
|
|
710
713
|
restoreOrder: () => OrderTempOrder;
|
|
711
714
|
getOrderProducts: () => OrderProduct[];
|
|
715
|
+
getVirtualCurrencyList: () => VirtualCurrencyAsset[];
|
|
716
|
+
clearOrderForSettlementSwitch: () => Promise<OrderTempOrder>;
|
|
712
717
|
getOrderSummary: () => Promise<OrderSummary>;
|
|
713
718
|
recalculateSummary: (options?: {
|
|
714
719
|
createIfMissing?: boolean;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { OrderProduct, OrderTempOrder } from '../types';
|
|
2
|
+
export interface SelectedSettlementSnapshot extends Record<string, any> {
|
|
3
|
+
settlement_type: 'legal_currency' | 'virtual_currency';
|
|
4
|
+
currency_product_id?: number;
|
|
5
|
+
price: string | number;
|
|
6
|
+
unit_label?: any;
|
|
7
|
+
symbol?: any;
|
|
8
|
+
amount_format?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface LegalCurrencySnapshot {
|
|
11
|
+
currency_code: string;
|
|
12
|
+
currency_symbol: string;
|
|
13
|
+
currency_format: string;
|
|
14
|
+
}
|
|
15
|
+
export declare function resolveSettlementDisplayValue(value: unknown): string;
|
|
16
|
+
export declare class OrderSettlementConflictError extends Error {
|
|
17
|
+
readonly currentSettlementKey: string;
|
|
18
|
+
readonly incomingSettlementKey: string;
|
|
19
|
+
readonly code = "ORDER_SETTLEMENT_CONFLICT";
|
|
20
|
+
constructor(currentSettlementKey: string, incomingSettlementKey: string);
|
|
21
|
+
}
|
|
22
|
+
export declare class VirtualCurrencyAssetNotFoundError extends Error {
|
|
23
|
+
readonly currencyProductId: number;
|
|
24
|
+
readonly code = "VIRTUAL_CURRENCY_ASSET_NOT_FOUND";
|
|
25
|
+
constructor(currencyProductId: number);
|
|
26
|
+
}
|
|
27
|
+
export declare class VirtualCurrencyBalanceError extends Error {
|
|
28
|
+
readonly balance: string;
|
|
29
|
+
readonly requiredAmount: string;
|
|
30
|
+
readonly code = "VIRTUAL_CURRENCY_BALANCE_INSUFFICIENT";
|
|
31
|
+
constructor(balance: string, requiredAmount: string);
|
|
32
|
+
}
|
|
33
|
+
export declare function getSelectedSettlementSnapshot(product: Partial<OrderProduct> | null | undefined): SelectedSettlementSnapshot | null;
|
|
34
|
+
export declare function getTempOrderSettlementSnapshot(tempOrder: OrderTempOrder | null | undefined): SelectedSettlementSnapshot | null;
|
|
35
|
+
export declare function isVirtualSettlementProduct(product: Partial<OrderProduct> | null | undefined): boolean;
|
|
36
|
+
export declare function getSettlementKey(snapshot: SelectedSettlementSnapshot | null | undefined): string | null;
|
|
37
|
+
export declare function getTempOrderSettlementKey(tempOrder: OrderTempOrder | null | undefined): string | null;
|
|
38
|
+
export declare function isVirtualSettlementOrder(tempOrder: OrderTempOrder | null | undefined): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* 详情展示识别同时支持已提交订单的 currency_settlement_config。
|
|
41
|
+
* cart_settlement_* 是交易过程内部状态,服务端详情不保证返回。
|
|
42
|
+
*/
|
|
43
|
+
export declare function isVirtualSettlementDisplayOrder(tempOrder: OrderTempOrder | null | undefined): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* 将购物车锁定的结算单位提升为订单级状态。
|
|
46
|
+
* 商品行快照只负责价格归一化;展示与提交统一读取 tempOrder.currency_*。
|
|
47
|
+
*/
|
|
48
|
+
export declare function applyTempOrderSettlementState(tempOrder: OrderTempOrder, snapshot: SelectedSettlementSnapshot): void;
|
|
49
|
+
/** 清空购物车结算锁,并恢复进入虚拟币结算前的店铺法币。 */
|
|
50
|
+
export declare function releaseTempOrderSettlementState(tempOrder: OrderTempOrder): void;
|
|
51
|
+
/**
|
|
52
|
+
* 将已选择虚拟币的订单商品行固化为最终价语义。
|
|
53
|
+
* 函数幂等,可安全用于加车、合并、hydrate 和提交前兜底。
|
|
54
|
+
*/
|
|
55
|
+
export declare function normalizeVirtualSettlementOrderProduct<T extends Partial<OrderProduct>>(product: T): T;
|
|
56
|
+
export declare function normalizeVirtualSettlementProducts<T extends Partial<OrderProduct>>(products: T[]): T[];
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
2
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
3
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
5
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
6
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
7
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
8
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
9
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
10
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
11
|
+
function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); }
|
|
12
|
+
function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct.bind(); } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
|
|
13
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
14
|
+
function _isNativeFunction(fn) { try { return Function.toString.call(fn).indexOf("[native code]") !== -1; } catch (e) { return typeof fn === "function"; } }
|
|
15
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
16
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
17
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
18
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
19
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
20
|
+
import Decimal from 'decimal.js';
|
|
21
|
+
export function resolveSettlementDisplayValue(value) {
|
|
22
|
+
var _ref, _ref2, _ref3, _ref4, _ref5, _localized$auto;
|
|
23
|
+
if (value === undefined || value === null) return '';
|
|
24
|
+
if (typeof value === 'string' || typeof value === 'number') {
|
|
25
|
+
return String(value);
|
|
26
|
+
}
|
|
27
|
+
var localized = value;
|
|
28
|
+
return String((_ref = (_ref2 = (_ref3 = (_ref4 = (_ref5 = (_localized$auto = localized.auto) !== null && _localized$auto !== void 0 ? _localized$auto : localized.default) !== null && _ref5 !== void 0 ? _ref5 : localized.original) !== null && _ref4 !== void 0 ? _ref4 : localized.en) !== null && _ref3 !== void 0 ? _ref3 : localized['zh-CN']) !== null && _ref2 !== void 0 ? _ref2 : localized['zh-HK']) !== null && _ref !== void 0 ? _ref : '');
|
|
29
|
+
}
|
|
30
|
+
export var OrderSettlementConflictError = /*#__PURE__*/function (_Error) {
|
|
31
|
+
_inherits(OrderSettlementConflictError, _Error);
|
|
32
|
+
var _super = _createSuper(OrderSettlementConflictError);
|
|
33
|
+
function OrderSettlementConflictError(currentSettlementKey, incomingSettlementKey) {
|
|
34
|
+
var _this;
|
|
35
|
+
_classCallCheck(this, OrderSettlementConflictError);
|
|
36
|
+
_this = _super.call(this, 'Different currencies and WalletPass units cannot be mixed in one cart.');
|
|
37
|
+
_defineProperty(_assertThisInitialized(_this), "code", 'ORDER_SETTLEMENT_CONFLICT');
|
|
38
|
+
_this.currentSettlementKey = currentSettlementKey;
|
|
39
|
+
_this.incomingSettlementKey = incomingSettlementKey;
|
|
40
|
+
_this.name = 'OrderSettlementConflictError';
|
|
41
|
+
return _this;
|
|
42
|
+
}
|
|
43
|
+
return _createClass(OrderSettlementConflictError);
|
|
44
|
+
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
45
|
+
export var VirtualCurrencyAssetNotFoundError = /*#__PURE__*/function (_Error2) {
|
|
46
|
+
_inherits(VirtualCurrencyAssetNotFoundError, _Error2);
|
|
47
|
+
var _super2 = _createSuper(VirtualCurrencyAssetNotFoundError);
|
|
48
|
+
function VirtualCurrencyAssetNotFoundError(currencyProductId) {
|
|
49
|
+
var _this2;
|
|
50
|
+
_classCallCheck(this, VirtualCurrencyAssetNotFoundError);
|
|
51
|
+
_this2 = _super2.call(this, 'No matching virtual currency card is available.');
|
|
52
|
+
_defineProperty(_assertThisInitialized(_this2), "code", 'VIRTUAL_CURRENCY_ASSET_NOT_FOUND');
|
|
53
|
+
_this2.currencyProductId = currencyProductId;
|
|
54
|
+
_this2.name = 'VirtualCurrencyAssetNotFoundError';
|
|
55
|
+
return _this2;
|
|
56
|
+
}
|
|
57
|
+
return _createClass(VirtualCurrencyAssetNotFoundError);
|
|
58
|
+
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
59
|
+
export var VirtualCurrencyBalanceError = /*#__PURE__*/function (_Error3) {
|
|
60
|
+
_inherits(VirtualCurrencyBalanceError, _Error3);
|
|
61
|
+
var _super3 = _createSuper(VirtualCurrencyBalanceError);
|
|
62
|
+
function VirtualCurrencyBalanceError(balance, requiredAmount) {
|
|
63
|
+
var _this3;
|
|
64
|
+
_classCallCheck(this, VirtualCurrencyBalanceError);
|
|
65
|
+
_this3 = _super3.call(this, 'Insufficient virtual currency balance.');
|
|
66
|
+
_defineProperty(_assertThisInitialized(_this3), "code", 'VIRTUAL_CURRENCY_BALANCE_INSUFFICIENT');
|
|
67
|
+
_this3.balance = balance;
|
|
68
|
+
_this3.requiredAmount = requiredAmount;
|
|
69
|
+
_this3.name = 'VirtualCurrencyBalanceError';
|
|
70
|
+
return _this3;
|
|
71
|
+
}
|
|
72
|
+
return _createClass(VirtualCurrencyBalanceError);
|
|
73
|
+
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
74
|
+
export function getSelectedSettlementSnapshot(product) {
|
|
75
|
+
var _product$metadata;
|
|
76
|
+
var snapshot = product === null || product === void 0 || (_product$metadata = product.metadata) === null || _product$metadata === void 0 ? void 0 : _product$metadata.selected_settlement_snapshot;
|
|
77
|
+
if (!snapshot || _typeof(snapshot) !== 'object') return null;
|
|
78
|
+
if (snapshot.settlement_type !== 'legal_currency' && snapshot.settlement_type !== 'virtual_currency') {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
return snapshot;
|
|
82
|
+
}
|
|
83
|
+
export function getTempOrderSettlementSnapshot(tempOrder) {
|
|
84
|
+
var _tempOrder$metadata, _tempOrder$products;
|
|
85
|
+
var snapshot = tempOrder === null || tempOrder === void 0 || (_tempOrder$metadata = tempOrder.metadata) === null || _tempOrder$metadata === void 0 ? void 0 : _tempOrder$metadata.cart_settlement_snapshot;
|
|
86
|
+
if (snapshot && _typeof(snapshot) === 'object' && (snapshot.settlement_type === 'legal_currency' || snapshot.settlement_type === 'virtual_currency')) {
|
|
87
|
+
return snapshot;
|
|
88
|
+
}
|
|
89
|
+
return getSelectedSettlementSnapshot(tempOrder === null || tempOrder === void 0 || (_tempOrder$products = tempOrder.products) === null || _tempOrder$products === void 0 ? void 0 : _tempOrder$products[0]);
|
|
90
|
+
}
|
|
91
|
+
export function isVirtualSettlementProduct(product) {
|
|
92
|
+
var _getSelectedSettlemen;
|
|
93
|
+
return ((_getSelectedSettlemen = getSelectedSettlementSnapshot(product)) === null || _getSelectedSettlemen === void 0 ? void 0 : _getSelectedSettlemen.settlement_type) === 'virtual_currency';
|
|
94
|
+
}
|
|
95
|
+
export function getSettlementKey(snapshot) {
|
|
96
|
+
if (!snapshot) return null;
|
|
97
|
+
if (snapshot.settlement_type === 'legal_currency') return 'legal_currency';
|
|
98
|
+
var currencyProductId = Number(snapshot.currency_product_id);
|
|
99
|
+
return Number.isFinite(currencyProductId) && currencyProductId > 0 ? "virtual_currency:".concat(currencyProductId) : null;
|
|
100
|
+
}
|
|
101
|
+
export function getTempOrderSettlementKey(tempOrder) {
|
|
102
|
+
var _tempOrder$products2, _tempOrder$metadata2;
|
|
103
|
+
if (!(tempOrder !== null && tempOrder !== void 0 && (_tempOrder$products2 = tempOrder.products) !== null && _tempOrder$products2 !== void 0 && _tempOrder$products2.length)) return null;
|
|
104
|
+
var storedKey = (_tempOrder$metadata2 = tempOrder.metadata) === null || _tempOrder$metadata2 === void 0 ? void 0 : _tempOrder$metadata2.cart_settlement_key;
|
|
105
|
+
if (typeof storedKey === 'string' && storedKey) return storedKey;
|
|
106
|
+
return getSettlementKey(getTempOrderSettlementSnapshot(tempOrder)) || 'legal_currency';
|
|
107
|
+
}
|
|
108
|
+
export function isVirtualSettlementOrder(tempOrder) {
|
|
109
|
+
var _getTempOrderSettleme;
|
|
110
|
+
return ((_getTempOrderSettleme = getTempOrderSettlementKey(tempOrder)) === null || _getTempOrderSettleme === void 0 ? void 0 : _getTempOrderSettleme.startsWith('virtual_currency:')) === true;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* 详情展示识别同时支持已提交订单的 currency_settlement_config。
|
|
115
|
+
* cart_settlement_* 是交易过程内部状态,服务端详情不保证返回。
|
|
116
|
+
*/
|
|
117
|
+
export function isVirtualSettlementDisplayOrder(tempOrder) {
|
|
118
|
+
var _tempOrder$metadata3;
|
|
119
|
+
return (tempOrder === null || tempOrder === void 0 || (_tempOrder$metadata3 = tempOrder.metadata) === null || _tempOrder$metadata3 === void 0 || (_tempOrder$metadata3 = _tempOrder$metadata3.currency_settlement_config) === null || _tempOrder$metadata3 === void 0 ? void 0 : _tempOrder$metadata3.settlement_type) === 'virtual_currency' || isVirtualSettlementOrder(tempOrder);
|
|
120
|
+
}
|
|
121
|
+
function getLegalCurrencySnapshot(tempOrder) {
|
|
122
|
+
var _tempOrder$metadata4;
|
|
123
|
+
var snapshot = (_tempOrder$metadata4 = tempOrder.metadata) === null || _tempOrder$metadata4 === void 0 ? void 0 : _tempOrder$metadata4.legal_currency_snapshot;
|
|
124
|
+
if (!snapshot || _typeof(snapshot) !== 'object') return null;
|
|
125
|
+
return {
|
|
126
|
+
currency_code: String(snapshot.currency_code || ''),
|
|
127
|
+
currency_symbol: String(snapshot.currency_symbol || ''),
|
|
128
|
+
currency_format: String(snapshot.currency_format || 'symbol_first')
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
function captureLegalCurrencySnapshot(tempOrder) {
|
|
132
|
+
tempOrder.metadata = tempOrder.metadata || {};
|
|
133
|
+
if (getLegalCurrencySnapshot(tempOrder)) return;
|
|
134
|
+
tempOrder.metadata.legal_currency_snapshot = {
|
|
135
|
+
currency_code: String(tempOrder.currency_code || ''),
|
|
136
|
+
currency_symbol: String(tempOrder.currency_symbol || ''),
|
|
137
|
+
currency_format: String(tempOrder.currency_format || 'symbol_first')
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* 将购物车锁定的结算单位提升为订单级状态。
|
|
143
|
+
* 商品行快照只负责价格归一化;展示与提交统一读取 tempOrder.currency_*。
|
|
144
|
+
*/
|
|
145
|
+
export function applyTempOrderSettlementState(tempOrder, snapshot) {
|
|
146
|
+
tempOrder.metadata = tempOrder.metadata || {};
|
|
147
|
+
var settlementKey = getSettlementKey(snapshot) || 'legal_currency';
|
|
148
|
+
if (snapshot.settlement_type === 'virtual_currency') {
|
|
149
|
+
captureLegalCurrencySnapshot(tempOrder);
|
|
150
|
+
var _currencyProductId = Number(snapshot.currency_product_id);
|
|
151
|
+
tempOrder.metadata.currency_settlement_config = {
|
|
152
|
+
settlement_type: 'virtual_currency',
|
|
153
|
+
settlement_ids: Number.isFinite(_currencyProductId) && _currencyProductId > 0 ? [_currencyProductId] : []
|
|
154
|
+
};
|
|
155
|
+
} else {
|
|
156
|
+
delete tempOrder.metadata.currency_settlement_config;
|
|
157
|
+
}
|
|
158
|
+
tempOrder.metadata.cart_settlement_key = settlementKey;
|
|
159
|
+
tempOrder.metadata.cart_settlement_snapshot = _objectSpread({}, snapshot);
|
|
160
|
+
tempOrder.currency_code = resolveSettlementDisplayValue(snapshot.unit_label) || tempOrder.currency_code;
|
|
161
|
+
tempOrder.currency_symbol = resolveSettlementDisplayValue(snapshot.symbol) || tempOrder.currency_symbol;
|
|
162
|
+
tempOrder.currency_format = String(snapshot.amount_format || tempOrder.currency_format || 'symbol_first');
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** 清空购物车结算锁,并恢复进入虚拟币结算前的店铺法币。 */
|
|
166
|
+
export function releaseTempOrderSettlementState(tempOrder) {
|
|
167
|
+
tempOrder.metadata = tempOrder.metadata || {};
|
|
168
|
+
var legalCurrency = getLegalCurrencySnapshot(tempOrder);
|
|
169
|
+
if (legalCurrency) {
|
|
170
|
+
tempOrder.currency_code = legalCurrency.currency_code;
|
|
171
|
+
tempOrder.currency_symbol = legalCurrency.currency_symbol;
|
|
172
|
+
tempOrder.currency_format = legalCurrency.currency_format;
|
|
173
|
+
}
|
|
174
|
+
delete tempOrder.metadata.cart_settlement_key;
|
|
175
|
+
delete tempOrder.metadata.cart_settlement_snapshot;
|
|
176
|
+
delete tempOrder.metadata.currency_settlement_config;
|
|
177
|
+
}
|
|
178
|
+
function toMoney(value) {
|
|
179
|
+
try {
|
|
180
|
+
return new Decimal(String(value !== null && value !== void 0 ? value : 0)).toDecimalPlaces(2).toFixed(2);
|
|
181
|
+
} catch (_unused) {
|
|
182
|
+
return '0.00';
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
function zeroOptions(options) {
|
|
186
|
+
if (!Array.isArray(options)) return [];
|
|
187
|
+
return options.map(function (option) {
|
|
188
|
+
return _objectSpread(_objectSpread({}, option), {}, {
|
|
189
|
+
add_price: 0
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
function zeroBundles(bundles) {
|
|
194
|
+
if (!Array.isArray(bundles)) return [];
|
|
195
|
+
return bundles.map(function (bundle) {
|
|
196
|
+
return _objectSpread(_objectSpread({}, bundle), {}, {
|
|
197
|
+
price: 0,
|
|
198
|
+
custom_price: 0,
|
|
199
|
+
bundle_selling_price: 0,
|
|
200
|
+
bundle_payment_price: 0,
|
|
201
|
+
surcharge_fee: 0,
|
|
202
|
+
tax_fee: 0,
|
|
203
|
+
original_tax_fee: 0,
|
|
204
|
+
is_charge_tax: 0,
|
|
205
|
+
discount_list: [],
|
|
206
|
+
relation_surcharge_ids: [],
|
|
207
|
+
option: zeroOptions(bundle === null || bundle === void 0 ? void 0 : bundle.option),
|
|
208
|
+
metadata: _objectSpread(_objectSpread({}, (bundle === null || bundle === void 0 ? void 0 : bundle.metadata) || {}), {}, {
|
|
209
|
+
surcharge_fee: '0.00',
|
|
210
|
+
relation_surcharge_ids: [],
|
|
211
|
+
product_discount_difference: '',
|
|
212
|
+
tax_fee_rounding_remainder: '0.00',
|
|
213
|
+
surcharge_rounding_remainder: '0.00'
|
|
214
|
+
})
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* 将已选择虚拟币的订单商品行固化为最终价语义。
|
|
221
|
+
* 函数幂等,可安全用于加车、合并、hydrate 和提交前兜底。
|
|
222
|
+
*/
|
|
223
|
+
export function normalizeVirtualSettlementOrderProduct(product) {
|
|
224
|
+
var _product$product_sku;
|
|
225
|
+
var snapshot = getSelectedSettlementSnapshot(product);
|
|
226
|
+
if ((snapshot === null || snapshot === void 0 ? void 0 : snapshot.settlement_type) !== 'virtual_currency') return product;
|
|
227
|
+
var virtualPrice = toMoney(snapshot.price);
|
|
228
|
+
var metadata = _objectSpread(_objectSpread({}, product.metadata || {}), {}, {
|
|
229
|
+
source_product_price: virtualPrice,
|
|
230
|
+
main_product_original_price: virtualPrice,
|
|
231
|
+
main_product_selling_price: virtualPrice,
|
|
232
|
+
main_product_attached_bundle_selling_price: virtualPrice,
|
|
233
|
+
main_product_attached_bundle_payment_price: virtualPrice,
|
|
234
|
+
main_product_attached_bundle_surcharge_fee: '0.00',
|
|
235
|
+
main_product_attached_bundle_tax_fee: '0.00',
|
|
236
|
+
surcharge_rounding_remainder: '0.00',
|
|
237
|
+
tax_fee_rounding_remainder: '0.00',
|
|
238
|
+
relation_surcharge_ids: [],
|
|
239
|
+
average_discount_amount_rate: '1',
|
|
240
|
+
product_discount_difference: '',
|
|
241
|
+
discountable_flag: 0,
|
|
242
|
+
price_schema_version: 2,
|
|
243
|
+
selected_settlement_snapshot: _objectSpread(_objectSpread({}, snapshot), {}, {
|
|
244
|
+
price: virtualPrice
|
|
245
|
+
})
|
|
246
|
+
});
|
|
247
|
+
return _objectSpread(_objectSpread({}, product), {}, {
|
|
248
|
+
selling_price: virtualPrice,
|
|
249
|
+
original_price: virtualPrice,
|
|
250
|
+
payment_price: virtualPrice,
|
|
251
|
+
discount_list: [],
|
|
252
|
+
is_charge_tax: 0,
|
|
253
|
+
tax_fee: '0.00',
|
|
254
|
+
original_tax_fee: 0,
|
|
255
|
+
tax_fee_rounding_remainder: 0,
|
|
256
|
+
original_tax_fee_rounding_remainder: 0,
|
|
257
|
+
surcharge_fee: '0.00',
|
|
258
|
+
surcharge_rounding_remainder: 0,
|
|
259
|
+
relation_surcharge_ids: [],
|
|
260
|
+
product_sku: _objectSpread(_objectSpread({}, product.product_sku || {}), {}, {
|
|
261
|
+
option: zeroOptions((_product$product_sku = product.product_sku) === null || _product$product_sku === void 0 ? void 0 : _product$product_sku.option)
|
|
262
|
+
}),
|
|
263
|
+
product_bundle: zeroBundles(product.product_bundle),
|
|
264
|
+
metadata: metadata
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
export function normalizeVirtualSettlementProducts(products) {
|
|
268
|
+
return (products || []).map(function (product) {
|
|
269
|
+
return normalizeVirtualSettlementOrderProduct(product);
|
|
270
|
+
});
|
|
271
|
+
}
|