Bladeren bron

1、商品分类树区分办公家具和家用家具;

Lawsun 1 jaar geleden
bovenliggende
commit
319f243be2
1 gewijzigde bestanden met toevoegingen van 15 en 3 verwijderingen
  1. 15 3
      app/controller/home/productCategory.js

+ 15 - 3
app/controller/home/productCategory.js

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