Quellcode durchsuchen

refactor: 统一代码风格

runphp vor 2 Wochen
Ursprung
Commit
8e4832c24c

+ 2 - 1
config.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 return [
@@ -141,4 +142,4 @@ return [
             ]
         ]
     ]
-];
+];

+ 1 - 0
info.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 return [

+ 3 - 3
route/admin.php

@@ -1,7 +1,7 @@
 <?php
+
 declare(strict_types=1);
 
-use SixShop\Core\Middleware\AuthMiddleware;
 use SixShop\News\Controller\Admin\CategoryController;
 use SixShop\News\Controller\Admin\NewsController;
 use SixShop\News\Controller\Admin\UploadController;
@@ -22,10 +22,10 @@ Route::group('news', function () {
 
 })->middleware(['auth']);
 
-  // 上传接口
+// 上传接口
 Route::post('upload', [UploadController::class, 'image'])->middleware(['auth']);
 
-Route::group('category', function () { 
+Route::group('category', function () {
     // 分类管理路由 - 在 news 下
     Route::get('', [CategoryController::class, 'index'])->middleware(['auth']);
     Route::get(':id', [CategoryController::class, 'read'])->middleware(['auth']);

+ 1 - 1
route/api.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 use SixShop\News\Controller\Api\CategoryController;
@@ -14,4 +15,3 @@ Route::resource('category', CategoryController::class);
 Route::resource('news', NewsController::class);
 // 增加阅读数路由
 Route::post('news/:id/views', [NewsController::class, 'incrementViews']);
-

+ 2 - 1
src/Controller/Admin/CategoryController.php

@@ -1,4 +1,5 @@
 <?php
+
 namespace SixShop\News\Controller\Admin;
 
 use think\Request;
@@ -85,4 +86,4 @@ class CategoryController
         }
         return json(['code' => 200, 'msg' => '删除成功']);
     }
-} 
+}

+ 16 - 16
src/Controller/Admin/NewsController.php

@@ -1,10 +1,10 @@
 <?php
+
 namespace SixShop\News\Controller\Admin;
 
 use think\Request;
 use think\facade\Validate;
 use SixShop\News\Service\NewsServiceAdapter;
-use SixShop\News\Service\NewsCategoryServiceAdapter;
 
 class NewsController
 {
@@ -28,8 +28,8 @@ class NewsController
             $where['status'] = $request->get('status');
         }
         $limit = (int)$request->get('limit', 20);
-        $data = $this->service->getList($where, ['is_top'=>'desc','id'=>'desc'], $limit);
-        
+        $data = $this->service->getList($where, ['is_top' => 'desc','id' => 'desc'], $limit);
+
         // 从数据库获取分类数据
         $categoryMap = [];
         try {
@@ -40,7 +40,7 @@ class NewsController
                 ->field('id,name')
                 ->select()
                 ->toArray();
-            
+
             // 构建分类映射
             foreach ($categories as $category) {
                 $categoryMap[$category['id']] = $category['name'];
@@ -50,11 +50,11 @@ class NewsController
             error_log('获取分类数据失败: ' . $e->getMessage());
             $categoryMap = [
                 1 => '默认分类',
-                2 => '新闻分类', 
+                2 => '新闻分类',
                 3 => '公告分类'
             ];
         }
-        
+
         // 字段映射:数据库cover_image -> 前端cover,添加分类名称
         if (is_array($data) && isset($data['data'])) {
             foreach ($data['data'] as &$item) {
@@ -84,7 +84,7 @@ class NewsController
                 }
             }
         }
-        
+
         return json(['code' => 200, 'msg' => 'success', 'data' => $data]);
     }
 
@@ -97,12 +97,12 @@ class NewsController
         if (!$info) {
             return json(['code' => 404, 'msg' => '文章不存在']);
         }
-        
+
         // 字段映射:数据库cover_image -> 前端cover
         if (isset($info['cover_image'])) {
             $info['cover'] = $info['cover_image'];
         }
-        
+
         return json(['code' => 200, 'msg' => 'success', 'data' => $info]);
     }
 
