@pisell/pisellos 2.1.171 → 2.1.172

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 (230) hide show
  1. package/dist/index.d.ts +1 -1
  2. package/dist/index.js +1 -3
  3. package/dist/model/strategy/adapter/index.d.ts +0 -4
  4. package/dist/model/strategy/adapter/index.js +1 -5
  5. package/dist/model/strategy/adapter/promotion/evaluator.js +99 -26
  6. package/dist/model/strategy/adapter/walletPass/evaluator.d.ts +2 -0
  7. package/dist/model/strategy/adapter/walletPass/evaluator.js +61 -8
  8. package/dist/model/strategy/adapter/walletPass/locales.js +12 -3
  9. package/dist/model/strategy/engine.d.ts +18 -5
  10. package/dist/model/strategy/engine.js +145 -45
  11. package/dist/model/strategy/type.d.ts +17 -0
  12. package/dist/model/strategy/type.js +4 -0
  13. package/dist/modules/Cart/types.d.ts +2 -0
  14. package/dist/modules/Cart/utils/cartProduct.js +56 -25
  15. package/dist/modules/Cart/utils/changePrice.js +9 -16
  16. package/dist/modules/Discount/index.d.ts +4 -13
  17. package/dist/modules/Discount/index.js +12 -124
  18. package/dist/modules/Discount/types.d.ts +18 -13
  19. package/dist/modules/Order/index.d.ts +1 -67
  20. package/dist/modules/Order/index.js +30 -918
  21. package/dist/modules/Order/types.d.ts +12 -176
  22. package/dist/modules/Order/types.js +0 -2
  23. package/dist/modules/Order/utils.d.ts +0 -118
  24. package/dist/modules/Order/utils.js +2 -586
  25. package/dist/modules/Payment/index.d.ts +2 -1
  26. package/dist/modules/Payment/index.js +10 -7
  27. package/dist/modules/Payment/utils.js +3 -0
  28. package/dist/modules/Payment/walletpass.d.ts +23 -0
  29. package/dist/modules/Payment/walletpass.js +191 -95
  30. package/dist/modules/Product/utils.js +2 -2
  31. package/dist/modules/ProductList/index.d.ts +2 -4
  32. package/dist/modules/ProductList/index.js +12 -24
  33. package/dist/modules/Rules/index.d.ts +9 -5
  34. package/dist/modules/Rules/index.js +669 -173
  35. package/dist/modules/Rules/types.d.ts +2 -0
  36. package/dist/modules/Schedule/getDateIsInSchedule.js +18 -16
  37. package/dist/modules/Schedule/utils.d.ts +1 -1
  38. package/dist/modules/Summary/types.d.ts +2 -0
  39. package/dist/modules/Summary/utils.d.ts +9 -3
  40. package/dist/modules/Summary/utils.js +57 -67
  41. package/dist/modules/index.d.ts +0 -4
  42. package/dist/modules/index.js +1 -5
  43. package/dist/plugins/window.d.ts +2 -0
  44. package/dist/solution/BookingByStep/index.d.ts +3 -2
  45. package/dist/solution/BookingByStep/index.js +43 -46
  46. package/dist/solution/BookingByStep/types.d.ts +1 -3
  47. package/dist/solution/BookingByStep/types.js +1 -5
  48. package/dist/solution/BookingByStep/utils/timeslots.d.ts +1 -3
  49. package/dist/solution/BookingByStep/utils/timeslots.js +12 -19
  50. package/dist/solution/Checkout/index.js +2 -0
  51. package/dist/solution/ShopDiscount/index.d.ts +2 -3
  52. package/dist/solution/ShopDiscount/index.js +60 -62
  53. package/dist/solution/ShopDiscount/types.d.ts +1 -1
  54. package/dist/solution/ShopDiscount/types.js +2 -1
  55. package/dist/solution/ShopDiscount/utils.js +26 -12
  56. package/dist/solution/index.d.ts +0 -2
  57. package/dist/solution/index.js +1 -3
  58. package/lib/index.d.ts +1 -1
  59. package/lib/index.js +3 -4
  60. package/lib/model/strategy/adapter/index.d.ts +0 -4
  61. package/lib/model/strategy/adapter/index.js +2 -13
  62. package/lib/model/strategy/adapter/promotion/evaluator.js +57 -8
  63. package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +2 -0
  64. package/lib/model/strategy/adapter/walletPass/evaluator.js +34 -3
  65. package/lib/model/strategy/adapter/walletPass/locales.js +12 -3
  66. package/lib/model/strategy/engine.d.ts +18 -5
  67. package/lib/model/strategy/engine.js +85 -21
  68. package/lib/model/strategy/type.d.ts +17 -0
  69. package/lib/modules/Cart/types.d.ts +2 -0
  70. package/lib/modules/Cart/utils/cartProduct.js +39 -12
  71. package/lib/modules/Cart/utils/changePrice.js +9 -13
  72. package/lib/modules/Discount/index.d.ts +4 -13
  73. package/lib/modules/Discount/index.js +5 -76
  74. package/lib/modules/Discount/types.d.ts +18 -13
  75. package/lib/modules/Order/index.d.ts +1 -67
  76. package/lib/modules/Order/index.js +1 -525
  77. package/lib/modules/Order/types.d.ts +12 -176
  78. package/lib/modules/Order/utils.d.ts +0 -118
  79. package/lib/modules/Order/utils.js +2 -483
  80. package/lib/modules/Payment/index.d.ts +2 -1
  81. package/lib/modules/Payment/index.js +1 -0
  82. package/lib/modules/Payment/utils.js +3 -0
  83. package/lib/modules/Payment/walletpass.d.ts +23 -0
  84. package/lib/modules/Payment/walletpass.js +94 -17
  85. package/lib/modules/Product/utils.js +2 -2
  86. package/lib/modules/ProductList/index.d.ts +2 -4
  87. package/lib/modules/ProductList/index.js +39 -46
  88. package/lib/modules/Rules/index.d.ts +9 -5
  89. package/lib/modules/Rules/index.js +776 -292
  90. package/lib/modules/Rules/types.d.ts +2 -0
  91. package/lib/modules/Schedule/getDateIsInSchedule.js +11 -13
  92. package/lib/modules/Schedule/utils.d.ts +1 -1
  93. package/lib/modules/Summary/types.d.ts +2 -0
  94. package/lib/modules/Summary/utils.d.ts +9 -3
  95. package/lib/modules/Summary/utils.js +34 -45
  96. package/lib/modules/index.d.ts +0 -4
  97. package/lib/modules/index.js +1 -9
  98. package/lib/plugins/window.d.ts +2 -0
  99. package/lib/solution/BookingByStep/index.d.ts +3 -2
  100. package/lib/solution/BookingByStep/index.js +4 -6
  101. package/lib/solution/BookingByStep/types.d.ts +1 -3
  102. package/lib/solution/BookingByStep/types.js +0 -10
  103. package/lib/solution/BookingByStep/utils/timeslots.d.ts +1 -3
  104. package/lib/solution/BookingByStep/utils/timeslots.js +11 -19
  105. package/lib/solution/Checkout/index.js +2 -0
  106. package/lib/solution/ShopDiscount/index.d.ts +2 -3
  107. package/lib/solution/ShopDiscount/index.js +27 -22
  108. package/lib/solution/ShopDiscount/types.d.ts +1 -1
  109. package/lib/solution/ShopDiscount/utils.js +10 -6
  110. package/lib/solution/index.d.ts +0 -2
  111. package/lib/solution/index.js +1 -5
  112. package/package.json +2 -2
  113. package/dist/apis/picoding.d.ts +0 -0
  114. package/dist/apis/picoding.js +0 -1
  115. package/dist/model/strategy/adapter/dataVariant/adapter.d.ts +0 -50
  116. package/dist/model/strategy/adapter/dataVariant/adapter.js +0 -167
  117. package/dist/model/strategy/adapter/dataVariant/evaluator.d.ts +0 -89
  118. package/dist/model/strategy/adapter/dataVariant/evaluator.js +0 -780
  119. package/dist/model/strategy/adapter/dataVariant/examples.d.ts +0 -39
  120. package/dist/model/strategy/adapter/dataVariant/examples.js +0 -277
  121. package/dist/model/strategy/adapter/dataVariant/index.d.ts +0 -4
  122. package/dist/model/strategy/adapter/dataVariant/index.js +0 -4
  123. package/dist/model/strategy/adapter/dataVariant/type.d.ts +0 -148
  124. package/dist/model/strategy/adapter/dataVariant/type.js +0 -54
  125. package/dist/modules/OpenData/index.d.ts +0 -24
  126. package/dist/modules/OpenData/index.js +0 -173
  127. package/dist/modules/OpenData/types.d.ts +0 -73
  128. package/dist/modules/OpenData/types.js +0 -1
  129. package/dist/modules/OpenData/utils.d.ts +0 -2
  130. package/dist/modules/OpenData/utils.js +0 -75
  131. package/dist/modules/Quotation/index.d.ts +0 -48
  132. package/dist/modules/Quotation/index.js +0 -248
  133. package/dist/modules/Quotation/types.d.ts +0 -42
  134. package/dist/modules/Quotation/types.js +0 -1
  135. package/dist/modules/SalesSummary/index.d.ts +0 -63
  136. package/dist/modules/SalesSummary/index.js +0 -174
  137. package/dist/modules/SalesSummary/types.d.ts +0 -60
  138. package/dist/modules/SalesSummary/types.js +0 -1
  139. package/dist/modules/SalesSummary/utils.d.ts +0 -30
  140. package/dist/modules/SalesSummary/utils.js +0 -480
  141. package/dist/modules/ScanOrderLogger/index.d.ts +0 -23
  142. package/dist/modules/ScanOrderLogger/index.js +0 -174
  143. package/dist/modules/ScanOrderLogger/providers/feishu.d.ts +0 -2
  144. package/dist/modules/ScanOrderLogger/providers/feishu.js +0 -221
  145. package/dist/modules/ScanOrderLogger/providers/grafana.d.ts +0 -2
  146. package/dist/modules/ScanOrderLogger/providers/grafana.js +0 -50
  147. package/dist/modules/ScanOrderLogger/types.d.ts +0 -53
  148. package/dist/modules/ScanOrderLogger/types.js +0 -1
  149. package/dist/solution/ScanOrder/index.d.ts +0 -158
  150. package/dist/solution/ScanOrder/index.js +0 -3474
  151. package/dist/solution/ScanOrder/types.d.ts +0 -306
  152. package/dist/solution/ScanOrder/types.js +0 -35
  153. package/dist/solution/ScanOrder/utils.d.ts +0 -172
  154. package/dist/solution/ScanOrder/utils.js +0 -796
  155. package/dist/solution/VenueBooking/index.d.ts +0 -262
  156. package/dist/solution/VenueBooking/index.js +0 -3991
  157. package/dist/solution/VenueBooking/sales-section-4-annotated.json +0 -343
  158. package/dist/solution/VenueBooking/types.d.ts +0 -156
  159. package/dist/solution/VenueBooking/types.js +0 -22
  160. package/dist/solution/VenueBooking/utils/dateSummary.d.ts +0 -11
  161. package/dist/solution/VenueBooking/utils/dateSummary.js +0 -91
  162. package/dist/solution/VenueBooking/utils/resource.d.ts +0 -14
  163. package/dist/solution/VenueBooking/utils/resource.js +0 -131
  164. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +0 -32
  165. package/dist/solution/VenueBooking/utils/slotMerge.js +0 -233
  166. package/dist/solution/VenueBooking/utils/smartPricing.d.ts +0 -70
  167. package/dist/solution/VenueBooking/utils/smartPricing.js +0 -233
  168. package/dist/solution/VenueBooking/utils/timeSlot.d.ts +0 -34
  169. package/dist/solution/VenueBooking/utils/timeSlot.js +0 -458
  170. package/dist/solution/VenueBooking/utils.d.ts +0 -1
  171. package/dist/solution/VenueBooking/utils.js +0 -1
  172. package/lib/apis/picoding.d.ts +0 -0
  173. package/lib/apis/picoding.js +0 -0
  174. package/lib/model/strategy/adapter/dataVariant/adapter.d.ts +0 -50
  175. package/lib/model/strategy/adapter/dataVariant/adapter.js +0 -149
  176. package/lib/model/strategy/adapter/dataVariant/evaluator.d.ts +0 -89
  177. package/lib/model/strategy/adapter/dataVariant/evaluator.js +0 -583
  178. package/lib/model/strategy/adapter/dataVariant/examples.d.ts +0 -39
  179. package/lib/model/strategy/adapter/dataVariant/examples.js +0 -293
  180. package/lib/model/strategy/adapter/dataVariant/index.d.ts +0 -4
  181. package/lib/model/strategy/adapter/dataVariant/index.js +0 -38
  182. package/lib/model/strategy/adapter/dataVariant/type.d.ts +0 -148
  183. package/lib/model/strategy/adapter/dataVariant/type.js +0 -31
  184. package/lib/modules/OpenData/index.d.ts +0 -24
  185. package/lib/modules/OpenData/index.js +0 -119
  186. package/lib/modules/OpenData/types.d.ts +0 -73
  187. package/lib/modules/OpenData/types.js +0 -17
  188. package/lib/modules/OpenData/utils.d.ts +0 -2
  189. package/lib/modules/OpenData/utils.js +0 -111
  190. package/lib/modules/Quotation/index.d.ts +0 -48
  191. package/lib/modules/Quotation/index.js +0 -152
  192. package/lib/modules/Quotation/types.d.ts +0 -42
  193. package/lib/modules/Quotation/types.js +0 -17
  194. package/lib/modules/SalesSummary/index.d.ts +0 -63
  195. package/lib/modules/SalesSummary/index.js +0 -105
  196. package/lib/modules/SalesSummary/types.d.ts +0 -60
  197. package/lib/modules/SalesSummary/types.js +0 -17
  198. package/lib/modules/SalesSummary/utils.d.ts +0 -30
  199. package/lib/modules/SalesSummary/utils.js +0 -420
  200. package/lib/modules/ScanOrderLogger/index.d.ts +0 -23
  201. package/lib/modules/ScanOrderLogger/index.js +0 -147
  202. package/lib/modules/ScanOrderLogger/providers/feishu.d.ts +0 -2
  203. package/lib/modules/ScanOrderLogger/providers/feishu.js +0 -157
  204. package/lib/modules/ScanOrderLogger/providers/grafana.d.ts +0 -2
  205. package/lib/modules/ScanOrderLogger/providers/grafana.js +0 -52
  206. package/lib/modules/ScanOrderLogger/types.d.ts +0 -53
  207. package/lib/modules/ScanOrderLogger/types.js +0 -17
  208. package/lib/solution/ScanOrder/index.d.ts +0 -158
  209. package/lib/solution/ScanOrder/index.js +0 -2135
  210. package/lib/solution/ScanOrder/types.d.ts +0 -306
  211. package/lib/solution/ScanOrder/types.js +0 -36
  212. package/lib/solution/ScanOrder/utils.d.ts +0 -172
  213. package/lib/solution/ScanOrder/utils.js +0 -658
  214. package/lib/solution/VenueBooking/index.d.ts +0 -262
  215. package/lib/solution/VenueBooking/index.js +0 -2394
  216. package/lib/solution/VenueBooking/sales-section-4-annotated.json +0 -343
  217. package/lib/solution/VenueBooking/types.d.ts +0 -156
  218. package/lib/solution/VenueBooking/types.js +0 -45
  219. package/lib/solution/VenueBooking/utils/dateSummary.d.ts +0 -11
  220. package/lib/solution/VenueBooking/utils/dateSummary.js +0 -105
  221. package/lib/solution/VenueBooking/utils/resource.d.ts +0 -14
  222. package/lib/solution/VenueBooking/utils/resource.js +0 -92
  223. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +0 -32
  224. package/lib/solution/VenueBooking/utils/slotMerge.js +0 -236
  225. package/lib/solution/VenueBooking/utils/smartPricing.d.ts +0 -70
  226. package/lib/solution/VenueBooking/utils/smartPricing.js +0 -180
  227. package/lib/solution/VenueBooking/utils/timeSlot.d.ts +0 -34
  228. package/lib/solution/VenueBooking/utils/timeSlot.js +0 -343
  229. package/lib/solution/VenueBooking/utils.d.ts +0 -1
  230. package/lib/solution/VenueBooking/utils.js +0 -69
