初始化

This commit is contained in:
liut
2021-10-12 11:06:24 +08:00
commit ff0b4d5b12
1270 changed files with 405680 additions and 0 deletions
+89
View File
@@ -0,0 +1,89 @@
<?php
namespace app\common\controller;
use app\admin\controller\User;
use app\common\model\Users;
use think\Controller;
use think\exception\HttpResponseException;
use think\Response;
class Admin extends Controller
{
protected $middleware = ['AdminLoginCheck'];
protected $adminInfo = [];
public function initialize(){
parent::initialize(); // TODO: Change the autogenerated stub
$this->adminInfo = (new Users())->login_info('admin');
}
protected function callModelMethods($model,$methods,...$args){
$class_name = 'app\common\model\\'.$model;
$class = new $class_name;
try {
call_user_func_array([$class,$methods],$args);
}catch (\Throwable $e){
$this->returnError($e->getMessage(),505);
}
}
protected function returnSuccess($msg = '操作成功',$data = []){
$result = [
'code' => 200,
'msg' => $msg,
'time' => time(),
'data' => $data,
];
$type = 'json';
$response = Response::create($result, $type)->header([]);
throw new HttpResponseException($response);
}
protected function returnSuccessLayTable($count,$data = []){
$result = [
'code' => 0,
'msg' => '加载成功',
'count' => $count,
'data' => $data,
];
$type = 'json';
$response = Response::create($result, $type)->header([]);
throw new HttpResponseException($response);
}
protected function returnError($msg = '操作失败,系统错误',$code = 502,$data = []){
$result = [
'code' => $code,
'msg' => $msg,
'time' => time(),
'data' => $data,
];
$type = 'json';
$response = Response::create($result, $type)->header([]);
throw new HttpResponseException($response);
}
protected function getQueryMap($methods,$kw = [],$ql = []){
$map = [];
foreach ($ql as $item){
$value = input($methods.'.'.$item);
if(!empty($value)){
$map[$item] = $value;
}
}
foreach ($kw as $item){
$value = input($methods.'.'.$item);
if(!empty($value)){
$map[$item] = $value;
}
}
return $map;
}
}
+115
View File
@@ -0,0 +1,115 @@
<?php
namespace app\common\controller;
use app\common\model\Groups;
use app\common\model\Policys;
use app\common\model\Users;
use think\Controller;
class Home extends Controller
{
protected $middleware = ['UserLoginCheck'];
protected $userInfo = [];
protected $groupData = [];
protected $vip_info = [];
protected $is_login = 0;
public function initialize(){
parent::initialize(); // TODO: Change the autogenerated stub
$this->userInfo = (new Users())->login_info('default');
// 是否登录
$this->is_login = empty($this->userInfo) ? 0 : 1;
// 用户组信息
if($this->is_login){
// 登录用户组
$this->groupData = Groups::where('id',$this->userInfo['group'])->find();
}else{
// 游客用户组
$this->groupData = Groups::where('id',2)->find();
}
// 获取VIP用户组ID
$vip_group = config('vip.vip_group');
// 获取普通用户组ID
$default_group = config('register.default_group');
// 判断是否VIP
if($this->userInfo['group'] == $vip_group){
// VIP过期
if(intval($this->userInfo['group_expire']) < time()){
Users::where('id',$this->userInfo['id'])->update([
'group' => $default_group,
'group_expire' => 0
]);
$this->vip_info['is_vip'] = 0;
$this->vip_info['expire_time'] = 0;
}else{
$this->vip_info['is_vip'] = 1;
$this->vip_info['expire_time'] = date('Y-m-d',$this->userInfo['group_expire']);
}
}else{
$this->vip_info['is_vip'] = 0;
$this->vip_info['expire_time'] = 0;
}
$this->assign('group',$this->groupData);
$this->assign('info',$this->userInfo);
$this->assign('is_login',$this->is_login);
$this->assign('vip_info',$this->vip_info);
$this->assign('url_path',$this->request->path());
}
protected function getPolicy(): array
{
$policy = Policys::where('id',$this->groupData['policy_id'])->find()->toArray();
return $policy;
}
protected function getPolicyUrl($policy,$param = []): string
{
if($policy['type'] != 'remote'){
return url('upload/file');
}
$data = [
'uid' => $this->userInfo['id'],
'policy_id' => $policy['id'],
'save_dir' => $policy['config']['save_dir']
];
$data = array_merge($data,$param);
$data['sign'] = $this->remote_sign_params($data,$policy['config']['access_token']);
return $policy['config']['server_uri'].'?'.urldecode(http_build_query($data));
}
protected function remote_sign_params($params,$key): string
{
// 过滤参数
$params = array_filter($params,function($key) use ($params){
if(empty($params[$key]) || $key == 'sign'){
return false;
}
return true;
},ARRAY_FILTER_USE_KEY);
// ascii排序
ksort($params);
reset($params);
// 签名
return md5(urldecode(http_build_query($params)) . $key);
}
}