@@ -125,16 +125,16 @@ class NewsController
         if (!$validate->check($data)) {
             return json(['code' => 422, 'msg' => $validate->getError()]);
         }
-        
+
         // 字段映射:前端cover -> 数据库cover_image
         if (isset($data['cover'])) {
             $data['cover_image'] = $data['cover'];
             unset($data['cover']);
         }
-        
+
         // 不传递时间字段,让 Go 服务自动设置
         // Go 服务会在创建时自动设置 create_time 和 update_time
-        
+
         $res = $this->service->create($data);
         return json(['code' => 200, 'msg' => '创建成功', 'data' => $res]);
     }
@@ -157,16 +157,16 @@ class NewsController
         if (!$validate->check($data)) {
             return json(['code' => 422, 'msg' => $validate->getError()]);
         }
-        
+
         // 字段映射:前端cover -> 数据库cover_image
         if (isset($data['cover'])) {
             $data['cover_image'] = $data['cover'];
             unset($data['cover']);
         }
-        
+
         // 不传递时间字段,让 Go 服务自动设置
         // Go 服务会在更新时自动设置 update_time
-        
+
         $res = $this->service->update($id, $data);
         if (!$res) {
             return json(['code' => 404, 'msg' => '文章不存在']);
@@ -185,4 +185,4 @@ class NewsController
         }
         return json(['code' => 200, 'msg' => '删除成功']);
     }
-} 
+}

+ 3 - 2
src/Controller/Api/CategoryController.php

@@ -1,4 +1,5 @@
 <?php
+
 namespace SixShop\News\Controller\Api;
 
 use think\Response;
@@ -36,7 +37,7 @@ class CategoryController
         $item = $this->service->getById($id);
         return json($item);
     }
-    
+
     /**
      * Save a new resource in storage.
      *
@@ -75,4 +76,4 @@ class CategoryController
         $result = $this->service->delete($id);
         return json($result);
     }
-} 
+}

+ 3 - 2
src/Controller/Api/NewsController.php

@@ -1,4 +1,5 @@
 <?php
+
 namespace SixShop\News\Controller\Api;
 
 use think\Response;
@@ -76,7 +77,7 @@ class NewsController
         $result = $this->service->incrementViews($id);
         return json($result);
     }
-    
+
     /**
      * Save a new resource in storage.
      *
@@ -115,4 +116,4 @@ class NewsController
         $result = $this->service->delete($id);
         return json($result);
     }
-} 
+}

+ 2 - 1
src/Extension.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 namespace SixShop\News;
@@ -66,4 +67,4 @@ class Extension extends ExtensionAbstract
             NewsHook::class,
         ];
     }
-}
+}

+ 2 - 1
src/Hook/NewsHook.php

@@ -1,4 +1,5 @@
 <?php
+
 namespace SixShop\News\Hook;
 
 use SixShop\Core\Attribute\Hook;
@@ -28,4 +29,4 @@ class NewsHook
     {
         // 在这里编写订单创建后的逻辑
     }
-} 
+}

+ 2 - 1
src/Model/News.php

@@ -1,4 +1,5 @@
 <?php
+
 namespace SixShop\News\Model;
 
 use think\Model;
@@ -22,4 +23,4 @@ class News extends Model
     {
         return $this->belongsTo(NewsCategory::class, 'category_id', 'id');
     }
-}
+}

+ 2 - 1
src/Model/NewsCategory.php

@@ -1,4 +1,5 @@
 <?php
+
 namespace SixShop\News\Model;
 
 use think\Model;
@@ -33,4 +34,4 @@ class NewsCategory extends Model
      * - sort_order: 排序
      * - status: 状态:1启用,-1禁用
      */
-}
+}

+ 2 - 1
src/Service/NewsCategoryService.php

@@ -1,4 +1,5 @@
 <?php
+
 namespace SixShop\News\Service;
 
 // The original Model is no longer used directly by this service.
@@ -55,4 +56,4 @@ class NewsCategoryService
     {
         return $this->ffiService->deleteCategory($id);
     }
-} 
+}

