@pisell/pisellos 2.2.131 → 2.2.132
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.
- package/dist/core/index.js +0 -1
- package/dist/modules/Discount/types.d.ts +1 -1
- package/dist/modules/Rules/index.js +4 -4
- package/dist/server/index.d.ts +5 -0
- package/dist/server/index.js +530 -416
- package/lib/core/index.js +0 -1
- package/lib/modules/Discount/types.d.ts +1 -1
- package/lib/modules/Rules/index.js +2 -2
- package/lib/server/index.d.ts +5 -0
- package/lib/server/index.js +78 -2
- package/package.json +1 -1
package/lib/core/index.js
CHANGED
|
@@ -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;
|
|
@@ -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) {
|
package/lib/server/index.d.ts
CHANGED
|
@@ -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
|
*/
|
package/lib/server/index.js
CHANGED
|
@@ -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 } };
|