【类 型】:

【原  因】:
【过  程】:
【影  响】:
This commit is contained in:
air 2025-06-16 23:03:47 +08:00
parent 7909a35f1f
commit 6507855e89

View File

@ -523,63 +523,31 @@ class PlaneController extends PublicController
*/ */
public function setNoflyData() public function setNoflyData()
{ {
// 判断 shop_id 是否存在 if ($_REQUEST['shop_id']) {
if ($this->tokenShop_id != C('powerId')) { if ($this->tokenShop_id != C('powerId')) { // 非总管理员
// 非总管理员:用 token 中的 shop_id $where['shop_id'] = $this->tokenShop_id;
$shop_id = $this->tokenShop_id; } else {
} else { $where['shop_id'] = $_REQUEST['shop_id']; // 总管理员可指定 shop_id
// 总管理员:允许传入 shop_id
if (!isset($_REQUEST['shop_id'])) {
$this->ajaxReturn(['status' => 0, 'msg' => '缺少参数 shop_id']);
return;
} }
$shop_id = trim($_REQUEST['shop_id']); // 保留字符串,不转 int $noflyDb = D('nofly');
} // 要更新的数据
if ($_REQUEST['nofly_data']) {
// 获取禁飞区数据 $data['nofly_data'] = $_REQUEST['nofly_data'];
$noflyData = isset($_REQUEST['nofly_data']) ? $_REQUEST['nofly_data'] : '[]'; } else {
$restrictFlyData = isset($_REQUEST['restrictfly_data']) ? $_REQUEST['restrictfly_data'] : '[]'; $data['nofly_data'] = "[]";
}
// 验证是否为 JSON 字符串 if ($_REQUEST['restrictfly_data']) {
json_decode($noflyData); $data['restrictfly_data'] = $_REQUEST['restrictfly_data'];
if (json_last_error() !== JSON_ERROR_NONE) { } else {
$this->ajaxReturn(['status' => 0, 'msg' => 'nofly_data 不是合法 JSON']); $data['nofly_data'] = "[]";
return; }
} if ($noflyDb->where($where)->save($data)) {
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) {
$this->ajaxReturn(['status' => 1, 'msg' => '禁飞区数据更新成功']); $this->ajaxReturn(['status' => 1, 'msg' => '禁飞区数据更新成功']);
} else { } else {
$this->ajaxReturn(['status' => 0, 'msg' => '禁飞区数据更新失败']); $this->ajaxReturn(['status' => 0, 'msg' => '禁飞区数据更新失败']);
} }
} else { } else {
$data['shop_id'] = $shop_id; echo json_encode(array('status' => 0, 'msg' => '参数有误'));
$insertId = $noflyDb->add($data);
if ($insertId) {
$this->ajaxReturn(['status' => 1, 'msg' => '禁飞区数据保存成功']);
} else {
$this->ajaxReturn(['status' => 0, 'msg' => '禁飞区数据保存失败']);
}
} }
} }
/** /**