moonsflyer 4 месяцев назад
Родитель
Сommit
cdfb64bcfb
2 измененных файлов с 49 добавлено и 2 удалено
  1. 17 1
      app/shopapi/controller/GoodsController.php
  2. 32 1
      app/shopapi/logic/GoodsLogic.php

+ 17 - 1
app/shopapi/controller/GoodsController.php

@@ -28,7 +28,7 @@ use app\shopapi\logic\GoodsLogic;
 class GoodsController extends BaseShopController
 {
 
-    public array $notNeedLogin = ['lists','detail','goodsMarketing','searchRecord'];
+    public array $notNeedLogin = ['lists','detail','shopGoods','goodsMarketing','searchRecord'];
     /**
      * @notes 首页商品列表
      * @return \think\response\Json
@@ -74,6 +74,22 @@ class GoodsController extends BaseShopController
     }
 
     /**
+     * @note 商城分类商品
+     * @return \think\response\Json
+     * @author cjhao
+     * @date 2021/7/26 17:15
+     */
+    public function shopGoods()
+    {
+
+        $list = (new GoodsLogic)->getshopGoods();
+        if (false === $list) {
+            return $this->fail(GoodsLogic::getError());
+        }
+        return $this->success('获取成功', $list);
+    }
+
+    /**
      * @notes 商品营销接口
      * @return \think\response\Json
      * @author cjhao

+ 32 - 1
app/shopapi/logic/GoodsLogic.php

@@ -33,6 +33,7 @@ use app\common\{cache\HandleConcurrencyCache,
     model\Goods,
     logic\BaseLogic,
     logic\DiscountLogic,
+    model\GoodsCategoryIndex,
     model\GoodsItem,
     model\GoodsServiceGuarantee,
     model\GoodsVisit,
@@ -44,7 +45,8 @@ use app\common\{cache\HandleConcurrencyCache,
     enum\GoodsCommentEnum,
     model\User,
     model\UserAddress,
-    service\FileService};
+    service\FileService,
+    model\GoodsCategory};
 use app\common\service\ConfigService;
 
 
@@ -171,6 +173,35 @@ class GoodsLogic extends BaseLogic
         return $goods->toArray();
     }
 
+    public function getshopGoods(){
+        $goods_cate = GoodsCategory::where(['is_show'=>1])->field('id,name')->order('sort asc')->select()->toArray();
+
+        foreach($goods_cate as &$v){
+            $cate_arr = [];
+            array_push($cate_arr,$v['id']);
+            $second =   GoodsCategory::where(['is_show'=>1,'pid'=>$v['id']])->field('id,name')->order('sort asc')->select()->toArray();
+
+            $second_arr = array_column($second,'id');
+            $cate_arr = array_merge($cate_arr,$second_arr);
+
+            foreach($second as $sv){
+                $three = GoodsCategory::where(['is_show'=>1,'pid'=>$sv['id']])->field('id,name')->order('sort asc')->select()->toArray();
+
+                $three_arr= array_column($three,'id');
+                $cate_arr = array_merge($cate_arr,$three_arr);
+            }
+
+            $good_id_list = GoodsCategoryIndex::where(['category_id'=>$cate_arr])->select()->toArray();
+            $goods_list=[];
+            if($good_id_list){
+                $goods_id_arr = array_column($good_id_list,'goods_id');
+                $goods_list =  Goods::where(['id'=>$goods_id_arr,'status'=>1])->field('id,name,min_price,0min_lineation_price,image')->limit(4)->select()->toArray();
+            }
+
+            return ['goods_list'=>$goods_list];
+        }
+
+    }
     /**
      * @notes 商品搜索记录
      * @param $userId