From 6507855e896893a3b4869abb969abee9426b04c8 Mon Sep 17 00:00:00 2001 From: air <30444667+sszdot@users.noreply.github.com> Date: Mon, 16 Jun 2025 23:03:47 +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 | 70 +++++-------------- 1 file changed, 19 insertions(+), 51 deletions(-) diff --git a/FlyCube/MpApi/Controller/PlaneController.class.php b/FlyCube/MpApi/Controller/PlaneController.class.php index 5cc5a7e..47ae289 100644 --- a/FlyCube/MpApi/Controller/PlaneController.class.php +++ b/FlyCube/MpApi/Controller/PlaneController.class.php @@ -523,63 +523,31 @@ class PlaneController extends PublicController */ public function setNoflyData() { - // 判断 shop_id 是否存在 - if ($this->tokenShop_id != C('powerId')) { - // 非总管理员:用 token 中的 shop_id - $shop_id = $this->tokenShop_id; - } else { - // 总管理员:允许传入 shop_id - if (!isset($_REQUEST['shop_id'])) { - $this->ajaxReturn(['status' => 0, 'msg' => '缺少参数 shop_id']); - return; + if ($_REQUEST['shop_id']) { + if ($this->tokenShop_id != C('powerId')) { // 非总管理员 + $where['shop_id'] = $this->tokenShop_id; + } else { + $where['shop_id'] = $_REQUEST['shop_id']; // 总管理员可指定 shop_id } - $shop_id = trim($_REQUEST['shop_id']); // 保留字符串,不转 int - } - - // 获取禁飞区数据 - $noflyData = isset($_REQUEST['nofly_data']) ? $_REQUEST['nofly_data'] : '[]'; - $restrictFlyData = isset($_REQUEST['restrictfly_data']) ? $_REQUEST['restrictfly_data'] : '[]'; - - // 验证是否为 JSON 字符串 - json_decode($noflyData); - if (json_last_error() !== JSON_ERROR_NONE) { - $this->ajaxReturn(['status' => 0, 'msg' => 'nofly_data 不是合法 JSON']); - return; - } - - json_decode($restrictFlyData); - if (json_last_error() !== JSON_ERROR_NONE) { - $this->ajaxReturn(['status' => 0, 'msg' => 'restrictfly_data 不是合法 JSON']); - return; - } - - $noflyDb = D('nofly'); - - $where['shop_id'] = $shop_id; - - // 要更新的数据 - $data = [ - 'nofly_data' => $noflyData, - 'restrictfly_data' => $restrictFlyData - ]; - - $exist = $noflyDb->where($where)->find(); - - if ($exist) { - $result = $noflyDb->where($where)->save($data); - if ($result !== false) { + $noflyDb = D('nofly'); + // 要更新的数据 + if ($_REQUEST['nofly_data']) { + $data['nofly_data'] = $_REQUEST['nofly_data']; + } else { + $data['nofly_data'] = "[]"; + } + if ($_REQUEST['restrictfly_data']) { + $data['restrictfly_data'] = $_REQUEST['restrictfly_data']; + } else { + $data['nofly_data'] = "[]"; + } + if ($noflyDb->where($where)->save($data)) { $this->ajaxReturn(['status' => 1, 'msg' => '禁飞区数据更新成功']); } else { $this->ajaxReturn(['status' => 0, 'msg' => '禁飞区数据更新失败']); } } else { - $data['shop_id'] = $shop_id; - $insertId = $noflyDb->add($data); - if ($insertId) { - $this->ajaxReturn(['status' => 1, 'msg' => '禁飞区数据保存成功']); - } else { - $this->ajaxReturn(['status' => 0, 'msg' => '禁飞区数据保存失败']); - } + echo json_encode(array('status' => 0, 'msg' => '参数有误')); } } /**