wesmiler 2 gün önce
ebeveyn
işleme
d46e1a915e

+ 3 - 0
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\Api\OrderService;
 use App\Services\Api\SupervisorsService;
 use App\Services\Common\AdService;
@@ -75,6 +76,8 @@ class IndexController extends webApp
                 ],
                 // 轮播
                 'banners' => AdService::make()->getListByPosition(1), // 轮播
+                'goods1' => GoodsService::make()->getListByZoneType(2), // 限定商品
+                'goods2' => GoodsService::make()->getListByZoneType(3), // 优选商品
                 'config'=>[
                     'short_name' => ConfigService::make()->getConfigByCode('short_name'),
                     'index_logo' => get_image_url(ConfigService::make()->getConfigByCode('index_logo')),

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

@@ -324,4 +324,29 @@ class GoodsService extends BaseService
 
         return false;
     }
+
+    /**
+     * 专区商品
+     * @param $type 专区类型:2-午夜限定,3-蜜友优选
+     * @return array|mixed
+     */
+    public function getListByZoneType($type)
+    {
+        $cacheKey = "caches:goods:zoneList_{$type}";
+        $data = RedisService::get($cacheKey);
+        if($data){
+            return $data;
+        }
+
+        $data = $this->model->where(['zone_type'=>$type,'status'=>1,'mark'=>1])
+            ->select(['id','thumb','price','sku_type','goods_name','sales','stock','category_id','type','zone_type','is_new','status'])
+            ->orderBy('sort','desc')
+            ->orderBy('id','asc')
+            ->get();
+        $data = $data? $data->toArray() :[];
+        if($data){
+            RedisService::set($cacheKey, $data, rand(300, 600));
+        }
+        return $data;
+    }
 }