@pisell/pisellos 2.2.131 → 2.2.133

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.
@@ -480,7 +480,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
480
480
  this.setDiscountList(newDiscountList || []);
481
481
  this.store.originalDiscountList = newDiscountList || [];
482
482
  this.setProductList(newProductList || []);
483
- if (!(this.isWalkIn() && resultDiscountList.length && ((_this$options$otherPa6 = this.options.otherParams) === null || _this$options$otherPa6 === void 0 ? void 0 : _this$options$otherPa6.platform) === 'shop')) {
483
+ if (!(this.isWalkIn() && resultDiscountList.length && ((_this$options$otherPa6 = this.options.otherParams) === null || _this$options$otherPa6 === void 0 ? void 0 : _this$options$otherPa6.platform) === 'shop' && !((resultDiscountList[0].customer_id || 1) === 1))) {
484
484
  _context5.next = 24;
485
485
  break;
486
486
  }
package/lib/core/index.js CHANGED
@@ -50,7 +50,6 @@ var PisellOSCore = class {
50
50
  this.serverOptions = options.server;
51
51
  }
52
52
  this.initialize(options);
53
- console.log("initialize123");
54
53
  }
55
54
  initialize(options) {
56
55
  if (options == null ? void 0 : options.plugins) {
@@ -0,0 +1,49 @@
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);
28
+
29
+ // src/model/strategy/adapter/promotion/index.ts
30
+ var promotion_exports = {};
31
+ __export(promotion_exports, {
32
+ BUY_X_GET_Y_FREE_STRATEGY: () => import_examples.BUY_X_GET_Y_FREE_STRATEGY,
33
+ PromotionAdapter: () => import_adapter.PromotionAdapter,
34
+ PromotionEvaluator: () => import_evaluator.PromotionEvaluator,
35
+ X_ITEMS_FOR_Y_PRICE_STRATEGY: () => import_examples.X_ITEMS_FOR_Y_PRICE_STRATEGY,
36
+ default: () => import_adapter2.default
37
+ });
38
+ module.exports = __toCommonJS(promotion_exports);
39
+ var import_evaluator = require("./evaluator");
40
+ var import_adapter = require("./adapter");
41
+ var import_adapter2 = __toESM(require("./adapter"));
42
+ var import_examples = require("./examples");
43
+ // Annotate the CommonJS export names for ESM import in node:
44
+ 0 && (module.exports = {
45
+ BUY_X_GET_Y_FREE_STRATEGY,
46
+ PromotionAdapter,
47
+ PromotionEvaluator,
48
+ X_ITEMS_FOR_Y_PRICE_STRATEGY
49
+ });
@@ -19,7 +19,7 @@ interface PackageSubItemUsageRules {
19
19
  type: 'universal_discount' | 'package_exclusive' | 'single_item_promo' | 'custom_usage_rules';
20
20
  rules: ("original_price" | "markup_price")[];
21
21
  package_scope?: {
22
- type: 'all_packages' | 'specific_packages';
22
+ type: 'all_packages' | 'specific_packages' | 'product_all' | 'products';
23
23
  exclude_bundle_product_ids: number[];
24
24
  include_bundle_product_ids: number[];
25
25
  filter: 0 | 1;
@@ -105,12 +105,12 @@ var RulesModule = class extends import_BaseModule.BaseModule {
105
105
  };
106
106
  }
107
107
  const filteredOldDiscountList = oldDiscountList.filter(
108
- (discount) => !discount.isEditMode && discount.tag !== "good_pass"
109
- );
110
- const mergedDiscountList = (0, import_utils.uniqueById)(
111
- (0, import_utils.uniqueById)([...filteredOldDiscountList, ...newDiscountList]),
112
- "product_id"
108
+ (discount) => !discount.isEditMode && (discount.tag !== "good_pass" || discount.isScan)
113
109
  );
110
+ const mergedDiscountList = (0, import_utils.uniqueById)([
111
+ ...filteredOldDiscountList,
112
+ ...newDiscountList
113
+ ]);
114
114
  const result = this.calcDiscount(
115
115
  {
116
116
  discountList: mergedDiscountList,
@@ -1621,14 +1621,14 @@ var RulesModule = class extends import_BaseModule.BaseModule {
1621
1621
  const _isMarkupPrice = isMarkupPrice && rules.includes("markup_price");
1622
1622
  const isPriceValid = _isOriginalPrice || _isMarkupPrice;
1623
1623
  let isScopeValid = false;
1624
- if (scopeType === "all_packages") {
1624
+ if (scopeType === "all_packages" || scopeType === "product_all") {
1625
1625
  if (!filter) {
1626
1626
  isScopeValid = true;
1627
1627
  } else {
1628
1628
  isScopeValid = !exclude_bundle_product_ids.includes(Number(mainProductId));
1629
1629
  }
1630
1630
  }
1631
- if (scopeType === "specific_packages") {
1631
+ if (scopeType === "specific_packages" || scopeType === "products") {
1632
1632
  isScopeValid = include_bundle_product_ids.includes(Number(mainProductId));
1633
1633
  }
1634
1634
  if (isPriceValid && isScopeValid) {
@@ -166,6 +166,11 @@ declare class Server {
166
166
  * 存储订阅者信息,便于数据变更时推送最新结果
167
167
  */
168
168
  private handleProductQuery;
169
+ /**
170
+ * 按商品 id 查询单条(GET /shop/product/query/:productId)
171
+ * schedule_date 必填:query 或 data;schedule_datetime 可选。不走订阅。
172
+ */
173
+ private handleProductQueryById;
169
174
  /**
170
175
  * 取消商品查询订阅(HTTP 路由入口)
171
176
  */
@@ -168,6 +168,49 @@ var Server = class {
168
168
  }
169
169
  return this.computeProductQueryResult({ menu_list_ids, schedule_date, schedule_datetime });
170
170
  };
171
+ /**
172
+ * 按商品 id 查询单条(GET /shop/product/query/:productId)
173
+ * schedule_date 必填:query 或 data;schedule_datetime 可选。不走订阅。
174
+ */
175
+ this.handleProductQueryById = async ({ path, method, data, url }) => {
176
+ const pathname = this.parseRequestPath(url || "", path);
177
+ const idMatch = pathname.match(/^\/shop\/product\/query\/(\d+)$/);
178
+ const productId = idMatch ? Number(idMatch[1]) : NaN;
179
+ console.log("[Server] handleProductQueryById:", pathname, method, data);
180
+ if (!Number.isFinite(productId)) {
181
+ this.logWarning("handleProductQueryById: 无效的商品 id", { path: pathname });
182
+ return {
183
+ code: 400,
184
+ message: "无效的商品路径",
185
+ status: false,
186
+ data: { item: null }
187
+ };
188
+ }
189
+ const scheduleDateFromData = data && typeof data === "object" && typeof data.schedule_date === "string" ? data.schedule_date.trim() : "";
190
+ const schedule_date = scheduleDateFromData || (this.extractQueryParam(url || "", "schedule_date") || "").trim() || (0, import_dayjs.default)().format("YYYY-MM-DD");
191
+ if (!schedule_date) {
192
+ this.logWarning("handleProductQueryById: 缺少 schedule_date", { productId });
193
+ return {
194
+ code: 400,
195
+ message: "schedule_date 为必填(query 或 data)",
196
+ status: false,
197
+ data: null
198
+ };
199
+ }
200
+ const scheduleDtFromData = data && typeof data === "object" && typeof data.schedule_datetime === "string" ? data.schedule_datetime.trim() : "";
201
+ const scheduleDtFromUrl = (this.extractQueryParam(url || "", "schedule_datetime") || "").trim();
202
+ const scheduleDatetime = scheduleDtFromData || scheduleDtFromUrl || `${schedule_date}T00:00:00`;
203
+ this.logInfo("handleProductQueryById: 开始", {
204
+ productId,
205
+ schedule_date,
206
+ schedule_datetime: scheduleDatetime
207
+ });
208
+ return this.computeProductQueryResult({
209
+ schedule_date,
210
+ schedule_datetime: scheduleDatetime,
211
+ product_id: productId
212
+ });
213
+ };
171
214
  /**
172
215
  * 取消商品查询订阅(HTTP 路由入口)
173
216
  */
@@ -920,6 +963,9 @@ var Server = class {
920
963
  if (exact) {
921
964
  return exact;
922
965
  }
966
+ if (method === "get" && /^\/shop\/product\/query\/\d+$/.test(path)) {
967
+ return this.handleProductQueryById;
968
+ }
923
969
  if (method === "get" && this.prefixRouterGet.length > 0) {
924
970
  for (const { prefix, handler } of this.prefixRouterGet) {
925
971
  if (path === prefix || path.startsWith(`${prefix}/`)) {
@@ -1712,18 +1758,48 @@ var Server = class {
1712
1758
  */
1713
1759
  async computeProductQueryResult(context, options) {
1714
1760
  const tTotal = performance.now();
1715
- const { menu_list_ids, schedule_date, schedule_datetime } = context;
1716
- debugger;
1761
+ const { menu_list_ids, schedule_date, schedule_datetime, product_id } = context;
1717
1762
  this.logInfo("computeProductQueryResult 开始", {
1718
1763
  menuListIdsCount: (menu_list_ids == null ? void 0 : menu_list_ids.length) ?? 0,
1719
1764
  schedule_datetime,
1720
1765
  schedule_date,
1766
+ product_id,
1721
1767
  changedIds: options == null ? void 0 : options.changedIds
1722
1768
  });
1723
1769
  if (!this.products) {
1724
1770
  this.logError("computeProductQueryResult: Products 模块未注册");
1725
1771
  return { message: "Products 模块未注册", data: { list: [], count: 0 } };
1726
1772
  }
1773
+ if (product_id != null && Number.isFinite(Number(product_id))) {
1774
+ const pid = Number(product_id);
1775
+ const tPrice2 = performance.now();
1776
+ const allProductsWithPrice2 = await this.products.getProductsWithPrice(schedule_date, {
1777
+ scheduleModule: this.getSchedule()
1778
+ }, {
1779
+ changedIds: options == null ? void 0 : options.changedIds
1780
+ });
1781
+ (0, import_product.perfMark)("computeQuery.getProductsWithPrice(single)", performance.now() - tPrice2, {
1782
+ count: allProductsWithPrice2.length,
1783
+ productId: pid
1784
+ });
1785
+ const published = allProductsWithPrice2.filter((p) => ((p == null ? void 0 : p.status) || "published") === "published");
1786
+ const item = published.find((p) => Number(p.id) === pid) ?? null;
1787
+ (0, import_product.perfMark)("computeProductQueryResult", performance.now() - tTotal, {
1788
+ mode: "single",
1789
+ productId: pid,
1790
+ found: !!item
1791
+ });
1792
+ this.logInfo("computeProductQueryResult 完成(单商品)", {
1793
+ productId: pid,
1794
+ found: !!item
1795
+ });
1796
+ return {
1797
+ code: 200,
1798
+ data: item,
1799
+ message: item ? "" : "商品不存在或未发布",
1800
+ status: true
1801
+ };
1802
+ }
1727
1803
  if (!this.menu) {
1728
1804
  this.logError("computeProductQueryResult: Menu 模块未注册");
1729
1805
  return { message: "Menu 模块未注册", data: { list: [], count: 0 } };
@@ -322,7 +322,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
322
322
  this.setDiscountList(newDiscountList || []);
323
323
  this.store.originalDiscountList = newDiscountList || [];
324
324
  this.setProductList(newProductList || []);
325
- if (this.isWalkIn() && resultDiscountList.length && ((_c = this.options.otherParams) == null ? void 0 : _c.platform) === "shop") {
325
+ if (this.isWalkIn() && resultDiscountList.length && ((_c = this.options.otherParams) == null ? void 0 : _c.platform) === "shop" && !((resultDiscountList[0].customer_id || 1) === 1)) {
326
326
  await this.getCustomerWallet(
327
327
  resultDiscountList[0].customer_id
328
328
  );
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.2.131",
4
+ "version": "2.2.133",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",