@pisell/pisellos 2.3.74 → 2.3.75

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.
Files changed (276) hide show
  1. package/dist/core/index.js +6 -10
  2. package/dist/model/strategy/adapter/promotion/index.js +9 -0
  3. package/dist/model/strategy/adapter/walletPass/example.js +3 -26
  4. package/dist/model/strategy/strategy-example.js +5 -19
  5. package/dist/modules/Cart/index.js +0 -3
  6. package/dist/modules/Cart/utils/cartProduct.js +0 -1
  7. package/dist/modules/Date/index.js +1 -5
  8. package/dist/modules/Discount/index.js +2 -4
  9. package/dist/modules/OpenData/index.js +0 -2
  10. package/dist/modules/Order/index.js +36 -64
  11. package/dist/modules/Payment/index.js +97 -162
  12. package/dist/modules/Rules/index.js +1 -4
  13. package/dist/modules/Schedule/index.js +0 -1
  14. package/dist/modules/Schedule/utils.js +0 -1
  15. package/dist/modules/Step/index.js +0 -1
  16. package/dist/plugins/request.js +1 -4
  17. package/dist/plugins/window.js +2 -6
  18. package/dist/server/index.js +97 -129
  19. package/dist/server/modules/menu/index.js +32 -41
  20. package/dist/server/modules/order/index.js +2 -4
  21. package/dist/server/modules/products/index.js +24 -42
  22. package/dist/server/modules/quotation/index.js +29 -38
  23. package/dist/server/modules/resource/index.js +3 -4
  24. package/dist/server/modules/schedule/index.js +27 -35
  25. package/dist/server/utils/product.js +0 -1
  26. package/dist/solution/BaseSales/index.js +38 -41
  27. package/dist/solution/BookingByStep/index.js +7 -59
  28. package/dist/solution/BookingByStep/utils/capacity.js +1 -11
  29. package/dist/solution/BookingByStep/utils/resources.js +1 -3
  30. package/dist/solution/BookingByStep/utils/timeslots.js +2 -43
  31. package/dist/solution/BookingTicket/index.js +0 -2
  32. package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +6 -7
  33. package/dist/solution/BookingTicket/utils/scan/handleScan.js +25 -31
  34. package/dist/solution/BookingTicket/utils/scan/index.js +6 -10
  35. package/dist/solution/BuyTickets/index.js +9 -12
  36. package/dist/solution/Checkout/index.js +177 -252
  37. package/dist/solution/Checkout/utils/index.js +4 -16
  38. package/dist/solution/RegisterAndLogin/index.js +30 -76
  39. package/dist/solution/ScanOrder/index.js +50 -60
  40. package/dist/solution/ShopDiscount/index.js +2 -7
  41. package/dist/solution/VenueBooking/index.js +45 -55
  42. package/dist/utils/task.js +15 -18
  43. package/dist/utils/watch.js +0 -1
  44. package/lib/apis/picoding.js +2 -0
  45. package/lib/core/index.js +134 -134
  46. package/lib/effects/index.js +46 -57
  47. package/lib/index.js +82 -49
  48. package/lib/model/index.js +14 -21
  49. package/lib/model/strategy/adapter/dataVariant/adapter.js +38 -50
  50. package/lib/model/strategy/adapter/dataVariant/evaluator.js +162 -236
  51. package/lib/model/strategy/adapter/dataVariant/examples.js +229 -237
  52. package/lib/model/strategy/adapter/dataVariant/index.js +39 -34
  53. package/lib/model/strategy/adapter/dataVariant/type.js +57 -28
  54. package/lib/model/strategy/adapter/index.js +100 -64
  55. package/lib/model/strategy/adapter/itemRule/adapter.js +156 -144
  56. package/lib/model/strategy/adapter/itemRule/evaluator.js +36 -48
  57. package/lib/model/strategy/adapter/itemRule/examples.js +295 -225
  58. package/lib/model/strategy/adapter/itemRule/index.js +83 -57
  59. package/lib/model/strategy/adapter/itemRule/type.js +97 -36
  60. package/lib/model/strategy/adapter/promotion/adapter.js +91 -69
  61. package/lib/model/strategy/adapter/promotion/evaluator.js +444 -310
  62. package/lib/model/strategy/adapter/promotion/examples.js +222 -234
  63. package/lib/model/strategy/adapter/promotion/index.js +1 -0
  64. package/lib/model/strategy/adapter/promotion/type.js +243 -36
  65. package/lib/model/strategy/adapter/type.js +4 -16
  66. package/lib/model/strategy/adapter/walletPass/evaluator.js +180 -150
  67. package/lib/model/strategy/adapter/walletPass/example.js +217 -190
  68. package/lib/model/strategy/adapter/walletPass/index.js +75 -51
  69. package/lib/model/strategy/adapter/walletPass/locales.js +36 -58
  70. package/lib/model/strategy/adapter/walletPass/type.js +4 -16
  71. package/lib/model/strategy/adapter/walletPass/utils.js +588 -378
  72. package/lib/model/strategy/engine.js +270 -168
  73. package/lib/model/strategy/index.js +49 -34
  74. package/lib/model/strategy/strategy-example.js +243 -239
  75. package/lib/model/strategy/type.js +100 -40
  76. package/lib/modules/Account/index.js +39 -53
  77. package/lib/modules/Account/types.js +20 -33
  78. package/lib/modules/AccountList/index.js +116 -154
  79. package/lib/modules/AccountList/types.js +30 -31
  80. package/lib/modules/AccountList/utils.js +18 -30
  81. package/lib/modules/BaseModule.js +23 -42
  82. package/lib/modules/BookingContext/index.js +158 -136
  83. package/lib/modules/BookingContext/types.js +46 -32
  84. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +138 -146
  85. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +78 -83
  86. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +170 -150
  87. package/lib/modules/BookingContext/utils/flexible.js +38 -55
  88. package/lib/modules/BookingContext/utils/formatResourceList.js +19 -34
  89. package/lib/modules/BookingContext/utils/index.js +124 -41
  90. package/lib/modules/BookingContext/utils/noResource.js +58 -70
  91. package/lib/modules/BookingContext/utils/orderLineDisplay.js +14 -41
  92. package/lib/modules/BookingContext/utils/productExtend.js +202 -155
  93. package/lib/modules/BookingContext/utils/resourceErrors.js +53 -53
  94. package/lib/modules/BookingContext/utils/resourceSelection.js +19 -41
  95. package/lib/modules/BookingContext/utils/resources.js +209 -167
  96. package/lib/modules/BookingContext/utils/serviceTimes.js +115 -116
  97. package/lib/modules/BookingContext/utils/timeSlices.js +76 -86
  98. package/lib/modules/Cart/index.js +170 -124
  99. package/lib/modules/Cart/types.js +46 -51
  100. package/lib/modules/Cart/utils/cartAccount.js +40 -39
  101. package/lib/modules/Cart/utils/cartDate.js +56 -61
  102. package/lib/modules/Cart/utils/cartDiscount.js +28 -33
  103. package/lib/modules/Cart/utils/cartNote.js +27 -32
  104. package/lib/modules/Cart/utils/cartProduct.js +321 -251
  105. package/lib/modules/Cart/utils/cartRelationForms.js +29 -35
  106. package/lib/modules/Cart/utils/cartResource.js +70 -78
  107. package/lib/modules/Cart/utils/changePrice.js +22 -50
  108. package/lib/modules/Cart/utils/index.js +106 -48
  109. package/lib/modules/Customer/constants.js +13 -34
  110. package/lib/modules/Customer/index.js +235 -172
  111. package/lib/modules/Customer/types.js +38 -35
  112. package/lib/modules/Date/index.js +116 -115
  113. package/lib/modules/Date/types.js +16 -28
  114. package/lib/modules/Date/utils.js +174 -123
  115. package/lib/modules/Discount/index.js +122 -127
  116. package/lib/modules/Discount/types.js +9 -31
  117. package/lib/modules/Guests/index.js +30 -56
  118. package/lib/modules/Guests/types.js +23 -33
  119. package/lib/modules/Holder/index.js +209 -189
  120. package/lib/modules/Holder/types.js +4 -16
  121. package/lib/modules/Holder/utils.js +20 -49
  122. package/lib/modules/OpenData/index.js +70 -76
  123. package/lib/modules/OpenData/types.js +4 -16
  124. package/lib/modules/OpenData/utils.js +44 -78
  125. package/lib/modules/Order/index.js +1713 -2118
  126. package/lib/modules/Order/payment-utils.js +77 -120
  127. package/lib/modules/Order/types.js +88 -35
  128. package/lib/modules/Order/utils/bundleDiscountHydration.js +41 -74
  129. package/lib/modules/Order/utils/discountProductLineIdentity.js +142 -100
  130. package/lib/modules/Order/utils/manualProductDiscount.js +124 -123
  131. package/lib/modules/Order/utils/orderCollectionIdentity.js +184 -244
  132. package/lib/modules/Order/utils.js +814 -647
  133. package/lib/modules/Payment/cash.js +20 -33
  134. package/lib/modules/Payment/cashRecommendationAlgorithm.js +145 -76
  135. package/lib/modules/Payment/eftpos.js +16 -30
  136. package/lib/modules/Payment/index.js +532 -399
  137. package/lib/modules/Payment/mx51.js +1 -0
  138. package/lib/modules/Payment/types.js +230 -108
  139. package/lib/modules/Payment/utils.js +52 -51
  140. package/lib/modules/Payment/walletpass.js +485 -660
  141. package/lib/modules/Product/index.js +51 -46
  142. package/lib/modules/Product/types.js +4 -16
  143. package/lib/modules/Product/utils.js +32 -33
  144. package/lib/modules/ProductList/index.js +113 -123
  145. package/lib/modules/ProductList/types.js +9 -31
  146. package/lib/modules/Quotation/index.js +81 -118
  147. package/lib/modules/Quotation/types.js +4 -16
  148. package/lib/modules/Resource/index.js +27 -59
  149. package/lib/modules/Resource/types.js +22 -32
  150. package/lib/modules/Resource/utils.js +30 -38
  151. package/lib/modules/ResourcePlanner/index.js +25 -23
  152. package/lib/modules/ResourcePlanner/localClock.js +54 -119
  153. package/lib/modules/ResourcePlanner/planner.js +589 -770
  154. package/lib/modules/ResourcePlanner/types.js +10 -29
  155. package/lib/modules/Rules/index.js +1218 -959
  156. package/lib/modules/Rules/types.js +17 -40
  157. package/lib/modules/SalesSummary/index.js +85 -90
  158. package/lib/modules/SalesSummary/types.js +4 -16
  159. package/lib/modules/SalesSummary/utils.js +355 -430
  160. package/lib/modules/ScanOrderLogger/index.js +59 -79
  161. package/lib/modules/ScanOrderLogger/providers/feishu.js +54 -78
  162. package/lib/modules/ScanOrderLogger/providers/grafana.js +13 -36
  163. package/lib/modules/ScanOrderLogger/types.js +4 -16
  164. package/lib/modules/Schedule/getDateIsInSchedule.js +334 -163
  165. package/lib/modules/Schedule/index.js +100 -114
  166. package/lib/modules/Schedule/type.js +4 -16
  167. package/lib/modules/Schedule/types.js +4 -16
  168. package/lib/modules/Schedule/utils.js +433 -291
  169. package/lib/modules/Step/index.js +40 -52
  170. package/lib/modules/Step/tyeps.js +4 -16
  171. package/lib/modules/Summary/index.js +66 -71
  172. package/lib/modules/Summary/types.js +4 -16
  173. package/lib/modules/Summary/utils.js +773 -418
  174. package/lib/modules/SurchargeList/index.js +46 -60
  175. package/lib/modules/SurchargeList/types.js +4 -16
  176. package/lib/modules/index.js +245 -63
  177. package/lib/plugins/app.js +4 -16
  178. package/lib/plugins/index.js +36 -25
  179. package/lib/plugins/request.js +137 -126
  180. package/lib/plugins/shopStore.js +4 -16
  181. package/lib/plugins/user.js +4 -16
  182. package/lib/plugins/window.js +171 -179
  183. package/lib/server/index.js +3050 -2665
  184. package/lib/server/modules/floor-plan/index.js +118 -134
  185. package/lib/server/modules/floor-plan/types.js +15 -30
  186. package/lib/server/modules/index.js +106 -68
  187. package/lib/server/modules/menu/index.js +142 -122
  188. package/lib/server/modules/menu/types.js +18 -31
  189. package/lib/server/modules/order/index.js +784 -1002
  190. package/lib/server/modules/order/types.js +122 -33
  191. package/lib/server/modules/order/utils/filterBookings.js +219 -194
  192. package/lib/server/modules/order/utils/filterOrders.js +118 -92
  193. package/lib/server/modules/payment/index.js +59 -83
  194. package/lib/server/modules/payment/types.js +4 -16
  195. package/lib/server/modules/products/index.js +583 -471
  196. package/lib/server/modules/products/types.js +44 -34
  197. package/lib/server/modules/quotation/index.js +137 -172
  198. package/lib/server/modules/quotation/types.js +21 -31
  199. package/lib/server/modules/resource/index.js +220 -186
  200. package/lib/server/modules/resource/types.js +42 -33
  201. package/lib/server/modules/schedule/index.js +135 -123
  202. package/lib/server/modules/schedule/types.js +14 -21
  203. package/lib/server/modules/schedule/utils.js +334 -163
  204. package/lib/server/types.js +4 -16
  205. package/lib/server/utils/index.js +25 -23
  206. package/lib/server/utils/product.js +196 -139
  207. package/lib/server/utils/schedule.js +34 -41
  208. package/lib/server/utils/small-ticket.js +479 -456
  209. package/lib/server/utils/time.js +40 -49
  210. package/lib/solution/BaseSales/index.js +1186 -1410
  211. package/lib/solution/BaseSales/types.js +42 -38
  212. package/lib/solution/BaseSales/utils/cartPromotion.js +642 -498
  213. package/lib/solution/BaseSales/utils/parseSalesResponse.js +85 -105
  214. package/lib/solution/BaseSales/utils/quotationPrice.js +56 -114
  215. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +108 -145
  216. package/lib/solution/BaseSales/utils.js +158 -143
  217. package/lib/solution/BookingByStep/index.js +1527 -1340
  218. package/lib/solution/BookingByStep/types.js +40 -99
  219. package/lib/solution/BookingByStep/utils/capacity.js +192 -160
  220. package/lib/solution/BookingByStep/utils/products.js +42 -52
  221. package/lib/solution/BookingByStep/utils/resources.js +527 -330
  222. package/lib/solution/BookingByStep/utils/stock.js +65 -44
  223. package/lib/solution/BookingByStep/utils/timeslots.js +129 -131
  224. package/lib/solution/BookingTicket/index.js +607 -522
  225. package/lib/solution/BookingTicket/types.js +99 -77
  226. package/lib/solution/BookingTicket/utils/addProductDecision.js +226 -189
  227. package/lib/solution/BookingTicket/utils/addTimeAvailability.js +58 -89
  228. package/lib/solution/BookingTicket/utils/bookingStatus.js +107 -78
  229. package/lib/solution/BookingTicket/utils/cartView.js +114 -99
  230. package/lib/solution/BookingTicket/utils/exampleData.js +185 -0
  231. package/lib/solution/BookingTicket/utils/orderCustomer.js +18 -41
  232. package/lib/solution/BookingTicket/utils/resolveBestAddTimePlan.js +219 -86
  233. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +168 -116
  234. package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +79 -91
  235. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.js +54 -41
  236. package/lib/solution/BookingTicket/utils/scan/handleScan.js +84 -81
  237. package/lib/solution/BookingTicket/utils/scan/index.js +98 -104
  238. package/lib/solution/BookingTicket/utils/scan/scanCache.js +90 -43
  239. package/lib/solution/BookingTicket/utils/scan/scanProductValues.js +52 -64
  240. package/lib/solution/BookingTicket/utils/sessionCatalogStale.js +56 -58
  241. package/lib/solution/BookingTicket/utils/weighingProductSku.js +34 -48
  242. package/lib/solution/BuyTickets/index.js +67 -70
  243. package/lib/solution/BuyTickets/types.js +22 -38
  244. package/lib/solution/Checkout/index.js +1451 -1158
  245. package/lib/solution/Checkout/types.js +91 -61
  246. package/lib/solution/Checkout/utils/index.js +228 -156
  247. package/lib/solution/PlaceOrder/index.js +55 -0
  248. package/lib/solution/RegisterAndLogin/config.js +493 -460
  249. package/lib/solution/RegisterAndLogin/index.js +633 -630
  250. package/lib/solution/RegisterAndLogin/types.js +189 -76
  251. package/lib/solution/RegisterAndLogin/utils.js +183 -125
  252. package/lib/solution/Sales/index.js +328 -324
  253. package/lib/solution/Sales/types.js +27 -33
  254. package/lib/solution/ScanOrder/index.js +832 -864
  255. package/lib/solution/ScanOrder/types.js +33 -34
  256. package/lib/solution/ScanOrder/utils.js +409 -374
  257. package/lib/solution/ShopDiscount/index.js +226 -232
  258. package/lib/solution/ShopDiscount/types.js +15 -37
  259. package/lib/solution/ShopDiscount/utils.js +300 -172
  260. package/lib/solution/UnifiedBookingSales/index.js +1035 -1201
  261. package/lib/solution/UnifiedBookingSales/remoteOccupancyCache.js +99 -159
  262. package/lib/solution/UnifiedBookingSales/types.js +10 -32
  263. package/lib/solution/VenueBooking/index.js +811 -879
  264. package/lib/solution/VenueBooking/types.js +19 -39
  265. package/lib/solution/VenueBooking/utils/dateSummary.js +27 -56
  266. package/lib/solution/VenueBooking/utils/resource.js +31 -54
  267. package/lib/solution/VenueBooking/utils/slotMerge.js +94 -107
  268. package/lib/solution/VenueBooking/utils/timeSlot.js +132 -132
  269. package/lib/solution/VenueBooking/utils.js +130 -67
  270. package/lib/solution/index.js +124 -41
  271. package/lib/store/createStore.js +32 -29
  272. package/lib/types/index.js +4 -16
  273. package/lib/utils/payment-number.js +26 -46
  274. package/lib/utils/task.js +36 -36
  275. package/lib/utils/watch.js +81 -47
  276. package/package.json +2 -1
