From ec342694856c57e87c39936383a8f7a3698a3231 Mon Sep 17 00:00:00 2001 From: air <30444667+sszdot@users.noreply.github.com> Date: Wed, 18 Jun 2025 18:26:37 +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=9A=20=E3=80=90=E5=8E=9F=20=20=E5=9B=A0=E3=80=91=EF=BC=9A?= =?UTF-8?q?=20=E3=80=90=E8=BF=87=20=20=E7=A8=8B=E3=80=91=EF=BC=9A=20?= =?UTF-8?q?=E3=80=90=E5=BD=B1=20=20=E5=93=8D=E3=80=91=EF=BC=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controller/PlaneController.class.php | 44 +++++++++++++------ 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/FlyCube/MpApi/Controller/PlaneController.class.php b/FlyCube/MpApi/Controller/PlaneController.class.php index 5cd69cf..8f5e32e 100644 --- a/FlyCube/MpApi/Controller/PlaneController.class.php +++ b/FlyCube/MpApi/Controller/PlaneController.class.php @@ -524,30 +524,48 @@ class PlaneController extends PublicController public function setNoflyData() { if ($_REQUEST['shop_id']) { - if ($this->tokenShop_id != C('powerId')) { // 非总管理员 + if ($this->tokenShop_id != C('powerId')) { $where['shop_id'] = $this->tokenShop_id; } else { - $where['shop_id'] = $_REQUEST['shop_id']; // 总管理员可指定 shop_id + $where['shop_id'] = $_REQUEST['shop_id']; } + $noflyDb = D('nofly'); - // 要更新的数据 - if ($_REQUEST['nofly_data']) { + $data = []; + + // 判断是禁飞区更新 + if (isset($_REQUEST['nofly_data']) && !isset($_REQUEST['restrictfly_data']) && !isset($_REQUEST['restrictfly_height'])) { $data['nofly_data'] = $_REQUEST['nofly_data']; - } else { - $data['nofly_data'] = "[]"; + $updateType = 'nofly'; } - if ($_REQUEST['restrictfly_data']) { + + // 判断是限飞区更新 + if (isset($_REQUEST['restrictfly_data']) && isset($_REQUEST['restrictfly_height'])) { + $restrictData = json_decode($_REQUEST['restrictfly_data'], true); + $restrictHeight = json_decode($_REQUEST['restrictfly_height'], true); + + // 校验数组长度是否一致 + if (!is_array($restrictData) || !is_array($restrictHeight) || count($restrictData) !== count($restrictHeight)) { + $this->ajaxReturn(['status' => 0, 'msg' => '限制飞区坐标组与高度组数量不一致']); + } + $data['restrictfly_data'] = $_REQUEST['restrictfly_data']; - } else { - $data['nofly_data'] = "[]"; + $data['restrictfly_height'] = $_REQUEST['restrictfly_height']; + $updateType = 'restrict'; } - if ($noflyDb->where($where)->save($data)) { - $this->ajaxReturn(['status' => 1, 'msg' => '禁飞区数据更新成功']); + + if (empty($data)) { + $this->ajaxReturn(['status' => 0, 'msg' => '未提交任何可更新的数据']); + } + + if ($noflyDb->where($where)->save($data) !== false) { + $msg = ($updateType === 'restrict') ? '限制飞区数据更新成功' : '禁飞区数据更新成功'; + $this->ajaxReturn(['status' => 1, 'msg' => $msg]); } else { - $this->ajaxReturn(['status' => 0, 'msg' => '禁飞区数据更新失败']); + $this->ajaxReturn(['status' => 0, 'msg' => '数据更新失败']); } } else { - echo json_encode(array('status' => 0, 'msg' => '参数有误')); + echo json_encode(['status' => 0, 'msg' => '参数有误']); } } /**