rkljw 3 giorni fa
parent
commit
80f33da749

+ 158 - 31
app/JsonRpc/WebsiteService.php

@@ -46,6 +46,7 @@ use function PHPUnit\Framework\isNull;
 use Overtrue\Pinyin\Pinyin;
 use App\Tools\buildTree;
 use App\Model\WhiteRouter;
+use App\Model\Size;
 #[RpcService(name: "WebsiteService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
 class WebsiteService implements WebsiteServiceInterface
 {
@@ -835,43 +836,59 @@ class WebsiteService implements WebsiteServiceInterface
     }
 
     /**
-     * 获取模板类型
+     * 获取风格
      * @return void
      */
     public function getTemplateClass(array $data): array
     {
+        // return Result::success($data);
         $where = [];
         if (isset($data['name']) && $data['name']) {
             array_push($where, ['name', 'like', '%' . $data['name'] . '%']);
         }
-        $result = TemplateClass::where($where)->orderBy('sort', 'asc')->get();
+        $template = TemplateClass::when($where, function ($query) use ($where) {
+            $query->where($where);
+            })
+            ->orderBy('updated_at', 'desc');
+        $count = $template->count();
+        $row = $template
+            ->offset(($data['page'] - 1) * $data['pageSize'])
+            ->limit($data['pageSize'])
+            ->get();
+        $result = [
+            'rows' => $row,
+            'count' => $count,
+        ];
         if (empty($result)) {
-            return Result::error("没有模板类型", 0);
+            return Result::error("暂无风格", 0);
         } else {
             return Result::success($result);
         }
     }
 
     /**
-     * 添加模板类型
+     * 添加风格
      * @param
      * @return void
      */
     public function addTemplateClass(array $data): array
     {
-        $insertData = [
-            'name' => $data['name'],
-        ];
-        $result = TemplateClass::insertGetId($insertData);
+        $data['keyword'] = json_encode($data['keyword']);
+        $template = TemplateClass::where(['name' => $data['name']])->first();
+        if ($template) {
+            return Result::error("风格名称已存在", 0);
+        }
+        // return Result::success($data);
+        $result = TemplateClass::insertGetId($data);
         if (empty($result)) {
-            return Result::error("创建失败", 0);
+            return Result::error("创建风格失败", 0);
         } else {
             return Result::success(["id" => $result]);
         }
     }
 
     /**
-     * 更新模板
+     * 更新风格
      * @param array $data
      * @return array
      */
@@ -880,19 +897,31 @@ class WebsiteService implements WebsiteServiceInterface
         $where = [
             'id' => $data['id'],
         ];
-        $insertData = [
+        $template = TemplateClass::where($where)->first();
+        if (empty($template)) {
+            return Result::error("未查询到风格", 0);
+        }
+        if($template->type == 1){
+            return Result::error("默认风格不能修改", 0);
+        }
+        $template = TemplateClass::where(['name' => $data['name']])->where('id','!=','id')->first();
+        if ($template) {
+            return Result::error("风格名称已存在", 0);
+        }
+        $updateData = [
             'name' => $data['name'],
+            'keyword' => json_encode($data['keyword']),
         ];
-        $result = TemplateClass::where($where)->update($insertData);
+        $result = TemplateClass::where($where)->update($updateData);
         if (empty($result)) {
             return Result::error("更新失败", 0);
         } else {
-            return Result::success();
+            return Result::success($result);
         }
     }
 
     /**
-     * 删除模板
+     * 删除风格
      * @param array $data
      * @return array
      */
@@ -901,12 +930,18 @@ class WebsiteService implements WebsiteServiceInterface
         $where = [
             'id' => $data['id'],
         ];
-
+        $template = TemplateClass::where($where)->first();
+        if (empty($template)) {
+            return Result::error("未查询到风格", 0);
+        }
+        if($template->type == 1){
+            return Result::error("默认风格不能删除", 0);
+        }
         $result = TemplateClass::where($where)->delete();
         if (empty($result)) {
             return Result::error("删除失败", 0);
         } else {
-            return Result::success();
+            return Result::success($result);
         }
     }
 
