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' => '参数有误')); } } /**