|
|
@@ -2545,68 +2545,137 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
|
|
|
}
|
|
|
/**
|
|
|
- * 通栏版式管理-版式画布
|
|
|
- * @param array $data
|
|
|
- * @return array
|
|
|
- */
|
|
|
- public function changeSectorPlaceJson($sector_type)
|
|
|
- {
|
|
|
- $component = SectorPlace::where('type_id', 2)->where('sector_type', $sector_type)->get()->all();
|
|
|
- // $component[count($component)] = $data;
|
|
|
- $sector_type_info = SectorPlace::where('sector_type', $sector_type)->where('type_id', 1)->first();
|
|
|
- if (empty($sector_type_info)) {
|
|
|
- return Result::error('通栏版式类别不存在!');
|
|
|
- }
|
|
|
- $row_num = 1;
|
|
|
- $cat_num = 0;
|
|
|
- $row_width = [];
|
|
|
- $map = [];
|
|
|
- if(count($component) == $sector_type_info['component_num']){
|
|
|
- foreach($component as $key => $val){
|
|
|
- if(in_array($val['type'],[23,24])){
|
|
|
- $cat_num = $cat_num + 2;
|
|
|
- }
|
|
|
- if(in_array($val['type'],[7,14])){
|
|
|
- $cat_num = $cat_num + 1;
|
|
|
- }
|
|
|
- if(!isset($map[$val['column_num'] - 1]['col_data']['row_num'])){
|
|
|
- $row_num = 1;
|
|
|
- $map[$val['column_num'] - 1]['col_data']['row_num'] = $row_num;
|
|
|
- }else{
|
|
|
- $map[$val['column_num'] - 1]['col_data']['row_num'] = $row_num +1;
|
|
|
- }
|
|
|
- // 原代码使用 $sector_type['width'] 有误,应该使用 $sector_type_info
|
|
|
- $width = number_format((($val['width'] / $sector_type_info['width']) * 100 - 1.5), 2);
|
|
|
- $height = number_format((($val['height'] / $sector_type_info['height']) * 100 - 2.5), 2);
|
|
|
- $col_width = $width;
|
|
|
- if(!isset($column_num_width[$val['column_num']])){
|
|
|
- $column_num_width[$val['column_num']] = $val['width'];
|
|
|
- var_dump(array_keys($column_num_width));
|
|
|
- }else if($column_num_width[$val['column_num']] != $val['width']){
|
|
|
- $col_width = min($val['width'],$column_num_width[$val['column_num']]);
|
|
|
- $col_width = number_format((($col_width / $sector_type_info['width']) * 100 - 1.5), 2);
|
|
|
- $width = number_format((($val['width'] / $column_num_width[$val['column_num']]) * 100 - 2.5), 2);
|
|
|
- }
|
|
|
- $row_key = intval($val['line_num'] - 1);
|
|
|
- $map[$val['column_num'] - 1]['col_data']['row_data'][$row_key] = [
|
|
|
- 'row_width' => $width.'%',
|
|
|
- 'row_height' => $height.'%',
|
|
|
- 'component_sort' => $val['sort_id'],
|
|
|
- ];
|
|
|
- $map[$val['column_num'] - 1]['col_data']['col_width'] = $col_width.'%';
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- $map_data = [
|
|
|
- 'map_json'=>$map ?? [],
|
|
|
- 'component'=>count($component),
|
|
|
- 'row_num'=>$row_num ?? 0,
|
|
|
- 'cat_num'=>$cat_num ?? 0,
|
|
|
- 'component_info'=>$component,
|
|
|
- ];
|
|
|
-
|
|
|
- return $map_data;
|
|
|
- }
|
|
|
+ * 通栏版式管理-版式画布
|
|
|
+ * @param array $data
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function changeSectorPlaceJson($sector_type)
|
|
|
+ {
|
|
|
+ $component = SectorPlace::where('type_id', 2)->where('sector_type', $sector_type)->get()->all();
|
|
|
+ // $component[count($component)] = $data;
|
|
|
+ $sector_type_info = SectorPlace::where('sector_type', $sector_type)->where('type_id', 1)->first();
|
|
|
+ if (empty($sector_type_info)) {
|
|
|
+ return Result::error('通栏版式类别不存在!');
|
|
|
+ }
|
|
|
+ $allcomponent_type = array_column($component, 'type');
|
|
|
+ if($sector_type_info['column_num'] > 1 && in_array(13,$allcomponent_type)){
|
|
|
+ $aboutArtcle_catkey = array_search(13,$allcomponent_type);
|
|
|
+ // 确保取到的是数字类型的 width,避免与模型对象相乘
|
|
|
+ $width = (int) ($component[$aboutArtcle_catkey]['width'] ?? 1);
|
|
|
+ $sector_type_info['width'] = $sector_type_info['width'] + $width;
|
|
|
+ }
|
|
|
+ $row_num = 1;
|
|
|
+ $cat_num = 0;
|
|
|
+ $row_width = [];
|
|
|
+ $map = [];
|
|
|
+
|
|
|
+ // 按 column_num 分组并取每组最小 width
|
|
|
+ $col_width = [];
|
|
|
+ foreach ($component as $item) {
|
|
|
+ $col = $item['column_num']-1;
|
|
|
+ if (!isset($grouped[$col]) || $item['width'] < $grouped[$col]['width']) {
|
|
|
+ $column_width[$col] = $item['width'];
|
|
|
+ // $column_width[$col][$item['line_num']-1] = $item['line_num'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // $grouped 即为分组后各组 width 最小的记录
|
|
|
+ // return Result::success($column_width);
|
|
|
+ if(count($component) == $sector_type_info['component_num']){
|
|
|
+ foreach($component as $key => $val){
|
|
|
+ if(in_array($val['type'],[23,24])){
|
|
|
+ $cat_num = $cat_num + 2;
|
|
|
+ }
|
|
|
+ if(in_array($val['type'],[7,14])){
|
|
|
+ $cat_num = $cat_num + 1;
|
|
|
+ }
|
|
|
+ if(!isset($map[$val['column_num'] - 1]['col_data']['row_num'])){
|
|
|
+ $row_num = 1;
|
|
|
+ $map[$val['column_num'] - 1]['col_data']['row_num'] = $row_num;
|
|
|
+ }else{
|
|
|
+ $map[$val['column_num'] - 1]['col_data']['row_num'] = $row_num +1;
|
|
|
+ }
|
|
|
+ // 原代码使用 $sector_type['width'] 有误,应该使用 $sector_type_info
|
|
|
+ // $width = number_format((($val['width'] / $sector_type_info['width']) * 100 - 1.5), 2);
|
|
|
+ $height = number_format((($val['height'] / $sector_type_info['height']) * 100 - 2.5), 2);
|
|
|
+ $col_width = $column_width[$val['column_num'] - 1];
|
|
|
+
|
|
|
+ $width = number_format((($val['width'] / $col_width) * 100 - 1.5), 2);
|
|
|
+ $col_width = number_format((($col_width / $sector_type_info['width']) * 100 - 1.5), 2);
|
|
|
+ $row_key = intval($val['line_num'] - 1);
|
|
|
+ $map[$val['column_num'] - 1]['col_data']['row_data'][$row_key] = [
|
|
|
+ 'row_width' => $width.'%',
|
|
|
+ 'row_height' => $height.'%',
|
|
|
+ 'component_sort' => $val['sort_id'],
|
|
|
+ ];
|
|
|
+ $map[$val['column_num'] - 1]['col_data']['col_width'] = $col_width.'%';
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 补全缺失的行,确保row_data是连续的索引数组
|
|
|
+ if (!empty($map)) {
|
|
|
+ // 为每一列补全缺失的行
|
|
|
+ for ($col_index = 0; $col_index < count($map); $col_index++) {
|
|
|
+ if (isset($map[$col_index]['col_data']['row_data'])) {
|
|
|
+ $row_data = &$map[$col_index]['col_data']['row_data'];
|
|
|
+
|
|
|
+ // 检查当前行数据是否是连续的索引数组
|
|
|
+ $rows = array_keys($row_data);
|
|
|
+ if (empty($rows)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查是否存在断连
|
|
|
+ $min_row = min($rows);
|
|
|
+ $max_row = max($rows);
|
|
|
+ $is_continuous = (count($rows) === $max_row - $min_row + 1);
|
|
|
+
|
|
|
+ // 只有当行号不连续时才进行补全
|
|
|
+ if (!$is_continuous || $min_row > 0) {
|
|
|
+ $temp_row_data = [];
|
|
|
+
|
|
|
+ // 遍历从0到最大行号的所有行
|
|
|
+ for ($row_index = 0; $row_index <= $max_row; $row_index++) {
|
|
|
+ if (isset($row_data[$row_index])) {
|
|
|
+ // 保留原有行数据
|
|
|
+ $temp_row_data[$row_index] = $row_data[$row_index];
|
|
|
+ } else {
|
|
|
+ // 补全新行数据
|
|
|
+ $temp_row_data[$row_index] = [
|
|
|
+ 'row_width' => '1%', // 固定为1%
|
|
|
+ 'row_height' => '30.83%', // 默认高度
|
|
|
+ 'component_sort' => null // 补全的行没有component_sort
|
|
|
+ ];
|
|
|
+
|
|
|
+ // 如果不是第一列,尝试从上一列获取高度
|
|
|
+ if ($col_index > 0 && isset($map[$col_index - 1]['col_data']['row_data'][$row_index])) {
|
|
|
+ $temp_row_data[$row_index]['row_height'] = $map[$col_index - 1]['col_data']['row_data'][$row_index]['row_height'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新为连续的索引数组
|
|
|
+ $map[$col_index]['col_data']['row_data'] = array_values($temp_row_data);
|
|
|
+ // 更新row_num
|
|
|
+ $map[$col_index]['col_data']['row_num'] = count($temp_row_data);
|
|
|
+ } elseif (!is_array(reset($row_data))) {
|
|
|
+ // 如果是关联数组但键是连续的,转换为索引数组
|
|
|
+ ksort($row_data);
|
|
|
+ $map[$col_index]['col_data']['row_data'] = array_values($row_data);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $map_data = [
|
|
|
+ 'map_json'=>$map ?? [],
|
|
|
+ 'component'=>count($component),
|
|
|
+ 'row_num'=>$row_num ?? 0,
|
|
|
+ 'cat_num'=>$cat_num ?? 0,
|
|
|
+ 'component_info'=>$component,
|
|
|
+ ];
|
|
|
+
|
|
|
+ return $map_data;
|
|
|
+ }
|
|
|
/**
|
|
|
* 通栏版式管理-修改通栏版式
|
|
|
*/
|
|
|
@@ -3913,9 +3982,6 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
// 提取并返回 component_imgs 内容,添加空安全检查
|
|
|
// return $sectors[0]['sector_components'][0]['component']['component_imgs'] ?? [];
|
|
|
// return $sectors;
|
|
|
-
|
|
|
- $query = WebsiteCategory::where('website_id', $data['website_id']);
|
|
|
- // $cate_num = $query->where('is_show', 1)->count();
|
|
|
$cat_column = [
|
|
|
'website_id' => $data['website_id'],
|
|
|
'is_show' => 1,
|
|
|
@@ -3928,7 +3994,7 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
// 本项目中已存在 WebsiteServer 及其 getWebsiteModelCategory 方法,直接调用
|
|
|
$websiteServer = new \App\JsonRpc\WebsiteService();
|
|
|
$all_cate_data = $websiteServer->getWebsiteModelCategory($cat_column);
|
|
|
- $all_cate = $all_cate_data['data'];
|
|
|
+ $all_cate = $all_cate_data['data'] ?? [];
|
|
|
|
|
|
// $all_cate = $query->where('is_show', 1)
|
|
|
// // ->where('pid', 0)
|
|
|
@@ -3940,9 +4006,19 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
if ($cate_num < 5) {
|
|
|
return 此网站栏目过少,无法进行随机模板!;
|
|
|
}
|
|
|
+ $all_cate = $all_cate->toArray();
|
|
|
+ $del_catid = 0;
|
|
|
+ foreach ($all_cate as $k => $v) {
|
|
|
+ $cat_arr_id = json_decode($v['category_arr_id'],true) ?? [];
|
|
|
+ if (!empty($v['web_url']) || $v['type'] != 1 || $v['pid'] == $del_catid) {
|
|
|
+ $del_catid = $v['category_id'] ?? '';
|
|
|
+ unset($all_cate[$k]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $all_cate = array_values($all_cate);
|
|
|
$cate_num = min($cate_num, 24);
|
|
|
$all_sector_type = array_column($sectors, 'sector_type');
|
|
|
- // return $all_sector_type;
|
|
|
+ // return $all_cate;
|
|
|
$grouped = array_reduce(array_keys($sectors),function ($carry, $idx) use ($sectors) {
|
|
|
$carry[$sectors[$idx]['sector_type']][] = $idx;
|
|
|
return $carry;
|