【类 型】:

【原  因】:
【过  程】:
【影  响】:
This commit is contained in:
air 2025-06-16 22:36:42 +08:00
parent 60a2e9d640
commit 10823828db

View File

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