BaseModel.php
6.0 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
<?php
// +----------------------------------------------------------------------
// | 狂团[kt8.cn]旗下KtAdmin是为独立版SAAS系统而生的快速开发框架.
// +----------------------------------------------------------------------
// | [KtAdmin] Copyright (c) 2022 http://ktadmin.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
namespace app\base\model;
use think\facade\Db;
use think\facade\Session;
/*
* 基础功能model
*/
class BaseModel
{
static protected $uid;
/**
* 获取应用下xml配置信息
* @param $app 应用目录
* @return
*/
static public function getMainfest($app){
$path = base_path().'/'.$app.'/mainfest.xml';
if(!file_exists($path)) $path = base_path().'/'.$app.'/manifest.xml';
$xml = [];
if(is_file($path)) $xml = json_decode(json_encode(simplexml_load_file($path,'SimpleXMLElement', LIBXML_NOCDATA)), 1);
return $xml;
}
/**
* 获取 随机数
* @param leg 长度
* @return
*/
static public function getCode(){
return rand(100000,999999);
}
/**
* 获取
* @param $host 域名,不带协议
* @return
*/
static public function getLoginInfo($host){
$admin = Db::table('kt_base_agent')->field('id,key_word,describe,record_number,user_logo,login_logo,domain,webname,webtitle,login_background,register_check,registration_audit,company_name')->where('domain',$host)->find();
if(!$admin) $admin = Db::table('kt_base_agent')->field('id,key_word,record_number,describe,user_logo,login_logo,domain,webname,webtitle,login_background,register_check,registration_audit,company_name')->where('isadmin',1)->find();
$gptcms_path = root_path().'/public/static/gptcms/hot/verify.txt';
$admin['gptcms_c_s'] = 0;
if(file_exists($gptcms_path) && filesize($gptcms_path) !== 0){
$admin['gptcms_c_s'] = 1;
}
return $admin;
}
/**
* 判断当前代理是否是 管理员
*
* @return
*/
static public function isAdmin($uid){
$res = Db::table('kt_base_agent')->where('id',$uid)->value('isadmin') ?: 0;
return $res;
}
/**
* 获取当前uid
*
* @return
*/
static public function getUid(){
$uid = Db::table('kt_base_agent')->where('isadmin',1)->value('id');
return $uid;
}
/**
* 获取管理员id
*
* @return
*/
static public function getAdminId(){
$res = Db::table('kt_base_agent')->where('isadmin',1)->value('id');
return $res;
}
/**
* 根据文件夹获取配置信息
* @return
*/
static public function getMainfestByName($code){
$res = [];
$base = base_path();
$filePath = $base."/".$code."/mainfest.xml";
if(!file_exists($filePath)) $filePath = $base."/".$code."/manifest.xml";
if(is_file($filePath)){
$xml=simplexml_load_file($filePath,'SimpleXMLElement', LIBXML_NOCDATA);
$xmlArr = json_decode(json_encode($xml), 1);
if(isset($xmlArr['application'])) $res = $xmlArr['application'];
}
return $res;
}
/**
* 获取当前代理下所有代理id,包括下级的下级代理id
*
* @return $ids 代理id array()
*/
static public function getAdentIds($uid){
$ids = [];
$ids[] = $uid;
self::getAdentId($uid,$ids);
return $ids;
}
static public function getAdentId($uid,&$ids){
$res = Db::table('kt_base_agent')->where('pid',$uid)->column('id');
if(count($res)>0){
foreach ($res as $id) {
$ids[] = $id;
self::getAdentId($id,$ids);
}
}
return $ids;
}
/**
* 获取 云存储配置, 当前代理未设置自动获取上级代理配置
* @param $uid 账户id
* @return
*/
static public function getStorageInfo($uid=''){
$uid = $uid ?: Session::get('uid');
$res = Db::table('kt_base_storage_config')->field('uid,type,oss_id,oss_secret,oss_endpoint,oss_bucket,cos_secretId,cos_secretKey,cos_bucket,cos_endpoint,kodo_key,kodo_secret,kodo_domain,kodo_bucket')->where('uid',$uid)->find();
if(!$res){
$user = Db::table('kt_base_agent')->find($uid);
if($user['isadmin'] == 1) return $res;
$res = self::getStorageInfo($user['pid']);
}
return $res;
}
/**
* 获取 当前用户云存储配置
* @param $uid 账户id
* @return
*/
static public function storageInfo(){
$uid = Session::get('uid');
$res = Db::table('kt_base_storage_config')->field('uid,type,oss_id,oss_secret,oss_endpoint,oss_bucket,cos_secretId,cos_secretKey,cos_bucket,cos_endpoint,kodo_key,kodo_secret,kodo_domain,kodo_bucket')->where('uid',$uid)->find();
return $res;
}
/**
* 保存 云存储配置
* @param $data 更新数据 array
* @return
*/
static public function storageUpdate($data){
$uid = Session::get('uid');
$config = Db::table('kt_base_storage_config')->where('uid',$uid)->find();
$param = [];
if($config) $param['id'] = $config['id'];
$param['uid'] = $uid;
$param['type'] = $data['type'];
switch ($data['type']) {
case '2':
$param['oss_id'] = $data['oss_id'];
$param['oss_secret'] = $data['oss_secret'];
$param['oss_endpoint'] = $data['oss_endpoint'];
$param['oss_bucket'] = $data['oss_bucket'];
break;
case '3':
$param['cos_secretId'] = $data['cos_secretId'];
$param['cos_secretKey'] = $data['cos_secretKey'];
$param['cos_bucket'] = $data['cos_bucket'];
$param['cos_endpoint'] = $data['cos_endpoint'];
break;
case '4':
$param['kodo_key'] = $data['kodo_key'];
$param['kodo_secret'] = $data['kodo_secret'];
$param['kodo_domain'] = $data['kodo_domain'];
$param['kodo_bucket'] = $data['kodo_bucket'];
break;
}
$res = Db::table('kt_base_storage_config')->save($param);
return 'ok';
}
/**
* 初始化云存储数据
* @return
*/
static private function inisetStorage(){
$uid = Session::get('uid');
$config = Db::table('kt_base_storage_config')->where('wid',$wid)->find();
if(!$config){
Db::table('kt_base_storage_config')->insert(
[
'uid' => $uid,
'type' => 1,
'create_time'=>date("Y-m-d H:i:s"),
'update_time'=>date("Y-m-d H:i:s"),
]
);
}
}
}