wesmiler 2 лет назад
Родитель
Сommit
9d5dda9e1c

+ 4 - 47
app/Http/Controllers/Api/v1/IndexController.php

@@ -60,7 +60,9 @@ class IndexController extends webApp
                 }
 
                 # 用户充值协议
-                $rechargeAgree = ArticleService::make()->getInfo(3);
+                $locale = RedisService::get("stores:locale:lang_{$this->userId}");
+                $locale = $locale? $locale : session('locale_lang');
+                $rechargeAgree = ArticleService::make()->getInfo(3, $this->userId);
                 $rechargeAgree = isset($rechargeAgree['content'])? $rechargeAgree['content'] : '';
                 $config = [
                     'app_name' => ConfigService::make()->getConfigByCode('app_name'),
@@ -76,6 +78,7 @@ class IndexController extends webApp
                     'recharge_agree' => $rechargeAgree,
                     'xd_price' => $xdPrice,
                     'rechargeMeals'=> $meals,
+                    'lang'=> $locale,
                 ];
                 RedisService::set($cacheKey, $config, 7200);
             }
@@ -89,14 +92,6 @@ class IndexController extends webApp
         }
     }
 
-    /**
-     * 物流公司
-     * @return array
-     */
-    public function express()
-    {
-        return showJson(1010, true, config('express'));
-    }
 
     /**
      * 验证APP更新
@@ -123,42 +118,4 @@ class IndexController extends webApp
         }
     }
 
-    /**
-     * 直播参数
-     * @return array
-     */
-    public function liveConfig()
-    {
-        $userId = request()->post('user_id', 0);
-        $roomId = request()->post('room_id', 0);
-        $refresh = request()->post('refresh', 0);
-        return showJson(1010, true);
-    }
-
-
-    public function noticeCount()
-    {
-        $noticeUid = request()->post('id',0);
-        $userId = request()->post('uid',0);
-        $userType = request()->post('type',0);
-        return message(1010, true, []);
-    }
-
-    /**
-     * 验证视频通话剩余时长
-     * @return array
-     */
-    public function checkChat()
-    {
-        $toUserId = request()->post('to_user_id', 0);
-        $fromUserId = request()->post('from_user_id', 0);
-        $type = request()->post('type', 2);
-        $data = ImChatService::make()->checkChat($fromUserId, $toUserId, $type);
-        $config = ConfigService::make()->getConfigByCode('chat_buy_time_money');
-        $config = $config ? explode('/', $config) : [];
-        $money = isset($config[0]) && $config[0] > 0 ? $config[0] : 10;
-        $num = isset($config[1]) && $config[1] > 0 ? $config[1] : 5;
-        $tips = "抱歉您的免费时长已经用完,请先余额支付【{$money}元】购买【{$num}分钟】聊天时长再使用视频聊天服务。";
-        return message(1010, true, ['time' => $data, 'tips' => $tips]);
-    }
 }

+ 15 - 0
app/Http/Middleware/WebLogin.php

@@ -45,6 +45,21 @@ class WebLogin extends Middleware
             $userId = 0;
         }
 
+        // 语言本地化,参数预处理
+        $locale = session('locale_lang');
+        if($userId>0){
+            $locale = RedisService::get("stores:locale:lang_{$userId}");
+            $locale = $locale? $locale : session('locale_lang');
+            if($locale){
+                session(['locale_lang'=>$locale]);
+                app()->setLocale($locale);
+            }
+
+        }else if ($locale){
+            session(['locale_lang'=>$locale]);
+            app()->setLocale($locale);
+        }
+
         // 接口验证
         $sign = $request->headers->get('sign');
         $params = $request->except('s');

+ 9 - 1
app/Services/Api/ArticleService.php

@@ -151,9 +151,17 @@ class ArticleService extends BaseService
             return $info;
         }
 
+        $locale = RedisService::get("stores:locale:lang_{$userId}");
+        $locale = $locale? $locale : session('locale_lang');
+        if($locale == 'zh-cn'){
+            $field = ['id','title','cover','views','author','publish_at','file_url','type','content'];
+        }else{
+            ['id',"title_{$locale} as title",'cover','views','author','publish_at','file_url','type',"content_{$locale} as content"];
+        }
+
         $info = $this->model->where(['id'=> $id,'status'=>1,'mark'=>1])
             ->where('publish_at','<=', date('Y-m-d H:i:s'))
-            ->select(['id','title','cover','views','author','publish_at','file_url','type','content'])
+            ->select($field)
             ->first();
         $info = $info? $info->toArray() : [];
         if($info){

+ 1 - 0
routes/api.php

@@ -45,6 +45,7 @@ Route::prefix('v1')->group(function(){
     Route::post('/index/rechargeMeals', [\App\Http\Controllers\Api\v1\IndexController::class, 'rechargeMeals']);
     Route::post('/index/notice', [\App\Http\Controllers\Api\v1\IndexController::class, 'noticeCount']);
     Route::post('/index/video', [\App\Http\Controllers\Api\v1\IndexController::class, 'videoList']);
+    Route::match(['get','post'],'/lang/switch', [\App\Http\Controllers\Api\LangController::class, 'switch']);
 
     // 直播
     Route::get('/live/url', [\App\Http\Controllers\Api\v1\LiveController::class, 'getUrl']);