Skip to content

Commit c2c48c6

Browse files
author
zhangjiangbin
committed
使用数据迁移和播种机,更方便的更新数据库
1 parent 7687898 commit c2c48c6

48 files changed

Lines changed: 1756 additions & 108 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎app/Console/Commands/AutoBanSubscribeJob.php‎

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,23 @@ class AutoBanSubscribeJob extends Command
1313
protected $signature = 'command:autoBanSubscribeJob';
1414
protected $description = '自动封禁异常订阅链接';
1515

16-
protected static $config;
17-
1816
public function __construct()
1917
{
2018
parent::__construct();
21-
22-
$config = Config::query()->get();
23-
$data = [];
24-
foreach ($config as $vo) {
25-
$data[$vo->name] = $vo->value;
26-
}
27-
28-
self::$config = $data;
2919
}
3020

3121
public function handle()
3222
{
23+
$config = $this->systemConfig();
24+
3325
// 封禁24小时访问异常的订阅链接
34-
if (self::$config['is_subscribe_ban']) {
26+
if ($config['is_subscribe_ban']) {
3527
$subscribeList = UserSubscribe::query()->where('status', 1)->get();
3628
if (!$subscribeList->isEmpty()) {
3729
foreach ($subscribeList as $subscribe) {
3830
// 24小时内的请求次数
3931
$request_times = UserSubscribeLog::query()->where('sid', $subscribe->id)->where('request_time', '>=', date("Y-m-d H:i:s", strtotime("-24 hours")))->distinct('request_ip')->count('request_ip');
40-
if ($request_times >= self::$config['subscribe_ban_times']) {
32+
if ($request_times >= $config['subscribe_ban_times']) {
4133
UserSubscribe::query()->where('id', $subscribe->id)->update(['status' => 0, 'ban_time' => time(), 'ban_desc' => '存在异常,自动封禁']);
4234
}
4335
}
@@ -46,4 +38,15 @@ public function handle()
4638

4739
Log::info('定时任务:' . $this->description);
4840
}
41+
42+
// 系统配置
43+
private function systemConfig() {
44+
$config = Config::query()->get();
45+
$data = [];
46+
foreach ($config as $vo) {
47+
$data[$vo->name] = $vo->value;
48+
}
49+
50+
return $data;
51+
}
4952
}

‎app/Console/Commands/AutoBanUserJob.php‎

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,42 +14,46 @@ class AutoBanUserJob extends Command
1414
protected $signature = 'command:autoBanUserJob';
1515
protected $description = '自动封禁用户';
1616

17-
protected static $config;
18-
1917
public function __construct()
2018
{
2119
parent::__construct();
22-
23-
$config = Config::query()->get();
24-
$data = [];
25-
foreach ($config as $vo) {
26-
$data[$vo->name] = $vo->value;
27-
}
28-
29-
self::$config = $data;
3020
}
3121

3222
public function handle()
3323
{
24+
$config = $this->systemConfig();
25+
3426
// 封禁24小时内流量异常账号
35-
if (self::$config['is_traffic_ban']) {
27+
if ($config['is_traffic_ban']) {
3628
$userList = User::query()->where('status', '>=', 0)->where('enable', 1)->get();
3729
foreach ($userList as $user) {
3830
$time = date('Y-m-d H:i:s', time() - 24 * 60 * 60);
3931
$totalTraffic = UserTrafficHourly::query()->where('user_id', $user->id)->where('node_id', 0)->where('created_at', '>=', $time)->sum('total');
40-
if ($totalTraffic >= (self::$config['traffic_ban_value'] * 1024 * 1024 * 1024)) {
41-
$ban_time = date('Y-m-d H:i:s', strtotime("+" . self::$config['traffic_ban_time'] . " minutes"));
32+
if ($totalTraffic >= ($config['traffic_ban_value'] * 1024 * 1024 * 1024)) {
33+
$ban_time = date('Y-m-d H:i:s', strtotime("+" . $config['traffic_ban_time'] . " minutes"));
4234
User::query()->where('id', $user->id)->update(['enable' => 0, 'ban_time' => $ban_time]);
4335

4436
// 写入日志
45-
$this->log($user->id, self::$config['traffic_ban_time'], '【自动封禁】-流量异常');
37+
$this->log($user->id, $config['traffic_ban_time'], '【自动封禁】-流量异常');
4638
}
4739
}
4840
}
4941

5042
Log::info('定时任务:' . $this->description);
5143
}
5244

45+
// 系统配置
46+
private function systemConfig()
47+
{
48+
$config = Config::query()->get();
49+
$data = [];
50+
foreach ($config as $vo) {
51+
$data[$vo->name] = $vo->value;
52+
}
53+
54+
return $data;
55+
}
56+
5357
private function log($user_id, $minutes, $desc)
5458
{
5559
$log = new UserBanLog();

‎app/Console/Commands/AutoCheckNodeStatusJob.php‎

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,16 @@ class AutoCheckNodeStatusJob extends Command
1818
protected $signature = 'command:autoCheckNodeStatusJob';
1919
protected $description = '自动监测节点是否宕机';
2020
protected $cacheKey = 'node_shutdown_warning_';
21-
protected static $config;
2221

2322
public function __construct()
2423
{
2524
parent::__construct();
26-
27-
$config = Config::query()->get();
28-
$data = [];
29-
foreach ($config as $vo) {
30-
$data[$vo->name] = $vo->value;
31-
}
32-
33-
self::$config = $data;
3425
}
3526

3627
public function handle()
3728
{
29+
$config = $this->systemConfig();
30+
3831
$nodeList = SsNode::query()->where('status', 1)->get();
3932
foreach ($nodeList as $node) {
4033
// 10分钟内无节点信息则认为是宕机,因为每个节点的负载信息最多保存10分钟
@@ -49,9 +42,9 @@ public function handle()
4942
$content = "系统监测到节点【{$node->name}】({$node->server})可能宕机了,请及时检查。";
5043

5144
// 发邮件通知管理员
52-
if (self::$config['is_node_crash_warning'] && self::$config['crash_warning_email']) {
45+
if ($config['is_node_crash_warning'] && $config['crash_warning_email']) {
5346
try {
54-
Mail::to(self::$config['crash_warning_email'])->send(new nodeCrashWarning(self::$config['website_name'], $node->name, $node->server));
47+
Mail::to($config['crash_warning_email'])->send(new nodeCrashWarning($config['website_name'], $node->name, $node->server));
5548
$this->sendEmailLog(1, $title, $content);
5649
} catch (\Exception $e) {
5750
$this->sendEmailLog(1, $title, $content, 0, $e->getMessage());
@@ -62,9 +55,9 @@ public function handle()
6255
}
6356

6457
// 通过ServerChan发微信消息提醒管理员
65-
if (self::$config['is_server_chan'] && self::$config['server_chan_key']) {
58+
if ($config['is_server_chan'] && $config['server_chan_key']) {
6659
$serverChan = new ServerChan();
67-
$result = $serverChan->send($title, $content, self::$config['server_chan_key']);
60+
$result = $serverChan->send($title, $content, $config['server_chan_key']);
6861
if ($result->errno > 0) {
6962
$this->sendEmailLog(1, '[ServerChan]' . $title, $content);
7063
} else {
@@ -99,4 +92,16 @@ private function sendEmailLog($user_id, $title, $content, $status = 1, $error =
9992
$emailLogObj->created_at = date('Y-m-d H:i:s');
10093
$emailLogObj->save();
10194
}
95+
96+
// 系统配置
97+
private function systemConfig()
98+
{
99+
$config = Config::query()->get();
100+
$data = [];
101+
foreach ($config as $vo) {
102+
$data[$vo->name] = $vo->value;
103+
}
104+
105+
return $data;
106+
}
102107
}

‎app/Console/Commands/AutoClearLogJob.php‎

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,16 @@ class AutoClearLogJob extends Command
1616
protected $signature = 'command:autoClearLogJob';
1717
protected $description = '自动清除日志';
1818

19-
protected static $config;
20-
2119
public function __construct()
2220
{
2321
parent::__construct();
24-
25-
$config = Config::query()->get();
26-
$data = [];
27-
foreach ($config as $vo) {
28-
$data[$vo->name] = $vo->value;
29-
}
30-
31-
self::$config = $data;
3222
}
3323

3424
public function handle()
3525
{
36-
if (self::$config['is_clear_log']) {
26+
$config = $this->systemConfig();
27+
28+
if ($config['is_clear_log']) {
3729
// 自动清除10分钟以前的节点负载信息日志
3830
SsNodeInfo::query()->where('log_time', '<=', strtotime(date('Y-m-d H:i:s', strtotime("-10 minutes"))))->delete();
3931

@@ -52,4 +44,15 @@ public function handle()
5244

5345
Log::info('定时任务:' . $this->description);
5446
}
47+
48+
// 系统配置
49+
private function systemConfig() {
50+
$config = Config::query()->get();
51+
$data = [];
52+
foreach ($config as $vo) {
53+
$data[$vo->name] = $vo->value;
54+
}
55+
56+
return $data;
57+
}
5558
}

‎app/Console/Commands/AutoResetUserTrafficJob.php‎

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,27 @@ class AutoResetUserTrafficJob extends Command
1212
{
1313
protected $signature = 'command:autoResetUserTrafficJob';
1414
protected $description = '自动重置用户可用流量';
15-
protected static $config;
1615

1716
public function __construct()
1817
{
1918
parent::__construct();
20-
21-
$config = Config::query()->get();
22-
$data = [];
23-
foreach ($config as $vo) {
24-
$data[$vo->name] = $vo->value;
25-
}
26-
27-
self::$config = $data;
2819
}
2920

3021
public function handle()
3122
{
32-
if (self::$config['reset_traffic']) {
23+
$config = $this->systemConfig();
24+
25+
if ($config['reset_traffic']) {
3326
$userList = User::query()->where('status', '>=', 0)->where('enable', 1)->get();
3427
foreach ($userList as $user) {
3528
if (!$user->traffic_reset_day) {
3629
continue;
3730
}
3831

3932
// 取出用户最后购买的有效套餐
40-
$order = Order::query()->with(['user', 'goods'])->whereHas('goods', function ($q) { $q->where('type', 2); })->where('user_id', $user->id)->where('is_expire', 0)->orderBy('oid', 'desc')->first();
33+
$order = Order::query()->with(['user', 'goods'])->whereHas('goods', function ($q) {
34+
$q->where('type', 2);
35+
})->where('user_id', $user->id)->where('is_expire', 0)->orderBy('oid', 'desc')->first();
4136
if (!$order) {
4237
continue;
4338
}
@@ -61,4 +56,16 @@ public function handle()
6156

6257
Log::info('定时任务:' . $this->description);
6358
}
59+
60+
// 系统配置
61+
private function systemConfig()
62+
{
63+
$config = Config::query()->get();
64+
$data = [];
65+
foreach ($config as $vo) {
66+
$data[$vo->name] = $vo->value;
67+
}
68+
69+
return $data;
70+
}
6471
}

‎app/Console/Commands/UserExpireWarningJob.php‎

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,13 @@ class UserExpireWarningJob extends Command
2020
public function __construct()
2121
{
2222
parent::__construct();
23-
24-
$config = Config::query()->get();
25-
$data = [];
26-
foreach ($config as $vo) {
27-
$data[$vo->name] = $vo->value;
28-
}
29-
30-
self::$config = $data;
3123
}
3224

3325
public function handle()
3426
{
35-
if (self::$config['expire_warning']) {
27+
$config = $this->systemConfig();
28+
29+
if ($config['expire_warning']) {
3630
$userList = User::query()->where('transfer_enable', '>', 0)->whereIn('status', [0, 1])->where('enable', 1)->get();
3731
foreach ($userList as $user) {
3832
// 用户名不是邮箱的跳过
@@ -41,12 +35,12 @@ public function handle()
4135
}
4236

4337
$lastCanUseDays = floor(round(strtotime($user->expire_time) - strtotime(date('Y-m-d H:i:s'))) / 3600 / 24);
44-
if ($lastCanUseDays > 0 && $lastCanUseDays <= self::$config['expire_days']) {
38+
if ($lastCanUseDays > 0 && $lastCanUseDays <= $config['expire_days']) {
4539
$title = '账号过期提醒';
4640
$content = '账号还剩' . $lastCanUseDays . '天即将过期';
4741

4842
try {
49-
Mail::to($user->username)->send(new userExpireWarning(self::$config['website_name'], $lastCanUseDays));
43+
Mail::to($user->username)->send(new userExpireWarning($config['website_name'], $lastCanUseDays));
5044
$this->sendEmailLog($user->id, $title, $content);
5145
} catch (\Exception $e) {
5246
$this->sendEmailLog($user->id, $title, $content, 0, $e->getMessage());
@@ -77,4 +71,15 @@ private function sendEmailLog($user_id, $title, $content, $status = 1, $error =
7771
$emailLogObj->created_at = date('Y-m-d H:i:s');
7872
$emailLogObj->save();
7973
}
74+
75+
// 系统配置
76+
private function systemConfig() {
77+
$config = Config::query()->get();
78+
$data = [];
79+
foreach ($config as $vo) {
80+
$data[$vo->name] = $vo->value;
81+
}
82+
83+
return $data;
84+
}
8085
}

‎app/Console/Commands/UserTrafficWarningJob.php‎

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,13 @@ class UserTrafficWarningJob extends Command
2020
public function __construct()
2121
{
2222
parent::__construct();
23-
24-
$config = Config::query()->get();
25-
$data = [];
26-
foreach ($config as $vo) {
27-
$data[$vo->name] = $vo->value;
28-
}
29-
30-
self::$config = $data;
3123
}
3224

3325
public function handle()
3426
{
35-
if (self::$config['traffic_warning']) {
27+
$config = $this->systemConfig();
28+
29+
if ($config['traffic_warning']) {
3630
$userList = User::query()->where('transfer_enable', '>', 0)->whereIn('status', [0, 1])->where('enable', 1)->get();
3731
foreach ($userList as $user) {
3832
// 用户名不是邮箱的跳过
@@ -41,12 +35,12 @@ public function handle()
4135
}
4236

4337
$usedPercent = round(($user->d + $user->u) / $user->transfer_enable, 2) * 100; // 已使用流量百分比
44-
if ($usedPercent >= self::$config['traffic_warning_percent']) {
38+
if ($usedPercent >= $config['traffic_warning_percent']) {
4539
$title = '流量警告';
46-
$content = '流量已使用:' . $usedPercent . '%,超过设置的流量阈值' . self::$config['traffic_warning_percent'] . '%';
40+
$content = '流量已使用:' . $usedPercent . '%,超过设置的流量阈值' . $config['traffic_warning_percent'] . '%';
4741

4842
try {
49-
Mail::to($user->username)->send(new userTrafficWarning(self::$config['website_name'], $usedPercent));
43+
Mail::to($user->username)->send(new userTrafficWarning($config['website_name'], $usedPercent));
5044
$this->sendEmailLog($user->id, $title, $content);
5145
} catch (\Exception $e) {
5246
$this->sendEmailLog($user->id, $title, $content, 0, $e->getMessage());
@@ -77,4 +71,15 @@ private function sendEmailLog($user_id, $title, $content, $status = 1, $error =
7771
$emailLogObj->created_at = date('Y-m-d H:i:s');
7872
$emailLogObj->save();
7973
}
74+
75+
// 系统配置
76+
private function systemConfig() {
77+
$config = Config::query()->get();
78+
$data = [];
79+
foreach ($config as $vo) {
80+
$data[$vo->name] = $vo->value;
81+
}
82+
83+
return $data;
84+
}
8085
}

0 commit comments

Comments
 (0)