From 1a0127ca9068ca0b82c3591f221ab5ac297f7f25 Mon Sep 17 00:00:00 2001 From: air <30444667+sszdot@users.noreply.github.com> Date: Mon, 22 Sep 2025 19:43:58 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E7=B1=BB=20=20=E5=9E=8B=E3=80=91?= =?UTF-8?q?=EF=BC=9Afeat=20=E3=80=90=E5=8E=9F=20=20=E5=9B=A0=E3=80=91?= =?UTF-8?q?=EF=BC=9A=E5=9C=B0=E5=9B=BE=E6=B7=BB=E5=8A=A0=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=20=E6=8E=A5=E5=8F=A3=20=E3=80=90=E8=BF=87=20=20=E7=A8=8B?= =?UTF-8?q?=E3=80=91=EF=BC=9A=20=E3=80=90=E5=BD=B1=20=20=E5=93=8D=E3=80=91?= =?UTF-8?q?=EF=BC=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controller/PlaneController.class.php | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/FlyCube/MpApi/Controller/PlaneController.class.php b/FlyCube/MpApi/Controller/PlaneController.class.php index 86f904a..bcfbab5 100644 --- a/FlyCube/MpApi/Controller/PlaneController.class.php +++ b/FlyCube/MpApi/Controller/PlaneController.class.php @@ -1145,4 +1145,86 @@ class PlaneController extends PublicController echo json_encode(array('status' => 0, 'msg' => '参数有误')); } } + + /** + * @description: 创建新的地图样式 + */ + public function addMapStyle() + { + + // 必填字段校验 + $required = ['name', 'version', 'source_name', 'source_type', 'tile_size', 'tiles', 'layer_id', 'layer_type', 'layer_source']; + foreach ($required as $key) { + if (!isset($_REQUEST[$key]) || $_REQUEST[$key] === '') { + echo json_encode(['status' => 0, 'msg' => '参数缺失: ' . $key]); + return; + } + } + + $data = []; + $data['name'] = $_REQUEST['name']; + $data['sprite'] = isset($_REQUEST['sprite']) ? $_REQUEST['sprite'] : ''; + $data['glyphs'] = isset($_REQUEST['glyphs']) ? $_REQUEST['glyphs'] : ''; + $data['version'] = intval($_REQUEST['version']); + $data['source_name'] = $_REQUEST['source_name']; + $data['source_type'] = $_REQUEST['source_type']; + $data['tile_size'] = intval($_REQUEST['tile_size']); + // tiles 直接保存为字符串(JSON),getMapStyleList 时再 decode + $data['tiles'] = $_REQUEST['tiles']; + $data['attribution'] = isset($_REQUEST['attribution']) ? $_REQUEST['attribution'] : ''; + $data['layer_id'] = $_REQUEST['layer_id']; + $data['layer_type'] = $_REQUEST['layer_type']; + $data['layer_source'] = $_REQUEST['layer_source']; + $data['is_active'] = isset($_REQUEST['is_active']) ? intval($_REQUEST['is_active']) : 1; + $data['sort_order'] = isset($_REQUEST['sort_order']) ? intval($_REQUEST['sort_order']) : 0; + + $db = D('map_styles'); + if ($db->data($data)->add()) { + echo json_encode(['status' => 1, 'msg' => '创建成功']); + } else { + echo json_encode(['status' => 0, 'msg' => '创建失败']); + } + } + + /** + * @description: 更新地图样式 + */ + public function saveMapStyle() + { + + if (!isset($_REQUEST['id']) || $_REQUEST['id'] === '') { + echo json_encode(['status' => 0, 'msg' => '参数缺失: id']); + return; + } + + $where['id'] = intval($_REQUEST['id']); + $data = []; + // 可更新字段 + if (isset($_REQUEST['name'])) $data['name'] = $_REQUEST['name']; + if (isset($_REQUEST['sprite'])) $data['sprite'] = $_REQUEST['sprite']; + if (isset($_REQUEST['glyphs'])) $data['glyphs'] = $_REQUEST['glyphs']; + if (isset($_REQUEST['version'])) $data['version'] = intval($_REQUEST['version']); + if (isset($_REQUEST['source_name'])) $data['source_name'] = $_REQUEST['source_name']; + if (isset($_REQUEST['source_type'])) $data['source_type'] = $_REQUEST['source_type']; + if (isset($_REQUEST['tile_size'])) $data['tile_size'] = intval($_REQUEST['tile_size']); + if (isset($_REQUEST['tiles'])) $data['tiles'] = $_REQUEST['tiles']; + if (isset($_REQUEST['attribution'])) $data['attribution'] = $_REQUEST['attribution']; + if (isset($_REQUEST['layer_id'])) $data['layer_id'] = $_REQUEST['layer_id']; + if (isset($_REQUEST['layer_type'])) $data['layer_type'] = $_REQUEST['layer_type']; + if (isset($_REQUEST['layer_source'])) $data['layer_source'] = $_REQUEST['layer_source']; + if (isset($_REQUEST['is_active'])) $data['is_active'] = intval($_REQUEST['is_active']); + if (isset($_REQUEST['sort_order'])) $data['sort_order'] = intval($_REQUEST['sort_order']); + + if (empty($data)) { + echo json_encode(['status' => 0, 'msg' => '无可更新字段']); + return; + } + + $db = D('map_styles'); + if ($db->where($where)->save($data) !== false) { + echo json_encode(['status' => 1, 'msg' => '更新成功']); + } else { + echo json_encode(['status' => 0, 'msg' => '更新失败']); + } + } }