更新命名问题

This commit is contained in:
2025-06-25 11:52:01 +08:00
parent 9f374011ae
commit 6b78ee29cf
57 changed files with 3295 additions and 1288 deletions
+76 -13
View File
@@ -1,4 +1,5 @@
<?php
/**
* @copyright Copyright (c) 2023-2024 美天智能科技
* @author 李志强
@@ -44,6 +45,14 @@ abstract class BaseController
* @var array
*/
protected $middleware = [];
protected $module;
protected $controller;
protected $action;
protected $param;
protected $uid;
protected $did;
protected $name;
/**
* 分页数量
@@ -73,13 +82,11 @@ abstract class BaseController
protected function initialize()
{
// 检测权限
// $this->checkLogin();
//每页显示数据量
$this->pageSize = Request::param('page_size', \think\facade\Config::get('app.page_size'));
//显示当前登录账户权限
// $this->showLoginUserInfo();
$this->checkLogin();
$this->param = $this->request->param();
}
/**
* 显示当前登录账户信息
*/
@@ -98,14 +105,71 @@ abstract class BaseController
*/
protected function checkLogin()
{
$session_admin = get_config('app.session_admin');
if (!Session::has($session_admin)) {
$this->apiError('请先登录');
} else {
$this->uid = Session::get($session_admin)['id'];
View::assign('login_user', $this->uid);
// 定义一个不需要登录验证的接口白名单
$noNeedLogin = [
'apiout/businessinfo/product_info',
'apiout/businessinfo/bifill',
'apiout/index/getpicbedfolder',
'apiout/download/catelist',
'apiout/download/cateinfo',
];
// 当前请求的路径
$currentPath = $this->module . '/' . $this->controller . '/' . $this->action;
// 检查当前路径是否在白名单中
if (in_array($currentPath, $noNeedLogin)) {
return true;
}
if ($this->controller !== 'login' && $this->controller !== 'captcha') {
$session_admin = get_config('app.session_admin');
if (!Session::has($session_admin)) {
if ($this->request->isAjax()) {
return to_assign(404, '请先登录');
} else {
// redirect('/home/login/index.html')->send();
// exit;
return to_assign(404, '请先登录');
}
} else {
$loginUser = Session::get($session_admin);
$loginInfo = Db::name('Admin')->where('id', $loginUser['id'])->find();
$this->uid = $loginInfo['id'];
$params = [
'uid' => $this->uid,
'name' => $loginInfo['name'],
'thumb' => $loginInfo['thumb'],
'module' => $this->module,
'controller' => $this->controller,
'action' => $this->action,
'url' => $this->module . '/' . $this->controller . '/' . $this->action,
'version' => get_system_config('web', 'version')
];
View::assign('params', $params);
// 验证用户访问权限
if (($this->module == 'api') || ($this->module == 'home') || ($this->module == 'apiout')) {
return true;
} else {
$reg_pwd = Db::name('Admin')->where(['id' => $this->uid])->value('reg_pwd');
if ($reg_pwd !== '') {
redirect('/home/user/edit_password.html')->send();
exit;
}
if (!$this->checkAuth()) {
if ($this->request->isAjax()) {
return to_assign(202, '你没有权限,请联系管理员或者人事部');
} else {
echo '<div style="text-align:center;color:red;margin-top:20%;">你没有权限,请联系管理员或者人事部</div>';
exit;
}
}
}
}
}
}
/**
* Api处理成功结果返回方法
* @param $message
@@ -156,5 +220,4 @@ abstract class BaseController
throw new HttpResponseException($response);
}
}
}
+106
View File
@@ -0,0 +1,106 @@
<?php
/**
* @copyright Copyright (c)
* @company 美天智能科技
* @author 李志强
* @link http://www.meteteme.com
*/
declare(strict_types=1);
namespace app\apiout\controller;
use app\apiout\BaseController;
use think\facade\Db;
class BusinessInfo extends BaseController
{
//商机填写接口
public function bifill()
{
// 允许来自指定域名的跨域请求
header('Access-Control-Allow-Origin: https://kd.meteteme.top');
header('Access-Control-Allow-Headers: Content-Type');
header('Access-Control-Allow-Origin: https://www.meteteme.com');
header('Access-Control-Allow-Headers: Content-Type');
// 获取表单数据
$params = $this->request->post();
// 调试:打印接收到的参数
error_log('Received POST parameters: ' . json_encode($params));
// 判断表单数据是否完整
$requiredFields = ['name', 'email', 'phone', 'message', 'product', 'company', 'ip'];
foreach ($requiredFields as $field) {
if (!isset($params[$field]) || empty($params[$field])) {
error_log("Missing or empty field: $field");
return json(['code' => 2, 'msg' => '请填写完整的表单数据!']);
}
}
// 向数据库插入数据
$result = Db::name('Information')->insert([
'name' => $params['name'],
'email' => $params['email'],
'phone' => $params['phone'],
'message' => $params['message'],
'product' => $params['product'],
'company' => $params['company'],
'ip' => $params['ip'],
'create_time' => time(),
]);
// 判断插入结果
if ($result) {
$webhook = 'https://oapi.dingtalk.com/robot/send?access_token=c39726abd36659f92442847430eda90bebb360c438270f7c05bea388f1c8168c';
$title = '**有新的商机生成!**';
$line = '------------------------------';
$companynames = '公司名称:' . $params['company'];
$names = '联 系 人 ' . $params['name'];
$contents = '请及时进入项管系统查看!';
$times = '创建日期:' . date('Y-m-d H:i:s', time());
$data = array(
'msgtype' => 'actionCard',
'actionCard' => array(
'title' => $title,
'text' => $title . "\n\n" . $companynames . "\n\n" . $names . "\n\n" . $times,
'btnOrientation' => '0',
'btns' => [
[
'title' => '查看商机',
'actionURL' => 'dingtalk://dingtalkclient/page/link?url=' . urlencode('https://project.meteteme.com/information/index/index') . '&pc_slide=false'
]
]
)
);
$options = array(
'http' => array(
'header' => "Content-type: application/json",
'method' => 'POST',
'content' => json_encode($data),
)
);
$context = stream_context_create($options);
$result = file_get_contents($webhook, false, $context);
return json(['code' => 0, 'msg' => '留言提交成功!']);
} else {
return json(['code' => 1, 'msg' => '留言提交失败!']);
}
}
//获取产品信息
public function product_info()
{
// 查询Product表中的所有产品信息
$products = Db::name('Product')->field('id, name')->select();
// 返回产品信息数组给前端,包括id和name
return json(['code' => 0, 'msg' => '获取产品信息成功', 'data' => $products]);
}
}
+49
View File
@@ -0,0 +1,49 @@
<?php
/**
* @copyright Copyright (c) 2023-2024 美天智能科技
* @link http://www.meteteme.com
*/
namespace app\apiout\controller;
use app\apiout\BaseController;
use app\model\Download as DownloadList;
use app\model\DownloadCate as DownloadCateList;
use think\facade\Db;
use think\facade\View;
class Download extends BaseController
{
//获取软件分类
public function catelist()
{
$catelist = DownloadCateList::field('id, name, sort')
->where('delete_time', null)
->order('sort', 'desc')
->select();
return json(['code' => 0, 'msg' => '', 'data' => $catelist]);
}
//获取分类详情
public function cateinfo()
{
$id = get_params('id'); // 获取分类 ID 参数
if (!$id) {
return json(['code' => 1, 'msg' => '分类 ID 不能为空', 'data' => []]);
}
// 查询对应分类下的所有数据
$cateinfo = DownloadList::field('id, cid, name, path, download_url, download_code, size ,type')
->where('cid', $id)
->select(); // 使用 select() 返回多个数据
if ($cateinfo->isEmpty()) {
return json(['code' => 1, 'msg' => '该分类下没有数据', 'data' => []]);
}
return json(['code' => 0, 'msg' => '', 'data' => $cateinfo]);
}
}
+11 -4
View File
@@ -1,8 +1,15 @@
<?php
/**
* @copyright Copyright (c) 2023-2024 美天智能科技
* @author 李志强
* @link http://www.meteteme.com
*/
// 这是系统自动生成的middleware定义文件
return [
//开启session中间件
//'think\middleware\SessionInit',
//验证勾股cms是否完成安装
\app\home\middleware\Install::class,
//开启session中间件
//'think\middleware\SessionInit',
\app\home\middleware\Install::class,
// 跳过登录验证 AuthMiddleware
\app\apiout\middleware\Auth::class,
];
+30
View File
@@ -0,0 +1,30 @@
<?php
namespace app\apiout\middleware;
use Closure;
use think\Request;
use think\Response;
class Auth
{
public function handle(Request $request, Closure $next): Response
{
// 获取当前请求的控制器和方法
$controller = $request->controller();
$action = $request->action();
// 如果请求的控制器是 BusinessInfo 且方法是 product_info 或者是登录页面,则跳过验证
if (($controller === 'BusinessInfo' && $action === 'product_info') || ($controller === 'Login' && $action === 'index')) {
return $next($request);
}
// 执行登录验证逻辑
// if (!session('?user_id')) {
// // 未登录,返回错误或重定向到登录页面
// return redirect('login/index');
// }
return $next($request);
}
}