wesmiler 3 bulan lalu
induk
melakukan
e62953b07b
2 mengubah file dengan 48 tambahan dan 35 penghapusan
  1. 45 33
      app/Http/Controllers/Api/v1/IndexController.php
  2. 3 2
      routes/api.php

+ 45 - 33
app/Http/Controllers/Api/v1/IndexController.php

@@ -47,39 +47,7 @@ class IndexController extends webApp
                     'withdraw_min' => ConfigService::make()->getConfigByCode('withdraw_min', 0),
                     'withdraw_fee' => ConfigService::make()->getConfigByCode('withdraw_fee', 0),
                     'notices' => NoticeService::make()->getRecommandList(),
-                    'menuList' => [
-                        [
-                            "name" => '首页',
-                            "code" => 'home',
-                            "icon" => 'home',
-                            "status"=> 1,
-                            "page" => '/pages/index/index'
-                        ], [
-                            "name" => '客服',
-                            "code" => 'custom',
-                            "icon" => 'custom',
-                            "status"=> 1,
-                        ], [
-                            "name" => '',
-                            "code" => 'social',
-                            "icon" => 'social',
-                            "status"=> $socialOpen?1:0,
-                            "page" => '/pages/social/index'
-                        ], [
-                            "name" => '购物车',
-                            "code" => 'cart',
-                            "icon" => 'cart',
-                            "badge" => OrderService::make()->getCountByStatus($this->userId,1),
-                            "status"=> 1,
-                            "page" => '/pages/cart/index'
-                        ], [
-                            "name" => '我的',
-                            "code" => 'mine',
-                            "icon" => 'mine',
-                            "status"=> 1,
-                            "page" => '/pages/mine/index'
-                        ]
-                    ]
+                    'menuList' => $this->getMenus($socialOpen)
                 ];
                 RedisService::set($cacheKey, $config, 3600);
             }
@@ -92,6 +60,49 @@ class IndexController extends webApp
     }
 
     /**
+     * 菜单
+     * @param int $socialOpen
+     * @return array[]
+     */
+    public function getMenus($socialOpen=-1)
+    {
+        $socialOpen = $socialOpen>=0?$socialOpen:ConfigService::make()->getConfigByCode('social_open', 0);
+        return [
+            [
+                "name" => '首页',
+                "code" => 'home',
+                "icon" => 'home',
+                "status"=> 1,
+                "page" => '/pages/index/index'
+            ], [
+                "name" => '客服',
+                "code" => 'custom',
+                "icon" => 'custom',
+                "status"=> 1,
+            ], [
+                "name" => '',
+                "code" => 'social',
+                "icon" => 'social',
+                "status"=> $socialOpen?1:0,
+                "page" => '/pages/social/index'
+            ], [
+                "name" => '购物车',
+                "code" => 'cart',
+                "icon" => 'cart',
+                "badge" => OrderService::make()->getCountByStatus($this->userId,1),
+                "status"=> 1,
+                "page" => '/pages/cart/index'
+            ], [
+                "name" => '我的',
+                "code" => 'mine',
+                "icon" => 'mine',
+                "status"=> 1,
+                "page" => '/pages/mine/index'
+            ]
+        ];
+    }
+
+    /**
      * 首页数据
      * @return array
      */
@@ -110,6 +121,7 @@ class IndexController extends webApp
                 $data['socials'] = SocialCircleService::make()->getIndexList();
             } else {
                 $data['notices'] = NoticeService::make()->getRecommandList();
+                $data['menuList'] = $this->getMenus();
             }
 
             return showJson(1010, true, $data);

+ 3 - 2
routes/api.php

@@ -29,8 +29,7 @@ Route::prefix('v1')->group(function() {
     Route::post('/upload/image', [\App\Http\Controllers\Api\UploadController::class, 'uploadImage']);
     Route::post('/upload/file', [\App\Http\Controllers\Api\UploadController::class, 'uploadFile']);
 
-    // 配置和首页数据
-    Route::get('/config', [\App\Http\Controllers\Api\v1\IndexController::class, 'config']);
+
 
     // 文章
     Route::post('/article/index', [\App\Http\Controllers\Api\v1\ArticleController::class, 'index']);
@@ -51,6 +50,8 @@ Route::prefix('v1')->group(function() {
 Route::prefix('v1')->middleware('web.login')->group(function() {
     Route::get('/logout', [\App\Http\Controllers\Api\v1\LoginController::class, 'logout']);
 
+    // 配置和首页数据
+    Route::get('/config', [\App\Http\Controllers\Api\v1\IndexController::class, 'config']);
     Route::get('/index/data', [\App\Http\Controllers\Api\v1\IndexController::class, 'data']);
     Route::post('/index/storeGoods', [\App\Http\Controllers\Api\v1\IndexController::class, 'storeGoods']);