@pisell/pisellos 2.3.95 → 2.3.97

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 (29) hide show
  1. package/dist/model/strategy/adapter/dataVariant/evaluator.js +13 -2
  2. package/dist/model/strategy/adapter/promotion/index.js +0 -9
  3. package/dist/modules/Order/index.d.ts +2 -0
  4. package/dist/modules/Order/index.js +51 -28
  5. package/dist/modules/SalesSummary/index.js +6 -4
  6. package/dist/server/index.js +14 -8
  7. package/dist/server/modules/products/index.d.ts +2 -2
  8. package/dist/server/modules/products/index.js +10 -9
  9. package/dist/server/utils/product.d.ts +1 -1
  10. package/dist/server/utils/product.js +186 -22
  11. package/dist/server/utils/small-ticket.d.ts +9 -1
  12. package/dist/server/utils/small-ticket.js +136 -41
  13. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +3 -2
  14. package/dist/solution/BookingByStep/index.d.ts +2 -2
  15. package/lib/model/strategy/adapter/dataVariant/evaluator.js +12 -2
  16. package/lib/model/strategy/adapter/promotion/index.js +46 -1
  17. package/lib/modules/Order/index.d.ts +2 -0
  18. package/lib/modules/Order/index.js +33 -14
  19. package/lib/modules/SalesSummary/index.js +3 -1
  20. package/lib/server/index.js +10 -6
  21. package/lib/server/modules/products/index.d.ts +2 -2
  22. package/lib/server/modules/products/index.js +5 -4
  23. package/lib/server/utils/product.d.ts +1 -1
  24. package/lib/server/utils/product.js +163 -3
  25. package/lib/server/utils/small-ticket.d.ts +9 -1
  26. package/lib/server/utils/small-ticket.js +126 -33
  27. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +3 -2
  28. package/lib/solution/BookingByStep/index.d.ts +2 -2
  29. package/package.json +1 -1