+ 22 - 6
src/Service/NewsCategoryServiceAdapter.php

@@ -1,4 +1,5 @@
 <?php
+
 namespace SixShop\News\Service;
 
 // 资讯分类服务适配器:开发模式用 PHP Service,分发模式用 FFI 适配层(通过 NewsServiceAdapter 代理实现)
@@ -17,9 +18,24 @@ class NewsCategoryServiceAdapter
             $this->service = new NewsServiceAdapter();
         }
     }
-    public function getList(...$args) { return $this->service->getList(...$args); }
-    public function getById(...$args) { return $this->service->getById(...$args); }
-    public function create(...$args) { return $this->service->create(...$args); }
-    public function update(...$args) { return $this->service->update(...$args); }
-    public function delete(...$args) { return $this->service->delete(...$args); }
-} 
+    public function getList(...$args)
+    {
+        return $this->service->getList(...$args);
+    }
+    public function getById(...$args)
+    {
+        return $this->service->getById(...$args);
+    }
+    public function create(...$args)
+    {
+        return $this->service->create(...$args);
+    }
+    public function update(...$args)
+    {
+        return $this->service->update(...$args);
+    }
+    public function delete(...$args)
+    {
+        return $this->service->delete(...$args);
+    }
+}

+ 1 - 1
src/Service/NewsFfiService.php

@@ -170,4 +170,4 @@ class NewsFfiService
     {
         return $this->call('IncrementNewsViews', $id);
     }
-} 
+}

+ 3 - 2
src/Service/NewsService.php

@@ -1,4 +1,5 @@
 <?php
+
 namespace SixShop\News\Service;
 
 // The original Model is no longer used directly by this service.
@@ -25,7 +26,7 @@ class NewsService
 
         $params = [
             'where' => empty($where) ? new \stdClass() : $where,
-            'order' => is_array($order) ? implode(', ', array_map(fn($k, $v) => "$k $v", array_keys($order), $order)) : $order,
+            'order' => is_array($order) ? implode(', ', array_map(fn ($k, $v) => "$k $v", array_keys($order), $order)) : $order,
             'limit' => $limit,
             'page'  => $page,
         ];
@@ -71,4 +72,4 @@ class NewsService
     {
         return $this->ffiService->incrementNewsViews($id);
     }
-} 
+}

+ 35 - 9
src/Service/NewsServiceAdapter.php

@@ -1,5 +1,7 @@
 <?php
+
 namespace SixShop\News\Service;
+
 // 资讯服务适配器:开发模式用 PHP Service,分发模式用 FFI 适配层
 class NewsServiceAdapter
 {
@@ -16,12 +18,36 @@ class NewsServiceAdapter
             $this->service = new NewsService();
         }
     }
-    public function getList(...$args) { return $this->service->getList(...$args); }
-    public function getById(...$args) { return $this->service->getById(...$args); }
-    public function create(...$args) { return $this->service->create(...$args); }
-    public function update(...$args) { return $this->service->update(...$args); }
-    public function delete(...$args) { return $this->service->delete(...$args); }
-    public function generateSummary(...$args) { return $this->service->generateSummary(...$args); }
-    public function checkContent(...$args) { return $this->service->checkContent(...$args); }
-    public function extractKeywords(...$args) { return $this->service->extractKeywords(...$args); }
-} 
+    public function getList(...$args)
+    {
+        return $this->service->getList(...$args);
+    }
+    public function getById(...$args)
+    {
+        return $this->service->getById(...$args);
+    }
+    public function create(...$args)
+    {
+        return $this->service->create(...$args);
+    }
+    public function update(...$args)
+    {
+        return $this->service->update(...$args);
+    }
+    public function delete(...$args)
+    {
+        return $this->service->delete(...$args);
+    }
+    public function generateSummary(...$args)
+    {
+        return $this->service->generateSummary(...$args);
+    }
+    public function checkContent(...$args)
+    {
+        return $this->service->checkContent(...$args);
+    }
+    public function extractKeywords(...$args)
+    {
+        return $this->service->extractKeywords(...$args);
+    }
+}