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