Parcourir la source

Merge branch '20250522_diywebfr'

15313670163 il y a 3 jours
Parent
commit
4675baf125
2 fichiers modifiés avec 56 ajouts et 13 suppressions
  1. 54 13
      app/JsonRpc/PublicRpcService.php
  2. 2 0
      app/JsonRpc/PublicRpcServiceInterface.php

+ 54 - 13
app/JsonRpc/PublicRpcService.php

@@ -1644,12 +1644,12 @@ class PublicRpcService implements PublicRpcServiceInterface
         if(isset($data['sector_type']) && !empty($data['sector_type'])){
             $where['sector_place.sector_type'] = $data['sector_type'];
         }
-        if(isset($data['component_type']) && !empty($data['component_type'])){
-            $where['sector_place.component_type'] = $data['component_type'];
-        }
+        // if(isset($data['component_type']) && !empty($data['component_type'])){
+        //     $where['sector_place.component_type'] = $data['component_type'];
+        // }
         if(isset($data['name']) && !empty($data['name'])){
             array_push($where,['sector_place.name', 'like', '%'.$data['name'].'%']);
-        }
+        } 
         if (isset($data['width']) && !empty($data['width']) && isset($data['height']) && !empty($data['height'])){
             $size_id = Size::where('width','like','%' .$data['width'].'%')->where('height','like','%' .$data['height'].'%')->pluck('id');
         } else if( isset($data['width']) && !empty($data['width'])){
@@ -1693,12 +1693,15 @@ class PublicRpcService implements PublicRpcServiceInterface
                 'type_id' => $data['type_id'],
             ];
         }else{
-            $sector_type = SectorPlace::where('sector_type', $data['type'])->where('type_id',1)->first();
+            $sector_type = SectorPlace::where('sector_type', $data['sector_type'])->where('type_id',1)->first();
             if(empty($sector_type)){
                 return Result::error('通栏版式类别不存在!');
             }
-            $component_type = SectorPlace::where('component_type', $data['type'])->where('type_id',2)->first();
-            if(!empty($component_type)){
+            $component = SectorPlace::where('sector_type', $data['sector_type'])
+            ->where('component_type', $data['type'])
+            ->where('type_id',2)
+            ->first();
+            if(!empty($component)){
                 return Result::error('组件版式类别编号已存在!');
             }
             $data = [
@@ -1709,6 +1712,7 @@ class PublicRpcService implements PublicRpcServiceInterface
                 'sector_img' => $data['sector_img'],
                 'component_type' => $data['type'],
                 'type_id' => $data['type_id'],
+                'sector_type' => $data['sector_type'],
             ];
         }
         
@@ -1723,6 +1727,7 @@ class PublicRpcService implements PublicRpcServiceInterface
      */ 
     public function upSectorPlace(array $data): array
     {
+        $id = $data['id'];
        // 1:通栏;2:组件;
         if($data['type_id'] == 1){
             $sector_place = SectorPlace::where('sector_type', $data['type'])->first();
@@ -1730,7 +1735,6 @@ class PublicRpcService implements PublicRpcServiceInterface
                 return Result::error('通栏版式类别编号已存在!');
             }
             $data = [
-                'id' => $data['id'],
                 'name' => $data['name'],
                 'component_num' => $data['component_num'], 
                 'size_id' => $data['size_id'],
@@ -1740,16 +1744,18 @@ class PublicRpcService implements PublicRpcServiceInterface
                 'type_id' => $data['type_id'],
             ];
         }else{
-            $sector_type = SectorPlace::where('sector_type', $data['type'])->where('type_id',1)->first();
+            $sector_type = SectorPlace::where('sector_type', $data['sector_type'])->where('type_id',1)->first();
             if(empty($sector_type)){
                 return Result::error('通栏版式类别不存在!');
             }
-            $component_type = SectorPlace::where('component_type', $data['type'])->where('type_id',2)->first();
-            if(!empty($component_type)){
+            $component = SectorPlace::where('sector_type', $data['sector_type'])
+            ->where('component_type', $data['type'])
+            ->where('type_id',2)
+            ->first();
+            if(!empty($component)){
                 return Result::error('组件版式类别编号已存在!');
             }
             $data = [
-                'id' => $data['id'],
                 'name' => $data['name'],
                 'component_num' => 0, 
                 'size_id' => $data['size_id'],
@@ -1757,9 +1763,11 @@ class PublicRpcService implements PublicRpcServiceInterface
                 'sector_img' => $data['sector_img'],
                 'component_type' => $data['type'],
                 'type_id' => $data['type_id'],
+                'sector_type' => $data['sector_type'],
             ];
         }
-        $result = SectorPlace::where('id',$data['id'])->update($data);
+        
+        $result = SectorPlace::where('id',$id)->update($data);
         if(empty($result)){
             return Result::error('修改失败!');
         }
@@ -1805,4 +1813,37 @@ class PublicRpcService implements PublicRpcServiceInterface
         }
         return Result::success($result);
     }
+    /**
+     * 自助建站-通栏版式管理-获取通栏版式列表
+     */
+    public function getSectorPlaceSort(array $data): array
+    {
+        $sector = SectorPlace::where('sector_type',$data['sector_type'])->first();
+        if(empty($sector)){
+            return Result::error('通栏版式不存在!');
+        }
+        $component = SectorPlace::where('type_id',2)->where('sector_type',$sector['sector_type'])->pluck('sort_id')->toArray();
+        if(count($component) < $sector['component_num']){
+            // 根据 $sector['component_num'] 的值生成对应元素数量的数组
+            if (isset($sector['component_num']) && is_numeric($sector['component_num'])) {
+                $num = intval($sector['component_num']);
+                if ($num > 0 && $num <= 10) {
+                    $sector_arr = range(1, $num);
+                } else {
+                    $sector_arr = [];
+                }
+            } else {
+                $sector_arr = [];
+            }
+            // 获取 $sector_arr 中不在 $component 里的元素
+            $sort = array_diff($sector_arr, $component);
+            // return Result::success($sort);
+        }
+        if(!empty($sort)){
+            $sort = array_values($sort);
+        }else{
+            return Result::error("组件版式数量已达上限!");
+        }
+        return Result::success($sort);
+    }
 }

+ 2 - 0
app/JsonRpc/PublicRpcServiceInterface.php

@@ -192,4 +192,6 @@ interface PublicRpcServiceInterface
     public function upSectorPlace(array $data): array;
     public function delSectorPlace(array $data): array;
     public function getSectorPlaceInfo(array $data): array;
+    // 通栏版式管理-通栏版式位置
+    public function getSectorPlaceSort(array $data): array;
 }