Просмотр исходного кода

Merge branch '20250522_diywebfr'

15313670163 5 месяцев назад
Родитель
Сommit
0c660b2f40
1 измененных файлов с 64 добавлено и 48 удалено
  1. 64 48
      app/JsonRpc/PublicRpcService.php

+ 64 - 48
app/JsonRpc/PublicRpcService.php

@@ -1198,7 +1198,7 @@ class PublicRpcService implements PublicRpcServiceInterface
         if (empty($template)) {
             return Result::error('皮肤不存在!');
         }
-        $sector_id = Sector::where('sector_id',$data['sector_id'])->first();
+        $sector_id = Sector::where('sector_id',$data['sector_id'])->where('template_id',$data['template_id'])->first();
         if(!empty($sector_id)){
             return Result::error('通栏编号已存在!');
         }
@@ -1207,32 +1207,35 @@ class PublicRpcService implements PublicRpcServiceInterface
             return Result::error('位置不存在!');
         }
         $sort = json_decode($data['component_code'],true);
-        // $kw = 0;
+        $sector = 0;
         // $flattened = [];
-        // $component = [];
+        // $sector = [];
         $sector_component = [];
         foreach ($sort as $key => $subArray) {
-            foreach ($subArray as $k => $item) {
-                // $component[] = $item;
+        //     foreach ($subArray as $k => $item) {
+        //         // $component[] = $item;
                 $sector_component[] = [
                     'sector_id' => $data['sector_id'],
-                    'component_id' => $item,
+                    'component_id' => $subArray[0],
                     'sort_id' => $key + 1,
                     'place_id' => $data['place_type'],
+                    'sectorid' => $sector,
                 ];
-                //  // ---------同步通栏的sort_id到组件之中,目前已废弃,涉及到批量修改------
-                // $componentTypes[] = $item;
-                // $components[] = [
-                //     'sort_id' => $key + 1,
-                //     'component_type' => $item,
-                // ];
-                // $place_ids[] = $data['place_type'];
-            }
+        //         //  // ---------同步通栏的sort_id到组件之中,目前已废弃,涉及到批量修改------
+        //         // $componentTypes[] = $item;
+        //         // $components[] = [
+        //         //     'sort_id' => $key + 1,
+        //         //     'component_type' => $item,
+        //         // ];
+        //         // $place_ids[] = $data['place_type'];
+        //     }
         }
         // $component_num = count($component);
         // $count = count(array_unique($component));
+
+        // 使用array_map批量替换sector_id
        
-        // return Result::success($sector_component);
+        // return Result::success($updatedArray);
         if(count($sort) != $data['component_num']){
             return Result::error('组件关联错误!');
         }
