【类 型】:feat

【原  因】:setNoflyData设置禁飞区数据接口
【过  程】:
【影  响】:
This commit is contained in:
air 2025-06-16 22:14:56 +08:00
parent c195a1c9a8
commit 589e9bb6fa

View File

@ -521,25 +521,49 @@ class PlaneController extends PublicController
/**
* @description: 设置禁飞区
*/
public function setNofly()
public function setNoflyData()
{
//总管理员 可接收任何shop_id 非总管理员 只可以调用自身shop_id 否则会中断
$this->isPower();
if ($this->tokenShop_id != C('powerId')) { // 非总管理员
$where['shop_id'] = $this->tokenShop_id;
} else {
$where['shop_id'] = I('post.shop_id'); // 总管理员可指定 shop_id使用I函数更安全
}
if ($_REQUEST['shop_id']) {
$noflyDb = D('nofly');
$where['shop_id'] = $_REQUEST['shop_id'];
$data['nofly_data'] = $_REQUEST['nofly_data'];
$data['restrictfly_data'] = $_REQUEST['restrictfly_data'];
// 接收前端传来的禁飞区数据和限制飞区数据预期是json字符串
$noflyData = I('post.nofly_data', '[]'); // 默认空数组json字符串
$restrictFlyData = I('post.restrictfly_data', '[]');
//录入数据库
if ($noflyDb->where($where)->save($data)) {
echo json_encode(array('status' => 1, 'msg' => '创建成功'));
// 验证数据是否是合法JSON字符串这里简单判断也可以更严谨
if (!is_string($noflyData) || !is_string($restrictFlyData)) {
$this->ajaxReturn(['status' => 0, 'msg' => '传入数据格式错误']);
return;
}
$noflyDb = D('nofly');
// 查询是否已有禁飞区数据
$exist = $noflyDb->where($where)->find();
$data['nofly_data'] = $noflyData;
$data['restrictfly_data'] = $restrictFlyData;
if ($exist) {
// 更新
$result = $noflyDb->where($where)->save($data);
if ($result !== false) {
$this->ajaxReturn(['status' => 1, 'msg' => '禁飞区数据更新成功']);
} else {
echo json_encode(array('status' => 0, 'msg' => '创建失败'));
$this->ajaxReturn(['status' => 0, 'msg' => '禁飞区数据更新失败']);
}
} else {
echo json_encode(array('status' => 0, 'msg' => '参数有误'));
// 插入
$data['shop_id'] = $where['shop_id'];
$insertId = $noflyDb->add($data);
if ($insertId) {
$this->ajaxReturn(['status' => 1, 'msg' => '禁飞区数据保存成功']);
} else {
$this->ajaxReturn(['status' => 0, 'msg' => '禁飞区数据保存失败']);
}
}
}
/**