Repository navigation
Expand file tree
/
Copy pathHelpers.php
More file actions
204 lines (175 loc) · 5.18 KB
/
Copy pathHelpers.php
File metadata and controls
204 lines (175 loc) · 5.18 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
<?php
namespace App\Components;
use App\Http\Models\Config;
use App\Http\Models\CouponLog;
use App\Http\Models\EmailLog;
use App\Http\Models\Level;
use App\Http\Models\SsConfig;
use App\Http\Models\User;
use App\Http\Models\UserTrafficModifyLog;
class Helpers
{
// 不生成的端口
private static $denyPorts = [
1068, 1109, 1434, 3127, 3128,
3129, 3130, 3332, 4444, 5554,
6669, 8080, 8081, 8082, 8181,
8282, 9996, 17185, 24554, 35601,
60177, 60179
];
// 获取系统配置
public static function systemConfig()
{
$config = Config::query()->get();
$data = [];
foreach ($config as $vo) {
$data[$vo->name] = $vo->value;
}
return $data;
}
// 获取默认加密方式
public static function getDefaultMethod()
{
$config = SsConfig::query()->where('type', 1)->where('is_default', 1)->first();
return $config ? $config->name : 'aes-256-cfb';
}
// 获取默认混淆
public static function getDefaultObfs()
{
$config = SsConfig::query()->where('type', 3)->where('is_default', 1)->first();
return $config ? $config->name : 'plain';
}
// 获取默认协议
public static function getDefaultProtocol()
{
$config = SsConfig::query()->where('type', 2)->where('is_default', 1)->first();
return $config ? $config->name : 'origin';
}
// 获取一个随机端口
public static function getRandPort()
{
$config = self::systemConfig();
$port = mt_rand($config['min_port'], $config['max_port']);
$exists_port = User::query()->pluck('port')->toArray();
if (in_array($port, $exists_port) || in_array($port, self::$denyPorts)) {
$port = self::getRandPort();
}
return $port;
}
// 获取一个端口
public static function getOnlyPort()
{
$config = self::systemConfig();
$port = $config['min_port'];
$exists_port = User::query()->where('port', '>=', $config['min_port'])->pluck('port')->toArray();
while (in_array($port, $exists_port) || in_array($port, self::$denyPorts)) {
$port = $port + 1;
}
return $port;
}
// 加密方式
public static function methodList()
{
return SsConfig::query()->where('type', 1)->get();
}
// 协议
public static function protocolList()
{
return SsConfig::query()->where('type', 2)->get();
}
// 混淆
public static function obfsList()
{
return SsConfig::query()->where('type', 3)->get();
}
// 等级
public static function levelList()
{
return Level::query()->get()->sortBy('level');
}
/**
* 添加邮件投递日志
*
* @param string $address 收信地址
* @param string $title 标题
* @param string $content 内容
* @param int $status 投递状态
* @param string $error 投递失败时记录的异常信息
*
* @return int
*/
public static function addEmailLog($address, $title, $content, $status = 1, $error = '')
{
$log = new EmailLog();
$log->type = 1;
$log->address = $address;
$log->title = $title;
$log->content = $content;
$log->status = $status;
$log->error = $error;
$log->created_at = date('Y-m-d H:i:s');
return $log->save();
}
/**
* 添加serverChan投递日志
*
* @param string $title 标题
* @param string $content 内容
* @param int $status 投递状态
* @param string $error 投递失败时记录的异常信息
*
* @return int
*/
public static function addServerChanLog($title, $content, $status = 1, $error = '')
{
$log = new EmailLog();
$log->type = 2;
$log->address = 'admin';
$log->title = $title;
$log->content = $content;
$log->status = $status;
$log->error = $error;
$log->created_at = date('Y-m-d H:i:s');
return $log->save();
}
/**
* 添加优惠券操作日志
*
* @param int $couponId 优惠券ID
* @param int $goodsId 商品ID
* @param int $orderId 订单ID
* @param string $desc 备注
*
* @return int
*/
public static function addCouponLog($couponId, $goodsId, $orderId, $desc = '')
{
$log = new CouponLog();
$log->coupon_id = $couponId;
$log->goods_id = $goodsId;
$log->order_id = $orderId;
$log->desc = $desc;
return $log->save();
}
/**
* 记录流量变动日志
*
* @param int $userId 用户ID
* @param string $oid 订单ID
* @param int $before 记录前的值
* @param int $after 记录后的值
* @param string $desc 描述
*
* @return int
*/
public static function addUserTrafficModifyLog($userId, $oid, $before, $after, $desc = '')
{
$log = new UserTrafficModifyLog();
$log->user_id = $userId;
$log->order_id = $oid;
$log->before = $before;
$log->after = $after;
$log->desc = $desc;
return $log->save();
}
}