@pisell/pisellos 2.3.100 → 2.3.102
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/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 +9 -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 +14 -0
- package/dist/modules/Order/index.js +617 -368
- package/dist/modules/Order/types.d.ts +11 -3
- package/dist/modules/Order/utils/virtualSettlement.d.ts +63 -0
- package/dist/modules/Order/utils/virtualSettlement.js +284 -0
- package/dist/modules/Order/utils.d.ts +1 -0
- package/dist/modules/Order/utils.js +63 -24
- package/dist/modules/Product/types.d.ts +23 -0
- package/dist/modules/Rules/index.d.ts +5 -0
- package/dist/modules/Rules/index.js +27 -12
- 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/solution/BaseSales/index.d.ts +10 -1
- package/dist/solution/BaseSales/index.js +1099 -784
- package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +1 -0
- package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +72 -9
- package/dist/solution/BookingByStep/index.d.ts +2 -2
- package/dist/solution/BookingTicket/utils/addProductDecision.js +2 -1
- package/lib/model/strategy/adapter/dataVariant/evaluator.d.ts +18 -2
- package/lib/model/strategy/adapter/dataVariant/evaluator.js +137 -6
- package/lib/model/strategy/adapter/dataVariant/type.d.ts +25 -0
- package/lib/modules/Discount/index.d.ts +2 -0
- package/lib/modules/Discount/index.js +31 -2
- package/lib/modules/Discount/types.d.ts +11 -0
- package/lib/modules/Order/index.d.ts +14 -0
- package/lib/modules/Order/index.js +195 -15
- package/lib/modules/Order/types.d.ts +11 -3
- package/lib/modules/Order/utils/virtualSettlement.d.ts +63 -0
- package/lib/modules/Order/utils/virtualSettlement.js +262 -0
- package/lib/modules/Order/utils.d.ts +1 -0
- package/lib/modules/Order/utils.js +57 -20
- package/lib/modules/Product/types.d.ts +23 -0
- package/lib/modules/Rules/index.d.ts +5 -0
- package/lib/modules/Rules/index.js +20 -11
- package/lib/modules/SalesSummary/index.d.ts +1 -0
- package/lib/modules/SalesSummary/index.js +4 -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 +17 -1
- package/lib/solution/BaseSales/index.d.ts +10 -1
- package/lib/solution/BaseSales/index.js +211 -9
- package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +1 -0
- package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +38 -0
- package/lib/solution/BookingByStep/index.d.ts +2 -2
- package/lib/solution/BookingTicket/utils/addProductDecision.js +1 -0
- 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';
|
|
@@ -205,6 +205,7 @@ export interface OrderProduct extends OrderProductIdentity {
|
|
|
205
205
|
gift_card?: number;
|
|
206
206
|
selling_price: string;
|
|
207
207
|
original_price: string;
|
|
208
|
+
payment_price?: string;
|
|
208
209
|
tax_fee: string;
|
|
209
210
|
is_charge_tax: number;
|
|
210
211
|
discount_list: OrderProductDiscountItem[];
|
|
@@ -353,6 +354,7 @@ export interface OrderTempOrder {
|
|
|
353
354
|
notes: SalesNote[];
|
|
354
355
|
bookings: any[];
|
|
355
356
|
payments: any[];
|
|
357
|
+
refunds?: any[];
|
|
356
358
|
surcharges: any[];
|
|
357
359
|
discount_list?: any[];
|
|
358
360
|
relation_forms: any[];
|
|
@@ -372,8 +374,9 @@ export interface OrderSubmitProduct extends Omit<OrderProduct, 'unique_identific
|
|
|
372
374
|
payment_price: string;
|
|
373
375
|
product_sku: OrderProductSku;
|
|
374
376
|
}
|
|
375
|
-
export interface OrderSubmitPayload extends Omit<OrderTempOrder, 'platform' | 'products' | 'notes' | '_extend' | 'customer' | 'discount_list' | 'created_at'> {
|
|
377
|
+
export interface OrderSubmitPayload extends Omit<OrderTempOrder, 'platform' | 'products' | 'notes' | '_extend' | 'customer' | 'discount_list' | 'created_at' | 'payment_status'> {
|
|
376
378
|
platform: string;
|
|
379
|
+
payment_status?: string;
|
|
377
380
|
created_at?: string | undefined;
|
|
378
381
|
request_unique_idempotency_token?: string;
|
|
379
382
|
form_record_ids?: Array<{
|
|
@@ -392,6 +395,7 @@ export interface OrderState {
|
|
|
392
395
|
syncState?: OrderSyncState;
|
|
393
396
|
discountList: any[];
|
|
394
397
|
availableWalletIds?: number[];
|
|
398
|
+
virtualCurrencyList?: VirtualCurrencyAsset[];
|
|
395
399
|
discount: DiscountModule | null;
|
|
396
400
|
rules: RulesModule | null;
|
|
397
401
|
}
|
|
@@ -530,7 +534,7 @@ export interface SubmitSalesOrderParams {
|
|
|
530
534
|
sales_channel: string;
|
|
531
535
|
order_sales_channel: string;
|
|
532
536
|
status: string;
|
|
533
|
-
payment_status
|
|
537
|
+
payment_status?: string;
|
|
534
538
|
shipping_status: string;
|
|
535
539
|
customer_id: number | null;
|
|
536
540
|
customer_name: string;
|
|
@@ -794,6 +798,8 @@ export interface OrderModuleAPI {
|
|
|
794
798
|
addNewOrder: () => Promise<OrderTempOrder>;
|
|
795
799
|
restoreOrder: () => OrderTempOrder;
|
|
796
800
|
getOrderProducts: () => OrderProduct[];
|
|
801
|
+
getVirtualCurrencyList: () => VirtualCurrencyAsset[];
|
|
802
|
+
clearOrderForSettlementSwitch: () => Promise<OrderTempOrder>;
|
|
797
803
|
getOrderSummary: () => Promise<OrderSummary>;
|
|
798
804
|
recalculateSummary: (options?: {
|
|
799
805
|
createIfMissing?: boolean;
|
|
@@ -864,6 +870,8 @@ export interface OrderModuleAPI {
|
|
|
864
870
|
isTempOrderPersistEnabled: () => boolean;
|
|
865
871
|
/** 提交 tempOrder 变更并触发 `{moduleName}:changed` 事件 */
|
|
866
872
|
notifyTempOrderChanged: () => void;
|
|
873
|
+
/** PC/H5 为在线店铺;其它或缺失平台统一按 POS 处理。 */
|
|
874
|
+
isOnlineStorePlatform: () => boolean;
|
|
867
875
|
submitTempOrder: <T = any>(params?: {
|
|
868
876
|
cacheId?: string;
|
|
869
877
|
platform?: string;
|
|
@@ -0,0 +1,63 @@
|
|
|
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 interface CurrencyDisplaySnapshot {
|
|
16
|
+
amount_format: string;
|
|
17
|
+
symbol: unknown;
|
|
18
|
+
unit_label: unknown;
|
|
19
|
+
}
|
|
20
|
+
export declare function buildCurrencyDisplaySnapshot(snapshot: Pick<SelectedSettlementSnapshot, 'amount_format' | 'symbol' | 'unit_label'>): CurrencyDisplaySnapshot;
|
|
21
|
+
export declare function resolveSettlementDisplayValue(value: unknown): string;
|
|
22
|
+
export declare class OrderSettlementConflictError extends Error {
|
|
23
|
+
readonly currentSettlementKey: string;
|
|
24
|
+
readonly incomingSettlementKey: string;
|
|
25
|
+
readonly code = "ORDER_SETTLEMENT_CONFLICT";
|
|
26
|
+
constructor(currentSettlementKey: string, incomingSettlementKey: string);
|
|
27
|
+
}
|
|
28
|
+
export declare class VirtualCurrencyAssetNotFoundError extends Error {
|
|
29
|
+
readonly currencyProductId: number;
|
|
30
|
+
readonly code = "VIRTUAL_CURRENCY_ASSET_NOT_FOUND";
|
|
31
|
+
constructor(currencyProductId: number);
|
|
32
|
+
}
|
|
33
|
+
export declare class VirtualCurrencyBalanceError extends Error {
|
|
34
|
+
readonly balance: string;
|
|
35
|
+
readonly requiredAmount: string;
|
|
36
|
+
readonly code = "VIRTUAL_CURRENCY_BALANCE_INSUFFICIENT";
|
|
37
|
+
constructor(balance: string, requiredAmount: string);
|
|
38
|
+
}
|
|
39
|
+
export declare function getSelectedSettlementSnapshot(product: Partial<OrderProduct> | null | undefined): SelectedSettlementSnapshot | null;
|
|
40
|
+
export declare function getTempOrderSettlementSnapshot(tempOrder: OrderTempOrder | null | undefined): SelectedSettlementSnapshot | null;
|
|
41
|
+
export declare function isVirtualSettlementProduct(product: Partial<OrderProduct> | null | undefined): boolean;
|
|
42
|
+
export declare function getSettlementKey(snapshot: SelectedSettlementSnapshot | null | undefined): string | null;
|
|
43
|
+
export declare function getTempOrderSettlementKey(tempOrder: OrderTempOrder | null | undefined): string | null;
|
|
44
|
+
export declare function isVirtualSettlementOrder(tempOrder: OrderTempOrder | null | undefined): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* 详情展示识别同时支持已提交订单的 currency_settlement_config。
|
|
47
|
+
* cart_settlement_* 是交易过程内部状态,服务端详情不保证返回。
|
|
48
|
+
*/
|
|
49
|
+
export declare function isVirtualSettlementDisplayOrder(tempOrder: OrderTempOrder | null | undefined): boolean;
|
|
50
|
+
/**
|
|
51
|
+
* 将购物车锁定的结算单位提升为订单级状态。
|
|
52
|
+
* 商品行快照同时负责价格归一化和生成订单级多语言展示快照;
|
|
53
|
+
* 交易中的即时展示仍统一读取 tempOrder.currency_*。
|
|
54
|
+
*/
|
|
55
|
+
export declare function applyTempOrderSettlementState(tempOrder: OrderTempOrder, snapshot: SelectedSettlementSnapshot): void;
|
|
56
|
+
/** 清空购物车结算锁,并恢复进入虚拟币结算前的店铺法币。 */
|
|
57
|
+
export declare function releaseTempOrderSettlementState(tempOrder: OrderTempOrder): void;
|
|
58
|
+
/**
|
|
59
|
+
* 将已选择虚拟币的订单商品行固化为最终价语义。
|
|
60
|
+
* 函数幂等,可安全用于加车、合并、hydrate 和提交前兜底。
|
|
61
|
+
*/
|
|
62
|
+
export declare function normalizeVirtualSettlementOrderProduct<T extends Partial<OrderProduct>>(product: T): T;
|
|
63
|
+
export declare function normalizeVirtualSettlementProducts<T extends Partial<OrderProduct>>(products: T[]): T[];
|
|
@@ -0,0 +1,284 @@
|
|
|
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
|
+
import { cloneDeep } from 'lodash-es';
|
|
22
|
+
export function buildCurrencyDisplaySnapshot(snapshot) {
|
|
23
|
+
var _snapshot$symbol, _snapshot$unit_label;
|
|
24
|
+
return cloneDeep({
|
|
25
|
+
amount_format: String(snapshot.amount_format || '').trim(),
|
|
26
|
+
symbol: (_snapshot$symbol = snapshot.symbol) !== null && _snapshot$symbol !== void 0 ? _snapshot$symbol : {},
|
|
27
|
+
unit_label: (_snapshot$unit_label = snapshot.unit_label) !== null && _snapshot$unit_label !== void 0 ? _snapshot$unit_label : {}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
export function resolveSettlementDisplayValue(value) {
|
|
31
|
+
var _ref, _ref2, _ref3, _ref4, _ref5, _localized$auto;
|
|
32
|
+
if (value === undefined || value === null) return '';
|
|
33
|
+
if (typeof value === 'string' || typeof value === 'number') {
|
|
34
|
+
return String(value);
|
|
35
|
+
}
|
|
36
|
+
var localized = value;
|
|
37
|
+
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 : '');
|
|
38
|
+
}
|
|
39
|
+
export var OrderSettlementConflictError = /*#__PURE__*/function (_Error) {
|
|
40
|
+
_inherits(OrderSettlementConflictError, _Error);
|
|
41
|
+
var _super = _createSuper(OrderSettlementConflictError);
|
|
42
|
+
function OrderSettlementConflictError(currentSettlementKey, incomingSettlementKey) {
|
|
43
|
+
var _this;
|
|
44
|
+
_classCallCheck(this, OrderSettlementConflictError);
|
|
45
|
+
_this = _super.call(this, 'Different currencies and WalletPass units cannot be mixed in one cart.');
|
|
46
|
+
_defineProperty(_assertThisInitialized(_this), "code", 'ORDER_SETTLEMENT_CONFLICT');
|
|
47
|
+
_this.currentSettlementKey = currentSettlementKey;
|
|
48
|
+
_this.incomingSettlementKey = incomingSettlementKey;
|
|
49
|
+
_this.name = 'OrderSettlementConflictError';
|
|
50
|
+
return _this;
|
|
51
|
+
}
|
|
52
|
+
return _createClass(OrderSettlementConflictError);
|
|
53
|
+
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
54
|
+
export var VirtualCurrencyAssetNotFoundError = /*#__PURE__*/function (_Error2) {
|
|
55
|
+
_inherits(VirtualCurrencyAssetNotFoundError, _Error2);
|
|
56
|
+
var _super2 = _createSuper(VirtualCurrencyAssetNotFoundError);
|
|
57
|
+
function VirtualCurrencyAssetNotFoundError(currencyProductId) {
|
|
58
|
+
var _this2;
|
|
59
|
+
_classCallCheck(this, VirtualCurrencyAssetNotFoundError);
|
|
60
|
+
_this2 = _super2.call(this, 'No matching virtual currency card is available.');
|
|
61
|
+
_defineProperty(_assertThisInitialized(_this2), "code", 'VIRTUAL_CURRENCY_ASSET_NOT_FOUND');
|
|
62
|
+
_this2.currencyProductId = currencyProductId;
|
|
63
|
+
_this2.name = 'VirtualCurrencyAssetNotFoundError';
|
|
64
|
+
return _this2;
|
|
65
|
+
}
|
|
66
|
+
return _createClass(VirtualCurrencyAssetNotFoundError);
|
|
67
|
+
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
68
|
+
export var VirtualCurrencyBalanceError = /*#__PURE__*/function (_Error3) {
|
|
69
|
+
_inherits(VirtualCurrencyBalanceError, _Error3);
|
|
70
|
+
var _super3 = _createSuper(VirtualCurrencyBalanceError);
|
|
71
|
+
function VirtualCurrencyBalanceError(balance, requiredAmount) {
|
|
72
|
+
var _this3;
|
|
73
|
+
_classCallCheck(this, VirtualCurrencyBalanceError);
|
|
74
|
+
_this3 = _super3.call(this, 'Insufficient virtual currency balance.');
|
|
75
|
+
_defineProperty(_assertThisInitialized(_this3), "code", 'VIRTUAL_CURRENCY_BALANCE_INSUFFICIENT');
|
|
76
|
+
_this3.balance = balance;
|
|
77
|
+
_this3.requiredAmount = requiredAmount;
|
|
78
|
+
_this3.name = 'VirtualCurrencyBalanceError';
|
|
79
|
+
return _this3;
|
|
80
|
+
}
|
|
81
|
+
return _createClass(VirtualCurrencyBalanceError);
|
|
82
|
+
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
83
|
+
export function getSelectedSettlementSnapshot(product) {
|
|
84
|
+
var _product$metadata;
|
|
85
|
+
var snapshot = product === null || product === void 0 || (_product$metadata = product.metadata) === null || _product$metadata === void 0 ? void 0 : _product$metadata.selected_settlement_snapshot;
|
|
86
|
+
if (!snapshot || _typeof(snapshot) !== 'object') return null;
|
|
87
|
+
if (snapshot.settlement_type !== 'legal_currency' && snapshot.settlement_type !== 'virtual_currency') {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
return snapshot;
|
|
91
|
+
}
|
|
92
|
+
export function getTempOrderSettlementSnapshot(tempOrder) {
|
|
93
|
+
var _tempOrder$metadata, _tempOrder$products;
|
|
94
|
+
var snapshot = tempOrder === null || tempOrder === void 0 || (_tempOrder$metadata = tempOrder.metadata) === null || _tempOrder$metadata === void 0 ? void 0 : _tempOrder$metadata.cart_settlement_snapshot;
|
|
95
|
+
if (snapshot && _typeof(snapshot) === 'object' && (snapshot.settlement_type === 'legal_currency' || snapshot.settlement_type === 'virtual_currency')) {
|
|
96
|
+
return snapshot;
|
|
97
|
+
}
|
|
98
|
+
return getSelectedSettlementSnapshot(tempOrder === null || tempOrder === void 0 || (_tempOrder$products = tempOrder.products) === null || _tempOrder$products === void 0 ? void 0 : _tempOrder$products[0]);
|
|
99
|
+
}
|
|
100
|
+
export function isVirtualSettlementProduct(product) {
|
|
101
|
+
var _getSelectedSettlemen;
|
|
102
|
+
return ((_getSelectedSettlemen = getSelectedSettlementSnapshot(product)) === null || _getSelectedSettlemen === void 0 ? void 0 : _getSelectedSettlemen.settlement_type) === 'virtual_currency';
|
|
103
|
+
}
|
|
104
|
+
export function getSettlementKey(snapshot) {
|
|
105
|
+
if (!snapshot) return null;
|
|
106
|
+
if (snapshot.settlement_type === 'legal_currency') return 'legal_currency';
|
|
107
|
+
var currencyProductId = Number(snapshot.currency_product_id);
|
|
108
|
+
return Number.isFinite(currencyProductId) && currencyProductId > 0 ? "virtual_currency:".concat(currencyProductId) : null;
|
|
109
|
+
}
|
|
110
|
+
export function getTempOrderSettlementKey(tempOrder) {
|
|
111
|
+
var _tempOrder$products2, _tempOrder$metadata2;
|
|
112
|
+
if (!(tempOrder !== null && tempOrder !== void 0 && (_tempOrder$products2 = tempOrder.products) !== null && _tempOrder$products2 !== void 0 && _tempOrder$products2.length)) return null;
|
|
113
|
+
var storedKey = (_tempOrder$metadata2 = tempOrder.metadata) === null || _tempOrder$metadata2 === void 0 ? void 0 : _tempOrder$metadata2.cart_settlement_key;
|
|
114
|
+
if (typeof storedKey === 'string' && storedKey) return storedKey;
|
|
115
|
+
return getSettlementKey(getTempOrderSettlementSnapshot(tempOrder)) || 'legal_currency';
|
|
116
|
+
}
|
|
117
|
+
export function isVirtualSettlementOrder(tempOrder) {
|
|
118
|
+
var _getTempOrderSettleme;
|
|
119
|
+
return ((_getTempOrderSettleme = getTempOrderSettlementKey(tempOrder)) === null || _getTempOrderSettleme === void 0 ? void 0 : _getTempOrderSettleme.startsWith('virtual_currency:')) === true;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* 详情展示识别同时支持已提交订单的 currency_settlement_config。
|
|
124
|
+
* cart_settlement_* 是交易过程内部状态,服务端详情不保证返回。
|
|
125
|
+
*/
|
|
126
|
+
export function isVirtualSettlementDisplayOrder(tempOrder) {
|
|
127
|
+
var _tempOrder$metadata3;
|
|
128
|
+
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);
|
|
129
|
+
}
|
|
130
|
+
function getLegalCurrencySnapshot(tempOrder) {
|
|
131
|
+
var _tempOrder$metadata4;
|
|
132
|
+
var snapshot = (_tempOrder$metadata4 = tempOrder.metadata) === null || _tempOrder$metadata4 === void 0 ? void 0 : _tempOrder$metadata4.legal_currency_snapshot;
|
|
133
|
+
if (!snapshot || _typeof(snapshot) !== 'object') return null;
|
|
134
|
+
return {
|
|
135
|
+
currency_code: String(snapshot.currency_code || ''),
|
|
136
|
+
currency_symbol: String(snapshot.currency_symbol || ''),
|
|
137
|
+
currency_format: String(snapshot.currency_format || 'symbol_first')
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
function captureLegalCurrencySnapshot(tempOrder) {
|
|
141
|
+
tempOrder.metadata = tempOrder.metadata || {};
|
|
142
|
+
if (getLegalCurrencySnapshot(tempOrder)) return;
|
|
143
|
+
tempOrder.metadata.legal_currency_snapshot = {
|
|
144
|
+
currency_code: String(tempOrder.currency_code || ''),
|
|
145
|
+
currency_symbol: String(tempOrder.currency_symbol || ''),
|
|
146
|
+
currency_format: String(tempOrder.currency_format || 'symbol_first')
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* 将购物车锁定的结算单位提升为订单级状态。
|
|
152
|
+
* 商品行快照同时负责价格归一化和生成订单级多语言展示快照;
|
|
153
|
+
* 交易中的即时展示仍统一读取 tempOrder.currency_*。
|
|
154
|
+
*/
|
|
155
|
+
export function applyTempOrderSettlementState(tempOrder, snapshot) {
|
|
156
|
+
tempOrder.metadata = tempOrder.metadata || {};
|
|
157
|
+
var settlementKey = getSettlementKey(snapshot) || 'legal_currency';
|
|
158
|
+
if (snapshot.settlement_type === 'virtual_currency') {
|
|
159
|
+
var _tempOrder$metadata$c;
|
|
160
|
+
captureLegalCurrencySnapshot(tempOrder);
|
|
161
|
+
var _currencyProductId = Number(snapshot.currency_product_id);
|
|
162
|
+
var existingDisplaySnapshot = (_tempOrder$metadata$c = tempOrder.metadata.currency_settlement_config) === null || _tempOrder$metadata$c === void 0 ? void 0 : _tempOrder$metadata$c.currency_display_snapshot;
|
|
163
|
+
tempOrder.metadata.currency_settlement_config = {
|
|
164
|
+
settlement_type: 'virtual_currency',
|
|
165
|
+
settlement_ids: Number.isFinite(_currencyProductId) && _currencyProductId > 0 ? [_currencyProductId] : [],
|
|
166
|
+
currency_display_snapshot: existingDisplaySnapshot ? cloneDeep(existingDisplaySnapshot) : buildCurrencyDisplaySnapshot(snapshot)
|
|
167
|
+
};
|
|
168
|
+
} else {
|
|
169
|
+
delete tempOrder.metadata.currency_settlement_config;
|
|
170
|
+
}
|
|
171
|
+
tempOrder.metadata.cart_settlement_key = settlementKey;
|
|
172
|
+
tempOrder.metadata.cart_settlement_snapshot = _objectSpread({}, snapshot);
|
|
173
|
+
tempOrder.currency_code = resolveSettlementDisplayValue(snapshot.unit_label) || tempOrder.currency_code;
|
|
174
|
+
tempOrder.currency_symbol = resolveSettlementDisplayValue(snapshot.symbol) || tempOrder.currency_symbol;
|
|
175
|
+
tempOrder.currency_format = String(snapshot.amount_format || tempOrder.currency_format || 'symbol_first');
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** 清空购物车结算锁,并恢复进入虚拟币结算前的店铺法币。 */
|
|
179
|
+
export function releaseTempOrderSettlementState(tempOrder) {
|
|
180
|
+
tempOrder.metadata = tempOrder.metadata || {};
|
|
181
|
+
var legalCurrency = getLegalCurrencySnapshot(tempOrder);
|
|
182
|
+
if (legalCurrency) {
|
|
183
|
+
tempOrder.currency_code = legalCurrency.currency_code;
|
|
184
|
+
tempOrder.currency_symbol = legalCurrency.currency_symbol;
|
|
185
|
+
tempOrder.currency_format = legalCurrency.currency_format;
|
|
186
|
+
}
|
|
187
|
+
delete tempOrder.metadata.cart_settlement_key;
|
|
188
|
+
delete tempOrder.metadata.cart_settlement_snapshot;
|
|
189
|
+
delete tempOrder.metadata.currency_settlement_config;
|
|
190
|
+
}
|
|
191
|
+
function toMoney(value) {
|
|
192
|
+
try {
|
|
193
|
+
return new Decimal(String(value !== null && value !== void 0 ? value : 0)).toDecimalPlaces(2).toFixed(2);
|
|
194
|
+
} catch (_unused) {
|
|
195
|
+
return '0.00';
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
function zeroOptions(options) {
|
|
199
|
+
if (!Array.isArray(options)) return [];
|
|
200
|
+
return options.map(function (option) {
|
|
201
|
+
return _objectSpread(_objectSpread({}, option), {}, {
|
|
202
|
+
add_price: 0
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
function zeroBundles(bundles) {
|
|
207
|
+
if (!Array.isArray(bundles)) return [];
|
|
208
|
+
return bundles.map(function (bundle) {
|
|
209
|
+
return _objectSpread(_objectSpread({}, bundle), {}, {
|
|
210
|
+
price: 0,
|
|
211
|
+
custom_price: 0,
|
|
212
|
+
bundle_selling_price: 0,
|
|
213
|
+
bundle_payment_price: 0,
|
|
214
|
+
surcharge_fee: 0,
|
|
215
|
+
tax_fee: 0,
|
|
216
|
+
original_tax_fee: 0,
|
|
217
|
+
is_charge_tax: 0,
|
|
218
|
+
discount_list: [],
|
|
219
|
+
relation_surcharge_ids: [],
|
|
220
|
+
option: zeroOptions(bundle === null || bundle === void 0 ? void 0 : bundle.option),
|
|
221
|
+
metadata: _objectSpread(_objectSpread({}, (bundle === null || bundle === void 0 ? void 0 : bundle.metadata) || {}), {}, {
|
|
222
|
+
surcharge_fee: '0.00',
|
|
223
|
+
relation_surcharge_ids: [],
|
|
224
|
+
product_discount_difference: '',
|
|
225
|
+
tax_fee_rounding_remainder: '0.00',
|
|
226
|
+
surcharge_rounding_remainder: '0.00'
|
|
227
|
+
})
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* 将已选择虚拟币的订单商品行固化为最终价语义。
|
|
234
|
+
* 函数幂等,可安全用于加车、合并、hydrate 和提交前兜底。
|
|
235
|
+
*/
|
|
236
|
+
export function normalizeVirtualSettlementOrderProduct(product) {
|
|
237
|
+
var _product$product_sku;
|
|
238
|
+
var snapshot = getSelectedSettlementSnapshot(product);
|
|
239
|
+
if ((snapshot === null || snapshot === void 0 ? void 0 : snapshot.settlement_type) !== 'virtual_currency') return product;
|
|
240
|
+
var virtualPrice = toMoney(snapshot.price);
|
|
241
|
+
var metadata = _objectSpread(_objectSpread({}, product.metadata || {}), {}, {
|
|
242
|
+
source_product_price: virtualPrice,
|
|
243
|
+
main_product_original_price: virtualPrice,
|
|
244
|
+
main_product_selling_price: virtualPrice,
|
|
245
|
+
main_product_attached_bundle_selling_price: virtualPrice,
|
|
246
|
+
main_product_attached_bundle_payment_price: virtualPrice,
|
|
247
|
+
main_product_attached_bundle_surcharge_fee: '0.00',
|
|
248
|
+
main_product_attached_bundle_tax_fee: '0.00',
|
|
249
|
+
surcharge_rounding_remainder: '0.00',
|
|
250
|
+
tax_fee_rounding_remainder: '0.00',
|
|
251
|
+
relation_surcharge_ids: [],
|
|
252
|
+
average_discount_amount_rate: '1',
|
|
253
|
+
product_discount_difference: '',
|
|
254
|
+
discountable_flag: 0,
|
|
255
|
+
price_schema_version: 2,
|
|
256
|
+
selected_settlement_snapshot: _objectSpread(_objectSpread({}, snapshot), {}, {
|
|
257
|
+
price: virtualPrice
|
|
258
|
+
})
|
|
259
|
+
});
|
|
260
|
+
return _objectSpread(_objectSpread({}, product), {}, {
|
|
261
|
+
selling_price: virtualPrice,
|
|
262
|
+
original_price: virtualPrice,
|
|
263
|
+
payment_price: virtualPrice,
|
|
264
|
+
discount_list: [],
|
|
265
|
+
is_charge_tax: 0,
|
|
266
|
+
tax_fee: '0.00',
|
|
267
|
+
original_tax_fee: 0,
|
|
268
|
+
tax_fee_rounding_remainder: 0,
|
|
269
|
+
original_tax_fee_rounding_remainder: 0,
|
|
270
|
+
surcharge_fee: '0.00',
|
|
271
|
+
surcharge_rounding_remainder: 0,
|
|
272
|
+
relation_surcharge_ids: [],
|
|
273
|
+
product_sku: _objectSpread(_objectSpread({}, product.product_sku || {}), {}, {
|
|
274
|
+
option: zeroOptions((_product$product_sku = product.product_sku) === null || _product$product_sku === void 0 ? void 0 : _product$product_sku.option)
|
|
275
|
+
}),
|
|
276
|
+
product_bundle: zeroBundles(product.product_bundle),
|
|
277
|
+
metadata: metadata
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
export function normalizeVirtualSettlementProducts(products) {
|
|
281
|
+
return (products || []).map(function (product) {
|
|
282
|
+
return normalizeVirtualSettlementOrderProduct(product);
|
|
283
|
+
});
|
|
284
|
+
}
|
|
@@ -232,6 +232,7 @@ export declare function buildSubmitPayload(params: {
|
|
|
232
232
|
type?: string;
|
|
233
233
|
summary?: OrderSummary | null;
|
|
234
234
|
request_unique_idempotency_token?: string;
|
|
235
|
+
includePaymentStatus?: boolean;
|
|
235
236
|
enhance?: SubmitPayloadEnhancer;
|
|
236
237
|
}): OrderSubmitPayload;
|
|
237
238
|
export declare function mapPaymentItemToOrderPayment(paymentItem: OrderPaymentSource): OrderPaymentData;
|