@@ -1,72 +1,40 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
1
+ "use strict";
28
2
 
29
- // src/modules/Cart/utils/cartProduct.ts
30
- var cartProduct_exports = {};
31
- __export(cartProduct_exports, {
32
- formatBundle: () => formatBundle,
33
- formatBundleToOrigin: () => formatBundleToOrigin,
34
- formatOptions: () => formatOptions,
35
- formatOptionsToOrigin: () => formatOptionsToOrigin,
36
- formatProductToCartItem: () => formatProductToCartItem,
37
- formatProductToCartItemOrigin: () => formatProductToCartItemOrigin,
38
- getProductDeposit: () => getProductDeposit,
39
- getProductOriginTotalPrice: () => getProductOriginTotalPrice,
40
- getProductTotalPrice: () => getProductTotalPrice,
41
- handleProductDeposit: () => handleProductDeposit,
42
- handleVariantProduct: () => handleVariantProduct
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
43
5
  });
44
- module.exports = __toCommonJS(cartProduct_exports);
45
- var import_decimal = __toESM(require("decimal.js"));
46
- var import_utils = require("../../Product/utils");
47
- var import_utils2 = require("../../../solution/ShopDiscount/utils");
48
- var import_utils3 = require("../../Summary/utils");
49
- var import_utils4 = require("../../Order/utils");
50
- var toDiscountPayload = (discountItem) => {
51
- var _a, _b;
52
- return {
53
- amount: discountItem.amount,
54
- tag: discountItem.type,
55
- par_value: (_a = discountItem.discount) == null ? void 0 : _a.percent,
56
- config: discountItem.config,
57
- metadata: {
58
- discount_card_type: (_b = discountItem == null ? void 0 : discountItem.discount) == null ? void 0 : _b.discount_card_type
59
- }
60
- };
61
- };
62
- var handleVariantProduct = (product) => {
63
- var _a;
64
- if (product == null ? void 0 : product.product_variant_id) {
65
- const targetVariant = (_a = product == null ? void 0 : product.variant) == null ? void 0 : _a.find(
66
- (n) => n.id === product.product_variant_id
67
- );
6
+ exports.handleVariantProduct = exports.handleProductDeposit = exports.getProductTotalPrice = exports.getProductOriginTotalPrice = exports.getProductDeposit = exports.formatProductToCartItemOrigin = exports.formatProductToCartItem = exports.formatOptionsToOrigin = exports.formatOptions = exports.formatBundleToOrigin = exports.formatBundle = void 0;
7
+ var _decimal = _interopRequireDefault(require("decimal.js"));
8
+ var _utils = require("../../Product/utils");
9
+ var _utils2 = require("../../../solution/ShopDiscount/utils");
10
+ var _utils3 = require("../../Summary/utils");
11
+ var _utils4 = require("../../Order/utils");
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+ /** Rules / ShopDiscount 一致的折扣入参,用于主价与 option 单价 */
14
+ const toDiscountPayload = discountItem => ({
15
+ amount: discountItem.amount,
16
+ tag: discountItem.type,
17
+ par_value: discountItem.discount?.percent,
18
+ config: discountItem.config,
19
+ metadata: {
20
+ discount_card_type: discountItem?.discount?.discount_card_type
21
+ }
22
+ });
23
+
24
+ /**
25
+ * @title 处理组合商品
26
+ * @description 组合商品需要直接修改 product 里的价格和 is_charge_tax
27
+ * @param product 商品
28
+ * @returns 处理后的商品
29
+ */
30
+ const handleVariantProduct = product => {
31
+ // 判断组合商品,然后直接修改 product 里的价格和 is_charge_tax
32
+ if (product?.product_variant_id) {
33
+ // 还需要判断 能从 variant 里找到对应的组合规格信息,才可以替换
34
+ const targetVariant = product?.variant?.find(n => n.id === product.product_variant_id);
68
35
  if (targetVariant) {
69
36
  product.price = targetVariant.price;
37
+ // 如果 original_price 为 0,就不改了
70
38
  if (Number(targetVariant.original_price) > 0) {
71
39
  product.original_price = targetVariant.original_price;
72
40
  }
@@ -75,9 +43,14 @@ var handleVariantProduct = (product) => {
75
43
  }
76
44
  return product;
77
45
  };
78
- var formatProductToCartItem = (params) => {
79
- var _a, _b, _c;
80
- console.log("formatProductToCartItem>>>>>>", params);
46
+
47
+ /**
48
+ * 格式化商品到购物车
49
+ * @param product 商品
50
+ * @returns 格式化后的商品
51
+ */
52
+ exports.handleVariantProduct = handleVariantProduct;
53
+ const formatProductToCartItem = params => {
81
54
  const {
82
55
  cartItem,
83
56
  product,
@@ -87,14 +60,25 @@ var formatProductToCartItem = (params) => {
87
60
  quantity = 1,
88
61
  discounts
89
62
  } = params;
90
- const num = quantity;
63
+ const num = quantity; // 当前按照单个商品加入购物车
64
+
91
65
  if (product) {
92
- cartItem.id = product == null ? void 0 : product.id;
93
- cartItem.name = product == null ? void 0 : product.title;
94
- cartItem.price = product == null ? void 0 : product.price;
66
+ cartItem.id = product?.id;
67
+ cartItem.name = product?.title;
68
+ cartItem.price = product?.price;
95
69
  cartItem.num = num;
96
- cartItem.total = getProductTotalPrice({ product, bundle, options, num, discounts });
97
- cartItem.totalDifference = getTotalDifference({ product, bundle, discounts });
70
+ cartItem.total = getProductTotalPrice({
71
+ product,
72
+ bundle,
73
+ options,
74
+ num,
75
+ discounts
76
+ });
77
+ cartItem.totalDifference = getTotalDifference({
78
+ product,
79
+ bundle,
80
+ discounts
81
+ });
98
82
  cartItem.summaryTotal = cartItem.total * (num || 1);
99
83
  cartItem.origin_total = getProductOriginTotalPrice({
100
84
  product,
@@ -103,6 +87,7 @@ var formatProductToCartItem = (params) => {
103
87
  num,
104
88
  discounts
105
89
  });
90
+ // 不包含折扣卡商品券的总价
106
91
  const origin_total = getProductTotalPrice({
107
92
  product: cartItem._productInit || cartItem._productOrigin,
108
93
  bundle,
@@ -111,44 +96,38 @@ var formatProductToCartItem = (params) => {
111
96
  discounts: []
112
97
  });
113
98
  cartItem.summaryOriginTotal = (origin_total || 0) * (num || 1);
114
- cartItem.image = product == null ? void 0 : product.cover;
115
- cartItem.like_status = "common";
116
- cartItem.duration = product == null ? void 0 : product.duration;
117
- cartItem.isNormalProduct = (0, import_utils.isNormalProduct)(product);
118
- cartItem.is_charge_tax = product == null ? void 0 : product.is_charge_tax;
99
+ cartItem.image = product?.cover;
100
+ cartItem.like_status = 'common';
101
+ cartItem.duration = product?.duration;
102
+ cartItem.isNormalProduct = (0, _utils.isNormalProduct)(product);
103
+ cartItem.is_charge_tax = product?.is_charge_tax;
119
104
  }
120
- if (bundle == null ? void 0 : bundle.length) {
105
+ if (bundle?.length) {
121
106
  cartItem.bundle = formatBundle(bundle);
122
107
  }
123
- if (options == null ? void 0 : options.length) {
108
+ if (options?.length) {
124
109
  cartItem.options = formatOptions(options);
125
110
  }
111
+ // 拼装出 product_option_string
126
112
  if (product_variant_id) {
127
- const sku_key = (_b = (_a = product == null ? void 0 : product.variant) == null ? void 0 : _a.find(
128
- (n) => n.id === product_variant_id
129
- )) == null ? void 0 : _b.sku_key;
113
+ const sku_key = product?.variant?.find(n => n.id === product_variant_id)?.sku_key;
130
114
  if (sku_key) {
131
- const sku_key_arr = sku_key.split("_");
115
+ const sku_key_arr = sku_key.split('_');
132
116
  const product_option_string = [];
133
- sku_key_arr.forEach((item) => {
134
- var _a2, _b2;
135
- const keyMap = item.split(":");
136
- const targetVariantGroup = (_a2 = product == null ? void 0 : product.variant_group) == null ? void 0 : _a2.find(
137
- (n) => String(n.position_id) === keyMap[0]
138
- );
139
- const targetVariantItem = (_b2 = targetVariantGroup == null ? void 0 : targetVariantGroup.variant_item) == null ? void 0 : _b2.find(
140
- (n) => String(n.position_id) === keyMap[1]
141
- );
117
+ sku_key_arr.forEach(item => {
118
+ const keyMap = item.split(':');
119
+ const targetVariantGroup = product?.variant_group?.find(n => String(n.position_id) === keyMap[0]);
120
+ const targetVariantItem = targetVariantGroup?.variant_item?.find(n => String(n.position_id) === keyMap[1]);
142
121
  if (targetVariantGroup && targetVariantItem) {
143
- product_option_string.push(
144
- `${targetVariantGroup.name}:${targetVariantItem.name}`
145
- );
122
+ product_option_string.push(`${targetVariantGroup.name}:${targetVariantItem.name}`);
146
123
  }
147
124
  });
148
- cartItem.product_option_string = product_option_string.join(", ");
125
+ cartItem.product_option_string = product_option_string.join(', ');
149
126
  }
150
127
  }
151
- if (((_c = product == null ? void 0 : product.custom_deposit_data) == null ? void 0 : _c.has_deposit) == 1) {
128
+
129
+ // 如果商品有定金规则,则计算定金
130
+ if (product?.custom_deposit_data?.has_deposit == 1) {
152
131
  cartItem.deposit = getProductDeposit({
153
132
  cartItem,
154
133
  product,
@@ -161,8 +140,8 @@ var formatProductToCartItem = (params) => {
161
140
  cartItem._origin = oringin;
162
141
  return cartItem;
163
142
  };
164
- var formatProductToCartItemOrigin = (params) => {
165
- var _a, _b, _c, _d, _e;
143
+ exports.formatProductToCartItem = formatProductToCartItem;
144
+ const formatProductToCartItemOrigin = params => {
166
145
  const {
167
146
  cartItem,
168
147
  product,
@@ -172,35 +151,38 @@ var formatProductToCartItemOrigin = (params) => {
172
151
  quantity = 1
173
152
  } = params;
174
153
  let origin = cartItem._origin;
175
- const product_discount_difference = (((_a = origin.product) == null ? void 0 : _a.discount_list) || []).filter((item) => {
176
- var _a2;
177
- return !((_a2 = item == null ? void 0 : item.metadata) == null ? void 0 : _a2.custom_product_bundle_map_id);
178
- }).reduce((pre, cur) => {
179
- var _a2;
180
- return pre + (((_a2 = cur == null ? void 0 : cur.metadata) == null ? void 0 : _a2.product_discount_difference) || 0);
154
+ const product_discount_difference = (origin.product?.discount_list || []).filter(item => !item?.metadata?.custom_product_bundle_map_id).reduce((pre, cur) => {
155
+ return pre + (cur?.metadata?.product_discount_difference || 0);
181
156
  }, 0);
182
157
  if (product) {
183
158
  origin.product = {
184
- ...origin.product || {},
159
+ ...(origin.product || {}),
185
160
  num: quantity,
186
161
  product_id: product.id,
187
162
  product_variant_id: product_variant_id || 0,
188
- product_bundle: ((_b = origin.product) == null ? void 0 : _b.product_bundle) || [],
189
- product_sku: ((_c = origin.product) == null ? void 0 : _c.product_sku) || { option: [] },
163
+ product_bundle: origin.product?.product_bundle || [],
164
+ product_sku: origin.product?.product_sku || {
165
+ option: []
166
+ },
190
167
  metadata: {
191
168
  product_discount_difference
192
169
  }
193
170
  };
194
- origin.sub_type = (_d = product == null ? void 0 : product.duration) == null ? void 0 : _d.type;
195
- origin.duration = (_e = product == null ? void 0 : product.duration) == null ? void 0 : _e.value;
196
- if (bundle == null ? void 0 : bundle.length) {
171
+ // 时长类型
172
+ origin.sub_type = product?.duration?.type;
173
+ // 时长
174
+ origin.duration = product?.duration?.value;
175
+ if (bundle?.length) {
197
176
  origin.product.product_bundle = formatBundleToOrigin(bundle);
198
177
  }
199
- if (options == null ? void 0 : options.length) {
178
+ if (options?.length) {
200
179
  origin.product.product_sku = {
201
- ...origin.product.product_sku || {},
202
- option: formatOptionsToOrigin(options).map((option) => {
203
- const next = { ...option, add_price: option.add_price ?? option.price };
180
+ ...(origin.product.product_sku || {}),
181
+ option: formatOptionsToOrigin(options).map(option => {
182
+ const next = {
183
+ ...option,
184
+ add_price: option.add_price ?? option.price
185
+ };
204
186
  delete next.price;
205
187
  return next;
206
188
  })
@@ -209,92 +191,133 @@ var formatProductToCartItemOrigin = (params) => {
209
191
  }
210
192
  return origin;
211
193
  };
212
- var getProductTotalPrice = (params) => {
213
- const { product, bundle, options, discounts } = params;
194
+
195
+ /**
196
+ * 获取商品总价
197
+ * @description 当前总价计算基于商品数量为1
198
+ * @param item 商品
199
+ * @returns 商品总价
200
+ */
201
+ exports.formatProductToCartItemOrigin = formatProductToCartItemOrigin;
202
+ const getProductTotalPrice = params => {
203
+ const {
204
+ product,
205
+ bundle,
206
+ options,
207
+ discounts
208
+ } = params;
209
+ // const num = params.num || 1;
214
210
  let price = Number(product.price);
215
- const optionRows = (options == null ? void 0 : options.map((currentValue) => ({
211
+
212
+ // option 行:unit 折后价在循环中与主商品使用同一套 getDiscountAmount(含 deductOptionPrice)
213
+ const optionRows = options?.map(currentValue => ({
216
214
  unit: Number(currentValue.price ?? currentValue.add_price ?? 0),
217
215
  num: Number(currentValue.num ?? currentValue.quantity ?? 1)
218
- }))) ?? [];
219
- if (discounts == null ? void 0 : discounts.length) {
220
- discounts.forEach((currentValue) => {
221
- var _a;
216
+ })) ?? [];
217
+
218
+ // 如果商品有折扣,则计算折扣
219
+ if (discounts?.length) {
220
+ discounts.forEach(currentValue => {
222
221
  const payload = toDiscountPayload(currentValue);
223
- price = (0, import_utils2.getDiscountAmount)(payload, price, price);
224
- if (((_a = currentValue == null ? void 0 : currentValue.config) == null ? void 0 : _a.deductOptionPrice) && optionRows.length) {
222
+ price = (0, _utils2.getDiscountAmount)(payload, price, price);
223
+ if (currentValue?.config?.deductOptionPrice && optionRows.length) {
225
224
  for (let i = 0; i < optionRows.length; i++) {
226
225
  const row = optionRows[i];
227
226
  optionRows[i] = {
228
227
  ...row,
229
- unit: (0, import_utils2.getDiscountAmount)(payload, row.unit, row.unit)
228
+ unit: (0, _utils2.getDiscountAmount)(payload, row.unit, row.unit)
230
229
  };
231
230
  }
232
231
  }
233
232
  });
234
233
  }
235
- if (bundle == null ? void 0 : bundle.length) {
234
+ if (bundle?.length) {
236
235
  price = bundle.reduce((accumulator, currentValue) => {
237
236
  return accumulator + Number(currentValue.price) * Number(currentValue.num);
238
237
  }, price);
239
238
  }
239
+
240
+ // 单规格 / 加购 option
240
241
  if (optionRows.length) {
241
- price = optionRows.reduce(
242
- (accumulator, row) => accumulator + row.unit * row.num,
243
- price
244
- );
242
+ price = optionRows.reduce((accumulator, row) => accumulator + row.unit * row.num, price);
245
243
  }
246
244
  return Math.max(0, price);
247
245
  };
248
- var getTotalDifference = (params) => {
249
- const { bundle, discounts } = params;
246
+ exports.getProductTotalPrice = getProductTotalPrice;
247
+ const getTotalDifference = params => {
248
+ const {
249
+ bundle,
250
+ discounts
251
+ } = params;
250
252
  const bundleDiscountList = [];
251
- if (bundle == null ? void 0 : bundle.length) {
252
- bundle.forEach((currentValue) => {
253
- bundleDiscountList.push(...(currentValue == null ? void 0 : currentValue.discount_list) || []);
253
+ if (bundle?.length) {
254
+ bundle.forEach(currentValue => {
255
+ bundleDiscountList.push(...(currentValue?.discount_list || []));
254
256
  });
255
257
  }
256
- const allDiscounts = [...discounts || [], ...bundleDiscountList];
257
- const productDiscountProductDiscountDifference = (0, import_utils3.calcDiscountListDifference)(allDiscounts);
258
+ const allDiscounts = [...(discounts || []), ...bundleDiscountList];
259
+ const productDiscountProductDiscountDifference = (0, _utils3.calcDiscountListDifference)(allDiscounts);
258
260
  return productDiscountProductDiscountDifference || 0;
259
261
  };
260
- var getProductOriginTotalPrice = (params) => {
261
- const { product, bundle, options, discounts } = params;
262
- const num = (params == null ? void 0 : params.num) || 1;
262
+
263
+ /**
264
+ * 获取商品原始总价
265
+ * @description 当前总价计算基于商品数量为1
266
+ * @param item 商品
267
+ * @returns 商品原始总价
268
+ */
269
+ const getProductOriginTotalPrice = params => {
270
+ const {
271
+ product,
272
+ bundle,
273
+ options,
274
+ discounts
275
+ } = params;
276
+ const num = params?.num || 1;
263
277
  let price = Number(product.original_price);
264
- if ((isNaN(price) || price === 0) && !(discounts == null ? void 0 : discounts.length)) {
265
- return void 0;
278
+ if ((isNaN(price) || price === 0) && !discounts?.length) {
279
+ return undefined;
266
280
  }
267
- if (bundle == null ? void 0 : bundle.length) {
281
+ if (bundle?.length) {
268
282
  price = bundle.reduce((accumulator, currentValue) => {
269
283
  return accumulator + Number(currentValue.price) * Number(currentValue.num);
270
284
  }, price);
271
285
  }
272
- if (options == null ? void 0 : options.length) {
286
+
287
+ // 单规格
288
+ if (options?.length) {
273
289
  price = options.reduce((accumulator, currentValue) => {
274
290
  return accumulator + Number(currentValue.price) * Number(currentValue.num);
275
291
  }, price);
276
292
  }
277
293
  return price;
278
294
  };
279
- var formatOptions = (options) => {
280
- if (!(options == null ? void 0 : options.length))
281
- return [];
282
- return options.map((item) => {
295
+
296
+ /**
297
+ * 格式化套餐规格信息
298
+ * @param options 套餐规格信息
299
+ * @returns 格式化后的套餐规格信息
300
+ */
301
+ exports.getProductOriginTotalPrice = getProductOriginTotalPrice;
302
+ const formatOptions = options => {
303
+ if (!options?.length) return [];
304
+ return options.map(item => {
283
305
  return {
284
- id: item == null ? void 0 : item.id,
285
- name: item == null ? void 0 : item.name,
286
- num: item == null ? void 0 : item.num,
287
- price: item == null ? void 0 : item.price,
288
- total: item == null ? void 0 : item.price,
289
- origin_total: item == null ? void 0 : item.original_price
306
+ id: item?.id,
307
+ name: item?.name,
308
+ num: item?.num,
309
+ price: item?.price,
310
+ total: item?.price,
311
+ origin_total: item?.original_price
290
312
  };
291
313
  });
292
314
  };
293
- var formatOptionsToOrigin = (options) => {
294
- if (!(options == null ? void 0 : options.length)) {
315
+ exports.formatOptions = formatOptions;
316
+ const formatOptionsToOrigin = options => {
317
+ if (!options?.length) {
295
318
  return [];
296
319
  }
297
- return options.map((d) => {
320
+ return options.map(d => {
298
321
  return {
299
322
  num: d.num,
300
323
  option_group_item_id: d.option_group_item_id,
@@ -302,63 +325,67 @@ var formatOptionsToOrigin = (options) => {
302
325
  };
303
326
  });
304
327
  };
305
- var formatBundle = (bundle) => {
306
- if (!(bundle == null ? void 0 : bundle.length))
307
- return [];
308
- return bundle.map((item) => {
328
+
329
+ /**
330
+ * 格式化商品套餐信息
331
+ * @param bundle 商品套餐信息
332
+ * @returns 格式化后的商品套餐信息
333
+ */
334
+ exports.formatOptionsToOrigin = formatOptionsToOrigin;
335
+ const formatBundle = bundle => {
336
+ if (!bundle?.length) return [];
337
+ return bundle.map(item => {
309
338
  return {
310
- id: item == null ? void 0 : item.id,
311
- title: item == null ? void 0 : item.title,
312
- num: item == null ? void 0 : item.num,
313
- price: item == null ? void 0 : item.price,
314
- total: item == null ? void 0 : item.price,
315
- price_type: item == null ? void 0 : item.price_type,
316
- original_price: item == null ? void 0 : item.original_price,
317
- original_total: item == null ? void 0 : item.original_total,
318
- price_type_ext: item == null ? void 0 : item.price_type_ext,
319
- bundle_sum_price: item == null ? void 0 : item.bundle_sum_price,
320
- bundle_sum_type: item == null ? void 0 : item.bundle_sum_type,
321
- options: formatOptions(item == null ? void 0 : item.option),
339
+ id: item?.id,
340
+ title: item?.title,
341
+ num: item?.num,
342
+ price: item?.price,
343
+ total: item?.price,
344
+ price_type: item?.price_type,
345
+ original_price: item?.original_price,
346
+ original_total: item?.original_total,
347
+ price_type_ext: item?.price_type_ext,
348
+ bundle_sum_price: item?.bundle_sum_price,
349
+ bundle_sum_type: item?.bundle_sum_type,
350
+ options: formatOptions(item?.option),
322
351
  _bundle_product_id: item._bundle_product_id,
323
352
  discount_list: item.discount_list,
324
353
  originBundleItem: item.originBundleItem || item,
325
- is_charge_tax: item == null ? void 0 : item.is_charge_tax
354
+ is_charge_tax: item?.is_charge_tax
326
355
  };
327
356
  });
328
357
  };
329
- var formatBundleToOrigin = (bundle) => {
330
- if (!(bundle == null ? void 0 : bundle.length))
331
- return [];
332
- return bundle.map((d) => {
333
- const getBundleValueByKey = (key) => {
334
- var _a;
335
- return (d == null ? void 0 : d[key]) || ((_a = d == null ? void 0 : d.originBundleItem) == null ? void 0 : _a[key]);
358
+ exports.formatBundle = formatBundle;
359
+ const formatBundleToOrigin = bundle => {
360
+ if (!bundle?.length) return [];
361
+ return bundle.map(d => {
362
+ const getBundleValueByKey = key => {
363
+ return d?.[key] || d?.originBundleItem?.[key];
336
364
  };
337
- const product_discount_difference = ((d == null ? void 0 : d.discount_list) || []).reduce((pre, cur) => {
338
- var _a;
339
- return pre + (((_a = cur == null ? void 0 : cur.metadata) == null ? void 0 : _a.product_discount_difference) || 0);
365
+ const product_discount_difference = (d?.discount_list || []).reduce((pre, cur) => {
366
+ return pre + (cur?.metadata?.product_discount_difference || 0);
340
367
  }, 0);
341
368
  const normalizedBundle = {
342
369
  ...d,
343
370
  // 计算 markdown 净额时只传真实毛价;若仅有 bundle_selling_price,则由 helper 当历史净额兜底。
344
- price: (d == null ? void 0 : d.price) ?? (d == null ? void 0 : d.custom_price),
345
- bundle_selling_price: d == null ? void 0 : d.bundle_selling_price,
346
- price_type: (d == null ? void 0 : d.price_type) ?? (d == null ? void 0 : d.custom_price_type),
347
- price_type_ext: (d == null ? void 0 : d.price_type_ext) ?? (d == null ? void 0 : d.custom_price_type_ext),
348
- option: getBundleValueByKey("option")
371
+ price: d?.price ?? d?.custom_price,
372
+ bundle_selling_price: d?.bundle_selling_price,
373
+ price_type: d?.price_type ?? d?.custom_price_type,
374
+ price_type_ext: d?.price_type_ext ?? d?.custom_price_type_ext,
375
+ option: getBundleValueByKey('option')
349
376
  };
350
377
  return {
351
- bundle_group_id: getBundleValueByKey("group_id"),
378
+ bundle_group_id: getBundleValueByKey('group_id'),
352
379
  bundle_id: d.id,
353
- bundle_product_id: getBundleValueByKey("_bundle_product_id") || getBundleValueByKey("product_id"),
354
- bundle_variant_id: getBundleValueByKey("bundle_variant_id"),
380
+ bundle_product_id: getBundleValueByKey('_bundle_product_id') || getBundleValueByKey('product_id'),
381
+ bundle_variant_id: getBundleValueByKey('bundle_variant_id'),
355
382
  num: d.num,
356
- extension_id: getBundleValueByKey("extension_id"),
357
- extension_type: getBundleValueByKey("extension_type"),
358
- option: formatOptionsToOrigin(getBundleValueByKey("option")),
383
+ extension_id: getBundleValueByKey('extension_id'),
384
+ extension_type: getBundleValueByKey('extension_type'),
385
+ option: formatOptionsToOrigin(getBundleValueByKey('option')),
359
386
  discount_list: d.discount_list,
360
- "bundle_selling_price": (0, import_utils4.getBundleSellingMagnitude)(normalizedBundle).toFixed(2),
361
- "custom_price": d == null ? void 0 : d.price,
387
+ "bundle_selling_price": (0, _utils4.getBundleSellingMagnitude)(normalizedBundle).toFixed(2),
388
+ "custom_price": d?.price,
362
389
  metadata: {
363
390
  custom_product_bundle_map_id: d._id,
364
391
  product_discount_difference
@@ -366,103 +393,146 @@ var formatBundleToOrigin = (bundle) => {
366
393
  };
367
394
  });
368
395
  };
369
- var getProductDeposit = (params) => {
370
- var _a, _b;
371
- const { cartItem, product, bundle, options } = params;
372
- const num = (params == null ? void 0 : params.num) || 1;
373
- if (((_a = product == null ? void 0 : product.custom_deposit_data) == null ? void 0 : _a.has_deposit) == 1) {
374
- let total = new import_decimal.default(0);
396
+
397
+ /**
398
+ * 获取商品定金
399
+ * @description 定金基于商品售价来算,最终乘商品数量
400
+ * 1、如果套餐主商品有定金规则,则定金为:(套餐商品总售价 * 定金百分比 + 定金固定金额)* 商品数量
401
+ * 2、如果套餐主商品没有定金规则,子商品有定金规则,则定金为:(套餐子商品售价 * 套餐子商品定金百分比 + 套餐子商品定金固定金额)* 商品数量,最终将所有子商品定金相加
402
+ * 3、普通商品/单规格商品/组合规则商品,定金规则:(商品总售价 * 定金百分比 + 定金固定金额)* 商品数量
403
+ * @param params 参数
404
+ * @returns 商品定金
405
+ */
406
+ exports.formatBundleToOrigin = formatBundleToOrigin;
407
+ const getProductDeposit = params => {
408
+ const {
409
+ cartItem,
410
+ product,
411
+ bundle,
412
+ options
413
+ } = params;
414
+ const num = params?.num || 1;
415
+
416
+ // 判定商品是否有定金规则
417
+ if (product?.custom_deposit_data?.has_deposit == 1) {
418
+ let total = new _decimal.default(0);
375
419
  const {
376
420
  deposit_fixed,
377
421
  deposit_percentage,
378
422
  deposit_policy_data,
379
423
  self_deposit_policy_ids
380
- } = (product == null ? void 0 : product.custom_deposit_data) || {};
424
+ } = product?.custom_deposit_data || {};
425
+ // 所有协议数据
381
426
  const allProtocols = deposit_policy_data || [];
427
+ // 是否存在定金,主商品has_deposit为1,但是自身没有定金设置,需要判定子商品是否存在定金,如果不存在最终判定也是不存在定金
382
428
  let productHasDeposit = false;
429
+ // 关联的定金协议id
383
430
  const protocolIds = [];
384
- if (typeof deposit_fixed === "string" && typeof deposit_percentage === "string") {
385
- const { depositTotal, result } = handleProductDeposit({
386
- depositData: product == null ? void 0 : product.custom_deposit_data,
431
+
432
+ // 判断主商品是否有定金规则
433
+ if (typeof deposit_fixed === 'string' && typeof deposit_percentage === 'string') {
434
+ const {
435
+ depositTotal,
436
+ result
437
+ } = handleProductDeposit({
438
+ depositData: product?.custom_deposit_data,
387
439
  total: cartItem.total || 0,
388
440
  num
389
441
  });
390
442
  if (result) {
391
443
  total = depositTotal;
392
- protocolIds.push(...self_deposit_policy_ids || []);
444
+ protocolIds.push(...(self_deposit_policy_ids || []));
393
445
  productHasDeposit = true;
394
446
  }
395
447
  } else {
396
- if (product == null ? void 0 : product.product_variant_id) {
397
- const variantProduct = (_b = product == null ? void 0 : product.variant) == null ? void 0 : _b.find(
398
- (item) => (item == null ? void 0 : item.id) === (product == null ? void 0 : product.product_variant_id)
399
- );
448
+ // 组合规格商品
449
+ if (product?.product_variant_id) {
450
+ const variantProduct = product?.variant?.find(item => item?.id === product?.product_variant_id);
400
451
  if (variantProduct) {
401
- const depositData = variantProduct == null ? void 0 : variantProduct.custom_deposit_data;
402
- const { depositTotal, result } = handleProductDeposit({
452
+ const depositData = variantProduct?.custom_deposit_data;
453
+ const {
454
+ depositTotal,
455
+ result
456
+ } = handleProductDeposit({
403
457
  depositData,
404
- total: (cartItem == null ? void 0 : cartItem.total) || 0,
458
+ total: cartItem?.total || 0,
405
459
  num
406
460
  });
407
461
  if (result) {
408
462
  total = depositTotal;
409
- protocolIds.push(...(depositData == null ? void 0 : depositData.self_deposit_policy_ids) || []);
463
+ protocolIds.push(...(depositData?.self_deposit_policy_ids || []));
410
464
  productHasDeposit = true;
411
465
  }
412
466
  }
413
467
  }
414
- if (bundle == null ? void 0 : bundle.length) {
468
+ if (bundle?.length) {
415
469
  total = bundle.reduce((accumulator, currBundleProduct) => {
416
- const depositData = currBundleProduct == null ? void 0 : currBundleProduct.custom_deposit_data;
417
- const { depositTotal, result } = handleProductDeposit({
470
+ const depositData = currBundleProduct?.custom_deposit_data;
471
+ const {
472
+ depositTotal,
473
+ result
474
+ } = handleProductDeposit({
418
475
  depositData,
419
- total: currBundleProduct == null ? void 0 : currBundleProduct.price,
420
- num: (currBundleProduct == null ? void 0 : currBundleProduct.num) || 1
476
+ total: currBundleProduct?.price,
477
+ num: currBundleProduct?.num || 1
421
478
  });
422
479
  if (result) {
423
- protocolIds.push(...(depositData == null ? void 0 : depositData.self_deposit_policy_ids) || []);
480
+ protocolIds.push(...(depositData?.self_deposit_policy_ids || []));
424
481
  productHasDeposit = true;
425
482
  return accumulator.plus(depositTotal);
426
483
  }
427
484
  return accumulator;
428
- }, new import_decimal.default(0));
485
+ }, new _decimal.default(0));
429
486
  }
430
487
  }
431
488
  if (productHasDeposit) {
432
489
  const ids = new Set(protocolIds);
433
- const protocols = allProtocols.filter((item) => ids.has(item.id));
434
- return { total: total.toNumber(), protocols };
490
+ const protocols = allProtocols.filter(item => ids.has(item.id));
491
+ return {
492
+ total: total.toNumber(),
493
+ protocols
494
+ };
435
495
  }
436
496
  return null;
437
497
  }
438
498
  return null;
439
499
  };
440
- var handleProductDeposit = (params) => {
441
- const { depositData, total, num } = params;
500
+
501
+ /**
502
+ * 计算商品定金
503
+ * @param params 参数
504
+ * @returns 商品定金
505
+ */
506
+ exports.getProductDeposit = getProductDeposit;
507
+ const handleProductDeposit = params => {
508
+ const {
509
+ depositData,
510
+ total,
511
+ num
512
+ } = params;
442
513
  if (!depositData) {
443
- return { result: false, depositTotal: new import_decimal.default(0) };
514
+ return {
515
+ result: false,
516
+ depositTotal: new _decimal.default(0)
517
+ };
444
518
  }
445
- const { deposit_fixed, deposit_percentage } = depositData || {};
446
- if (typeof deposit_fixed === "string" && typeof deposit_percentage === "string") {
447
- const depositFixed = (0, import_decimal.default)(deposit_fixed || 0);
448
- const depositPercent = (0, import_decimal.default)(deposit_percentage || 0);
449
- const productTotalPrice = (0, import_decimal.default)(total || 0);
519
+ const {
520
+ deposit_fixed,
521
+ deposit_percentage
522
+ } = depositData || {};
523
+ if (typeof deposit_fixed === 'string' && typeof deposit_percentage === 'string') {
524
+ const depositFixed = (0, _decimal.default)(deposit_fixed || 0);
525
+ const depositPercent = (0, _decimal.default)(deposit_percentage || 0);
526
+ const productTotalPrice = (0, _decimal.default)(total || 0);
450
527
  const deposit = depositFixed.plus(depositPercent.times(productTotalPrice));
451
- return { depositTotal: deposit.times(num), result: true };
528
+ return {
529
+ depositTotal: deposit.times(num),
530
+ result: true
531
+ };
452
532
  }
453
- return { result: false, depositTotal: new import_decimal.default(0) };
533
+ return {
534
+ result: false,
535
+ depositTotal: new _decimal.default(0)
536
+ };
454
537
  };
455
- // Annotate the CommonJS export names for ESM import in node:
456
- 0 && (module.exports = {
457
- formatBundle,
458
- formatBundleToOrigin,
459
- formatOptions,
460
- formatOptionsToOrigin,
461
- formatProductToCartItem,
462
- formatProductToCartItemOrigin,
463
- getProductDeposit,
464
- getProductOriginTotalPrice,
465
- getProductTotalPrice,
466
- handleProductDeposit,
467
- handleVariantProduct
468
- });
538
+ exports.handleProductDeposit = handleProductDeposit;