AI 1 miesiąc temu
rodzic
commit
73bedec11f

+ 86 - 0
app/JsonRpc/NewsService.php

@@ -6,6 +6,8 @@ use App\Model\ArticleData;
 use App\Model\Category;
 use App\Model\WebsiteCategory;
 use App\Model\ArticleSurvey;
+use App\Model\Good;
+
 use Hyperf\DbConnection\Db;
 use Hyperf\RpcServer\Annotation\RpcService;
 use App\Tools\Result;
@@ -552,4 +554,88 @@ class NewsService implements NewsServiceInterface
         return Result::success($result);
 
     }
+
+    //20250226  产品列表
+
+    public function getGoodList(array $data): array
+    {
+        $where = [];
+        //类型
+        if (isset($data['type_id']) && $data['type_id']) {
+            $where = [
+                'type_id' => $data['type_id'],
+            ];
+        }
+        //名称
+        if (isset($data['name']) && $data['name']) {
+            $where = [
+                'name' => $data['name'],
+            ];
+        }
+        //website_id
+        if (isset($data['website_id']) && $data['website_id']) {
+            $where = [
+                'website_id' => $data['website_id'],
+            ];
+        }
+        //catid
+        if (isset($data['catid']) && $data['catid']) {
+            $where = [
+                'catid' => $data['catid'],
+            ];
+        }
+
+        // $result = Good::where($where)
+        // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
+        $result = Good::where($where)
+            ->orderBy("updated_at", "desc")
+            ->limit($data['page_size'])
+            ->offset(($data['page'] - 1) * $data['page_size'])
+            ->get();
+        $count = Good::where($where)->count();
+        $data = [
+            'rows' => $result->toArray(),
+            'count' => $count,
+        ];
+
+        if (empty($result)) {
+            return Result::error("此栏目暂无相关产品", 0);
+        }
+        return Result::success($data);
+    }
+    public function getGoodInfo(array $data): array
+    {
+        $result = Good::where('id', $data['id'])->first();
+        if (empty($result)) {
+            return Result::error("此产品不存在", 0);
+        }
+        return Result::success($result);
+    }
+    public function addGood(array $data): array
+    {
+
+        $result = Good::create($data);
+        if (empty($result)) {
+            return Result::error("添加失败", 0);
+        }
+        return Result::success($result);
+    }
+    public function updateGood(array $data): array
+    {
+        $result = Good::where('id', $data['id'])->update($data);
+        if (empty($result)) {
+            return Result::error("更新失败", 0);
+        }
+        return Result::success($result);
+    }
+    public function delGood(array $data): array
+    {
+        $result = Good::where('id', $data['id'])->delete();
+        if (empty($result)) {
+            return Result::error("删除失败", 0);
+        }
+        return Result::success($result);
+    }
+
+    //20250226  产品列表
 }

+ 9 - 0
app/JsonRpc/NewsServiceInterface.php

@@ -92,4 +92,13 @@ interface NewsServiceInterface
      */
     public function getWebsiteModelArticles(array $data): array;
 
+    //20250226  产品列表
+    public function getGoodList(array $data): array;
+    public function getGoodInfo(array $data): array;
+    public function addGood(array $data): array;
+    public function delGood(array $data): array;
+    public function updateGood(array $data): array;
+
+    //20250226  产品列表
+
 }

+ 27 - 0
app/Model/Good.php

@@ -0,0 +1,27 @@
+<?php
+
+declare(strict_types=1);
+
+namespace App\Model;
+
+use Hyperf\DbConnection\Model\Model;
+
+/**
+ */
+class Good extends Model
+{
+    /**
+     * The table associated with the model.
+     */
+    protected ?string $table = 'good';
+
+    /**
+     * The attributes that are mass assignable.
+     */
+    protected array $fillable = [];
+
+    /**
+     * The attributes that should be cast to native types.
+     */
+    protected array $casts = [];
+}