【类 型】:feat
【原 因】:地图添加更新 接口 【过 程】: 【影 响】:
This commit is contained in:
parent
ffd14622cd
commit
1a0127ca90
@ -1145,4 +1145,86 @@ class PlaneController extends PublicController
|
||||
echo json_encode(array('status' => 0, 'msg' => '参数有误'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: 创建新的地图样式
|
||||
*/
|
||||
public function addMapStyle()
|
||||
{
|
||||
|
||||
// 必填字段校验
|
||||
$required = ['name', 'version', 'source_name', 'source_type', 'tile_size', 'tiles', 'layer_id', 'layer_type', 'layer_source'];
|
||||
foreach ($required as $key) {
|
||||
if (!isset($_REQUEST[$key]) || $_REQUEST[$key] === '') {
|
||||
echo json_encode(['status' => 0, 'msg' => '参数缺失: ' . $key]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$data['name'] = $_REQUEST['name'];
|
||||
$data['sprite'] = isset($_REQUEST['sprite']) ? $_REQUEST['sprite'] : '';
|
||||
$data['glyphs'] = isset($_REQUEST['glyphs']) ? $_REQUEST['glyphs'] : '';
|
||||
$data['version'] = intval($_REQUEST['version']);
|
||||
$data['source_name'] = $_REQUEST['source_name'];
|
||||
$data['source_type'] = $_REQUEST['source_type'];
|
||||
$data['tile_size'] = intval($_REQUEST['tile_size']);
|
||||
// tiles 直接保存为字符串(JSON),getMapStyleList 时再 decode
|
||||
$data['tiles'] = $_REQUEST['tiles'];
|
||||
$data['attribution'] = isset($_REQUEST['attribution']) ? $_REQUEST['attribution'] : '';
|
||||
$data['layer_id'] = $_REQUEST['layer_id'];
|
||||
$data['layer_type'] = $_REQUEST['layer_type'];
|
||||
$data['layer_source'] = $_REQUEST['layer_source'];
|
||||
$data['is_active'] = isset($_REQUEST['is_active']) ? intval($_REQUEST['is_active']) : 1;
|
||||
$data['sort_order'] = isset($_REQUEST['sort_order']) ? intval($_REQUEST['sort_order']) : 0;
|
||||
|
||||
$db = D('map_styles');
|
||||
if ($db->data($data)->add()) {
|
||||
echo json_encode(['status' => 1, 'msg' => '创建成功']);
|
||||
} else {
|
||||
echo json_encode(['status' => 0, 'msg' => '创建失败']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: 更新地图样式
|
||||
*/
|
||||
public function saveMapStyle()
|
||||
{
|
||||
|
||||
if (!isset($_REQUEST['id']) || $_REQUEST['id'] === '') {
|
||||
echo json_encode(['status' => 0, 'msg' => '参数缺失: id']);
|
||||
return;
|
||||
}
|
||||
|
||||
$where['id'] = intval($_REQUEST['id']);
|
||||
$data = [];
|
||||
// 可更新字段
|
||||
if (isset($_REQUEST['name'])) $data['name'] = $_REQUEST['name'];
|
||||
if (isset($_REQUEST['sprite'])) $data['sprite'] = $_REQUEST['sprite'];
|
||||
if (isset($_REQUEST['glyphs'])) $data['glyphs'] = $_REQUEST['glyphs'];
|
||||
if (isset($_REQUEST['version'])) $data['version'] = intval($_REQUEST['version']);
|
||||
if (isset($_REQUEST['source_name'])) $data['source_name'] = $_REQUEST['source_name'];
|
||||
if (isset($_REQUEST['source_type'])) $data['source_type'] = $_REQUEST['source_type'];
|
||||
if (isset($_REQUEST['tile_size'])) $data['tile_size'] = intval($_REQUEST['tile_size']);
|
||||
if (isset($_REQUEST['tiles'])) $data['tiles'] = $_REQUEST['tiles'];
|
||||
if (isset($_REQUEST['attribution'])) $data['attribution'] = $_REQUEST['attribution'];
|
||||
if (isset($_REQUEST['layer_id'])) $data['layer_id'] = $_REQUEST['layer_id'];
|
||||
if (isset($_REQUEST['layer_type'])) $data['layer_type'] = $_REQUEST['layer_type'];
|
||||
if (isset($_REQUEST['layer_source'])) $data['layer_source'] = $_REQUEST['layer_source'];
|
||||
if (isset($_REQUEST['is_active'])) $data['is_active'] = intval($_REQUEST['is_active']);
|
||||
if (isset($_REQUEST['sort_order'])) $data['sort_order'] = intval($_REQUEST['sort_order']);
|
||||
|
||||
if (empty($data)) {
|
||||
echo json_encode(['status' => 0, 'msg' => '无可更新字段']);
|
||||
return;
|
||||
}
|
||||
|
||||
$db = D('map_styles');
|
||||
if ($db->where($where)->save($data) !== false) {
|
||||
echo json_encode(['status' => 1, 'msg' => '更新成功']);
|
||||
} else {
|
||||
echo json_encode(['status' => 0, 'msg' => '更新失败']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user