@@ -1,30 +0,0 @@
1
- import type { DepositInfo, SalesSummaryData, SalesSummaryProduct } from './types';
2
- export declare function createEmptySalesSummary(): SalesSummaryData;
3
- export declare function calculateSalesSummary(params: {
4
- products: SalesSummaryProduct[];
5
- isPriceIncludeTax: number;
6
- taxRate?: number;
7
- surchargeList: any[];
8
- scheduleById?: Record<string, any>;
9
- isInScheduleByDate?: any;
10
- }): SalesSummaryData | {
11
- product_quantity: number;
12
- product_original_amount: string;
13
- product_amount: string;
14
- product_expect_amount: string;
15
- product_tax_fee: string;
16
- shipping_fee: string;
17
- shipping_tax_fee: string;
18
- tax_fee: string;
19
- surcharge_fee: string;
20
- surcharges: any;
21
- discount_amount: string;
22
- deposit_amount: string;
23
- deposit: DepositInfo | undefined;
24
- expect_amount: string;
25
- total_amount: string;
26
- amount_gap: string;
27
- rounding_amount: string;
28
- pay_service_charge_amount: string;
29
- is_price_include_tax: number;
30
- };
@@ -1,480 +0,0 @@
1
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
2
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
3
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
5
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
6
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
7
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
8
- 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); }
9
- import Decimal from 'decimal.js';
10
- import { getSurcharge, getSurchargeAmount } from "../Summary/utils";
11
- function toDecimal(value) {
12
- return new Decimal(value || 0);
13
- }
14
- function toFixed2(value) {
15
- return new Decimal(value || 0).toFixed(2);
16
- }
17
- function getSafeNum(num) {
18
- if (!num || Number.isNaN(num)) return 1;
19
- if (num < 1) return 1;
20
- return Math.floor(num);
21
- }
22
- function getBundleUnitPrice(product) {
23
- var useOriginal = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
24
- var bundleItems = product.product_bundle || [];
25
- return bundleItems.reduce(function (sum, item) {
26
- var _ref, _item$original_price, _item$bundle_selling_;
27
- var quantity = getSafeNum(item === null || item === void 0 ? void 0 : item.num);
28
- var price = useOriginal ? toDecimal((_ref = (_item$original_price = item === null || item === void 0 ? void 0 : item.original_price) !== null && _item$original_price !== void 0 ? _item$original_price : item === null || item === void 0 ? void 0 : item.product_price) !== null && _ref !== void 0 ? _ref : item === null || item === void 0 ? void 0 : item.price) : toDecimal((_item$bundle_selling_ = item === null || item === void 0 ? void 0 : item.bundle_selling_price) !== null && _item$bundle_selling_ !== void 0 ? _item$bundle_selling_ : item === null || item === void 0 ? void 0 : item.price);
29
- return sum.plus(price.times(quantity));
30
- }, new Decimal(0));
31
- }
32
-
33
- // 单商品 composite 单价(随后再乘商品数量):
34
- // 新语义 v2 下 `metadata.main_product_selling_price` 已经是"含 option、含主商品折扣"的主价,
35
- // composite 单价 = main_product_selling_price + Σ(bundle_selling_price × num)。
36
- // 不再叠加 options(会重复计算),也不再用 variant/selling_price 兜底(选项已固化进 metadata)。
37
- function getUnitPaymentTotal(product) {
38
- var _product$metadata, _product$metadata2;
39
- var mainSelling = (_product$metadata = product.metadata) === null || _product$metadata === void 0 ? void 0 : _product$metadata.main_product_selling_price;
40
- var mainOriginal = (_product$metadata2 = product.metadata) === null || _product$metadata2 === void 0 ? void 0 : _product$metadata2.main_product_original_price;
41
- var basePrice = mainSelling !== undefined ? toDecimal(mainSelling) : mainOriginal !== undefined ? toDecimal(mainOriginal) : toDecimal(product.selling_price);
42
- return basePrice.plus(getBundleUnitPrice(product));
43
- }
44
- function getUnitOriginalTotal(product) {
45
- var _product$metadata3, _product$metadata4;
46
- var mainOriginal = (_product$metadata3 = product.metadata) === null || _product$metadata3 === void 0 ? void 0 : _product$metadata3.main_product_original_price;
47
- var mainSelling = (_product$metadata4 = product.metadata) === null || _product$metadata4 === void 0 ? void 0 : _product$metadata4.main_product_selling_price;
48
- var basePrice = mainOriginal !== undefined ? toDecimal(mainOriginal) : mainSelling !== undefined ? toDecimal(mainSelling) : toDecimal(product.original_price || product.selling_price);
49
- return basePrice.plus(getBundleUnitPrice(product, true));
50
- }
51
- function buildSurchargeServiceItems(products) {
52
- return products.map(function (product) {
53
- var _product$is_charge_ta, _product$metadata5, _product$metadata6;
54
- var quantity = getSafeNum(product.num);
55
- var unitTotal = getUnitPaymentTotal(product);
56
- return {
57
- id: product.product_id,
58
- num: quantity,
59
- total: unitTotal.toNumber(),
60
- price: unitTotal.toNumber(),
61
- is_charge_tax: (_product$is_charge_ta = product.is_charge_tax) !== null && _product$is_charge_ta !== void 0 ? _product$is_charge_ta : 0,
62
- isCustomItem: product.product_id === null,
63
- _origin: product._origin || {
64
- product: {
65
- discount_list: product.discount_list || [],
66
- product_bundle: product.product_bundle || [],
67
- product_option_item: product.product_option_item || []
68
- }
69
- },
70
- bundle: product.product_bundle || [],
71
- option: product.product_option_item || [],
72
- options: product.product_option_item || [],
73
- relation_details: [],
74
- metadata: product.metadata || {},
75
- start_date: ((_product$metadata5 = product.metadata) === null || _product$metadata5 === void 0 ? void 0 : _product$metadata5.start_date) || '',
76
- start_time: ((_product$metadata6 = product.metadata) === null || _product$metadata6 === void 0 ? void 0 : _product$metadata6.start_time) || ''
77
- };
78
- });
79
- }
80
- function getProductDepositData(product) {
81
- var _product$_origin, _product$_origin2;
82
- var rootDepositData = (_product$_origin = product._origin) === null || _product$_origin === void 0 ? void 0 : _product$_origin.custom_deposit_data;
83
- if (rootDepositData && _typeof(rootDepositData) === 'object') return rootDepositData;
84
- var nestedDepositData = (_product$_origin2 = product._origin) === null || _product$_origin2 === void 0 || (_product$_origin2 = _product$_origin2.product) === null || _product$_origin2 === void 0 ? void 0 : _product$_origin2.custom_deposit_data;
85
- if (nestedDepositData && _typeof(nestedDepositData) === 'object') return nestedDepositData;
86
- return undefined;
87
- }
88
- function collectDepositPolicyIds(depositData) {
89
- var rawIds = [].concat(_toConsumableArray(Array.isArray(depositData === null || depositData === void 0 ? void 0 : depositData.self_deposit_policy_ids) ? depositData.self_deposit_policy_ids : []), _toConsumableArray(Array.isArray(depositData === null || depositData === void 0 ? void 0 : depositData.deposit_policy_ids) ? depositData.deposit_policy_ids : []));
90
- return rawIds.reduce(function (result, id) {
91
- var normalizedId = Number(id);
92
- if (!Number.isFinite(normalizedId)) return result;
93
- result.push(Math.floor(normalizedId));
94
- return result;
95
- }, []);
96
- }
97
- function collectDepositPolicyData(depositData) {
98
- var rawPolicyData = Array.isArray(depositData === null || depositData === void 0 ? void 0 : depositData.deposit_policy_data) ? depositData.deposit_policy_data : [];
99
- return rawPolicyData.reduce(function (result, policy) {
100
- var normalizedId = Number(policy === null || policy === void 0 ? void 0 : policy.id);
101
- if (!Number.isFinite(normalizedId)) return result;
102
- result.push({
103
- id: Math.floor(normalizedId),
104
- title: String((policy === null || policy === void 0 ? void 0 : policy.title) || '')
105
- });
106
- return result;
107
- }, []);
108
- }
109
- function calculateProductsDeposit(products) {
110
- var totalDeposit = new Decimal(0);
111
- var hasDeposit = false;
112
- var policyIds = new Set();
113
- var policyDataMap = new Map();
114
- var _iterator = _createForOfIteratorHelper(products),
115
- _step;
116
- try {
117
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
118
- var product = _step.value;
119
- var depositData = getProductDepositData(product);
120
- if (!depositData || depositData.has_deposit != 1) continue;
121
- var num = getSafeNum(product.num);
122
- var unitTotal = getUnitPaymentTotal(product);
123
- var productTotal = unitTotal.times(num);
124
- var deposit_fixed = depositData.deposit_fixed,
125
- deposit_percentage = depositData.deposit_percentage;
126
- var fixed = toDecimal(deposit_fixed);
127
- var percentage = toDecimal(deposit_percentage);
128
- var itemDeposit = fixed.plus(percentage.times(productTotal));
129
- totalDeposit = totalDeposit.plus(itemDeposit);
130
- hasDeposit = true;
131
- var _iterator3 = _createForOfIteratorHelper(collectDepositPolicyIds(depositData)),
132
- _step3;
133
- try {
134
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
135
- var id = _step3.value;
136
- policyIds.add(id);
137
- }
138
- } catch (err) {
139
- _iterator3.e(err);
140
- } finally {
141
- _iterator3.f();
142
- }
143
- var _iterator4 = _createForOfIteratorHelper(collectDepositPolicyData(depositData)),
144
- _step4;
145
- try {
146
- for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
147
- var policy = _step4.value;
148
- if (!policyDataMap.has(policy.id)) {
149
- policyDataMap.set(policy.id, policy);
150
- }
151
- policyIds.add(policy.id);
152
- }
153
- } catch (err) {
154
- _iterator4.e(err);
155
- } finally {
156
- _iterator4.f();
157
- }
158
- }
159
- } catch (err) {
160
- _iterator.e(err);
161
- } finally {
162
- _iterator.f();
163
- }
164
- if (!hasDeposit) return undefined;
165
- var _iterator2 = _createForOfIteratorHelper(policyIds),
166
- _step2;
167
- try {
168
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
169
- var _id = _step2.value;
170
- if (!policyDataMap.has(_id)) {
171
- policyDataMap.set(_id, {
172
- id: _id,
173
- title: ''
174
- });
175
- }
176
- }
177
- } catch (err) {
178
- _iterator2.e(err);
179
- } finally {
180
- _iterator2.f();
181
- }
182
- return {
183
- total: totalDeposit.toFixed(2),
184
- deposit_policy_ids: _toConsumableArray(policyIds),
185
- deposit_policy_data: _toConsumableArray(policyDataMap.values()),
186
- hasDeposit: true
187
- };
188
- }
189
- function isBundleOriginalPrice(item) {
190
- return (item === null || item === void 0 ? void 0 : item.price_type) === 'markup' && (item === null || item === void 0 ? void 0 : item.price_type_ext) === 'product_price';
191
- }
192
- function isBundleMarkupOrDiscount(item) {
193
- var isMarkup = (item === null || item === void 0 ? void 0 : item.price_type) === 'markup' && ((item === null || item === void 0 ? void 0 : item.price_type_ext) === '' || !(item !== null && item !== void 0 && item.price_type_ext));
194
- var isDiscount = (item === null || item === void 0 ? void 0 : item.price_type) === 'markdown' && ((item === null || item === void 0 ? void 0 : item.price_type_ext) === '' || !(item !== null && item !== void 0 && item.price_type_ext));
195
- return isMarkup || isDiscount;
196
- }
197
-
198
- /**
199
- * 计算单个商品税费(返回精确值,不四舍五入)。
200
- * 与 Summary/utils.ts 的 getProductItemTax 公式一致,但不依赖 bookingDetail。
201
- *
202
- * @param taxRate 百分比税率(如 5 表示 5%),函数内部会 /100
203
- */
204
- function calculateSingleItemTax(params) {
205
- var price = params.price,
206
- taxRate = params.taxRate,
207
- isPriceIncludeTax = params.isPriceIncludeTax,
208
- isChargeTax = params.isChargeTax;
209
- if (price.lte(0)) return new Decimal(0);
210
- if (isChargeTax === 0 || !isChargeTax) return new Decimal(0);
211
- var rate = taxRate.div(100);
212
- if (isPriceIncludeTax === 0) {
213
- return price.times(rate);
214
- }
215
- var divisor = new Decimal(1).plus(rate);
216
- if (divisor.lte(0)) return new Decimal(0);
217
- return price.dividedBy(divisor).times(rate);
218
- }
219
-
220
- /**
221
- * 获取主商品折扣后总价(含 option、含主商品折扣、含加价/减价 bundle)。
222
- *
223
- * 新语义 v2 下:
224
- * - `metadata.main_product_selling_price` 已是"含 option、含折扣"的主价,直接读即可;
225
- * - 无需再 `minus(mainDiscountAmount)` 或 `plus(getOptionUnitPrice)`;
226
- * - 仅需叠加 `markup` / `markdown` 类 bundle(原价 bundle 已由 `calculateProductsTax` 独立处理)。
227
- */
228
- function getMainProductPaymentTotal(product) {
229
- var _ref2, _product$metadata$mai, _product$metadata7, _product$metadata8;
230
- var mainSelling = (_ref2 = (_product$metadata$mai = (_product$metadata7 = product.metadata) === null || _product$metadata7 === void 0 ? void 0 : _product$metadata7.main_product_selling_price) !== null && _product$metadata$mai !== void 0 ? _product$metadata$mai : (_product$metadata8 = product.metadata) === null || _product$metadata8 === void 0 ? void 0 : _product$metadata8.main_product_original_price) !== null && _ref2 !== void 0 ? _ref2 : 0;
231
- var total = toDecimal(mainSelling);
232
- var bundleItems = product.product_bundle || [];
233
- var _iterator5 = _createForOfIteratorHelper(bundleItems),
234
- _step5;
235
- try {
236
- for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
237
- var bundleItem = _step5.value;
238
- if (isBundleMarkupOrDiscount(bundleItem)) {
239
- var _ref3, _bundleItem$bundle_se, _bundleItem$num;
240
- var unit = toDecimal((_ref3 = (_bundleItem$bundle_se = bundleItem.bundle_selling_price) !== null && _bundleItem$bundle_se !== void 0 ? _bundleItem$bundle_se : bundleItem.price) !== null && _ref3 !== void 0 ? _ref3 : 0);
241
- var qty = getSafeNum((_bundleItem$num = bundleItem.num) !== null && _bundleItem$num !== void 0 ? _bundleItem$num : bundleItem.quantity);
242
- total = total.plus(unit.times(qty));
243
- }
244
- }
245
- } catch (err) {
246
- _iterator5.e(err);
247
- } finally {
248
- _iterator5.f();
249
- }
250
- return Decimal.max(total, 0);
251
- }
252
-
253
- /**
254
- * 遍历所有商品计算税费,回写 tax_fee 到每个商品及 bundle 原价子商品,处理舍入差值。
255
- * 参照 Summary/utils.ts 的 processItemsTax,适配 SalesSummaryProduct 结构。
256
- */
257
- function calculateProductsTax(products, taxRate, isPriceIncludeTax) {
258
- var rate = new Decimal(taxRate);
259
- var preciseTax = new Decimal(0);
260
- var roundedTax = new Decimal(0);
261
- var preciseOriginTax = new Decimal(0);
262
- var roundedOriginTax = new Decimal(0);
263
- var lastTaxableItem = null;
264
- var _iterator6 = _createForOfIteratorHelper(products),
265
- _step6;
266
- try {
267
- for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
268
- var _product$is_charge_ta2, _product$is_charge_ta3;
269
- var product = _step6.value;
270
- var quantity = new Decimal(getSafeNum(product.num));
271
-
272
- // --- 主商品折后税费 ---
273
- var mainTotal = getMainProductPaymentTotal(product);
274
- var surchargeFee = toDecimal(product.surcharge_fee);
275
- var mainTaxableBase = mainTotal.lte(0) ? surchargeFee : mainTotal.plus(surchargeFee);
276
- var mainTaxPrecise = calculateSingleItemTax({
277
- price: mainTaxableBase,
278
- taxRate: rate,
279
- isPriceIncludeTax: isPriceIncludeTax,
280
- isChargeTax: (_product$is_charge_ta2 = product.is_charge_tax) !== null && _product$is_charge_ta2 !== void 0 ? _product$is_charge_ta2 : 0
281
- });
282
- var mainTaxRounded = mainTaxPrecise.toDecimalPlaces(2, Decimal.ROUND_HALF_UP);
283
- if (mainTaxPrecise.gt(0)) {
284
- lastTaxableItem = {
285
- type: 'main',
286
- item: product
287
- };
288
- }
289
-
290
- // --- 主商品原价税费 ---
291
- var originalTotal = getUnitOriginalTotal(product);
292
- var originalTaxableBase = originalTotal.lte(0) ? surchargeFee : originalTotal.plus(surchargeFee);
293
- var originalTaxPrecise = calculateSingleItemTax({
294
- price: originalTaxableBase,
295
- taxRate: rate,
296
- isPriceIncludeTax: isPriceIncludeTax,
297
- isChargeTax: (_product$is_charge_ta3 = product.is_charge_tax) !== null && _product$is_charge_ta3 !== void 0 ? _product$is_charge_ta3 : 0
298
- });
299
-
300
- // --- bundle 原价子商品独立计税 ---
301
- var bundlePreciseTax = new Decimal(0);
302
- var bundleRoundedTax = new Decimal(0);
303
- var bundlePreciseOriginTax = new Decimal(0);
304
- var bundleRoundedOriginTax = new Decimal(0);
305
- var bundleItems = product.product_bundle || [];
306
- var _iterator7 = _createForOfIteratorHelper(bundleItems),
307
- _step7;
308
- try {
309
- for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
310
- var _bundleItem$num2, _ref4, _bundleItem$bundle_se2, _ref5, _ref6, _bundleItem$original_, _ref7, _bundleItem$is_charge, _ref8, _bundleItem$is_charge2;
311
- var bundleItem = _step7.value;
312
- if (!isBundleOriginalPrice(bundleItem)) continue;
313
- var bundleQuantity = new Decimal(getSafeNum((_bundleItem$num2 = bundleItem.num) !== null && _bundleItem$num2 !== void 0 ? _bundleItem$num2 : bundleItem.quantity));
314
- var bundlePrice = toDecimal((_ref4 = (_bundleItem$bundle_se2 = bundleItem.bundle_selling_price) !== null && _bundleItem$bundle_se2 !== void 0 ? _bundleItem$bundle_se2 : bundleItem.price) !== null && _ref4 !== void 0 ? _ref4 : 0);
315
- var bundleOriginalPrice = toDecimal((_ref5 = (_ref6 = (_bundleItem$original_ = bundleItem.original_price) !== null && _bundleItem$original_ !== void 0 ? _bundleItem$original_ : bundleItem.product_price) !== null && _ref6 !== void 0 ? _ref6 : bundleItem.price) !== null && _ref5 !== void 0 ? _ref5 : 0);
316
- var bundleTaxPrecise = calculateSingleItemTax({
317
- price: bundlePrice,
318
- taxRate: rate,
319
- isPriceIncludeTax: isPriceIncludeTax,
320
- isChargeTax: (_ref7 = (_bundleItem$is_charge = bundleItem.is_charge_tax) !== null && _bundleItem$is_charge !== void 0 ? _bundleItem$is_charge : product.is_charge_tax) !== null && _ref7 !== void 0 ? _ref7 : 0
321
- });
322
- var bundleTaxRounded = bundleTaxPrecise.toDecimalPlaces(2, Decimal.ROUND_HALF_UP);
323
- var bundleOrigTaxPrecise = calculateSingleItemTax({
324
- price: bundleOriginalPrice,
325
- taxRate: rate,
326
- isPriceIncludeTax: isPriceIncludeTax,
327
- isChargeTax: (_ref8 = (_bundleItem$is_charge2 = bundleItem.is_charge_tax) !== null && _bundleItem$is_charge2 !== void 0 ? _bundleItem$is_charge2 : product.is_charge_tax) !== null && _ref8 !== void 0 ? _ref8 : 0
328
- });
329
- var bundleOrigTaxRounded = bundleOrigTaxPrecise.toDecimalPlaces(2, Decimal.ROUND_HALF_UP);
330
- bundleItem.tax_fee = bundleTaxRounded.toNumber();
331
- bundleItem.original_tax_fee = bundleOrigTaxRounded.toNumber();
332
- bundlePreciseTax = bundlePreciseTax.plus(bundleTaxPrecise.times(bundleQuantity));
333
- bundleRoundedTax = bundleRoundedTax.plus(bundleTaxRounded.times(bundleQuantity));
334
- bundlePreciseOriginTax = bundlePreciseOriginTax.plus(bundleOrigTaxPrecise.times(bundleQuantity));
335
- bundleRoundedOriginTax = bundleRoundedOriginTax.plus(bundleOrigTaxRounded.times(bundleQuantity));
336
- if (bundleTaxPrecise.gt(0)) {
337
- lastTaxableItem = {
338
- type: 'bundle',
339
- item: bundleItem
340
- };
341
- }
342
- }
343
-
344
- // --- 汇总到商品级 ---
345
- } catch (err) {
346
- _iterator7.e(err);
347
- } finally {
348
- _iterator7.f();
349
- }
350
- var itemTaxPrecise = mainTaxPrecise.plus(bundlePreciseTax);
351
- var itemTaxRounded = mainTaxRounded.plus(bundleRoundedTax);
352
- var itemOriginTaxPrecise = originalTaxPrecise.plus(bundlePreciseOriginTax);
353
- var itemOriginTaxRounded = originalTaxPrecise.toDecimalPlaces(2, Decimal.ROUND_HALF_UP).plus(bundleRoundedOriginTax);
354
- product.tax_fee = itemTaxRounded.toDecimalPlaces(2, Decimal.ROUND_HALF_UP).toFixed(2);
355
- product.original_tax_fee = itemOriginTaxRounded.toDecimalPlaces(2, Decimal.ROUND_HALF_UP).toNumber();
356
- preciseTax = preciseTax.plus(itemTaxPrecise.times(quantity));
357
- roundedTax = roundedTax.plus(itemTaxRounded.times(quantity));
358
- preciseOriginTax = preciseOriginTax.plus(itemOriginTaxPrecise.times(quantity));
359
- roundedOriginTax = roundedOriginTax.plus(itemOriginTaxRounded.times(quantity));
360
- }
361
-
362
- // --- 舍入差值处理 ---
363
- } catch (err) {
364
- _iterator6.e(err);
365
- } finally {
366
- _iterator6.f();
367
- }
368
- var expectedTax = preciseTax.toDecimalPlaces(2, Decimal.ROUND_HALF_UP);
369
- var expectedOriginTax = preciseOriginTax.toDecimalPlaces(2, Decimal.ROUND_HALF_UP);
370
- var taxRemainder = expectedTax.minus(roundedTax).toNumber();
371
- var originTaxRemainder = expectedOriginTax.minus(roundedOriginTax).toNumber();
372
- if (lastTaxableItem) {
373
- if (taxRemainder !== 0) {
374
- lastTaxableItem.item.tax_fee_rounding_remainder = taxRemainder;
375
- }
376
- if (originTaxRemainder !== 0) {
377
- lastTaxableItem.item.original_tax_fee_rounding_remainder = originTaxRemainder;
378
- }
379
- }
380
- return {
381
- tax: expectedTax,
382
- originTax: expectedOriginTax
383
- };
384
- }
385
- export function createEmptySalesSummary() {
386
- return {
387
- product_quantity: 0,
388
- product_original_amount: '0.00',
389
- product_amount: '0.00',
390
- product_expect_amount: '0.00',
391
- product_tax_fee: '0.00',
392
- shipping_fee: '0.00',
393
- shipping_tax_fee: '0.00',
394
- tax_fee: '0.00',
395
- surcharge_fee: '0.00',
396
- surcharges: [],
397
- discount_amount: '0.00',
398
- deposit_amount: '0.00',
399
- expect_amount: '0.00',
400
- total_amount: '0.00',
401
- amount_gap: '0.00',
402
- rounding_amount: '0.00',
403
- pay_service_charge_amount: '0.00'
404
- };
405
- }
406
- export function calculateSalesSummary(params) {
407
- var products = params.products,
408
- isPriceIncludeTax = params.isPriceIncludeTax,
409
- taxRate = params.taxRate,
410
- surchargeList = params.surchargeList,
411
- _params$scheduleById = params.scheduleById,
412
- scheduleById = _params$scheduleById === void 0 ? {} : _params$scheduleById,
413
- isInScheduleByDate = params.isInScheduleByDate;
414
- if (!(products !== null && products !== void 0 && products.length)) return createEmptySalesSummary();
415
- var productQuantity = products.reduce(function (sum, item) {
416
- return sum + getSafeNum(item.num);
417
- }, 0);
418
- var productOriginalAmount = products.reduce(function (sum, item) {
419
- return sum.plus(getUnitOriginalTotal(item).times(getSafeNum(item.num)));
420
- }, new Decimal(0));
421
- var productAmount = products.reduce(function (sum, item) {
422
- return sum.plus(getUnitPaymentTotal(item).times(getSafeNum(item.num)));
423
- }, new Decimal(0));
424
- var surchargeServiceItems = buildSurchargeServiceItems(products);
425
- var surcharge = getSurcharge({
426
- service: surchargeServiceItems,
427
- addons: [],
428
- bookingDetail: null,
429
- bookingId: undefined
430
- }, {
431
- isEdit: false,
432
- isInScheduleByDate: isInScheduleByDate,
433
- surcharge_list: surchargeList,
434
- scheduleById: scheduleById
435
- });
436
- var surchargeAmount = new Decimal(getSurchargeAmount({
437
- bookingDetail: null,
438
- bookingId: undefined
439
- }, surcharge, {
440
- isEdit: false
441
- }) || 0);
442
- for (var i = 0; i < products.length; i++) {
443
- var _surchargeServiceItem;
444
- products[i].surcharge_fee = ((_surchargeServiceItem = surchargeServiceItems[i]) === null || _surchargeServiceItem === void 0 ? void 0 : _surchargeServiceItem.surcharge_fee) || 0;
445
- }
446
- var hasTaxRate = taxRate !== undefined && taxRate !== null && taxRate > 0;
447
- var productTaxFee;
448
- if (hasTaxRate) {
449
- var taxResult = calculateProductsTax(products, taxRate, isPriceIncludeTax);
450
- productTaxFee = taxResult.tax;
451
- } else {
452
- productTaxFee = products.reduce(function (sum, item) {
453
- return sum.plus(toDecimal(item.tax_fee).times(getSafeNum(item.num)));
454
- }, new Decimal(0));
455
- }
456
- var expectAmount = productAmount.plus(surchargeAmount);
457
- var totalAmount = isPriceIncludeTax === 1 ? expectAmount : expectAmount.plus(productTaxFee);
458
- var deposit = calculateProductsDeposit(products);
459
- return {
460
- product_quantity: productQuantity,
461
- product_original_amount: toFixed2(productOriginalAmount),
462
- product_amount: toFixed2(productAmount),
463
- product_expect_amount: toFixed2(productAmount),
464
- product_tax_fee: toFixed2(productTaxFee),
465
- shipping_fee: '0.00',
466
- shipping_tax_fee: '0.00',
467
- tax_fee: toFixed2(productTaxFee),
468
- surcharge_fee: toFixed2(surchargeAmount),
469
- surcharges: surcharge,
470
- discount_amount: toFixed2(Decimal.max(productOriginalAmount.minus(productAmount), 0)),
471
- deposit_amount: deposit ? deposit.total : '0.00',
472
- deposit: deposit,
473
- expect_amount: toFixed2(expectAmount),
474
- total_amount: toFixed2(totalAmount),
475
- amount_gap: '0.00',
476
- rounding_amount: '0.00',
477
- pay_service_charge_amount: '0.00',
478
- is_price_include_tax: isPriceIncludeTax
479
- };
480
- }
@@ -1,23 +0,0 @@
1
- import { BaseModule } from '../BaseModule';
2
- import { Module, ModuleOptions, PisellCore } from '../../types';
3
- import { ScanOrderLogInput, ScanOrderLoggerContext, ScanOrderLoggerProviderConfig, ScanOrderLoggerProviderType } from './types';
4
- export interface ScanOrderLoggerModuleAPI {
5
- addLog: (params: ScanOrderLogInput) => Promise<void>;
6
- setContext: (context: ScanOrderLoggerContext) => void;
7
- setProvider: (provider: ScanOrderLoggerProviderType) => void;
8
- setProviderConfig: (providerConfig: ScanOrderLoggerProviderConfig) => void;
9
- }
10
- export declare class ScanOrderLoggerModule extends BaseModule implements Module, ScanOrderLoggerModuleAPI {
11
- protected defaultName: string;
12
- protected defaultVersion: string;
13
- private store;
14
- private window?;
15
- initialize(core: PisellCore, options?: ModuleOptions): Promise<void>;
16
- setContext(context: ScanOrderLoggerContext): void;
17
- setProvider(provider: ScanOrderLoggerProviderType): void;
18
- setProviderConfig(providerConfig: ScanOrderLoggerProviderConfig): void;
19
- private getCurrentHost;
20
- private buildRecord;
21
- addLog(params: ScanOrderLogInput): Promise<void>;
22
- }
23
- export * from './types';