@pisell/pisellos 0.0.232 → 0.0.233

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.
@@ -517,7 +517,7 @@ export interface WalletDeductionRecommendParams {
517
517
  /** 订单待支付金额 */
518
518
  order_wait_pay_amount: number;
519
519
  /** 统计计数用户id */
520
- order_behavior_count_customer_id: number;
520
+ order_behavior_count_customer_id?: number;
521
521
  /** 已选商品 */
522
522
  products: {
523
523
  /** 商品id */
@@ -555,6 +555,7 @@ export interface WalletInitBusinessData {
555
555
  quantity: number;
556
556
  selling_price: number;
557
557
  }[];
558
+ order_wait_pay_amount?: number;
558
559
  }
559
560
  /**
560
561
  * 查询用户识别码列表请求参数
@@ -48,15 +48,19 @@ var WalletPassPaymentImpl = class {
48
48
  * 根据业务数据生成标准的钱包API参数,并存储在模块中
49
49
  */
50
50
  generateWalletParams(businessData) {
51
- const { customer_id, amountInfo, products } = businessData;
52
- const totalAmount = Number(amountInfo.subTotal) || Number(amountInfo.totalAmount);
51
+ const { customer_id, amountInfo, products, order_wait_pay_amount } = businessData;
52
+ const totalAmount = Number(amountInfo.totalAmount);
53
+ const subTotal = Number(amountInfo.subTotal);
53
54
  const walletParams = {
54
- sale_channel: "kiosk",
55
- customer_id,
55
+ sale_channel: "pos",
56
+ customer_id: customer_id || 0,
57
+ // 提供默认值,确保类型为 number
56
58
  order_expect_amount: totalAmount,
57
- order_product_amount: totalAmount,
58
- order_wait_pay_amount: totalAmount,
59
- order_behavior_count_customer_id: 1,
59
+ // 订单小计金额
60
+ order_product_amount: subTotal,
61
+ // 订单待支付金额
62
+ order_wait_pay_amount: order_wait_pay_amount || totalAmount,
63
+ // order_behavior_count_customer_id: 1,
60
64
  products,
61
65
  prepare_payments: []
62
66
  };
@@ -135,7 +139,7 @@ var WalletPassPaymentImpl = class {
135
139
  return this.walletRecommendList;
136
140
  } catch (error) {
137
141
  console.error("获取钱包推荐列表失败:", error);
138
- throw error;
142
+ return [];
139
143
  }
140
144
  }
141
145
  formatWalletPassList2PreparePayments(list) {
@@ -164,7 +168,7 @@ var WalletPassPaymentImpl = class {
164
168
  return this.userIdentificationCodes;
165
169
  } catch (error) {
166
170
  console.error("获取用户识别码列表失败:", error);
167
- throw error;
171
+ return [];
168
172
  }
169
173
  }
170
174
  /**
@@ -30,7 +30,7 @@ export declare class ScheduleModule extends BaseModule implements Module, Schedu
30
30
  * @param param0 { date: string, schedule: any } date: 日期, schedule: schedule
31
31
  * @returns
32
32
  */
33
- static isInScheduleByDate({ date, schedule }: {
33
+ static isInScheduleByDate({ date, schedule, }: {
34
34
  date: string;
35
35
  schedule: any;
36
36
  }): true | undefined;
@@ -162,9 +162,12 @@ var ScheduleModule = class extends import_BaseModule.BaseModule {
162
162
  /**
163
163
  * 传入一个时间, 判断改时间是否在schedule 内
164
164
  * @param param0 { date: string, schedule: any } date: 日期, schedule: schedule
165
- * @returns
165
+ * @returns
166
166
  */
167
- static isInScheduleByDate({ date, schedule }) {
167
+ static isInScheduleByDate({
168
+ date,
169
+ schedule
170
+ }) {
168
171
  var _a, _b, _c, _d;
169
172
  let _schedule = {
170
173
  ...schedule,
@@ -173,16 +176,28 @@ var ScheduleModule = class extends import_BaseModule.BaseModule {
173
176
  end_time: (0, import_dayjs.default)(date).add(1, "day").format("YYYY-MM-DD HH:mm:ss")
174
177
  };
175
178
  if (((_b = (_a = _schedule.repeat_rule) == null ? void 0 : _a.end) == null ? void 0 : _b.type) === "never") {
176
- _schedule.repeat_rule.end = {
177
- type: "date",
178
- end_date: _schedule.end_time,
179
- occurrence: null
179
+ _schedule = {
180
+ ..._schedule,
181
+ repeat_rule: {
182
+ ..._schedule.repeat_rule,
183
+ end: {
184
+ type: "date",
185
+ end_date: _schedule.end_time,
186
+ occurrence: null
187
+ }
188
+ }
180
189
  };
181
190
  }
182
191
  if (((_d = (_c = _schedule.repeat_rule) == null ? void 0 : _c.end) == null ? void 0 : _d.type) === "date") {
183
- _schedule.repeat_rule.end = {
184
- ..._schedule.repeat_rule.end,
185
- end_date: _schedule.end_time
192
+ _schedule = {
193
+ ..._schedule,
194
+ repeat_rule: {
195
+ ..._schedule.repeat_rule,
196
+ end: {
197
+ ..._schedule.repeat_rule.end,
198
+ end_date: _schedule.end_time
199
+ }
200
+ }
186
201
  };
187
202
  }
188
203
  const dateRanges = (0, import_utils2.calcScheduleDateRange)({ ..._schedule });
@@ -83,74 +83,93 @@ function findFastestAvailableResource({
83
83
  const currentTime = (0, import_dayjs.default)();
84
84
  let fastestTime = null;
85
85
  let fastestResources = [];
86
+ console.log("[TimeslotUtils] 查找最快可用资源:", {
87
+ currentTime: currentTime.format("YYYY-MM-DD HH:mm:ss"),
88
+ resourceCount: resources.length,
89
+ currentCapacity,
90
+ countMap
91
+ });
86
92
  for (const resource of resources) {
87
93
  const todayTimes = resource.times.filter((time) => {
88
- return (0, import_dayjs.default)(time.start_at).isSame(currentTime, "day");
94
+ const isToday = (0, import_dayjs.default)(time.start_at).isSame(currentTime, "day");
95
+ const isStillWorking = (0, import_dayjs.default)(time.end_at).isAfter(currentTime);
96
+ return isToday && isStillWorking;
89
97
  });
90
- if (todayTimes.length === 0)
98
+ if (todayTimes.length === 0) {
99
+ console.log(`[TimeslotUtils] 资源 ${resource.id}(${resource.main_field}) 今日无可用时间段`);
91
100
  continue;
92
- todayTimes.sort((a, b) => {
93
- return (0, import_dayjs.default)(a.start_at).diff((0, import_dayjs.default)(b.start_at));
94
- });
101
+ }
95
102
  for (const time of todayTimes) {
96
- const startTime = (0, import_dayjs.default)(time.start_at);
97
- if (startTime.isBefore(currentTime))
98
- continue;
99
- if (resource.resourceType === "single") {
100
- const hasBooking = (_a = time.event_list) == null ? void 0 : _a.some((event) => {
101
- return (0, import_dayjs.default)(event.start_at).isSame(startTime);
103
+ const workStartTime = (0, import_dayjs.default)(time.start_at);
104
+ const workEndTime = (0, import_dayjs.default)(time.end_at);
105
+ let nextAvailableTime = currentTime.isBefore(workStartTime) ? workStartTime : currentTime;
106
+ console.log(`[TimeslotUtils] 检查资源 ${resource.id}(${resource.main_field}):`, {
107
+ workTime: `${workStartTime.format("HH:mm")}-${workEndTime.format("HH:mm")}`,
108
+ checkStartTime: nextAvailableTime.format("HH:mm:ss"),
109
+ eventCount: ((_a = time.event_list) == null ? void 0 : _a.length) || 0
110
+ });
111
+ const relevantEvents = ((_b = time.event_list) == null ? void 0 : _b.filter((event) => {
112
+ const eventEnd = (0, import_dayjs.default)(event.end_at);
113
+ return eventEnd.isAfter(nextAvailableTime);
114
+ })) || [];
115
+ relevantEvents.sort(
116
+ (a, b) => (0, import_dayjs.default)(a.start_at).diff((0, import_dayjs.default)(b.start_at))
117
+ );
118
+ let finalAvailableTime = nextAvailableTime;
119
+ for (const event of relevantEvents) {
120
+ const eventStart = (0, import_dayjs.default)(event.start_at);
121
+ const eventEnd = (0, import_dayjs.default)(event.end_at);
122
+ console.log(`[TimeslotUtils] 检查事件冲突:`, {
123
+ resourceId: resource.id,
124
+ eventTime: `${eventStart.format("HH:mm")}-${eventEnd.format("HH:mm")}`,
125
+ checkTime: finalAvailableTime.format("HH:mm:ss"),
126
+ pax: event.pax || 1
102
127
  });
103
- if (!hasBooking) {
104
- if (!fastestTime || startTime.isSame(fastestTime)) {
105
- fastestTime = startTime;
106
- fastestResources.push(resource);
107
- } else if (startTime.isBefore(fastestTime)) {
108
- fastestTime = startTime;
109
- fastestResources = [resource];
128
+ if (resource.resourceType === "single" || (resource.capacity || 1) === 1) {
129
+ if (finalAvailableTime.isBefore(eventEnd) && eventStart.isBefore(finalAvailableTime.add(30, "minute"))) {
130
+ finalAvailableTime = eventEnd;
131
+ console.log(`[TimeslotUtils] 发现时间冲突,调整到: ${finalAvailableTime.format("HH:mm:ss")}`);
110
132
  }
111
- break;
112
- }
113
- } else {
114
- const totalCapacity = resource.capacity || 0;
115
- const usedCapacity = ((_b = time.event_list) == null ? void 0 : _b.reduce((sum, event) => {
116
- return (0, import_dayjs.default)(event.start_at).isSame(startTime) ? sum + (event.pax || 0) : sum;
117
- }, 0)) || 0;
118
- const remainingCapacity = totalCapacity - usedCapacity;
119
- if (remainingCapacity >= (countMap[resource.id] || 0) + currentCapacity) {
120
- if (!fastestTime || startTime.isSame(fastestTime)) {
121
- fastestTime = startTime;
122
- fastestResources.push(resource);
123
- } else if (startTime.isBefore(fastestTime)) {
124
- fastestTime = startTime;
125
- fastestResources = [resource];
133
+ } else {
134
+ const totalCapacity = resource.capacity || 0;
135
+ const currentUsedCapacity = countMap[resource.id] || 0;
136
+ const eventUsedCapacity = event.pax || 1;
137
+ if (finalAvailableTime.isBefore(eventEnd) && eventStart.isBefore(finalAvailableTime.add(30, "minute"))) {
138
+ const totalRequiredCapacity = currentUsedCapacity + currentCapacity + eventUsedCapacity;
139
+ if (totalRequiredCapacity > totalCapacity) {
140
+ finalAvailableTime = eventEnd;
141
+ console.log(`[TimeslotUtils] 容量不足,调整到: ${finalAvailableTime.format("HH:mm:ss")}`);
142
+ }
126
143
  }
127
- break;
128
144
  }
129
145
  }
146
+ if (finalAvailableTime.isAfter(workEndTime)) {
147
+ console.log(`[TimeslotUtils] 资源 ${resource.id} 可用时间超出工作时间,跳过`);
148
+ continue;
149
+ }
150
+ console.log(`[TimeslotUtils] 资源 ${resource.id}(${resource.main_field}) 最快可用时间: ${finalAvailableTime.format("HH:mm:ss")}`);
151
+ if (!fastestTime || finalAvailableTime.isBefore(fastestTime)) {
152
+ fastestTime = finalAvailableTime;
153
+ fastestResources = [resource];
154
+ console.log(`[TimeslotUtils] 更新最快时间: ${fastestTime.format("HH:mm:ss")}, 资源: ${resource.main_field}`);
155
+ } else if (finalAvailableTime.isSame(fastestTime)) {
156
+ fastestResources.push(resource);
157
+ console.log(`[TimeslotUtils] 添加相同时间资源: ${resource.main_field}`);
158
+ }
159
+ break;
130
160
  }
131
161
  }
132
- if (!fastestTime || fastestResources.length === 0)
162
+ if (!fastestTime || fastestResources.length === 0) {
163
+ console.log("[TimeslotUtils] 未找到可用资源");
133
164
  return null;
134
- if (fastestResources.length === 1)
165
+ }
166
+ console.log(`[TimeslotUtils] 找到 ${fastestResources.length} 个最快可用资源,时间: ${fastestTime.format("HH:mm:ss")}`);
167
+ if (fastestResources.length === 1) {
168
+ console.log(`[TimeslotUtils] 返回唯一最快资源: ${fastestResources[0].main_field}`);
135
169
  return fastestResources[0];
136
- let maxIdleTime = 0;
137
- let selectedResource = null;
138
- for (const resource of fastestResources) {
139
- const idleTime = calculateResourceAvailableTime({
140
- resource,
141
- timeSlots: {
142
- start_time: fastestTime.format("HH:mm"),
143
- end_time: fastestTime.format("HH:mm"),
144
- start_at: fastestTime,
145
- end_at: fastestTime
146
- },
147
- currentCapacity: (countMap[resource.id] || 0) + currentCapacity
148
- });
149
- if (idleTime > maxIdleTime) {
150
- maxIdleTime = idleTime;
151
- selectedResource = resource;
152
- }
153
170
  }
171
+ const selectedResource = fastestResources[0];
172
+ console.log(`[TimeslotUtils] 返回多个资源中的第一个: ${selectedResource.main_field}`);
154
173
  return selectedResource;
155
174
  }
156
175
  function filterConditionTimeSlots(times, startTime, endTime) {
@@ -111,7 +111,7 @@ export declare class BookingTicketImpl extends BaseModule implements Module {
111
111
  * 获取当前的客户搜索条件
112
112
  * @returns 当前搜索条件
113
113
  */
114
- getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "skip" | "num">;
114
+ getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "num" | "skip">;
115
115
  /**
116
116
  * 获取客户列表状态(包含滚动加载相关状态)
117
117
  * @returns 客户状态
@@ -40,6 +40,9 @@ export declare class CheckoutImpl extends BaseModule implements Module, Checkout
40
40
  quantity: number;
41
41
  selling_price: number;
42
42
  }[];
43
+ initWalletData(params?: {
44
+ order_wait_pay_amount: number;
45
+ }): Promise<void>;
43
46
  /**
44
47
  * 创建本地订单 (前端模拟下单流程)
45
48
  *
@@ -124,14 +124,40 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
124
124
  if (!this.store.currentOrder) {
125
125
  return [];
126
126
  }
127
- const productList = (_a = this.store.currentOrder.order_info) == null ? void 0 : _a.original_order_data.bookings.map((item) => ({
128
- product_id: item.product.product_id,
129
- product_variant_id: item.product.product_variant_id,
130
- quantity: item.product.num,
131
- selling_price: item.product.price - (item.product.discount_amount || 0)
132
- }));
127
+ const getDiscountListAmount = (list) => {
128
+ return list.reduce((pre, item) => {
129
+ return pre + (item.amount || 0);
130
+ }, 0);
131
+ };
132
+ const productList = (_a = this.store.currentOrder.order_info) == null ? void 0 : _a.original_order_data.bookings.map(
133
+ (item) => ({
134
+ product_id: item.product.product_id,
135
+ product_variant_id: item.product.product_variant_id,
136
+ quantity: item.product.num,
137
+ selling_price: item.product.price - (item.product.discount_amount || 0) - getDiscountListAmount(item.product.discount_list)
138
+ })
139
+ );
133
140
  return productList;
134
141
  }
142
+ async initWalletData(params) {
143
+ var _a, _b, _c;
144
+ const amountInfo = (_b = (_a = this.store.currentOrder) == null ? void 0 : _a.order_info) == null ? void 0 : _b.amount_breakdown;
145
+ if (!amountInfo) {
146
+ return;
147
+ }
148
+ const walletBusinessData = {
149
+ customer_id: ((_c = this.store.currentCustomer) == null ? void 0 : _c.customer_id) ? Number(this.store.currentCustomer.customer_id) : void 0,
150
+ amountInfo: {
151
+ totalAmount: amountInfo.totalAmount,
152
+ subTotal: amountInfo.subTotal
153
+ },
154
+ products: this.getProductListByOrder(),
155
+ ...params
156
+ };
157
+ await this.payment.wallet.initializeWalletDataFromBusinessAsync(
158
+ walletBusinessData
159
+ );
160
+ }
135
161
  /**
136
162
  * 创建本地订单 (前端模拟下单流程)
137
163
  *
@@ -140,7 +166,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
140
166
  * 方法会记录参数并创建本地虚拟订单,然后用 Payment 模块管理支付流程。
141
167
  */
142
168
  async createLocalOrderAsync(params) {
143
- var _a, _b, _c, _d, _e;
169
+ var _a, _b, _c, _d;
144
170
  try {
145
171
  await this.setStatus(import_types.CheckoutStatus.CreatingOrder);
146
172
  const validation = await this.validateLocalOrderData(params.orderData);
@@ -186,17 +212,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
186
212
  }
187
213
  });
188
214
  this.store.currentOrder = paymentOrder;
189
- const walletBusinessData = {
190
- customer_id: ((_e = this.store.currentCustomer) == null ? void 0 : _e.customer_id) ? Number(this.store.currentCustomer.customer_id) : void 0,
191
- amountInfo: {
192
- totalAmount: amountInfo.totalAmount,
193
- subTotal: amountInfo.subTotal
194
- },
195
- products: this.getProductListByOrder()
196
- };
197
- const walletData = await this.payment.wallet.initializeWalletDataFromBusinessAsync(walletBusinessData);
198
- console.log(walletData.walletRecommendList, "walletRecommendList");
199
- console.log(walletData.userIdentificationCodes, "userIdentificationCodes");
215
+ await this.initWalletData();
200
216
  await this.setStatus(import_types.CheckoutStatus.OrderCreated);
201
217
  await this.setStep(import_types.CheckoutStep.PaymentMethod);
202
218
  if (params.autoPayment) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.232",
4
+ "version": "0.0.233",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",