tv/extend/adm/app/api/homead.php
2025-11-28 14:28:58 +08:00

91 lines
3.9 KiB
PHP

<?php
/*
Name:首页广告API
Version:1.0
Author:易如意
Author QQ:51154393
Author Url:www.eruyi.cn
*/
if (!isset($islogin)) header("Location: /"); //非法访问
if ($act == 'add') { //添加配置
$name = isset($_POST['name']) ? purge($_POST['name']) : '';
$data = isset($_POST['data']) ? purge($_POST['data']) : '';
$appid = isset($_POST['appid']) ? intval($_POST['appid']) : 0;
$searchable = isset($_POST['searchable']) ? purge($_POST['searchable']) : 'n';
if ($name == '') json(201, '变量名称为空');
// if(preg_match ("/^[\w]{1,32}$/",$name)==0)json(201,'变量名称不合格');
if ($data == '') json(201, '扩展配置为空');
if ($appid == 0) json(201, '绑定应用为空');
$app_res = Db::table('app')->where('id', $appid)->find();
if (!$app_res) json(201, '应用不存在');
$homead_res = Db::table('app_homead')->where(['name' => $name])->find();
if ($homead_res) json(201, '变量名已存在');
$add_res = Db::table('app_homead')->add(['name' => $name, 'data' => $data, 'appid' => $appid, 'searchable' => $searchable]);
//die($add_res);
if ($add_res) {
if (defined('ADM_LOG') && ADM_LOG == 1) {
Db::table('log')->add(['group' => 'adm', 'type' => 'homead_add', 'status' => 200, 'time' => time(), 'ip' => getip(), 'data' => json_encode($_POST)]);
} //记录日志
json(200, '添加成功');
} else {
if (defined('ADM_LOG') && ADM_LOG == 1) {
Db::table('log')->add(['group' => 'adm', 'type' => 'homead_add', 'status' => 201, 'time' => time(), 'ip' => getip(), 'data' => json_encode($_POST)]);
} //记录日志
json(201, '添加失败');
}
}
if ($act == 'edit') { //编辑配置
$id = isset($_POST['id']) ? intval($_POST['id']) : 0;
$update['name'] = isset($_POST['name']) ? purge($_POST['name']) : '';
$update['data'] = isset($_POST['data']) ? purge($_POST['data']) : '';
$update['appid'] = isset($_POST['appid']) ? intval($_POST['appid']) : 0;
$update['searchable'] = isset($_POST['searchable']) ? intval($_POST['searchable']) : 0;
if ($update['name'] == '') json(201, '变量名称为空');
if ($update['data'] == '') json(201, '扩展配置为空');
if ($update['appid'] == 0) json(201, '绑定应用为空');
$app_res = Db::table('app')->where('id', $update['appid'])->find();
if (!$app_res) json(201, '应用不存在');
$homead_res = Db::table('app_homead')->where(['name' => $update['name']])->find();
if ($homead_res) {
if ($homead_res['id'] != $id) json(201, '变量名已存在');
}
$res = Db::table('app_homead')->where('id', $id)->update($update);
//die($res);
if ($res) {
if (defined('ADM_LOG') && ADM_LOG == 1) {
Db::table('log')->add(['group' => 'adm', 'type' => 'homead_edit', 'status' => 200, 'time' => time(), 'ip' => getip(), 'data' => json_encode($_POST)]);
} //记录日志
json(200, '编辑成功');
} else {
if (defined('ADM_LOG') && ADM_LOG == 1) {
Db::table('log')->add(['group' => 'adm', 'type' => 'homead_edit', 'status' => 201, 'time' => time(), 'ip' => getip(), 'data' => json_encode($_POST)]);
} //记录日志
json(201, '编辑失败');
}
}
if ($act == 'del') { //删除配置
$id = isset($_POST['id']) ? $_POST['id'] : '';
if ($id) {
$ids = '';
foreach ($id as $value) {
$ids .= intval($value) . ",";
}
$ids = rtrim($ids, ",");
$res = Db::table('app_homead')->where('id', 'in', '(' . $ids . ')')->del(); //false
//die($res);
if ($res) {
if (defined('ADM_LOG') && ADM_LOG == 1) {
Db::table('log')->add(['group' => 'adm', 'type' => 'homead_del', 'status' => 200, 'time' => time(), 'ip' => getip(), 'data' => json_encode($_POST)]);
} //记录日志
json(200, '删除成功');
} else {
if (defined('ADM_LOG') && ADM_LOG == 1) {
Db::table('log')->add(['group' => 'adm', 'type' => 'homead_del', 'status' => 201, 'time' => time(), 'ip' => getip(), 'data' => json_encode($_POST)]);
} //记录日志
json(201, '删除失败');
}
} else {
json(201, '没有需要删除的数据');
}
}
?>