wesmiler 2 лет назад
Родитель
Сommit
31e2b9f462

+ 1 - 1
app/Http/Controllers/Api/v1/ArticleController.php

@@ -22,7 +22,7 @@ class ArticleController extends webApp
     {
         $params =request()->post();
         $pageSize = request()->post('pageSize', 15);
-        $datas = ArticleService::make()->getDataList($params, $pageSize);
+        $datas = ArticleService::make()->getDataList($params, $pageSize, $this->userId);
         return showJson(1010, true, $datas);
     }
 

+ 13 - 2
app/Services/Api/ArticleService.php

@@ -54,7 +54,7 @@ class ArticleService extends BaseService
      * @param int $pageSize
      * @return array
      */
-    public function getDataList($params, $pageSize = 15)
+    public function getDataList($params, $pageSize = 15, $userId=0)
     {
         $where = ['a.mark' => 1];
         $status = isset($params['status'])? $params['status'] : 0;
@@ -91,12 +91,23 @@ class ArticleService extends BaseService
             ->paginate($pageSize > 0 ? $pageSize : 9999999);
         $list = $list? $list->toArray() :[];
         if($list){
+            $locale = RedisService::get("caches:locale:lang_{$userId}");
+            $locale = $locale? $locale : session('locale_lang');
+            $locale = $locale? $locale :'zh-cn';
             foreach($list['data'] as &$item){
                 $item['create_time'] = $item['create_time']? datetime($item['create_time'],'Y-m-d H.i.s') : '';
                 $item['time_text'] = $item['publish_at']? dateFormat(strtotime($item['publish_at'])) : '';
                 $item['cover'] = $item['cover']? get_image_url($item['cover']) : '';
                 $item['file_url'] = $item['file_url']? get_image_url($item['file_url']) : '';
-                $item['content'] = $item['content']? htmlspecialchars_decode($item['content']) : '';
+                $title = $item['title']? $item['title'] : '';
+                $content = $item['content']? htmlspecialchars_decode($item['content']) : '';
+                if($locale != 'zh-cn'){
+                    $item['title'] = isset($item['title_'.$locale]) && $item['title_'.$locale]? $item['title_'.$locale] : '';
+                    $item['content'] = isset($item['content_'.$locale]) && $item['content_'.$locale]? htmlspecialchars_decode($item['content_'.$locale]) : '';
+                }
+
+                $item['title'] = $item['title']? $item['title'] : $title;
+                $item['content'] = $item['content']? $item['content'] : $content;
             }
         }