@@ -1248,7 +1251,17 @@ class PublicRpcService implements PublicRpcServiceInterface
         $data['sector_code'] = json_encode($sector_code);
         Db::beginTransaction();
         try {
-            $com_sector = SectorComponent::insert($sector_component);
+            $sector = Sector::insertGetId($data);
+            if (empty($sector)) {
+                Db::rollBack();
+                return Result::error('添加失败');
+            }
+            $sector_com = array_map(function ($item) use ($sector) {
+                // 替换当前记录的sector_id为变量值(保留其他字段不变)
+                $item['sectorid'] = $sector;
+                return $item;
+            }, $sector_component);
+            $com_sector = SectorComponent::insert($sector_com);
             if(empty($com_sector)){
                 Db::rollBack();
                 return Result::error('通栏关联组件失败!');
@@ -1276,13 +1289,9 @@ class PublicRpcService implements PublicRpcServiceInterface
             //     Db::rollBack();
             //     return Result::error('组件位置关联失败!');
             // }
-            $result = Sector::insertGetId($data);
-            if (empty($result)) {
-                Db::rollBack();
-                return Result::error('添加失败');
-            }
+           
             Db::commit();
-            return Result::success($result);
+            return Result::success($sector);
         } catch (\Exception $e) {
             Db::rollBack();
             return Result::error($e->getMessage());
@@ -1331,7 +1340,7 @@ class PublicRpcService implements PublicRpcServiceInterface
             return Result::error('通栏不存在!');
         }
         if($sector['sector_id'] != $data['sector_id']){
-            $sector_id = Sector::where('sector_id',$data['sector_id'])->first();
+            $sector_id = Sector::where('sector_id',$data['sector_id'])->where('template_id',$data['template_id'])->first();
             if(!empty($sector_id)){
                 return Result::error('通栏编号已存在!');
             }
@@ -1357,22 +1366,23 @@ class PublicRpcService implements PublicRpcServiceInterface
         $sort = json_decode($data['component_code'],true);
         $sector_component = [];
         foreach ($sort as $key => $subArray) {
-            foreach ($subArray as $k => $item) {
-                // $component[] = $item;
-                $sector_component[] = [
-                    'sector_id' => $data['sector_id'],
-                    'component_id' => $item,
-                    'sort_id' => $key + 1,
-                    'place_id' => $data['place_type'],
-                ];
-                // ---------同步通栏的sort_id到组件之中,目前已废弃,涉及到批量修改------
-                // $componentTypes[] = $item;
-                // $components[] = [
-                //     'sort_id' => $key + 1,
-                //     'component_type' => $item,
-                // ];
-                // $place_ids[] = $data['place_type'];
-            }
+            //     foreach ($subArray as $k => $item) {
+            //         // $component[] = $item;
+                    $sector_component[] = [
+                        'sector_id' => $data['sector_id'],
+                        'component_id' => $subArray[0],
+                        'sort_id' => $key + 1,
+                        'place_id' => $data['place_type'],
+                        'sectorid' => $sector,
+                    ];
+            //         //  // ---------同步通栏的sort_id到组件之中,目前已废弃,涉及到批量修改------
+            //         // $componentTypes[] = $item;
+            //         // $components[] = [
+            //         //     'sort_id' => $key + 1,
+            //         //     'component_type' => $item,
+            //         // ];
+            //         // $place_ids[] = $data['place_type'];
+            //     }
         }
         if(count($sort) != $data['component_num']){
             return Result::error('组件关联错误!');
@@ -1390,7 +1400,17 @@ class PublicRpcService implements PublicRpcServiceInterface
                 Db::rollBack();
                 return Result::error('通栏解除组件关联失败!1');
             }
-            $com_sector = SectorComponent::insert($sector_component);
+            $sector = Sector::where('id', $data['id'])->update($data);
+            if (empty($sector)) {
+                Db::rollBack();
+                return Result::error('修改失败');
+            }
+             $sector_com = array_map(function ($item) use ($data) {
+                // 替换当前记录的sector_id为变量值(保留其他字段不变)
+                $item['sectorid'] =  $data['id'];
+                return $item;
+            }, $sector_component);
+            $com_sector = SectorComponent::insert($sector_com);
             if(empty($com_sector)){
                 Db::rollBack();
                 return Result::error('通栏关联组件失败!');
@@ -1419,13 +1439,9 @@ class PublicRpcService implements PublicRpcServiceInterface
             //     Db::rollBack();
             //     return Result::error('组件位置关联失败!');
             // }
-            $result = Sector::where('id', $data['id'])->update($data);
-            if (empty($result)) {
-                Db::rollBack();
-                return Result::error('修改失败');
-            }
+           
             Db::commit();
-            return Result::success($result);
+            return Result::success($sector);
         } catch (\Exception $e) {
             Db::rollBack();
             return Result::error($e->getMessage());
@@ -2667,7 +2683,7 @@ class PublicRpcService implements PublicRpcServiceInterface
             array_push($where,['sector.page_type', 'like', '%'.$data['page_type'].'%']);
         }
         $sector = Sector::where($where)
-        ->leftJoin('sector_component', 'sector.sector_id', '=', 'sector_component.sector_id')
+        ->leftJoin('sector_component', 'sector.id', '=', 'sector_component.sectorid')
         ->leftJoin('component', 'sector_component.component_id', '=', 'component.component_type')
         ->when(isset($data['template_id']), function ($query) use ($data) {
             // 当 type_id 等于 11 时,关联查询 component_img 表并添加 img_url 字段
@@ -2677,7 +2693,7 @@ class PublicRpcService implements PublicRpcServiceInterface
                     ->where('component.type_id', 11);
             });
         })
-        ->select('sector.sector_name', 'sector_component.sector_id', 'component.*', 'component_img.img_url'
+        ->select('sector.sector_name', 'sector.sector_id', 'component.*', 'component_img.img_url'
         ,'sector.pic_height','sector.sector_img','sector_component.sort_id')  
         ->orderBy('sector_component.sort_id')
         ->orderBy('sector_component.sector_id')