@@ -2590,14 +2625,19 @@ class WebsiteService implements WebsiteServiceInterface
     {
         // return Result::success($data);
         $where = [];
-        if(isset($data['keyword']) &&!empty($data['keyword'])){
-            $where = ['img_alias' => $data['keyword'],'name' => ['like', '%'. $data['keyword']. '%']];
-        }
-        if(isset($data['type']) &&!empty($data['type'])){
-            $where = ['type' => $data['type']];
-        }
-        if(isset($data['website_id']) &&!empty($data['website_id'])){
-            $where = ['website_id' => $data['website_id']];
+        if(isset($data['img_alias']) &&!empty($data['img_alias'])){
+            array_push($where, ['website_img.img_alias', 'like', '%'. $data['img_alias']. '%']);
+        }
+        if(isset($data['img_type']) &&!empty($data['img_type'])){
+            array_push($where, ['website_img.img_type', '=', $data['img_type']]);
+        }
+        if(isset($data['website_name']) &&!empty($data['website_name'])){
+            $website = Website::where('website_name','like','%'.$data['website_name'].'%')->first();
+            if(empty($website)){
+                return Result::error("没有查找到相关数据", 0);
+            }else{
+                array_push($where, ['website_img.website_id', '=', $website['id']]);
+            }
         }
         // return Result::success($where);
         $query = WebsiteImg::when(!empty($where), function ($query) use ($where) {
@@ -2605,7 +2645,11 @@ class WebsiteService implements WebsiteServiceInterface
         })
         ->orderBy('updated_at', 'desc');
         $count = $query->count();
-        $row = $query->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])->get();
+        $row = $query->leftJoin('website', 'website.id', '=', 'website_img.website_id')
+        ->select('website_img.*', 'website.website_name')
+        ->limit($data['pageSize'])
+        ->offset(($data['page'] - 1) * $data['pageSize'])
+        ->get();
         if (empty($row)) {
             return Result::error("没有查找到相关数据", 0);
         } else {
@@ -2624,8 +2668,8 @@ class WebsiteService implements WebsiteServiceInterface
         // $file = $data['img_url']->file('image');
         // $size = $file->getSize();
         $img_data = [
-            'website_id' => $data['website_id'],
-            'img_alias' => $data['img_alias'],
+            'website_id' => $data['website_id'] ?? 0,
+            'img_alias' => $data['img_alias'] ?? '',
             'img_url' => $data['img_url'],
             'img_size' => $data['img_size'],
         ];
@@ -2679,20 +2723,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 getStaticResourceInfo(array $data): array
+    public function delSize(array $data): array
     {
         $where = [
             'id' => $data['id'],
         ];
-        $result = WebsiteImg::where($where)->first();
+        $result = Size::where($where)->delete();
         if (empty($result)) {
-            return Result::error("没有查找到相关数据", 0);
+            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
 
     /**

+ 9 - 1
app/JsonRpc/WebsiteServiceInterface.php

@@ -149,10 +149,18 @@ interface WebsiteServiceInterface
     public function getStaticResourceList(array $data): array;
     public function addStaticResource(array $data): array;
     public function delStaticResource(array $data): array;
-    public function getStaticResourceInfo(array $data): array;
+
+//    public function getStaticResourceInfo(array $data): array;//冯蕊让删除的
     public function getWhiteRouterList(array $data): array;
     public function addWhiteRouter(array $data): array;
     public function upWhiteRouter(array $data): array;
     public function delWhiteRouter(array $data): array;
     public function getWhiteRouterInfo(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 = [];
+}

+ 1 - 0
vendor/composer/autoload_classmap.php

@@ -67,6 +67,7 @@ return array(
     'App\\Model\\Notice' => $baseDir . '/app/Model/Notice.php',
     'App\\Model\\Order' => $baseDir . '/app/Model/Order.php',
     'App\\Model\\Sector' => $baseDir . '/app/Model/Sector.php',
+    'App\\Model\\Size' => $baseDir . '/app/Model/Size.php',
     'App\\Model\\Template' => $baseDir . '/app/Model/Template.php',
     'App\\Model\\TemplateClass' => $baseDir . '/app/Model/TemplateClass.php',
     'App\\Model\\User' => $baseDir . '/app/Model/User.php',

+ 1 - 0
vendor/composer/autoload_static.php

@@ -781,6 +781,7 @@ class ComposerStaticInita4fab8fe7069cf132d8088fb346f5c2a
         'App\\Model\\Notice' => __DIR__ . '/../..' . '/app/Model/Notice.php',
         'App\\Model\\Order' => __DIR__ . '/../..' . '/app/Model/Order.php',
         'App\\Model\\Sector' => __DIR__ . '/../..' . '/app/Model/Sector.php',
+        'App\\Model\\Size' => __DIR__ . '/../..' . '/app/Model/Size.php',
         'App\\Model\\Template' => __DIR__ . '/../..' . '/app/Model/Template.php',
         'App\\Model\\TemplateClass' => __DIR__ . '/../..' . '/app/Model/TemplateClass.php',
         'App\\Model\\User' => __DIR__ . '/../..' . '/app/Model/User.php',