Răsfoiți Sursa

添加b端接口:随即模板初步、修改接口 :删除皮肤、删除组件、获取组件列表的接口

15313670163 18 ore în urmă
părinte
comite
554e935c50

+ 48 - 4
app/JsonRpc/PublicRpcService.php

@@ -43,6 +43,7 @@ use App\Model\AdPlace;
 use App\Model\WebsiteImg;
 use App\Model\SectorComponent;
 use App\Model\ComponentImg;
+use App\Model\TemplateRule;
 
 #[RpcService(name: "PublicRpcService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
 class PublicRpcService implements PublicRpcServiceInterface
@@ -913,8 +914,12 @@ class PublicRpcService implements PublicRpcServiceInterface
         if (!empty($web_template)) {
             return Result::error("此皮肤已被绑定网站,不可删除", 0);
         }
-        if ($template->type == 1) {
-            return Result::error("默认皮肤不能删除", 0);
+        // if ($template->type == 1) {
+        //     return Result::error("默认皮肤不能删除", 0);
+        // }
+        $component_img = ComponentImg::where('template_id',$template['template_id'])->get();
+        if(!empty($component_img)){
+            return Result::error('此皮肤已绑定组件预览图,不可删除!');
         }
         $result = Template::where('id', $data['id'])->delete();
         var_dump($result, '-------------------delete');
@@ -1656,11 +1661,20 @@ class PublicRpcService implements PublicRpcServiceInterface
                     }
                 }
             }
+            $component_img = ComponentImg::where('component_id',$component['id'])->get();
+            if(!empty($component_img)){
+                $component_img = ComponentImg::where('component_id',$component['id'])->delete();
+                if(empty($component_img)){
+                    Db::rollBack();
+                    return Result::error('删除组件预览图失败!');
+                }
+            }
             $result = Component::where('id',$data['id'])->delete();
             if(empty($result)){
                 Db::rollBack();
                 return Result::error('删除失败!');
             }
+            
             Db::commit();
             return Result::success($result);
         }catch(\Exception $e){
@@ -2587,6 +2601,10 @@ class PublicRpcService implements PublicRpcServiceInterface
         if(empty($component_img)){
             return Result::error('组件预览图不存在!');
         }
+        $component_img = [
+            'data' => $component_img,
+            'total' => $component_img['total'],
+        ];
         return Result::success($component_img);
     }
     /**
@@ -2637,7 +2655,33 @@ class PublicRpcService implements PublicRpcServiceInterface
         }
         return Result::success($component_img);
     }
+    /**
+     * 自助建站-随机生成模板
+     */
+    public function randomWebTemplate(array $data): array
+    {
+        // $where['website_id'] = $data['website_id'];
+        $web = Website::where('id',$data['website_id'])->first();
 
-
-
+        if(empty($web)){
+            return Result::error('网站不存在!');
+        }
+        $where['template_id'] = $data['template_id'];
+        $template = Template::where($where)->first();
+        if(empty($template)){
+            return Result::error('模板不存在!');
+        }
+        $rule = TemplateRule::first();
+        if(empty($rule)){
+            return Result::error('模板规则不存在!');
+        }
+        $index_rule = json_decode($rule->index_rule,true);
+        $index = $this->getRandomIndex($index_rule,$template);
+        return Result::success($index);
+    }
+    public function getRandomIndex($index_rule,$template){
+        // $where = ['page_type','like','%'.1.'%'];
+        $index = Sector::where('template_id',$template->template_id)->where('page_type','like','%1%')->limit(10)->get();
+        return $index;
+    }
 }

+ 2 - 0
app/JsonRpc/PublicRpcServiceInterface.php

@@ -206,6 +206,8 @@ interface PublicRpcServiceInterface
     public function delComponentImg(array $data): array;
     //组件管理-更新组件预览图
     public function updateComponentImg(array $data): array;
+    //自助建站-随机生成模板
+    public function randomWebTemplate(array $data): array;
 
 
 

+ 30 - 0
app/Model/TemplateRule.php

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