Files
yusheng-php/application/common/controller/BaseCom.php

87 lines
3.1 KiB
PHP
Raw Normal View History

2025-08-07 20:21:47 +08:00
<?php
namespace app\common\controller;
use think\Controller;
2025-08-11 15:55:11 +08:00
use think\Db;
2025-08-07 20:21:47 +08:00
class BaseCom extends Controller
{
public $uid = 0;
public $redis = '';
//初始化
protected function _initialize()
{
//允许跨域
header("Access-Control-Allow-Origin: *"); // 允许所有域访问
header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS");
header("Access-Control-Allow-Headers: Content-Type, Authorization");
header("Access-Control-Max-Age: 3600");
//检测系统是否维护中
$is_maintenance = get_system_config_value('is_maintenance');
if($is_maintenance == 2){
2025-10-20 09:59:39 +08:00
return V(0, '系统维护中');
2025-08-07 20:21:47 +08:00
}
2025-08-11 15:55:11 +08:00
//检测是什么系统
$system = input('system','');
if(empty($system)){
$system = request()->header('system');
2025-08-07 20:21:47 +08:00
}
2025-08-11 15:55:11 +08:00
//版本号
$version = input('App-Version','');
if(empty($version)){
$version = request()->header('App-Version');
}
$zhenshi_version = db::name('version')->where('type', 2)->value('oldversion');
$result = version_compare($version,$zhenshi_version);
2025-08-12 14:05:47 +08:00
//请求的接口
$api = request()->controller().'/'.request()->action();
2025-08-11 15:55:11 +08:00
if($system == 'iOS' && $result > 0){
2025-08-12 14:05:47 +08:00
if($api == 'Index/index_banner' || $api == 'Index/room_type_list' || $api == 'Index/room_list' || $api == 'UserZone/expand_zone' || $api == 'UserZone/zone_list' || $api == 'UserZone/topic_list' || $api == 'UserZone/get_zone_topic'){
$this->uid = 0;
//定义一个常量
define('UID', $this->uid);
}else{
$token = request()->header('token');
if (empty($token)) {
$token = input('token', '');
if(empty($token)){
return V(301, '登录失效');
}
}
$reslut = model('UserToken')->check_login_token($token);
if($reslut['code'] != 1) {
model('UserToken')->where('token', $token)->update(['token' => 1]);
return V($reslut['code'], $reslut['msg'],$reslut['data']);
} else {
$this->uid = $reslut['data'];
//定义一个常量
define('UID', $this->uid);
}
}
2025-08-11 15:55:11 +08:00
}else{
2025-08-12 11:16:48 +08:00
$token = request()->header('token');
2025-08-11 15:55:11 +08:00
if (empty($token)) {
2025-08-12 11:16:48 +08:00
$token = input('token', '');
2025-08-11 15:55:11 +08:00
if(empty($token)){
return V(301, '登录失效');
}
}
$reslut = model('UserToken')->check_login_token($token);
if($reslut['code'] != 1) {
model('UserToken')->where('token', $token)->update(['token' => 1]);
return V($reslut['code'], $reslut['msg'],$reslut['data']);
} else {
$this->uid = $reslut['data'];
//定义一个常量
define('UID', $this->uid);
}
2025-08-07 20:21:47 +08:00
}
}
}