@@ -32,6 +32,7 @@ const LABELS = {
32
32
  orderDiscount: 'Order discount',
33
33
  manualDiscount: 'Manual discount',
34
34
  payProcessingFee: 'Pay processing fee',
35
+ surchargeIncluded: 'Surcharge(Included)',
35
36
  rounding: 'Rounding',
36
37
  gross: 'Gross',
37
38
  tare: 'Tare'
@@ -58,6 +59,7 @@ const LABELS = {
58
59
  orderDiscount: '整单折扣',
59
60
  manualDiscount: '手动折扣',
60
61
  payProcessingFee: '支付手续费',
62
+ surchargeIncluded: '手续费(已含)',
61
63
  rounding: '抹零',
62
64
  gross: '重量',
63
65
  tare: '去皮'
@@ -84,6 +86,7 @@ const LABELS = {
84
86
  orderDiscount: '整單折扣',
85
87
  manualDiscount: '手動折扣',
86
88
  payProcessingFee: '支付手續費',
89
+ surchargeIncluded: '手續費(已含)',
87
90
  rounding: '抹零',
88
91
  gross: '重量',
89
92
  tare: '去皮'
@@ -141,6 +144,11 @@ function buildLocaleData(params) {
141
144
  locale,
142
145
  currencySymbol
143
146
  }),
147
+ wallets: buildWallets({
148
+ order,
149
+ locale,
150
+ currencySymbol
151
+ }),
144
152
  tickets: Array.isArray(order.tickets) ? order.tickets : [],
145
153
  source_shop: [],
146
154
  refund_data: [],
@@ -166,7 +174,10 @@ function buildBaseData(params) {
166
174
  is_repeat: 0,
167
175
  buzzer: stringify(order.buzzer || order.pickup_number || order.metadata?.buzzer),
168
176
  order_no: orderNumber,
169
- order_time: formatDateTime(order.created_at || order.sales_time || new Date(), locale)
177
+ order_time: formatDateTime(order.created_at || order.sales_time || new Date(), locale),
178
+ ...(isPresentId(order.updated_at) ? {
179
+ updated_at: formatDateTime(order.updated_at, locale)
180
+ } : {})
170
181
  };
171
182
  }
172
183
  function buildProducts(order, locale, productMap) {
@@ -200,6 +211,8 @@ function buildProducts(order, locale, productMap) {
200
211
  parentProduct,
201
212
  locale
202
213
  });
214
+ const productUid = firstPresentValue(product.metadata?.unique_identification_number, product.unique_identification_number);
215
+ const bookingUid = firstPresentValue(product.booking_uid, product.metadata?.booking_uid);
203
216
  const extensionList = buildProductExtensionList({
204
217
  product,
205
218
  locale,
@@ -214,6 +227,12 @@ function buildProducts(order, locale, productMap) {
214
227
  original_price: formatMoney(originalPrice, currencySymbol),
215
228
  total_original_price: formatMoney(new _decimal.default(toMoneyNumber(originalPrice)).mul(quantity), currencySymbol),
216
229
  extension_list: extensionList,
230
+ ...(isPresentId(productUid) ? {
231
+ product_uid: productUid
232
+ } : {}),
233
+ ...(isPresentId(bookingUid) ? {
234
+ booking_uid: bookingUid
235
+ } : {}),
217
236
  ...(options.length ? {
218
237
  options
219
238
  } : {}),
@@ -579,6 +598,9 @@ function isNonZeroId(value) {
579
598
  function isPresentId(value) {
580
599
  return value !== undefined && value !== null && value !== '';
581
600
  }
601
+ function firstPresentValue(...values) {
602
+ return values.find(value => isPresentId(value));
603
+ }
582
604
  function isSameId(left, right) {
583
605
  if (!isPresentId(left) || !isPresentId(right)) return false;
584
606
  return String(left) === String(right);
@@ -647,12 +669,13 @@ function buildFees(params) {
647
669
  });
648
670
  }
649
671
  const productExpectAmount = summary.product_expect_amount || summary.product_amount || order.product_expect_amount;
650
- const productOriginalAmount = summary.product_original_amount ?? order.product_original_amount ?? productExpectAmount;
672
+ const productOriginalAmount = firstPresentValue(summary.product_original_amount, order.product_original_amount) ?? calculateProductOriginalAmount(order);
651
673
  const totalSavingsAmount = new _decimal.default(toMoneyNumber(productOriginalAmount)).minus(toMoneyNumber(productExpectAmount)).plus(toMoneyNumber(discountAmount));
652
674
  return {
653
675
  fees,
654
676
  countFee: {
655
677
  total_amount: formatMoney(summary.total_amount || order.total_amount, currencySymbol),
678
+ original_item_amount: formatMoney(productOriginalAmount, currencySymbol),
656
679
  product_expect_amount: formatMoney(productExpectAmount, currencySymbol),
657
680
  expect_amount: formatMoney(summary.expect_amount || order.expect_amount || summary.total_amount || order.total_amount, currencySymbol),
658
681
  product_quantity: toNumber(summary.product_quantity || products.reduce((sum, product) => sum + product.product_quantity, 0), 0),
@@ -675,6 +698,13 @@ function buildFees(params) {
675
698
  }
676
699
  };
677
700
  }
701
+ function calculateProductOriginalAmount(order) {
702
+ return normalizeArray(order.products).reduce((total, product) => {
703
+ const quantity = toNumber(product.product_quantity ?? product.quantity ?? product.num ?? 1, 1);
704
+ const originalPrice = product.original_price ?? product.selling_price ?? product.payment_price ?? product.price ?? 0;
705
+ return total.plus(new _decimal.default(toMoneyNumber(originalPrice)).mul(quantity));
706
+ }, new _decimal.default(0));
707
+ }
678
708
  function buildCustomer(order, locale) {
679
709
  return [{
680
710
  item: label(locale, 'contactName'),
@@ -712,6 +742,27 @@ function buildDelivery(order, locale) {
712
742
  return items;
713
743
  }
714
744
  function buildAppointment(order, locale) {
745
+ const bookings = normalizeArray(order.bookings);
746
+ if (bookings.length) {
747
+ return bookings.map(booking => {
748
+ const snapshot = {
749
+ ...booking
750
+ };
751
+ delete snapshot.product_uid;
752
+ delete snapshot.booking_uid;
753
+ const productUid = firstPresentValue(booking.product_uid, booking.metadata?.product_uid);
754
+ const bookingUid = firstPresentValue(booking.metadata?.unique_identification_number, booking.booking_uid);
755
+ return {
756
+ ...snapshot,
757
+ ...(isPresentId(productUid) ? {
758
+ product_uid: productUid
759
+ } : {}),
760
+ ...(isPresentId(bookingUid) ? {
761
+ booking_uid: bookingUid
762
+ } : {})
763
+ };
764
+ });
765
+ }
715
766
  const tableName = order.table_name || order.metadata?.table_name || order.metadata?.table?.name || order.form_data?.table_name;
716
767
  if (!tableName) return [];
717
768
  return [{
@@ -729,41 +780,81 @@ function buildResources(order, locale) {
729
780
  }
730
781
  function buildPaymentData(params) {
731
782
  const payments = normalizeArray(params.order.payments);
732
- return payments.filter(payment => isPrintablePayment(payment)).map(payment => {
733
- const items = [{
734
- item: paymentMethodName(payment, params.locale),
735
- value: formatMoney(payment.amount ?? payment.origin_amount, params.currencySymbol)
736
- }];
737
- const fundRecord = getFundRecord(payment);
738
- if (fundRecord) {
739
- items.push(...buildFundRecordPaymentItems({
740
- payment,
741
- fundRecord,
742
- locale: params.locale,
743
- currencySymbol: params.currencySymbol
744
- }));
745
- } else {
746
- const remainingAmount = payment.remaining_amount ?? payment.balance ?? payment.metadata?.remaining_amount;
747
- if (remainingAmount !== undefined && remainingAmount !== null) {
748
- items.push({
749
- item: label(params.locale, 'remainingAmount'),
750
- value: formatMoney(remainingAmount, params.currencySymbol)
751
- });
752
- }
753
- }
783
+ return payments.filter(payment => isPrintablePayment(payment)).map(payment => buildPaymentItems({
784
+ payment,
785
+ locale: params.locale,
786
+ currencySymbol: params.currencySymbol,
787
+ includeFundRecordBalance: false
788
+ }));
789
+ }
790
+ function buildWallets(params) {
791
+ return normalizeArray(params.order.payments).filter(payment => isPrintablePayment(payment) && !!getFundRecord(payment)).map(payment => buildPaymentItems({
792
+ payment,
793
+ locale: params.locale,
794
+ currencySymbol: params.currencySymbol,
795
+ includeFundRecordBalance: true
796
+ }));
797
+ }
798
+ function buildPaymentItems(params) {
799
+ const {
800
+ payment,
801
+ locale,
802
+ currencySymbol,
803
+ includeFundRecordBalance
804
+ } = params;
805
+ const serviceFee = getPaymentServiceFee(payment);
806
+ const items = [{
807
+ item: paymentMethodName(payment, locale),
808
+ value: formatMoney(resolveReceiptPaymentAmount(payment, serviceFee), currencySymbol)
809
+ }];
810
+ if (serviceFee.gt(0)) {
754
811
  items.push({
755
- item: formatDateTime(payment.paid_at || payment.created_at || payment.updated_at || new Date(), params.locale),
756
- value: ''
812
+ item: label(locale, 'surchargeIncluded'),
813
+ value: formatMoney(serviceFee, currencySymbol)
757
814
  });
758
- return items;
815
+ }
816
+ const fundRecord = getFundRecord(payment);
817
+ if (fundRecord) {
818
+ items.push(...buildFundRecordPaymentItems({
819
+ payment,
820
+ fundRecord,
821
+ locale,
822
+ currencySymbol,
823
+ includeBalance: includeFundRecordBalance
824
+ }));
825
+ } else {
826
+ const remainingAmount = payment.remaining_amount ?? payment.balance ?? payment.metadata?.remaining_amount;
827
+ if (remainingAmount !== undefined && remainingAmount !== null) {
828
+ items.push({
829
+ item: label(locale, 'remainingAmount'),
830
+ value: formatMoney(remainingAmount, currencySymbol)
831
+ });
832
+ }
833
+ }
834
+ items.push({
835
+ item: formatDateTime(payment.paid_at || payment.created_at || payment.updated_at || new Date(), locale),
836
+ value: ''
759
837
  });
838
+ return items;
839
+ }
840
+ function getPaymentServiceFee(payment) {
841
+ return new _decimal.default(toMoneyNumber(payment.service_fee));
842
+ }
843
+ function resolveReceiptPaymentAmount(payment, serviceFee) {
844
+ const amount = new _decimal.default(toMoneyNumber(payment.amount ?? payment.origin_amount));
845
+ const hasAmount = payment.amount !== undefined && payment.amount !== null && payment.amount !== '';
846
+ const hasOriginAmount = payment.origin_amount !== undefined && payment.origin_amount !== null && payment.origin_amount !== '';
847
+ if (!hasAmount || !hasOriginAmount || serviceFee.lte(0)) return amount;
848
+ const originAmount = new _decimal.default(toMoneyNumber(payment.origin_amount));
849
+ return amount.eq(originAmount) ? amount.plus(serviceFee) : amount;
760
850
  }
761
851
  function buildFundRecordPaymentItems(params) {
762
852
  const {
763
853
  payment,
764
854
  fundRecord,
765
855
  locale,
766
- currencySymbol
856
+ currencySymbol,
857
+ includeBalance
767
858
  } = params;
768
859
  const items = [];
769
860
  const usingBeforeValue = fundRecord.using_before_value;
@@ -774,13 +865,15 @@ function buildFundRecordPaymentItems(params) {
774
865
  item: label(locale, 'redeemPoints'),
775
866
  value: trimDecimal(usedPoints)
776
867
  });
777
- items.push({
778
- item: label(locale, 'remainingPoints'),
779
- value: trimDecimal(new _decimal.default(toMoneyNumber(usingAfterValue)))
780
- });
868
+ if (includeBalance) {
869
+ items.push({
870
+ item: label(locale, 'remainingPoints'),
871
+ value: trimDecimal(new _decimal.default(toMoneyNumber(usingAfterValue)))
872
+ });
873
+ }
781
874
  return items;
782
875
  }
783
- if (usingAfterValue !== undefined && usingAfterValue !== null) {
876
+ if (includeBalance && usingAfterValue !== undefined && usingAfterValue !== null) {
784
877
  items.push({
785
878
  item: label(locale, 'remainingAmount'),
786
879
  value: formatMoney(usingAfterValue, currencySymbol)
@@ -191,9 +191,10 @@ function transformBaseProductToOrderProduct(params) {
191
191
  metadata.unique_identification_number = String(uniqueIdentificationNumber);
192
192
  }
193
193
  // 从源头补充商品多语言标题
194
+ const productTitleI18n = sourceProduct?.title_i18n || {};
194
195
  const productTitle = {
195
- ...(sourceProduct?.title_i18n || {}),
196
- original: sourceProduct?.original_title || sourceProduct?.title || ''
196
+ ...productTitleI18n,
197
+ original: productTitleI18n.original || sourceProduct?.original_title || sourceProduct?.title || ''
197
198
  };
198
199
  return {
199
200
  product_id: productId,
@@ -326,7 +326,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
326
326
  date: string;
327
327
  status: string;
328
328
  week: string;
329
- weekNum: 0 | 2 | 1 | 3 | 4 | 5 | 6;
329
+ weekNum: 0 | 5 | 3 | 1 | 2 | 4 | 6;
330
330
  }[]>;
331
331
  submitTimeSlot(timeSlots: TimeSliceItem): void;
332
332
  private getScheduleDataByIds;
@@ -345,7 +345,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
345
345
  count: number;
346
346
  left: number;
347
347
  summaryCount: number;
348
- status: "lots_of_space" | "filling_up_fast" | "sold_out";
348
+ status: "sold_out" | "lots_of_space" | "filling_up_fast";
349
349
  }[];
350
350
  /**
351
351
  * 找到多个资源的公共可用时间段
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.3.95",
4
+ "version": "2.3.97",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",