@pisell/pisellos 0.0.337 → 0.0.339
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/modules/Cart/utils/cartProduct.js +34 -19
- package/dist/modules/Discount/types.d.ts +10 -0
- package/dist/modules/Order/index.js +4 -1
- package/dist/modules/Order/utils.d.ts +1 -0
- package/dist/modules/Order/utils.js +9 -0
- package/dist/modules/Rules/index.d.ts +7 -0
- package/dist/modules/Rules/index.js +844 -170
- package/dist/modules/Rules/types.d.ts +2 -1
- package/dist/solution/RegisterAndLogin/index.d.ts +5 -0
- package/dist/solution/RegisterAndLogin/index.js +165 -70
- package/dist/solution/ShopDiscount/index.js +7 -5
- package/dist/solution/ShopDiscount/utils.d.ts +7 -0
- package/dist/solution/ShopDiscount/utils.js +19 -3
- package/lib/modules/Cart/utils/cartProduct.js +32 -17
- package/lib/modules/Discount/types.d.ts +10 -0
- package/lib/modules/Order/index.js +2 -0
- package/lib/modules/Order/utils.d.ts +1 -0
- package/lib/modules/Order/utils.js +11 -0
- package/lib/modules/Rules/index.d.ts +7 -0
- package/lib/modules/Rules/index.js +697 -159
- package/lib/modules/Rules/types.d.ts +2 -1
- package/lib/solution/BookingTicket/index.js +0 -6
- package/lib/solution/RegisterAndLogin/index.d.ts +5 -0
- package/lib/solution/RegisterAndLogin/index.js +53 -16
- package/lib/solution/ShopDiscount/index.js +10 -8
- package/lib/solution/ShopDiscount/utils.d.ts +7 -0
- package/lib/solution/ShopDiscount/utils.js +17 -3
- package/package.json +1 -1
|
@@ -50,8 +50,9 @@ export interface RulesParamsHooks {
|
|
|
50
50
|
origin_total?: number;
|
|
51
51
|
price?: string | number;
|
|
52
52
|
variant?: any[];
|
|
53
|
-
original_price?: number;
|
|
53
|
+
original_price?: number | string;
|
|
54
54
|
quantity?: number;
|
|
55
|
+
bundle?: any[];
|
|
55
56
|
}) => Record<string, any>;
|
|
56
57
|
}
|
|
57
58
|
export {};
|
|
@@ -17,6 +17,7 @@ export declare class RegisterAndLoginImpl extends BaseModule implements Module {
|
|
|
17
17
|
private apiCaller;
|
|
18
18
|
private otherParams;
|
|
19
19
|
private channel;
|
|
20
|
+
private countriesCache;
|
|
20
21
|
constructor(name?: string, version?: string);
|
|
21
22
|
/**
|
|
22
23
|
* 重新发送邮箱注册链接
|
|
@@ -179,5 +180,9 @@ export declare class RegisterAndLoginImpl extends BaseModule implements Module {
|
|
|
179
180
|
* 获取国家区号列表
|
|
180
181
|
*/
|
|
181
182
|
getCountries(): Promise<CountryInfo[]>;
|
|
183
|
+
/**
|
|
184
|
+
* 异步更新国家缓存数据
|
|
185
|
+
*/
|
|
186
|
+
private updateCountriesCache;
|
|
182
187
|
destroy(): Promise<void>;
|
|
183
188
|
}
|
|
@@ -43,6 +43,8 @@ export var RegisterAndLoginImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
43
43
|
_defineProperty(_assertThisInitialized(_this), "apiCaller", void 0);
|
|
44
44
|
_defineProperty(_assertThisInitialized(_this), "otherParams", {});
|
|
45
45
|
_defineProperty(_assertThisInitialized(_this), "channel", 'default');
|
|
46
|
+
// 内存缓存
|
|
47
|
+
_defineProperty(_assertThisInitialized(_this), "countriesCache", null);
|
|
46
48
|
return _this;
|
|
47
49
|
}
|
|
48
50
|
|
|
@@ -983,11 +985,11 @@ export var RegisterAndLoginImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
983
985
|
this.store.isLoggedIn = true;
|
|
984
986
|
|
|
985
987
|
// 保存到本地存储
|
|
986
|
-
this.window.localStorage.setItem('auth_token', token);
|
|
987
|
-
this.window.localStorage.setItem('user_info', JSON.stringify(user));
|
|
988
|
-
if (refreshToken) {
|
|
989
|
-
|
|
990
|
-
}
|
|
988
|
+
// this.window.localStorage.setItem('auth_token', token);
|
|
989
|
+
// this.window.localStorage.setItem('user_info', JSON.stringify(user));
|
|
990
|
+
// if (refreshToken) {
|
|
991
|
+
// this.window.localStorage.setItem('refresh_token', refreshToken);
|
|
992
|
+
// }
|
|
991
993
|
}
|
|
992
994
|
_context14.next = 13;
|
|
993
995
|
return this.core.effects.emit(RegisterAndLoginHooks.onRegisterSuccess, response.data);
|
|
@@ -1052,7 +1054,7 @@ export var RegisterAndLoginImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1052
1054
|
case 7:
|
|
1053
1055
|
response = _context15.sent;
|
|
1054
1056
|
if (!(response.status && response.data)) {
|
|
1055
|
-
_context15.next =
|
|
1057
|
+
_context15.next = 16;
|
|
1056
1058
|
break;
|
|
1057
1059
|
}
|
|
1058
1060
|
_response$data5 = response.data, user = _response$data5.user, token = _response$data5.token, refreshToken = _response$data5.refreshToken;
|
|
@@ -1060,45 +1062,45 @@ export var RegisterAndLoginImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1060
1062
|
this.store.isLoggedIn = true;
|
|
1061
1063
|
|
|
1062
1064
|
// 保存到本地存储
|
|
1063
|
-
this.window.localStorage.setItem('auth_token', token);
|
|
1064
|
-
this.window.localStorage.setItem('user_info', JSON.stringify(user));
|
|
1065
|
-
if (refreshToken) {
|
|
1066
|
-
|
|
1067
|
-
}
|
|
1068
|
-
_context15.next =
|
|
1065
|
+
// this.window.localStorage.setItem('auth_token', token);
|
|
1066
|
+
// this.window.localStorage.setItem('user_info', JSON.stringify(user));
|
|
1067
|
+
// if (refreshToken) {
|
|
1068
|
+
// this.window.localStorage.setItem('refresh_token', refreshToken);
|
|
1069
|
+
// }
|
|
1070
|
+
_context15.next = 14;
|
|
1069
1071
|
return this.core.effects.emit(RegisterAndLoginHooks.onLoginSuccess, response.data);
|
|
1070
|
-
case
|
|
1071
|
-
_context15.next =
|
|
1072
|
+
case 14:
|
|
1073
|
+
_context15.next = 19;
|
|
1072
1074
|
break;
|
|
1073
|
-
case
|
|
1075
|
+
case 16:
|
|
1074
1076
|
this.store.error = response.message || '登录失败';
|
|
1075
|
-
_context15.next =
|
|
1077
|
+
_context15.next = 19;
|
|
1076
1078
|
return this.core.effects.emit(RegisterAndLoginHooks.onLoginFailed, {
|
|
1077
1079
|
error: this.store.error,
|
|
1078
1080
|
params: params
|
|
1079
1081
|
});
|
|
1080
|
-
case
|
|
1082
|
+
case 19:
|
|
1081
1083
|
return _context15.abrupt("return", response);
|
|
1082
|
-
case
|
|
1083
|
-
_context15.prev =
|
|
1084
|
+
case 22:
|
|
1085
|
+
_context15.prev = 22;
|
|
1084
1086
|
_context15.t0 = _context15["catch"](0);
|
|
1085
1087
|
this.store.error = '登录失败';
|
|
1086
|
-
_context15.next =
|
|
1088
|
+
_context15.next = 27;
|
|
1087
1089
|
return this.core.effects.emit(RegisterAndLoginHooks.onLoginFailed, {
|
|
1088
1090
|
error: this.store.error,
|
|
1089
1091
|
params: params
|
|
1090
1092
|
});
|
|
1091
|
-
case
|
|
1093
|
+
case 27:
|
|
1092
1094
|
throw _context15.t0;
|
|
1093
|
-
case
|
|
1094
|
-
_context15.prev =
|
|
1095
|
+
case 28:
|
|
1096
|
+
_context15.prev = 28;
|
|
1095
1097
|
this.store.isLoading = false;
|
|
1096
|
-
return _context15.finish(
|
|
1097
|
-
case
|
|
1098
|
+
return _context15.finish(28);
|
|
1099
|
+
case 31:
|
|
1098
1100
|
case "end":
|
|
1099
1101
|
return _context15.stop();
|
|
1100
1102
|
}
|
|
1101
|
-
}, _callee15, this, [[0,
|
|
1103
|
+
}, _callee15, this, [[0, 22, 28, 31]]);
|
|
1102
1104
|
}));
|
|
1103
1105
|
function login(_x14) {
|
|
1104
1106
|
return _login.apply(this, arguments);
|
|
@@ -1128,7 +1130,7 @@ export var RegisterAndLoginImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1128
1130
|
case 7:
|
|
1129
1131
|
response = _context16.sent;
|
|
1130
1132
|
if (!(response.status && response.data)) {
|
|
1131
|
-
_context16.next =
|
|
1133
|
+
_context16.next = 16;
|
|
1132
1134
|
break;
|
|
1133
1135
|
}
|
|
1134
1136
|
_response$data6 = response.data, user = _response$data6.user, token = _response$data6.token, refreshToken = _response$data6.refreshToken;
|
|
@@ -1136,45 +1138,45 @@ export var RegisterAndLoginImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1136
1138
|
this.store.isLoggedIn = true;
|
|
1137
1139
|
|
|
1138
1140
|
// 保存到本地存储
|
|
1139
|
-
this.window.localStorage.setItem('auth_token', token);
|
|
1140
|
-
this.window.localStorage.setItem('user_info', JSON.stringify(user));
|
|
1141
|
-
if (refreshToken) {
|
|
1142
|
-
|
|
1143
|
-
}
|
|
1144
|
-
_context16.next =
|
|
1141
|
+
// this.window.localStorage.setItem('auth_token', token);
|
|
1142
|
+
// this.window.localStorage.setItem('user_info', JSON.stringify(user));
|
|
1143
|
+
// if (refreshToken) {
|
|
1144
|
+
// this.window.localStorage.setItem('refresh_token', refreshToken);
|
|
1145
|
+
// }
|
|
1146
|
+
_context16.next = 14;
|
|
1145
1147
|
return this.core.effects.emit(RegisterAndLoginHooks.onOAuthLoginSuccess, response.data);
|
|
1146
|
-
case
|
|
1147
|
-
_context16.next =
|
|
1148
|
+
case 14:
|
|
1149
|
+
_context16.next = 19;
|
|
1148
1150
|
break;
|
|
1149
|
-
case
|
|
1151
|
+
case 16:
|
|
1150
1152
|
this.store.error = response.message || 'OAuth 登录失败';
|
|
1151
|
-
_context16.next =
|
|
1153
|
+
_context16.next = 19;
|
|
1152
1154
|
return this.core.effects.emit(RegisterAndLoginHooks.onOAuthLoginFailed, {
|
|
1153
1155
|
error: this.store.error,
|
|
1154
1156
|
params: params
|
|
1155
1157
|
});
|
|
1156
|
-
case
|
|
1158
|
+
case 19:
|
|
1157
1159
|
return _context16.abrupt("return", response);
|
|
1158
|
-
case
|
|
1159
|
-
_context16.prev =
|
|
1160
|
+
case 22:
|
|
1161
|
+
_context16.prev = 22;
|
|
1160
1162
|
_context16.t0 = _context16["catch"](0);
|
|
1161
1163
|
this.store.error = 'OAuth 登录失败';
|
|
1162
|
-
_context16.next =
|
|
1164
|
+
_context16.next = 27;
|
|
1163
1165
|
return this.core.effects.emit(RegisterAndLoginHooks.onOAuthLoginFailed, {
|
|
1164
1166
|
error: this.store.error,
|
|
1165
1167
|
params: params
|
|
1166
1168
|
});
|
|
1167
|
-
case
|
|
1169
|
+
case 27:
|
|
1168
1170
|
throw _context16.t0;
|
|
1169
|
-
case
|
|
1170
|
-
_context16.prev =
|
|
1171
|
+
case 28:
|
|
1172
|
+
_context16.prev = 28;
|
|
1171
1173
|
this.store.isLoading = false;
|
|
1172
|
-
return _context16.finish(
|
|
1173
|
-
case
|
|
1174
|
+
return _context16.finish(28);
|
|
1175
|
+
case 31:
|
|
1174
1176
|
case "end":
|
|
1175
1177
|
return _context16.stop();
|
|
1176
1178
|
}
|
|
1177
|
-
}, _callee16, this, [[0,
|
|
1179
|
+
}, _callee16, this, [[0, 22, 28, 31]]);
|
|
1178
1180
|
}));
|
|
1179
1181
|
function oauthLogin(_x15) {
|
|
1180
1182
|
return _oauthLogin.apply(this, arguments);
|
|
@@ -2418,65 +2420,158 @@ export var RegisterAndLoginImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2418
2420
|
key: "getCountries",
|
|
2419
2421
|
value: (function () {
|
|
2420
2422
|
var _getCountries = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38() {
|
|
2421
|
-
var response;
|
|
2423
|
+
var CACHE_KEY, cachedData, cached, response, countries;
|
|
2422
2424
|
return _regeneratorRuntime().wrap(function _callee38$(_context38) {
|
|
2423
2425
|
while (1) switch (_context38.prev = _context38.next) {
|
|
2424
2426
|
case 0:
|
|
2425
|
-
|
|
2427
|
+
CACHE_KEY = 'pisell_countries_cache';
|
|
2428
|
+
_context38.prev = 1;
|
|
2426
2429
|
this.store.isLoading = true;
|
|
2427
2430
|
this.store.error = null;
|
|
2428
|
-
|
|
2431
|
+
|
|
2432
|
+
// 1. 检查内存缓存
|
|
2433
|
+
if (!this.countriesCache) {
|
|
2434
|
+
_context38.next = 7;
|
|
2435
|
+
break;
|
|
2436
|
+
}
|
|
2437
|
+
this.store.isLoading = false;
|
|
2438
|
+
return _context38.abrupt("return", this.countriesCache);
|
|
2439
|
+
case 7:
|
|
2440
|
+
// 2. 检查 localStorage 缓存
|
|
2441
|
+
cachedData = null;
|
|
2442
|
+
try {
|
|
2443
|
+
cached = this.window.localStorage.getItem(CACHE_KEY);
|
|
2444
|
+
if (cached) {
|
|
2445
|
+
cachedData = JSON.parse(cached);
|
|
2446
|
+
}
|
|
2447
|
+
} catch (error) {
|
|
2448
|
+
console.warn('[RegisterAndLogin] localStorage 缓存解析失败:', error);
|
|
2449
|
+
}
|
|
2450
|
+
|
|
2451
|
+
// 3. 如果有 localStorage 缓存,先返回缓存数据
|
|
2452
|
+
if (!(cachedData && Array.isArray(cachedData) && cachedData.length > 0)) {
|
|
2453
|
+
_context38.next = 14;
|
|
2454
|
+
break;
|
|
2455
|
+
}
|
|
2456
|
+
// 设置内存缓存
|
|
2457
|
+
this.countriesCache = cachedData;
|
|
2458
|
+
|
|
2459
|
+
// 异步请求后端数据进行对比和更新
|
|
2460
|
+
this.updateCountriesCache(CACHE_KEY, cachedData);
|
|
2461
|
+
this.store.isLoading = false;
|
|
2462
|
+
return _context38.abrupt("return", cachedData);
|
|
2463
|
+
case 14:
|
|
2464
|
+
_context38.next = 16;
|
|
2429
2465
|
return this.apiCaller.call('getCountries');
|
|
2430
|
-
case
|
|
2466
|
+
case 16:
|
|
2431
2467
|
response = _context38.sent;
|
|
2432
2468
|
if (!(response.status && response.data)) {
|
|
2433
|
-
_context38.next =
|
|
2469
|
+
_context38.next = 24;
|
|
2434
2470
|
break;
|
|
2435
2471
|
}
|
|
2436
|
-
|
|
2437
|
-
|
|
2472
|
+
countries = response.data; // 更新内存缓存
|
|
2473
|
+
this.countriesCache = countries;
|
|
2474
|
+
|
|
2475
|
+
// 更新 localStorage 缓存
|
|
2476
|
+
try {
|
|
2477
|
+
localStorage.setItem(CACHE_KEY, JSON.stringify(countries));
|
|
2478
|
+
} catch (error) {
|
|
2479
|
+
console.warn('[RegisterAndLogin] localStorage 存储失败:', error);
|
|
2480
|
+
}
|
|
2481
|
+
return _context38.abrupt("return", countries);
|
|
2482
|
+
case 24:
|
|
2438
2483
|
this.store.error = response.message || '获取国家区号失败';
|
|
2439
2484
|
throw new Error(this.store.error);
|
|
2440
|
-
case
|
|
2441
|
-
_context38.next =
|
|
2485
|
+
case 26:
|
|
2486
|
+
_context38.next = 33;
|
|
2442
2487
|
break;
|
|
2443
|
-
case
|
|
2444
|
-
_context38.prev =
|
|
2445
|
-
_context38.t0 = _context38["catch"](
|
|
2488
|
+
case 28:
|
|
2489
|
+
_context38.prev = 28;
|
|
2490
|
+
_context38.t0 = _context38["catch"](1);
|
|
2446
2491
|
this.store.error = '获取国家区号失败';
|
|
2447
2492
|
console.error('[RegisterAndLogin] 获取国家区号失败:', _context38.t0);
|
|
2448
2493
|
throw _context38.t0;
|
|
2449
|
-
case
|
|
2450
|
-
_context38.prev =
|
|
2494
|
+
case 33:
|
|
2495
|
+
_context38.prev = 33;
|
|
2451
2496
|
this.store.isLoading = false;
|
|
2452
|
-
return _context38.finish(
|
|
2453
|
-
case
|
|
2497
|
+
return _context38.finish(33);
|
|
2498
|
+
case 36:
|
|
2454
2499
|
case "end":
|
|
2455
2500
|
return _context38.stop();
|
|
2456
2501
|
}
|
|
2457
|
-
}, _callee38, this, [[
|
|
2502
|
+
}, _callee38, this, [[1, 28, 33, 36]]);
|
|
2458
2503
|
}));
|
|
2459
2504
|
function getCountries() {
|
|
2460
2505
|
return _getCountries.apply(this, arguments);
|
|
2461
2506
|
}
|
|
2462
2507
|
return getCountries;
|
|
2508
|
+
}()
|
|
2509
|
+
/**
|
|
2510
|
+
* 异步更新国家缓存数据
|
|
2511
|
+
*/
|
|
2512
|
+
)
|
|
2513
|
+
}, {
|
|
2514
|
+
key: "updateCountriesCache",
|
|
2515
|
+
value: (function () {
|
|
2516
|
+
var _updateCountriesCache = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39(cacheKey, cachedData) {
|
|
2517
|
+
var response, newData, hasChanged;
|
|
2518
|
+
return _regeneratorRuntime().wrap(function _callee39$(_context39) {
|
|
2519
|
+
while (1) switch (_context39.prev = _context39.next) {
|
|
2520
|
+
case 0:
|
|
2521
|
+
_context39.prev = 0;
|
|
2522
|
+
_context39.next = 3;
|
|
2523
|
+
return this.apiCaller.call('getCountries');
|
|
2524
|
+
case 3:
|
|
2525
|
+
response = _context39.sent;
|
|
2526
|
+
if (response.status && response.data) {
|
|
2527
|
+
newData = response.data; // 比较数据是否有变化(简单的长度和内容对比)
|
|
2528
|
+
hasChanged = newData.length !== cachedData.length || JSON.stringify(newData) !== JSON.stringify(cachedData);
|
|
2529
|
+
if (hasChanged) {
|
|
2530
|
+
// 更新内存缓存
|
|
2531
|
+
this.countriesCache = newData;
|
|
2532
|
+
|
|
2533
|
+
// 更新 localStorage 缓存
|
|
2534
|
+
try {
|
|
2535
|
+
localStorage.setItem(cacheKey, JSON.stringify(newData));
|
|
2536
|
+
} catch (error) {
|
|
2537
|
+
console.warn('[RegisterAndLogin] localStorage 更新失败:', error);
|
|
2538
|
+
}
|
|
2539
|
+
console.log('[RegisterAndLogin] 国家数据已更新');
|
|
2540
|
+
}
|
|
2541
|
+
}
|
|
2542
|
+
_context39.next = 10;
|
|
2543
|
+
break;
|
|
2544
|
+
case 7:
|
|
2545
|
+
_context39.prev = 7;
|
|
2546
|
+
_context39.t0 = _context39["catch"](0);
|
|
2547
|
+
console.warn('[RegisterAndLogin] 后台更新国家数据失败:', _context39.t0);
|
|
2548
|
+
case 10:
|
|
2549
|
+
case "end":
|
|
2550
|
+
return _context39.stop();
|
|
2551
|
+
}
|
|
2552
|
+
}, _callee39, this, [[0, 7]]);
|
|
2553
|
+
}));
|
|
2554
|
+
function updateCountriesCache(_x34, _x35) {
|
|
2555
|
+
return _updateCountriesCache.apply(this, arguments);
|
|
2556
|
+
}
|
|
2557
|
+
return updateCountriesCache;
|
|
2463
2558
|
}())
|
|
2464
2559
|
}, {
|
|
2465
2560
|
key: "destroy",
|
|
2466
2561
|
value: function () {
|
|
2467
|
-
var _destroy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2468
|
-
return _regeneratorRuntime().wrap(function
|
|
2469
|
-
while (1) switch (
|
|
2562
|
+
var _destroy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40() {
|
|
2563
|
+
return _regeneratorRuntime().wrap(function _callee40$(_context40) {
|
|
2564
|
+
while (1) switch (_context40.prev = _context40.next) {
|
|
2470
2565
|
case 0:
|
|
2471
|
-
|
|
2566
|
+
_context40.next = 2;
|
|
2472
2567
|
return this.core.effects.emit(RegisterAndLoginHooks.onDestroy, {});
|
|
2473
2568
|
case 2:
|
|
2474
2569
|
console.log('[RegisterAndLogin] 已销毁');
|
|
2475
2570
|
case 3:
|
|
2476
2571
|
case "end":
|
|
2477
|
-
return
|
|
2572
|
+
return _context40.stop();
|
|
2478
2573
|
}
|
|
2479
|
-
},
|
|
2574
|
+
}, _callee40, this);
|
|
2480
2575
|
}));
|
|
2481
2576
|
function destroy() {
|
|
2482
2577
|
return _destroy.apply(this, arguments);
|
|
@@ -561,12 +561,13 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
561
561
|
return n.id === (((_discount$discount = discount.discount) === null || _discount$discount === void 0 ? void 0 : _discount$discount.resource_id) || discount.id);
|
|
562
562
|
});
|
|
563
563
|
if (index !== -1) {
|
|
564
|
+
var _discount$metadata;
|
|
564
565
|
editModeDiscountList[index] = _objectSpread(_objectSpread({}, editModeDiscountList[index]), {}, {
|
|
565
566
|
amount: new Decimal(discount.amount || 0).plus(new Decimal(editModeDiscountList[index].amount || 0)).toNumber(),
|
|
566
|
-
savedAmount: new Decimal(discount.amount || 0).times((product === null || product === void 0 ? void 0 : product.num) || 1).plus(new Decimal(editModeDiscountList[index].savedAmount || 0)).toNumber()
|
|
567
|
+
savedAmount: new Decimal(discount.amount || 0).times((discount === null || discount === void 0 || (_discount$metadata = discount.metadata) === null || _discount$metadata === void 0 ? void 0 : _discount$metadata.num) || (product === null || product === void 0 ? void 0 : product.num) || 1).plus(new Decimal(editModeDiscountList[index].savedAmount || 0)).toNumber()
|
|
567
568
|
});
|
|
568
569
|
} else {
|
|
569
|
-
var _discount$discount2, _discount$discount3, _discount$discount4;
|
|
570
|
+
var _discount$metadata2, _discount$discount2, _discount$discount3, _discount$discount4;
|
|
570
571
|
if (discount.type && !discount.tag) {
|
|
571
572
|
discount.tag = discount.type;
|
|
572
573
|
}
|
|
@@ -574,7 +575,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
574
575
|
name: discount.name || discount.discount.title.auto,
|
|
575
576
|
isEditMode: true,
|
|
576
577
|
limited_relation_product_data: {},
|
|
577
|
-
savedAmount: discount.amount * ((product === null || product === void 0 ? void 0 : product.num) || 1),
|
|
578
|
+
savedAmount: discount.amount * ((discount === null || discount === void 0 || (_discount$metadata2 = discount.metadata) === null || _discount$metadata2 === void 0 ? void 0 : _discount$metadata2.num) || (product === null || product === void 0 ? void 0 : product.num) || 1),
|
|
578
579
|
isAvailable: true,
|
|
579
580
|
id: ((_discount$discount2 = discount.discount) === null || _discount$discount2 === void 0 ? void 0 : _discount$discount2.resource_id) || discount.id,
|
|
580
581
|
format_title: ((_discount$discount3 = discount.discount) === null || _discount$discount3 === void 0 ? void 0 : _discount$discount3.title) || discount.format_title,
|
|
@@ -595,6 +596,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
595
596
|
var targetProduct = productList.find(function (n) {
|
|
596
597
|
return n.id === id;
|
|
597
598
|
});
|
|
599
|
+
if (!targetProduct) return false;
|
|
598
600
|
var product = (_this3$hooks2 = _this3.hooks) === null || _this3$hooks2 === void 0 ? void 0 : _this3$hooks2.getProduct(targetProduct);
|
|
599
601
|
// 如果 product.total 是小于等于0有可能是她已经用过商品券或者折扣卡导致的,或者本身就是负数价格,所以此时还需要判断 origin_total 是否小于等于0
|
|
600
602
|
// 如果 product.vouchersApplicable是布尔值,并且是 false,也当做免费商品处理,此商品不可用优惠券或折扣卡
|
|
@@ -602,10 +604,10 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
602
604
|
};
|
|
603
605
|
var allUsedProductIds = newDiscountList.map(function (n) {
|
|
604
606
|
var _n$appliedProductDeta;
|
|
605
|
-
return n.isSelected ? (_n$appliedProductDeta = n.appliedProductDetails) === null || _n$appliedProductDeta === void 0 ? void 0 : _n$appliedProductDeta.map(function (n) {
|
|
607
|
+
return n.isSelected ? ((_n$appliedProductDeta = n.appliedProductDetails) === null || _n$appliedProductDeta === void 0 ? void 0 : _n$appliedProductDeta.map(function (n) {
|
|
606
608
|
var _n$discount;
|
|
607
609
|
return (_n$discount = n.discount) === null || _n$discount === void 0 ? void 0 : _n$discount.product_id;
|
|
608
|
-
}) : [];
|
|
610
|
+
})) || n.product_id : [];
|
|
609
611
|
}).flat();
|
|
610
612
|
newDiscountList.forEach(function (item) {
|
|
611
613
|
var _item$applicableProdu;
|
|
@@ -12,6 +12,13 @@ export declare const isAllNormalProduct: (items: any[]) => boolean;
|
|
|
12
12
|
* @returns
|
|
13
13
|
*/
|
|
14
14
|
export declare const getDiscountAmount: (discount: Discount, total: number, price: number) => number;
|
|
15
|
+
export declare const getDiscountListAmountTotal: (discount: Discount[]) => any;
|
|
16
|
+
/**
|
|
17
|
+
* 获取折扣金额 计算每个折扣的金额
|
|
18
|
+
* @param discount
|
|
19
|
+
* @returns
|
|
20
|
+
*/
|
|
21
|
+
export declare const getDiscountListAmount: (discount: Discount[]) => any;
|
|
15
22
|
export interface ScheduleItem {
|
|
16
23
|
id: number;
|
|
17
24
|
name: string | {
|
|
@@ -37,7 +37,7 @@ export var getDiscountAmount = function getDiscountAmount(discount, total, price
|
|
|
37
37
|
var _discount$metadata;
|
|
38
38
|
// 商品券
|
|
39
39
|
if (discount.tag === 'good_pass') {
|
|
40
|
-
return new Decimal(
|
|
40
|
+
return new Decimal(price).minus(new Decimal(price || 0)).toNumber();
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
// 判断是否是固定金额
|
|
@@ -45,11 +45,27 @@ export var getDiscountAmount = function getDiscountAmount(discount, total, price
|
|
|
45
45
|
|
|
46
46
|
// 固定金额 小于0时返回0
|
|
47
47
|
if (isFixedAmount) {
|
|
48
|
-
return Math.max(new Decimal(
|
|
48
|
+
return Math.max(new Decimal(price).minus(new Decimal(discount.par_value || 0)).toNumber(), 0);
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
// 百分比:根据折扣卡金额计算
|
|
52
|
-
return new Decimal(100).minus(discount.par_value || 0).div(100).mul(new Decimal(
|
|
52
|
+
return new Decimal(100).minus(discount.par_value || 0).div(100).mul(new Decimal(price)).toNumber();
|
|
53
|
+
};
|
|
54
|
+
export var getDiscountListAmountTotal = function getDiscountListAmountTotal(discount) {
|
|
55
|
+
return discount.reduce(function (acc, cur) {
|
|
56
|
+
return new Decimal(acc).plus(new Decimal(cur.num || 1).mul(new Decimal(cur.amount || 0))).toNumber();
|
|
57
|
+
}, new Decimal(0));
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* 获取折扣金额 计算每个折扣的金额
|
|
62
|
+
* @param discount
|
|
63
|
+
* @returns
|
|
64
|
+
*/
|
|
65
|
+
export var getDiscountListAmount = function getDiscountListAmount(discount) {
|
|
66
|
+
return discount.reduce(function (acc, cur) {
|
|
67
|
+
return new Decimal(acc).plus(new Decimal(cur.amount || 0)).toNumber();
|
|
68
|
+
}, new Decimal(0));
|
|
53
69
|
};
|
|
54
70
|
|
|
55
71
|
// 日程项接口定义
|
|
@@ -172,16 +172,6 @@ var formatProductToCartItemOrigin = (params) => {
|
|
|
172
172
|
var getProductTotalPrice = (params) => {
|
|
173
173
|
const { product, bundle, options, discounts } = params;
|
|
174
174
|
let price = Number(product.price);
|
|
175
|
-
if (bundle == null ? void 0 : bundle.length) {
|
|
176
|
-
price = bundle.reduce((accumulator, currentValue) => {
|
|
177
|
-
return accumulator + Number(currentValue.price) * Number(currentValue.num);
|
|
178
|
-
}, price);
|
|
179
|
-
}
|
|
180
|
-
if (options == null ? void 0 : options.length) {
|
|
181
|
-
price = options.reduce((accumulator, currentValue) => {
|
|
182
|
-
return accumulator + Number(currentValue.price) * Number(currentValue.num);
|
|
183
|
-
}, price);
|
|
184
|
-
}
|
|
185
175
|
if (discounts == null ? void 0 : discounts.length) {
|
|
186
176
|
discounts.forEach((currentValue) => {
|
|
187
177
|
var _a;
|
|
@@ -196,6 +186,16 @@ var getProductTotalPrice = (params) => {
|
|
|
196
186
|
}
|
|
197
187
|
});
|
|
198
188
|
}
|
|
189
|
+
if (bundle == null ? void 0 : bundle.length) {
|
|
190
|
+
price = bundle.reduce((accumulator, currentValue) => {
|
|
191
|
+
return accumulator + Number(currentValue.price) * Number(currentValue.num);
|
|
192
|
+
}, price);
|
|
193
|
+
}
|
|
194
|
+
if (options == null ? void 0 : options.length) {
|
|
195
|
+
price = options.reduce((accumulator, currentValue) => {
|
|
196
|
+
return accumulator + Number(currentValue.price) * Number(currentValue.num);
|
|
197
|
+
}, price);
|
|
198
|
+
}
|
|
199
199
|
return price;
|
|
200
200
|
};
|
|
201
201
|
var getProductOriginTotalPrice = (params) => {
|
|
@@ -254,9 +254,15 @@ var formatBundle = (bundle) => {
|
|
|
254
254
|
price: item == null ? void 0 : item.price,
|
|
255
255
|
total: item == null ? void 0 : item.price,
|
|
256
256
|
price_type: item == null ? void 0 : item.price_type,
|
|
257
|
+
original_price: item == null ? void 0 : item.original_price,
|
|
258
|
+
original_total: item == null ? void 0 : item.original_total,
|
|
259
|
+
price_type_ext: item == null ? void 0 : item.price_type_ext,
|
|
257
260
|
bundle_sum_price: item == null ? void 0 : item.bundle_sum_price,
|
|
258
261
|
bundle_sum_type: item == null ? void 0 : item.bundle_sum_type,
|
|
259
|
-
options: formatOptions(item == null ? void 0 : item.option)
|
|
262
|
+
options: formatOptions(item == null ? void 0 : item.option),
|
|
263
|
+
_bundle_product_id: item._bundle_product_id,
|
|
264
|
+
discount_list: item.discount_list,
|
|
265
|
+
originBundleItem: item
|
|
260
266
|
};
|
|
261
267
|
});
|
|
262
268
|
};
|
|
@@ -264,15 +270,24 @@ var formatBundleToOrigin = (bundle) => {
|
|
|
264
270
|
if (!(bundle == null ? void 0 : bundle.length))
|
|
265
271
|
return [];
|
|
266
272
|
return bundle.map((d) => {
|
|
273
|
+
const getBundleValueByKey = (key) => {
|
|
274
|
+
var _a;
|
|
275
|
+
return (d == null ? void 0 : d[key]) || ((_a = d == null ? void 0 : d.originBundleItem) == null ? void 0 : _a[key]);
|
|
276
|
+
};
|
|
267
277
|
return {
|
|
268
|
-
bundle_group_id:
|
|
278
|
+
bundle_group_id: getBundleValueByKey("group_id"),
|
|
269
279
|
bundle_id: d.id,
|
|
270
|
-
bundle_product_id: (
|
|
271
|
-
bundle_variant_id:
|
|
280
|
+
bundle_product_id: getBundleValueByKey("_bundle_product_id") || getBundleValueByKey("product_id"),
|
|
281
|
+
bundle_variant_id: getBundleValueByKey("bundle_variant_id"),
|
|
272
282
|
num: d.num,
|
|
273
|
-
extension_id:
|
|
274
|
-
extension_type:
|
|
275
|
-
option: formatOptionsToOrigin(
|
|
283
|
+
extension_id: getBundleValueByKey("extension_id"),
|
|
284
|
+
extension_type: getBundleValueByKey("extension_type"),
|
|
285
|
+
option: formatOptionsToOrigin(getBundleValueByKey("option")),
|
|
286
|
+
discount_list: d.discount_list,
|
|
287
|
+
"bundle_selling_price": d == null ? void 0 : d.price,
|
|
288
|
+
metadata: {
|
|
289
|
+
custom_product_bundle_map_id: d._id
|
|
290
|
+
}
|
|
276
291
|
};
|
|
277
292
|
});
|
|
278
293
|
};
|
|
@@ -15,11 +15,19 @@ interface Formattitle {
|
|
|
15
15
|
'zh-CN'?: any;
|
|
16
16
|
'zh-HK'?: any;
|
|
17
17
|
}
|
|
18
|
+
interface PackageSubItemUsageRules {
|
|
19
|
+
type: 'universal_discount' | 'package_exclusive' | 'single_item_promo' | 'custom_usage_rules';
|
|
20
|
+
custom_usage_rules: {
|
|
21
|
+
types: ("standalone_product" | "package_sub_item")[];
|
|
22
|
+
package_sub_item_rules: ("original_price" | "markup_price")[];
|
|
23
|
+
};
|
|
24
|
+
}
|
|
18
25
|
interface Limitedrelationproductdata {
|
|
19
26
|
id: number;
|
|
20
27
|
type: 'product_all' | 'products' | 'product_collection';
|
|
21
28
|
product_ids: number[];
|
|
22
29
|
product_collection_id: number[];
|
|
30
|
+
package_sub_item_usage_rules?: PackageSubItemUsageRules;
|
|
23
31
|
}
|
|
24
32
|
interface ApplicableProductDetails {
|
|
25
33
|
amount: string;
|
|
@@ -73,6 +81,7 @@ export interface Discount {
|
|
|
73
81
|
metadata?: {
|
|
74
82
|
discount_card_type?: 'fixed_amount' | 'percent';
|
|
75
83
|
validity_type?: "custom_schedule_validity" | "fixed_validity";
|
|
84
|
+
custom_product_bundle_map_id?: string;
|
|
76
85
|
};
|
|
77
86
|
product: Product;
|
|
78
87
|
type: "product" | 'good_pass';
|
|
@@ -102,6 +111,7 @@ export interface Discount {
|
|
|
102
111
|
custom_schedule_snapshot?: {
|
|
103
112
|
data: any[];
|
|
104
113
|
};
|
|
114
|
+
num?: number;
|
|
105
115
|
}
|
|
106
116
|
export interface DiscountState {
|
|
107
117
|
discountList: Discount[];
|
|
@@ -116,6 +116,8 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
116
116
|
item._origin.duration = duration;
|
|
117
117
|
item._origin.sub_type = durationType;
|
|
118
118
|
}
|
|
119
|
+
const discountList = (0, import_utils.getAllDiscountList)(item);
|
|
120
|
+
item._origin.product.discount_list = discountList;
|
|
119
121
|
if ((0, import_utils2.isNormalProduct)(item._origin)) {
|
|
120
122
|
order.relation_products.push(item._origin.product);
|
|
121
123
|
const relationForms = item._origin.relation_forms || [];
|
|
@@ -30,6 +30,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
var utils_exports = {};
|
|
31
31
|
__export(utils_exports, {
|
|
32
32
|
generateDuration: () => generateDuration,
|
|
33
|
+
getAllDiscountList: () => getAllDiscountList,
|
|
33
34
|
mergeRelationForms: () => mergeRelationForms
|
|
34
35
|
});
|
|
35
36
|
module.exports = __toCommonJS(utils_exports);
|
|
@@ -55,8 +56,18 @@ var mergeRelationForms = (relationForms) => {
|
|
|
55
56
|
}, {})
|
|
56
57
|
).filter((item) => item.form_record_ids.length > 0);
|
|
57
58
|
};
|
|
59
|
+
var getAllDiscountList = (cartItem) => {
|
|
60
|
+
var _a, _b, _c, _d;
|
|
61
|
+
let discountList = ((_b = (_a = cartItem == null ? void 0 : cartItem._origin) == null ? void 0 : _a.product) == null ? void 0 : _b.discount_list) || [];
|
|
62
|
+
(((_d = (_c = cartItem == null ? void 0 : cartItem._origin) == null ? void 0 : _c.product) == null ? void 0 : _d.product_bundle) || []).forEach((item) => {
|
|
63
|
+
discountList = [...discountList, ...item.discount_list];
|
|
64
|
+
item.discount_list = void 0;
|
|
65
|
+
});
|
|
66
|
+
return discountList;
|
|
67
|
+
};
|
|
58
68
|
// Annotate the CommonJS export names for ESM import in node:
|
|
59
69
|
0 && (module.exports = {
|
|
60
70
|
generateDuration,
|
|
71
|
+
getAllDiscountList,
|
|
61
72
|
mergeRelationForms
|
|
62
73
|
});
|
|
@@ -30,6 +30,13 @@ export declare class RulesModule extends BaseModule implements Module, RulesModu
|
|
|
30
30
|
selectedList?: SetDiscountSelectedParams[];
|
|
31
31
|
scan?: boolean;
|
|
32
32
|
}): DiscountResult;
|
|
33
|
+
/**
|
|
34
|
+
* 检查优惠是否符合 PackageSubItemUsageRules 配置
|
|
35
|
+
* @param discount 优惠券
|
|
36
|
+
* @param flatItem 扁平化后的商品项(可能是主商品或bundle子商品)
|
|
37
|
+
* @returns 是否可用
|
|
38
|
+
*/
|
|
39
|
+
private checkPackageSubItemUsageRules;
|
|
33
40
|
destroy(): Promise<void>;
|
|
34
41
|
clear(): Promise<void>;
|
|
35
42
|
}
|