wesmiler 2 недель назад
Родитель
Сommit
4dec6557b0
2 измененных файлов с 27 добавлено и 1 удалено
  1. 2 1
      app/Http/Controllers/Api/v1/IndexController.php
  2. 25 0
      app/Services/Api/GoodsService.php

+ 2 - 1
app/Http/Controllers/Api/v1/IndexController.php

@@ -4,6 +4,7 @@ namespace App\Http\Controllers\Api\v1;
 
 use App\Http\Controllers\Api\webApp;
 use App\Services\Api\ArticleService;
+use App\Services\Api\GoodsService;
 use App\Services\Common\AdService;
 use App\Services\Common\NoticeService;
 use App\Services\ConfigService;
@@ -67,7 +68,7 @@ class IndexController extends webApp
             $data = [
                 // 轮播
                 'banners' => AdService::make()->getListByPosition(1),
-                'articles' => ArticleService::make()->getListByType(1),
+                'goods' => GoodsService::make()->getListByType(2),
             ];
 
             return showJson(1010, true, $data);

+ 25 - 0
app/Services/Api/GoodsService.php

@@ -223,6 +223,31 @@ class GoodsService extends BaseService
     }
 
     /**
+     * 按类型获取商品
+     * @param $position
+     * @param int $num
+     * @return array|mixed
+     */
+    public function getListByType($type)
+    {
+        $cacheKey = "caches:goods:{$type}";
+        $datas = RedisService::get($cacheKey);
+        if($datas){
+            return $datas;
+        }
+
+        $datas = $this->model->where(['type'=> $type,'status'=> 1,'mark'=>1])
+            ->select(['id','thumb','type','goods_name','price','bd_score','content'])
+            ->get();
+        $datas = $datas? $datas->toArray() : [];
+        if($datas){
+            RedisService::set($cacheKey, $datas, rand(5, 10));
+        }
+
+        return $datas;
+    }
+
+    /**
      * @param $ids
      * @param $goods
      * @param $userId