@pisell/pisellos 2.2.248 → 2.2.250

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.
@@ -805,9 +805,12 @@ var OrderModule = class extends import_BaseModule.BaseModule {
805
805
  return ((_a = result == null ? void 0 : result.data) == null ? void 0 : _a.order_id) ?? (result == null ? void 0 : result.order_id) ?? ((_b = result == null ? void 0 : result.data) == null ? void 0 : _b.id) ?? (result == null ? void 0 : result.id) ?? null;
806
806
  }
807
807
  calculatePaymentEffectiveAmount(payment) {
808
- const amount = new import_decimal.default(payment.amount || 0).minus(new import_decimal.default(payment.service_fee || 0));
808
+ const amount = new import_decimal.default(payment.amount || 0);
809
+ const originAmount = new import_decimal.default(payment.origin_amount ?? payment.amount ?? 0);
810
+ const serviceFee = new import_decimal.default(payment.service_fee || 0);
811
+ const effectiveAmount = serviceFee.gt(0) && amount.eq(originAmount) ? amount.plus(serviceFee) : amount;
809
812
  const rounding = new import_decimal.default(payment.rounding_amount || 0);
810
- return amount.minus(rounding);
813
+ return effectiveAmount.minus(rounding);
811
814
  }
812
815
  calculatePaymentTotal(payments) {
813
816
  return (0, import_utils.mapPaymentItemsToOrderPayments)(payments, {
@@ -422,6 +422,10 @@ declare class Server {
422
422
  private canAssignStringProductTitleToLocale;
423
423
  private hasCjkText;
424
424
  private resolveFirstProductTitleValue;
425
+ private getPaymentCodeKey;
426
+ private isBlankPaymentName;
427
+ private shouldLookupPaymentMethodNameByCode;
428
+ private enrichPaymentNamesByCode;
425
429
  private withLocalSmallTicketData;
426
430
  private handleOrderSalesDetail;
427
431
  /**
@@ -3091,22 +3091,85 @@ var Server = class {
3091
3091
  );
3092
3092
  return firstValue === void 0 ? null : String(firstValue);
3093
3093
  }
3094
+ getPaymentCodeKey(code) {
3095
+ if (code === void 0 || code === null)
3096
+ return "";
3097
+ return String(code).trim().toUpperCase();
3098
+ }
3099
+ isBlankPaymentName(name) {
3100
+ if (name === void 0 || name === null)
3101
+ return true;
3102
+ if (typeof name === "string")
3103
+ return name.trim() === "";
3104
+ return false;
3105
+ }
3106
+ shouldLookupPaymentMethodNameByCode(code) {
3107
+ const codeKey = this.getPaymentCodeKey(code);
3108
+ if (!codeKey)
3109
+ return false;
3110
+ const builtInNameTokens = ["CASH", "EFTPOS", "CARD", "WALLET", "GIFT"];
3111
+ return !builtInNameTokens.some((token) => codeKey.includes(token));
3112
+ }
3113
+ async enrichPaymentNamesByCode(order) {
3114
+ const payments = Array.isArray(order == null ? void 0 : order.payments) ? order.payments : [];
3115
+ const hasMissingName = payments.some((payment) => this.isBlankPaymentName(payment == null ? void 0 : payment.name) && this.shouldLookupPaymentMethodNameByCode(payment == null ? void 0 : payment.code));
3116
+ if (!hasMissingName)
3117
+ return order;
3118
+ try {
3119
+ const paymentModule = await this.getPaymentRouteModule();
3120
+ const payMethods = await paymentModule.getPayMethodListAsync();
3121
+ const nameByCode = /* @__PURE__ */ new Map();
3122
+ for (const method of payMethods || []) {
3123
+ const codeKey = this.getPaymentCodeKey(method == null ? void 0 : method.code);
3124
+ const name = this.resolveFirstProductTitleValue(method == null ? void 0 : method.name);
3125
+ if (codeKey && name)
3126
+ nameByCode.set(codeKey, name);
3127
+ }
3128
+ let hasResolvedName = false;
3129
+ const enrichedPayments = payments.map((payment) => {
3130
+ if (!this.isBlankPaymentName(payment == null ? void 0 : payment.name))
3131
+ return payment;
3132
+ if (!this.shouldLookupPaymentMethodNameByCode(payment == null ? void 0 : payment.code))
3133
+ return payment;
3134
+ const name = nameByCode.get(this.getPaymentCodeKey(payment == null ? void 0 : payment.code));
3135
+ if (!name)
3136
+ return payment;
3137
+ hasResolvedName = true;
3138
+ return {
3139
+ ...payment,
3140
+ name
3141
+ };
3142
+ });
3143
+ if (!hasResolvedName)
3144
+ return order;
3145
+ return {
3146
+ ...order,
3147
+ payments: enrichedPayments
3148
+ };
3149
+ } catch (error) {
3150
+ this.logWarning("enrichPaymentNamesByCode: 支付方式名称回填失败", {
3151
+ error: error instanceof Error ? error.message : String(error)
3152
+ });
3153
+ return order;
3154
+ }
3155
+ }
3094
3156
  async withLocalSmallTicketData(order, options) {
3095
3157
  if (!this.shouldBuildSmallTicketData(order))
3096
3158
  return order;
3097
3159
  if ((options == null ? void 0 : options.requireFullyPaid) && !this.isSalesOrderFullyPaid(order))
3098
3160
  return order;
3099
3161
  try {
3100
- const productMap = (options == null ? void 0 : options.productMap) ?? await this.buildSmallTicketProductMap(order);
3162
+ const enrichedOrder = await this.enrichPaymentNamesByCode(order);
3163
+ const productMap = (options == null ? void 0 : options.productMap) ?? await this.buildSmallTicketProductMap(enrichedOrder);
3101
3164
  const smallTicketData = (0, import_small_ticket.buildSmallTicketData)({
3102
- order,
3165
+ order: enrichedOrder,
3103
3166
  shopInfo: this.getSmallTicketShopInfo(),
3104
3167
  productMap
3105
3168
  });
3106
3169
  return {
3107
- ...order,
3170
+ ...enrichedOrder,
3108
3171
  payment_info: {
3109
- ...order.payment_info || {},
3172
+ ...enrichedOrder.payment_info || {},
3110
3173
  small_ticket_data: smallTicketData
3111
3174
  }
3112
3175
  };
@@ -3985,6 +4048,8 @@ var Server = class {
3985
4048
  if (changedOrders.length === 0) {
3986
4049
  return;
3987
4050
  }
4051
+ if (window.isPaymentModalPluginOpen)
4052
+ return;
3988
4053
  for (const [subscriberId, subscriber] of this.salesSearchSubscribers.entries()) {
3989
4054
  try {
3990
4055
  const changedVisibleOrders = changedOrders.filter((order) => {
@@ -193,8 +193,10 @@ export declare class OrderModule extends BaseModule implements Module {
193
193
  private findOrderIndexByIdentity;
194
194
  private getOrderCompletenessScore;
195
195
  private pickPreferredOrder;
196
- private getProductMergeKey;
196
+ private getProductIdentityKeys;
197
197
  private mergeOrderProductLists;
198
+ private getPaymentMergeKey;
199
+ private mergeOrderPaymentLists;
198
200
  private mergeOrderRecords;
199
201
  private summarizeDuplicateOrders;
200
202
  private logDuplicateOrders;
@@ -1141,24 +1141,25 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1141
1141
  return right;
1142
1142
  return left;
1143
1143
  }
1144
- getProductMergeKey(product) {
1144
+ getProductIdentityKeys(product) {
1145
1145
  var _a;
1146
1146
  const record = product;
1147
1147
  if (!record)
1148
- return "";
1148
+ return [];
1149
+ const keys = [];
1149
1150
  const metadataUid = (_a = record.metadata) == null ? void 0 : _a.unique_identification_number;
1150
1151
  if (!this.isBlankIdentityValue(metadataUid))
1151
- return `uid:${String(metadataUid)}`;
1152
+ keys.push(`uid:${String(metadataUid)}`);
1152
1153
  const topLevelUid = record.unique_identification_number;
1153
1154
  if (!this.isBlankIdentityValue(topLevelUid))
1154
- return `uid:${String(topLevelUid)}`;
1155
+ keys.push(`uid:${String(topLevelUid)}`);
1155
1156
  const orderDetailId = record.order_detail_id;
1156
1157
  if (!this.isBlankIdentityValue(orderDetailId))
1157
- return `detail:${String(orderDetailId)}`;
1158
+ keys.push(`detail:${String(orderDetailId)}`);
1158
1159
  const bookingUid = record.booking_uid;
1159
1160
  if (!this.isBlankIdentityValue(bookingUid))
1160
- return `booking:${String(bookingUid)}`;
1161
- return "";
1161
+ keys.push(`booking:${String(bookingUid)}`);
1162
+ return keys;
1162
1163
  }
1163
1164
  mergeOrderProductLists(preferred, secondary) {
1164
1165
  const preferredList = Array.isArray(preferred) ? preferred : [];
@@ -1169,20 +1170,70 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1169
1170
  return secondaryList;
1170
1171
  const seenKeys = /* @__PURE__ */ new Set();
1171
1172
  for (const item of preferredList) {
1172
- const key = this.getProductMergeKey(item);
1173
- if (key)
1173
+ const keys = this.getProductIdentityKeys(item);
1174
+ for (const key of keys)
1174
1175
  seenKeys.add(key);
1175
1176
  }
1176
1177
  const result = [...preferredList];
1177
1178
  for (const item of secondaryList) {
1178
- const key = this.getProductMergeKey(item);
1179
- if (!key || seenKeys.has(key))
1179
+ const keys = this.getProductIdentityKeys(item);
1180
+ if (keys.length === 0 || keys.some((key) => seenKeys.has(key)))
1180
1181
  continue;
1181
- seenKeys.add(key);
1182
+ for (const key of keys)
1183
+ seenKeys.add(key);
1182
1184
  result.push((0, import_lodash_es.cloneDeep)(item));
1183
1185
  }
1184
1186
  return result;
1185
1187
  }
1188
+ getPaymentMergeKey(payment) {
1189
+ var _a;
1190
+ const record = payment;
1191
+ if (!record)
1192
+ return "";
1193
+ const uniquePaymentNumber = (_a = record.metadata) == null ? void 0 : _a.unique_payment_number;
1194
+ if (!this.isBlankIdentityValue(uniquePaymentNumber)) {
1195
+ return `unique:${String(uniquePaymentNumber)}`;
1196
+ }
1197
+ const orderPaymentId = record.order_payment_id;
1198
+ if (!this.isBlankIdentityValue(orderPaymentId))
1199
+ return `order_payment:${String(orderPaymentId)}`;
1200
+ const code = record.code;
1201
+ const customPaymentId = record.custom_payment_id;
1202
+ if (!this.isBlankIdentityValue(code) && !this.isBlankIdentityValue(customPaymentId)) {
1203
+ return `custom:${String(code)}#${String(customPaymentId)}`;
1204
+ }
1205
+ return "";
1206
+ }
1207
+ mergeOrderPaymentLists(existing, incoming) {
1208
+ const existingList = Array.isArray(existing) ? existing : [];
1209
+ const incomingList = Array.isArray(incoming) ? incoming : [];
1210
+ if (incomingList.length === 0)
1211
+ return (0, import_lodash_es.cloneDeep)(existingList);
1212
+ if (existingList.length === 0)
1213
+ return (0, import_lodash_es.cloneDeep)(incomingList);
1214
+ const existingByKey = /* @__PURE__ */ new Map();
1215
+ for (const payment of existingList) {
1216
+ const key = this.getPaymentMergeKey(payment);
1217
+ if (!key)
1218
+ continue;
1219
+ existingByKey.set(key, payment);
1220
+ }
1221
+ return incomingList.map((payment) => {
1222
+ const incomingPayment = payment;
1223
+ const key = this.getPaymentMergeKey(incomingPayment);
1224
+ const existingPayment = key ? existingByKey.get(key) : void 0;
1225
+ if (!existingPayment)
1226
+ return (0, import_lodash_es.cloneDeep)(incomingPayment);
1227
+ return {
1228
+ ...(0, import_lodash_es.cloneDeep)(existingPayment),
1229
+ ...(0, import_lodash_es.cloneDeep)(incomingPayment),
1230
+ metadata: {
1231
+ ...(0, import_lodash_es.cloneDeep)(existingPayment.metadata || {}),
1232
+ ...(0, import_lodash_es.cloneDeep)(incomingPayment.metadata || {})
1233
+ }
1234
+ };
1235
+ });
1236
+ }
1186
1237
  mergeOrderRecords(existing, incoming, options) {
1187
1238
  const preferred = this.pickPreferredOrder(existing, incoming);
1188
1239
  const secondary = preferred === existing ? incoming : existing;
@@ -1204,7 +1255,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1204
1255
  "updated_at",
1205
1256
  "shop_discount",
1206
1257
  "summary",
1207
- "payments",
1208
1258
  "products",
1209
1259
  "bookings"
1210
1260
  ];
@@ -1212,6 +1262,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1212
1262
  const preferredRecord = preferred;
1213
1263
  const secondaryRecord = secondary;
1214
1264
  const incomingRecord = incoming;
1265
+ const previousRecord = preferred === incoming ? secondaryRecord : preferredRecord;
1215
1266
  for (const field of fieldsToPreserve) {
1216
1267
  if (!this.isBlankIdentityValue(preferredRecord[field])) {
1217
1268
  mergedRecord[field] = preferredRecord[field];
@@ -1233,6 +1284,16 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1233
1284
  mergedRecord[field] = (0, import_lodash_es.cloneDeep)(incomingRecord[field]);
1234
1285
  }
1235
1286
  mergedRecord.products = shouldUseIncomingProductsSnapshot ? (0, import_lodash_es.cloneDeep)(incomingRecord.products) : this.mergeOrderProductLists(preferredRecord.products, secondaryRecord.products);
1287
+ if (Object.prototype.hasOwnProperty.call(incomingRecord, "payments")) {
1288
+ if (Array.isArray(incomingRecord.payments)) {
1289
+ mergedRecord.payments = this.mergeOrderPaymentLists(
1290
+ previousRecord.payments,
1291
+ incomingRecord.payments
1292
+ );
1293
+ } else if (incomingRecord.payments !== void 0 && incomingRecord.payments !== null) {
1294
+ mergedRecord.payments = (0, import_lodash_es.cloneDeep)(incomingRecord.payments);
1295
+ }
1296
+ }
1236
1297
  if (!this.isPendingSyncOrder(preferred) || !this.isPendingSyncOrder(secondary)) {
1237
1298
  merged.need_sync = 0;
1238
1299
  }
@@ -1465,8 +1465,11 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1465
1465
  const paymentTimestamp = (0, import_dayjs.default)().format("YYYY-MM-DD HH:mm:ss");
1466
1466
  const paymentTime = paymentRecord.payment_time ?? paymentTimestamp;
1467
1467
  const createdAt = paymentRecord.created_at ?? paymentTimestamp;
1468
+ const serviceCharge = paymentRecord.service_charge && typeof paymentRecord.service_charge === "object" ? paymentRecord.service_charge : null;
1469
+ const calculatedServiceFee = serviceCharge ? new import_decimal.default(paymentRecord.origin_amount ?? paymentRecord.amount ?? 0).times(serviceCharge.percentage || 0).plus(serviceCharge.amount || 0).toDecimalPlaces(2).toFixed(2) : void 0;
1468
1470
  const payments = this.store.order.addOrderPayment({
1469
1471
  ...paymentRecord,
1472
+ ...calculatedServiceFee !== void 0 ? { service_fee: calculatedServiceFee } : {},
1470
1473
  metadata,
1471
1474
  payment_time: paymentTime,
1472
1475
  created_at: createdAt
@@ -207,6 +207,10 @@ function transformBaseProductToOrderProduct(params) {
207
207
  if (uniqueIdentificationNumber) {
208
208
  metadata.unique_identification_number = String(uniqueIdentificationNumber);
209
209
  }
210
+ const productTitle = {
211
+ ...(sourceProduct == null ? void 0 : sourceProduct.title_i18n) || {},
212
+ original: (sourceProduct == null ? void 0 : sourceProduct.title) || ""
213
+ };
210
214
  return {
211
215
  product_id: productId,
212
216
  product_variant_id: productVariantId,
@@ -231,6 +235,7 @@ function transformBaseProductToOrderProduct(params) {
231
235
  ),
232
236
  metadata,
233
237
  note: payload.note != null ? String(payload.note) : "",
238
+ product_title: productTitle,
234
239
  _origin: {
235
240
  ...sourceProduct || {},
236
241
  callbackData: payload
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.2.248",
4
+ "version": "2.2.250",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",