Browse Source

自助建站-获取尺寸列表、添加尺寸、修改尺寸、删除尺寸、获取尺寸详情

15313670163 1 week ago
parent
commit
6e849aab0a
3 changed files with 131 additions and 0 deletions
  1. 99 0
      app/JsonRpc/WebsiteService.php
  2. 5 0
      app/JsonRpc/WebsiteServiceInterface.php
  3. 27 0
      app/Model/Size.php

+ 99 - 0
app/JsonRpc/WebsiteService.php

@@ -45,6 +45,7 @@ use PhpParser\Node\Stmt\Return_;
 use function PHPUnit\Framework\isNull;
 use Overtrue\Pinyin\Pinyin;
 use App\Tools\buildTree;
+use App\Model\Size;
 #[RpcService(name: "WebsiteService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
 class WebsiteService implements WebsiteServiceInterface
 {
@@ -2630,5 +2631,103 @@ class WebsiteService implements WebsiteServiceInterface
         }
         return Result::success($result);
     }
+    /**
+     * 获取尺寸列表
+     * @param array $data
+     */
+    public function getSizeList(array $data): array
+    {
+        $where = [];
+        if(isset($data['width']) &&!empty($data['width'])){
+            array_push($where, ['width','like','%'.$data['width'].'%']);
+        }
+        if(isset($data['height']) &&!empty($data['height'])){
+            array_push($where, ['height','like','%'.$data['height'].'%']);
+        }
+        $query = Size::when($where, function ($query) use ($where) {
+                $query->where($where);
+            })
+            ->orderBy('updated_at', 'desc');
+        $count = $query->count();
+        $rep = $query
+            ->offset(($data['page'] - 1) * $data['pageSize'])
+            ->limit($data['pageSize'])
+            ->get();
+        $result = [
+            'row' => $rep,
+            'count' => $count,
+        ];
+        if (empty($result)) {
+            return Result::error("获取失败", 0);
+        } else {
+            return Result::success($result);
+        }
+    }
+    /**
+     * 添加尺寸
+     * @param array $data
+     */
+    public function addSize(array $data): array
+    {
+        $size = Size::where('width', $data['width'])->where('height', $data['height'])->first();
+        if (!empty($size)) {
+            return Result::error("尺寸已存在", 0);
+        }
+        $result = Size::insertGetId($data);
+        if (empty($result)) {
+            return Result::error("添加失败", 0);
+        }
+        return Result::success($result);
+    }
+    /**
+     * 删除尺寸
+     * @param array $data
+     */
+    public function delSize(array $data): array
+    {
+        $where = [
+            'id' => $data['id'],
+        ];
+        $result = Size::where($where)->delete();
+        if (empty($result)) {
+            return Result::error("删除失败", 0);
+        }
+        return Result::success($result);
+    }
+    /**
+     * 修改尺寸
+     * @param array $data
+     */
+    public function upSize(array $data): array
+    {
+        $where = [
+            'id' => $data['id'],
+        ];
+        $size = Size::where('id','!=', $data['id'])->where('width',$data['width'])->where('height',$data['height'])->first();
+        if (!empty($size)) {
+            return Result::error("尺寸已存在", 0);
+        }
+        $result = Size::where($where)->update($data);
+        if (empty($result)) {
+            return Result::error("修改失败", 0);
+        }
+        return Result::success($result);
+    }
+    /**
+     * 获取尺寸详情
+     * @param array $data
+     */
+    public function getSizeInfo(array $data): array
+    {
+        $where = [
+            'id' => $data['id'],
+        ];
+        $result = Size::where($where)->first();
+        if (empty($result)) {
+            return Result::error("获取失败", 0);
+        } else {
+            return Result::success($result);
+        }
+    }
     // --自助建站-----------20250522fr----------------------end
 }

+ 5 - 0
app/JsonRpc/WebsiteServiceInterface.php

@@ -143,4 +143,9 @@ interface WebsiteServiceInterface
     public function getStaticResourceList(array $data): array;
     public function addStaticResource(array $data): array;
     public function delStaticResource(array $data): array;
+    public function getSizeList(array $data): array;
+    public function addSize(array $data): array;
+    public function delSize(array $data): array;
+    public function upSize(array $data): array;
+    public function getSizeInfo(array $data): array;
 }

+ 27 - 0
app/Model/Size.php

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