|
@@ -20,6 +20,17 @@ module.exports = class ProductCategoryController extends shopController {
|
|
|
return 30 * 60;// 2023/9/7 30分钟缓存时间
|
|
|
}
|
|
|
|
|
|
+ // 2023/9/20 查询分类
|
|
|
+ get treesValidate() {
|
|
|
+ const that = this;
|
|
|
+ return {
|
|
|
+ pid: that.ctx.rules.name('分类父类ID')
|
|
|
+ .required()
|
|
|
+ .number()
|
|
|
+ .notEmpty(),
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* [categoryValidate 查询分类下商品]
|
|
|
* @return {[type]} [description]
|
|
@@ -49,10 +60,11 @@ module.exports = class ProductCategoryController extends shopController {
|
|
|
async trees() {
|
|
|
const that = this;
|
|
|
try {
|
|
|
- let result = await that.service.redis.get(that.cacheKey);
|
|
|
+ const requestData = await that.ctx.validate(that.treesValidate, await that.ctx.getParse());
|
|
|
+ let result = await that.service.redis.get(that.cacheKey + 'pid' + requestData.pid);
|
|
|
if (!result) {
|
|
|
const opt = {
|
|
|
- where: { is_show: 1 },
|
|
|
+ where: { is_show: 1, pid: requestData.pid },
|
|
|
include: [
|
|
|
{
|
|
|
model: that.app.model.Products,
|
|
@@ -69,7 +81,7 @@ module.exports = class ProductCategoryController extends shopController {
|
|
|
};
|
|
|
const selectBean = await that.app.comoBean.instance({}, opt);
|
|
|
result = await that.service.manager.select(selectBean, that.useModel, '商品列表查看失败,请重试', false, true);
|
|
|
- if (result) await that.service.redis.set(that.cacheKey, result, that.cacheTime);
|
|
|
+ if (result) await that.service.redis.set(that.cacheKey + 'pid' + requestData.pid, result, that.cacheTime);
|
|
|
}
|
|
|
return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', result, false));
|
|
|
} catch (err) {
|