diff --git a/FlyCube/MpApi/Controller/PlaneController.class.php b/FlyCube/MpApi/Controller/PlaneController.class.php index 91c1a3f..ee4220f 100644 --- a/FlyCube/MpApi/Controller/PlaneController.class.php +++ b/FlyCube/MpApi/Controller/PlaneController.class.php @@ -523,45 +523,49 @@ class PlaneController extends PublicController */ public function setNoflyData() { - // 判断 shop_id 参数是否存在且合法 - if ($this->tokenShop_id != C('powerId')) { // 非总管理员,shop_id只能用token的 - $shopId = $this->tokenShop_id; + // 判断 shop_id 是否存在 + if ($this->tokenShop_id != C('powerId')) { + // 非总管理员:用 token 中的 shop_id + $shop_id = $this->tokenShop_id; } else { - $shopId = I('post.shop_id'); - if (empty($shopId) || !is_numeric($shopId)) { - $this->ajaxReturn(['status' => 0, 'msg' => '缺少或非法的shop_id参数']); - exit; + // 总管理员:允许传入 shop_id + if (!isset($_REQUEST['shop_id'])) { + $this->ajaxReturn(['status' => 0, 'msg' => '缺少参数 shop_id']); + return; } + $shop_id = intval($_REQUEST['shop_id']); // 强制转 int } - // 接收禁飞区和限制飞区数据,默认空数组json字符串 - $noflyData = I('post.nofly_data', '[]'); - $restrictFlyData = I('post.restrictfly_data', '[]'); + // 获取禁飞区数据 + $noflyData = isset($_REQUEST['nofly_data']) ? $_REQUEST['nofly_data'] : '[]'; + $restrictFlyData = isset($_REQUEST['restrictfly_data']) ? $_REQUEST['restrictfly_data'] : '[]'; - // 校验传入数据是否为合法的JSON字符串 - if (!is_string($noflyData) || json_decode($noflyData) === null) { - $this->ajaxReturn(['status' => 0, 'msg' => 'nofly_data参数不是合法的JSON字符串']); - exit; + // 验证是否为 JSON 字符串 + json_decode($noflyData); + if (json_last_error() !== JSON_ERROR_NONE) { + $this->ajaxReturn(['status' => 0, 'msg' => 'nofly_data 不是合法 JSON']); + return; } - if (!is_string($restrictFlyData) || json_decode($restrictFlyData) === null) { - $this->ajaxReturn(['status' => 0, 'msg' => 'restrictfly_data参数不是合法的JSON字符串']); - exit; + + 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' => $shopId]; + $where['shop_id'] = $shop_id; + // 要更新的数据 $data = [ 'nofly_data' => $noflyData, - 'restrictfly_data' => $restrictFlyData, + 'restrictfly_data' => $restrictFlyData ]; - // 查询是否已有禁飞区数据 $exist = $noflyDb->where($where)->find(); if ($exist) { - // 更新 $result = $noflyDb->where($where)->save($data); if ($result !== false) { $this->ajaxReturn(['status' => 1, 'msg' => '禁飞区数据更新成功']); @@ -569,8 +573,7 @@ class PlaneController extends PublicController $this->ajaxReturn(['status' => 0, 'msg' => '禁飞区数据更新失败']); } } else { - // 插入 - $data['shop_id'] = $shopId; + $data['shop_id'] = $shop_id; $insertId = $noflyDb->add($data); if ($insertId) { $this->ajaxReturn(['status' => 1, 'msg' => '禁飞区数据保存成功']);